parent
fd36491fcc
commit
4a72c48f1f
|
|
@ -2,7 +2,6 @@ package org.jeecg.modules.mini.controller;
|
|||
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.io.file.FileWriter;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.ContentType;
|
||||
import cn.hutool.http.HttpStatus;
|
||||
|
|
@ -11,7 +10,6 @@ import com.alibaba.fastjson.JSONObject;
|
|||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.ijpay.core.IJPayHttpResponse;
|
||||
import com.ijpay.core.enums.RequestMethodEnum;
|
||||
import com.ijpay.core.kit.AesUtil;
|
||||
import com.ijpay.core.kit.HttpKit;
|
||||
import com.ijpay.core.kit.PayKit;
|
||||
import com.ijpay.core.kit.WxPayKit;
|
||||
|
|
@ -37,11 +35,11 @@ import org.jeecg.modules.mini.douyin.util.DouWayPaymentMethod;
|
|||
import org.jeecg.modules.mini.douyin.util.DouYinUtil;
|
||||
import org.jeecg.modules.mini.douyin.util.Sign;
|
||||
import org.jeecg.modules.mini.dto.VipDTO;
|
||||
import org.jeecg.modules.mini.douyin.model.DouYinOrderModel;
|
||||
import org.jeecg.modules.mini.service.MiniUserService;
|
||||
import org.jeecg.modules.system.entity.SysUser;
|
||||
import org.jeecg.modules.system.service.ISysUserService;
|
||||
import org.jeecg.modules.system.util.OrderNumberGenerator;
|
||||
import org.jeecg.modules.yx.constant.YxConstant;
|
||||
import org.jeecg.modules.yx.entity.YxOrder;
|
||||
import org.jeecg.modules.yx.entity.YxVipSku;
|
||||
import org.jeecg.modules.yx.service.IYxOrderService;
|
||||
|
|
@ -50,12 +48,12 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.*;
|
||||
|
|
@ -163,7 +161,8 @@ public class MiniPayApiController {
|
|||
String orderCode = OrderNumberGenerator.generateOrderNumber();
|
||||
String openId = user.getWxOpenId();
|
||||
BigDecimal skuPrice = yxVipSku.getSkuPrice();
|
||||
BigDecimal totalAmount = skuPrice.multiply(new BigDecimal("100"));
|
||||
BigDecimal totalAmount = skuPrice.multiply(YxConstant.bigDecimal100);
|
||||
/*totalAmount = YxConstant.bigDecimal100;*/
|
||||
|
||||
String description = "艺体志愿宝VIP";
|
||||
if (StringUtils.isNotBlank(yxVipSku.getSkuName())) {
|
||||
|
|
@ -319,12 +318,12 @@ public class MiniPayApiController {
|
|||
if ("SUCCESS".equals(status) && sign.equals(msgSignature)) {
|
||||
//支付成功,修改订单信息
|
||||
Date date = new Date();
|
||||
date.setTime(paidAt*1000);
|
||||
date.setTime(paidAt*YxConstant.bigDecimal1000);
|
||||
yxOrderService.paymentOrderOver(cpOrderno, DouWayPaymentMethod.getByWay(way), "2", date);
|
||||
yxOrder = yxOrderService.getByOrderCode(cpOrderno);
|
||||
sysUser = sysUserService.getById(yxOrder.getPaymentUserId());
|
||||
|
||||
long createTimeLong = yxOrder.getCreateTime().getTime() / 1000;
|
||||
long createTimeLong = yxOrder.getCreateTime().getTime() / YxConstant.bigDecimal1000;
|
||||
//同步抖音订单
|
||||
DouYinOrderSyncModel douYinOrderSyncModel = new DouYinOrderSyncModel();
|
||||
douYinOrderSyncModel.setOrder_id(cpOrderno);
|
||||
|
|
@ -371,8 +370,59 @@ public class MiniPayApiController {
|
|||
Map<String, String> map = new HashMap<>(12);
|
||||
System.out.println("/dy/payNotify:");
|
||||
String result = HttpKit.readData(request);
|
||||
System.out.println(result);
|
||||
redisUtil.set(new Date().getTime()+"_dy_payNotify",request);
|
||||
cn.hutool.json.JSONObject requestJson = new cn.hutool.json.JSONObject(result);
|
||||
String type = requestJson.getStr("type");
|
||||
try {
|
||||
// 退款
|
||||
if ("refund".equals(type)) {
|
||||
// 验证签名一致性
|
||||
List<String> sortedString = new ArrayList<>();
|
||||
//token
|
||||
sortedString.add(douyinToken);
|
||||
//时间戳
|
||||
sortedString.add(requestJson.getStr("timestamp"));
|
||||
//随机数
|
||||
sortedString.add(requestJson.getStr("nonce"));
|
||||
//msg
|
||||
sortedString.add(requestJson.getStr("msg"));
|
||||
Collections.sort(sortedString);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sortedString.forEach(sb::append);
|
||||
String sign = Sign.callbackSign(sortedString);
|
||||
String msgSignature = requestJson.getStr("msg_signature");//签名
|
||||
String msg = requestJson.getStr("msg");
|
||||
JSONObject msgJson = JSONObject.parseObject(msg);
|
||||
if (sign.equals(msgSignature)) {
|
||||
//签名一致,更改订单状态为退款
|
||||
String orderCode = msgJson.getString("order_id");
|
||||
String cpRefundNo = msgJson.getString("cp_refundno");
|
||||
String refundNo = msgJson.getString("refund_no");
|
||||
BigDecimal refundAmount = msgJson.getBigDecimal("refund_amount").divide(YxConstant.bigDecimal100, 2, RoundingMode.HALF_UP);
|
||||
// 执行更改订单状态
|
||||
YxOrder yxOrder = yxOrderService.updateRefund(orderCode, cpRefundNo, refundNo, refundAmount);
|
||||
// 更改当前用户的状态
|
||||
if(yxOrder!=null &&StringUtils.isNotBlank(yxOrder.getCreateBy())){
|
||||
miniUserService.logoutUser(yxOrder.getCreateBy());
|
||||
}
|
||||
|
||||
response.setStatus(200);
|
||||
map.put("code", "SUCCESS");
|
||||
map.put("message", "SUCCESS");
|
||||
} else {
|
||||
response.setStatus(500);
|
||||
map.put("code", "ERROR");
|
||||
map.put("message", "签名错误");
|
||||
}
|
||||
}
|
||||
response.setHeader("Content-type", ContentType.JSON.toString());
|
||||
response.getOutputStream().write(JSONUtil.toJsonStr(map).getBytes(StandardCharsets.UTF_8));
|
||||
response.flushBuffer();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (Exception e){
|
||||
log.error("接收退款请求时出错,",e);
|
||||
//e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private String getSerialNumber() {
|
||||
|
|
@ -389,82 +439,4 @@ public class MiniPayApiController {
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
/* @RequestMapping("/get")
|
||||
@ResponseBody
|
||||
public String v3Get() {
|
||||
// 获取平台证书列表
|
||||
try {
|
||||
IJPayHttpResponse response = WxPayApi.v3(
|
||||
RequestMethodEnum.GET,
|
||||
WxDomainEnum.CHINA.toString(),
|
||||
OtherApiEnum.GET_CERTIFICATES.toString(),
|
||||
mchid,
|
||||
getSerialNumber(),
|
||||
null,
|
||||
certKeyPath,
|
||||
""
|
||||
);
|
||||
String serialNumber = response.getHeader("Wechatpay-Serial");
|
||||
String body = response.getBody();
|
||||
int status = response.getStatus();
|
||||
log.info("serialNumber: {}", serialNumber);
|
||||
log.info("status: {}", status);
|
||||
log.info("body: {}", body);
|
||||
int isOk = 200;
|
||||
if (status == isOk) {
|
||||
JSONObject jsonObject = JSONUtil.parseObj(body);
|
||||
JSONArray dataArray = jsonObject.tet("data");
|
||||
// 默认认为只有一个平台证书
|
||||
JSONObject encryptObject = dataArray.getJSONObject(0);
|
||||
JSONObject encryptCertificate = encryptObject.getJSONObject("encrypt_certificate");
|
||||
String associatedData = encryptCertificate.getStr("associated_data");
|
||||
String cipherText = encryptCertificate.getStr("ciphertext");
|
||||
String nonce = encryptCertificate.getStr("nonce");
|
||||
String serialNo = encryptObject.getStr("serial_no");
|
||||
final String platSerialNo = savePlatformCert(associatedData, nonce, cipherText, platFormPath);
|
||||
log.info("平台证书序列号: {} serialNo: {}", platSerialNo, serialNo);
|
||||
}
|
||||
// 根据证书序列号查询对应的证书来验证签名结果
|
||||
boolean verifySignature = WxPayKit.verifySignature(response, platFormPath);
|
||||
System.out.println("verifySignature:" + verifySignature);
|
||||
return body;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
/**
|
||||
* 保存平台证书
|
||||
*
|
||||
* @param associatedData associated_data
|
||||
* @param nonce nonce
|
||||
* @param cipherText cipherText
|
||||
* @param certPath 证书保存路径
|
||||
* @return
|
||||
*/
|
||||
private String savePlatformCert(String associatedData, String nonce, String cipherText, String certPath) {
|
||||
try {
|
||||
AesUtil aesUtil = new AesUtil(mchKey.getBytes(StandardCharsets.UTF_8));
|
||||
// 平台证书密文解密
|
||||
// encrypt_certificate 中的 associated_data nonce ciphertext
|
||||
String publicKey = aesUtil.decryptToString(
|
||||
associatedData.getBytes(StandardCharsets.UTF_8),
|
||||
nonce.getBytes(StandardCharsets.UTF_8),
|
||||
cipherText
|
||||
);
|
||||
// 保存证书
|
||||
FileWriter writer = new FileWriter(certPath);
|
||||
writer.write(publicKey);
|
||||
// 获取平台证书序列号
|
||||
X509Certificate certificate = PayKit.getCertificate(new ByteArrayInputStream(publicKey.getBytes()));
|
||||
return certificate.getSerialNumber().toString(16).toUpperCase();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return e.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ import javax.crypto.spec.IvParameterSpec;
|
|||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.security.Security;
|
||||
import java.security.spec.AlgorithmParameterSpec;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
|
|
@ -156,7 +157,7 @@ public class MiniUserController {
|
|||
return result;
|
||||
}
|
||||
//仅保留一端登录
|
||||
oneUserLogin(sysUser);
|
||||
miniUserService.oneUserLogin(sysUser);
|
||||
//用户登录信息
|
||||
//1.生成token
|
||||
String token = JwtUtil.sign(sysUser.getUsername(), syspassword);
|
||||
|
|
@ -231,8 +232,7 @@ public class MiniUserController {
|
|||
}
|
||||
}
|
||||
//仅保留一端登录
|
||||
oneUserLogin(user);
|
||||
|
||||
miniUserService.oneUserLogin(user);
|
||||
String username = user.getUsername();
|
||||
String syspassword = user.getPassword();
|
||||
//1.生成token
|
||||
|
|
@ -329,8 +329,7 @@ public class MiniUserController {
|
|||
}
|
||||
|
||||
//仅保留一端登录
|
||||
oneUserLogin(user);
|
||||
|
||||
miniUserService.oneUserLogin(user);
|
||||
String username = user.getUsername();
|
||||
String syspassword = user.getPassword();
|
||||
//1.生成token
|
||||
|
|
@ -394,30 +393,6 @@ public class MiniUserController {
|
|||
return Result.OK(2);
|
||||
}
|
||||
|
||||
|
||||
public void oneUserLogin(SysUser user){
|
||||
//仅保留一端登录
|
||||
Collection<String> keys = redisTemplate.keys(CommonConstant.PREFIX_USER_TOKEN + "*");
|
||||
for (String key : keys) {
|
||||
String token = (String)redisUtil.get(key);
|
||||
String username = JwtUtil.getUsername(token);
|
||||
if (username.equals(user.getUsername())) {
|
||||
SysUser sysUser = sysUserService.getUserByName(username);
|
||||
if (sysUser!=null) {
|
||||
if(sysUser.getId().equals(user.getId())){
|
||||
//清空用户登录Token缓存
|
||||
redisUtil.del(CommonConstant.PREFIX_USER_TOKEN + token);
|
||||
//清空用户登录Shiro权限缓存
|
||||
redisUtil.del(CommonConstant.PREFIX_USER_SHIRO_CACHE + sysUser.getId());
|
||||
//清空用户的缓存信息(包括部门信息),例如sys:cache:user::<username>
|
||||
redisUtil.del(String.format("%s::%s", CacheConstant.SYS_USERS_CACHE, sysUser.getUsername()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static String phoneDecrypt(String encrypted, String sessionKey, String iv) {
|
||||
String phoneNumber = null;
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import org.apache.commons.lang.StringUtils;
|
|||
import org.jeecg.common.exception.JeecgBootException;
|
||||
import org.jeecg.common.util.RestUtil;
|
||||
import org.jeecg.modules.mini.douyin.model.DouYinOrderSyncModel;
|
||||
import org.jeecg.modules.mini.douyin.model.ItemStruct;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
|
@ -49,7 +48,7 @@ public class DouYinUtil {
|
|||
//put("thirdparty_id", "");//tta4bad200000xxxxxx
|
||||
put("out_order_no", orderCode);
|
||||
put("total_amount", totalAmount);
|
||||
put("subject", skuName);
|
||||
put("subject", "艺体志愿宝"+skuName);
|
||||
put("body", description);
|
||||
put("valid_time", 172800);
|
||||
put("notify_url", notifyUrl);
|
||||
|
|
@ -101,22 +100,72 @@ public class DouYinUtil {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单同步
|
||||
*/
|
||||
public static void orderRefund(String orderCode,String appId,Long refundAmount,String salt,String notifyUrl){
|
||||
log.debug("抖音订单退款----订单号:"+orderCode);
|
||||
//文档 https://developer.open-douyin.com/docs/resource/zh-CN/mini-app/develop/server/ecpay/refund-list/refund
|
||||
Map<String, Object> testCase = new HashMap<String, Object>() {{
|
||||
put("app_id", appId);
|
||||
put("out_order_no", orderCode);// 商户分配支付单号,标识进行退款的订单
|
||||
put("out_refund_no","tk_"+orderCode);// 商户分配退款号,保证在商户中唯一
|
||||
put("reason","不想要了");// 退款原因
|
||||
put("refund_amount", refundAmount);// 退款金额
|
||||
put("cp_extra", "一些附加信息");
|
||||
put("notify_url", notifyUrl);
|
||||
put("salt",salt);
|
||||
}};
|
||||
String sign = Sign.requestSign(testCase);
|
||||
//发送post请求
|
||||
String douyinUrl="https://developer.toutiao.com/api/apps/ecpay/v1/create_refund";
|
||||
testCase.put("sign",sign);
|
||||
JSONObject post = RestUtil.post(douyinUrl, JSONObject.parseObject(JSONObject.toJSONString(testCase)));
|
||||
log.debug("抖音退款结果----:"+post.toJSONString());
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String openId="_000-8dokDbb5cDgK7gdSNOJrzIBFQZNqOrO";
|
||||
String appId="tt59a72f1ac6964bfa01";
|
||||
String appSecret="46882267247ca02561cf899d03adf562aa93ad3e";
|
||||
//getAccessToken(appId,appSecret);
|
||||
DouYinOrderSyncModel douYinOrderSyncModel=new DouYinOrderSyncModel();
|
||||
String orderId="2bba71312366498c900b3575c7d9cad5";
|
||||
douYinOrderSyncModel.setOrder_id(orderId);
|
||||
douYinOrderSyncModel.setCreate_time(1713104670);
|
||||
douYinOrderSyncModel.setStatus("已支付");
|
||||
douYinOrderSyncModel.setAmount(1);
|
||||
douYinOrderSyncModel.setTotal_price(1);
|
||||
douYinOrderSyncModel.setDetail_url("pages/zyb/order/detail?orderCode="+orderId);
|
||||
List<ItemStruct> itemList=new ArrayList<>();
|
||||
itemList.add(new ItemStruct("1002","https://mp-7a4eecb1-2a04-4d36-b050-1c4a78cc31a4.cdn.bspapp.com/images/vip.png",null,"艺体志愿宝-数据体验卡",1,1));
|
||||
douYinOrderSyncModel.setItem_list(itemList);
|
||||
orderSync(douYinOrderSyncModel,appId,appSecret,openId);
|
||||
/*String orderCode = "ORD240625150801447";
|
||||
//String notifyUrl = "https://yitisheng.vip/jbt/mini/pay/v1/dy/payNotify";
|
||||
String notifyUrl = "https://yitisheng.vip/py/dy/payNotify";
|
||||
Long refundAmount = 100l;
|
||||
String appId = "tt59a72f1ac6964bfa01";
|
||||
orderRefund(orderCode,appId,refundAmount,"wODf6Bg5BXndJ3IELXNb1w5CDMRjatXAmZVP2DQ7",notifyUrl);*/
|
||||
long time = new Date().getTime();
|
||||
String js="{\"count\":7800,\"dates\":[\"2016-09\",\"2018-06\",\"2019-07\",\"2020-01\",\"2022-03\",\"2024-05\"],\"description\":\"☘\uFE0F 如果喜欢秒达工具箱,请收藏和分享本网址MDGJX.COM(首拼缩写)\",\"info\":{\"codeGenTarget\":\"ES5\",\"extraLibs\":[],\"info\":{\"codeGenTarget\":\"ES5\",\"extraLibs\":[],\"info\":{\"codeGenTarget\":\"ES5\",\"extraLibs\":[],\"info\":{\"codeGenTarget\":\"ES5\",\"extraLibs\":[],\"moduleGenTarget\":\"\",\"noImplicitAny\":true,\"noLib\":false,\"scope\":\"/\",\"semanticValidation\":true,\"syntaxValidation\":true},\"moduleGenTarget\":\"\",\"noImplicitAny\":true,\"noLib\":false,\"scope\":\"/\",\"semanticValidation\":true,\"syntaxValidation\":true},\"moduleGenTarget\":\"\",\"noImplicitAny\":true,\"noLib\":false,\"scope\":\"/\",\"semanticValidation\":true,\"syntaxValidation\":true},\"moduleGenTarget\":\"\",\"noImplicitAny\":true,\"noLib\":false,\"scope\":\"/\",\"semanticValidation\":true,\"syntaxValidation\":true},\"link\":\"https://mdgjx.com\",\"name\":\"秒达工具箱\"}";
|
||||
JSONObject jsonObject = null;
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
jsonObject = JSONObject.parseObject(js);
|
||||
}
|
||||
long endTime = new Date().getTime();
|
||||
System.out.println("fastjson耗时:");
|
||||
System.out.println(endTime-time);
|
||||
|
||||
time = new Date().getTime();
|
||||
cn.hutool.json.JSONObject entries =null;
|
||||
for (int i = 0; i <10000; i++) {
|
||||
entries = new cn.hutool.json.JSONObject(js);
|
||||
}
|
||||
|
||||
endTime = new Date().getTime();
|
||||
System.out.println("hutool json耗时:");
|
||||
System.out.println(endTime-time);
|
||||
|
||||
// String openId="_000-8dokDbb5cDgK7gdSNOJrzIBFQZNqOrO";
|
||||
// String appId="tt59a72f1ac6964bfa01";
|
||||
// String appSecret="46882267247ca02561cf899d03adf562aa93ad3e";
|
||||
// //getAccessToken(appId,appSecret);
|
||||
// DouYinOrderSyncModel douYinOrderSyncModel=new DouYinOrderSyncModel();
|
||||
// String orderId="2bba71312366498c900b3575c7d9cad5";
|
||||
// douYinOrderSyncModel.setOrder_id(orderId);
|
||||
// douYinOrderSyncModel.setCreate_time(1713104670);
|
||||
// douYinOrderSyncModel.setStatus("已支付");
|
||||
// douYinOrderSyncModel.setAmount(1);
|
||||
// douYinOrderSyncModel.setTotal_price(1);
|
||||
// douYinOrderSyncModel.setDetail_url("pages/zyb/order/detail?orderCode="+orderId);
|
||||
// List<ItemStruct> itemList=new ArrayList<>();
|
||||
// itemList.add(new ItemStruct("1002","https://mp-7a4eecb1-2a04-4d36-b050-1c4a78cc31a4.cdn.bspapp.com/images/vip.png",null,"艺体志愿宝-数据体验卡",1,1));
|
||||
// douYinOrderSyncModel.setItem_list(itemList);
|
||||
// orderSync(douYinOrderSyncModel,appId,appSecret,openId);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,12 +4,16 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jeecg.common.constant.CacheConstant;
|
||||
import org.jeecg.common.constant.CommonConstant;
|
||||
import org.jeecg.common.system.util.JwtUtil;
|
||||
import org.jeecg.common.util.RedisUtil;
|
||||
import org.jeecg.modules.mini.dto.VipDTO;
|
||||
import org.jeecg.modules.system.entity.SysUser;
|
||||
import org.jeecg.modules.system.service.ISysUserService;
|
||||
import org.jeecg.modules.yx.entity.*;
|
||||
import org.jeecg.modules.yx.service.*;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
|
@ -42,7 +46,8 @@ public class MiniUserService {
|
|||
private IYxVipSkuService yxVipSkuService;
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
@Resource
|
||||
public RedisTemplate redisTemplate;
|
||||
public static SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
/**
|
||||
* 根据userId获取用户VIP信息
|
||||
|
|
@ -151,4 +156,113 @@ public class MiniUserService {
|
|||
//转移数据
|
||||
sysUserService.update(new LambdaUpdateWrapper<SysUser>().eq(SysUser::getId,nowUserId).set(SysUser::getPhone,oldSysUser.getPhone()).set(SysUser::getWxOpenId,wxOpenId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据userId 强制用户token退出
|
||||
* @param userId
|
||||
*/
|
||||
@Async
|
||||
public void logoutUser(String userId) {
|
||||
oneUserLogin(sysUserService.getById(userId));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param user
|
||||
*/
|
||||
public void oneUserLogin(SysUser user){
|
||||
//仅保留一端登录
|
||||
Collection<String> keys = redisTemplate.keys(CommonConstant.PREFIX_USER_TOKEN + "*");
|
||||
// 使用mget一次性获取所有令牌
|
||||
List<String> tokens = redisTemplate.opsForValue().multiGet(keys);
|
||||
String username = null;
|
||||
SysUser sysUser = null;
|
||||
String uname = user.getUsername();
|
||||
if (tokens!=null) {
|
||||
for (String token : tokens) {
|
||||
if (token != null) {
|
||||
username = JwtUtil.getUsername(token);
|
||||
if (username!=null && username.equals(uname)) {
|
||||
sysUser = sysUserService.getUserByName(username);
|
||||
if (sysUser!=null) {
|
||||
if(sysUser.getId().equals(user.getId())){
|
||||
//清空用户登录Token缓存
|
||||
redisUtil.del(CommonConstant.PREFIX_USER_TOKEN + token);
|
||||
//清空用户登录Shiro权限缓存
|
||||
redisUtil.del(CommonConstant.PREFIX_USER_SHIRO_CACHE + sysUser.getId());
|
||||
//清空用户的缓存信息(包括部门信息),例如sys:cache:user::<username>
|
||||
redisUtil.del(String.format("%s::%s", CacheConstant.SYS_USERS_CACHE, sysUser.getUsername()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*for (String key : keys) {
|
||||
token = (String) redisUtil.get(key);
|
||||
username = JwtUtil.getUsername(token);
|
||||
if (username.equals(uname)) {
|
||||
sysUser = sysUserService.getUserByName(username);
|
||||
if (sysUser!=null) {
|
||||
if(sysUser.getId().equals(user.getId())){
|
||||
//清空用户登录Token缓存
|
||||
redisUtil.del(CommonConstant.PREFIX_USER_TOKEN + token);
|
||||
//清空用户登录Shiro权限缓存
|
||||
redisUtil.del(CommonConstant.PREFIX_USER_SHIRO_CACHE + sysUser.getId());
|
||||
//清空用户的缓存信息(包括部门信息),例如sys:cache:user::<username>
|
||||
redisUtil.del(String.format("%s::%s", CacheConstant.SYS_USERS_CACHE, sysUser.getUsername()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
@Deprecated
|
||||
public void oneUserLogin_old(SysUser user){
|
||||
//仅保留一端登录
|
||||
Collection<String> keys = redisTemplate.keys(CommonConstant.PREFIX_USER_TOKEN + "*");
|
||||
// 使用mget一次性获取所有令牌
|
||||
List<String> tokens = redisTemplate.opsForValue().multiGet(keys);
|
||||
String username = null;
|
||||
SysUser sysUser = null;
|
||||
String uname = user.getUsername();
|
||||
if (tokens!=null) {
|
||||
for (String token : tokens) {
|
||||
if (token != null) {
|
||||
username = JwtUtil.getUsername(token);
|
||||
if (username!=null && username.equals(uname)) {
|
||||
sysUser = sysUserService.getUserByName(username);
|
||||
if (sysUser!=null) {
|
||||
if(sysUser.getId().equals(user.getId())){
|
||||
//清空用户登录Token缓存
|
||||
redisUtil.del(CommonConstant.PREFIX_USER_TOKEN + token);
|
||||
//清空用户登录Shiro权限缓存
|
||||
redisUtil.del(CommonConstant.PREFIX_USER_SHIRO_CACHE + sysUser.getId());
|
||||
//清空用户的缓存信息(包括部门信息),例如sys:cache:user::<username>
|
||||
redisUtil.del(String.format("%s::%s", CacheConstant.SYS_USERS_CACHE, sysUser.getUsername()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*for (String key : keys) {
|
||||
token = (String) redisUtil.get(key);
|
||||
username = JwtUtil.getUsername(token);
|
||||
if (username.equals(uname)) {
|
||||
sysUser = sysUserService.getUserByName(username);
|
||||
if (sysUser!=null) {
|
||||
if(sysUser.getId().equals(user.getId())){
|
||||
//清空用户登录Token缓存
|
||||
redisUtil.del(CommonConstant.PREFIX_USER_TOKEN + token);
|
||||
//清空用户登录Shiro权限缓存
|
||||
redisUtil.del(CommonConstant.PREFIX_USER_SHIRO_CACHE + sysUser.getId());
|
||||
//清空用户的缓存信息(包括部门信息),例如sys:cache:user::<username>
|
||||
redisUtil.del(String.format("%s::%s", CacheConstant.SYS_USERS_CACHE, sysUser.getUsername()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,6 +40,8 @@ public class YxConstant {
|
|||
public static BigDecimal bigDecimal0 = new BigDecimal(0);
|
||||
//100倍率
|
||||
public static BigDecimal bigDecimal100 = new BigDecimal("100");
|
||||
|
||||
public static long bigDecimal1000 = 1000;
|
||||
public static BigDecimal bigDecimal150 = new BigDecimal("150");
|
||||
public static BigDecimal bigDecimal200 = new BigDecimal("200");
|
||||
public static BigDecimal bigDecimal95x = new BigDecimal("95");
|
||||
|
|
@ -83,4 +85,5 @@ public class YxConstant {
|
|||
|
||||
// vip card redis key
|
||||
public static String VIP_CARD_KEY="vip_card";
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -102,6 +102,12 @@ public class YxOrder implements Serializable {
|
|||
@ApiModelProperty(value = "退款日期")
|
||||
private java.util.Date refundTime;
|
||||
|
||||
@ApiModelProperty(value = "系统退款号")
|
||||
private String cpRefundNo;
|
||||
|
||||
@ApiModelProperty(value = "抖音商户退款号")
|
||||
private String refundNo;
|
||||
|
||||
//==================
|
||||
@TableField(exist = false)
|
||||
private String skuName;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package org.jeecg.modules.yx.service;
|
|||
import org.jeecg.modules.yx.entity.YxOrder;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -25,4 +26,13 @@ public interface IYxOrderService extends IService<YxOrder> {
|
|||
void paymentOrderOver(String orderCode,String paymentType, String orderStatus, Date paymentTime);
|
||||
|
||||
YxOrder getByOrderCode(String orderCode);
|
||||
|
||||
/**
|
||||
* 更改订单状态为 退款
|
||||
* @param orderCode 订单号
|
||||
* @param cpRefundNo 系统退款号
|
||||
* @param refundNo 商户退款号
|
||||
* @param refundAmount 退款金额
|
||||
*/
|
||||
YxOrder updateRefund(String orderCode, String cpRefundNo, String refundNo, BigDecimal refundAmount);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import org.springframework.stereotype.Service;
|
|||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -43,4 +44,16 @@ public class YxOrderServiceImpl extends ServiceImpl<YxOrderMapper, YxOrder> impl
|
|||
public YxOrder getByOrderCode(String orderCode) {
|
||||
return baseMapper.selectByOrderCode(orderCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public YxOrder updateRefund(String orderCode, String cpRefundNo, String refundNo, BigDecimal refundAmount) {
|
||||
YxOrder yxOrder = this.getByOrderCode(orderCode);
|
||||
yxOrder.setCpRefundNo(cpRefundNo);
|
||||
yxOrder.setRefundNo(refundNo);
|
||||
yxOrder.setRefundAmount(refundAmount);
|
||||
yxOrder.setOrderStatus("8");
|
||||
yxOrder.setRefundTime(new Date());
|
||||
this.updateById(yxOrder);
|
||||
return yxOrder;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue