|
@@ -33,6 +33,7 @@ import java.security.InvalidKeyException;
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
import java.security.cert.*;
|
|
import java.security.cert.*;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
+import java.util.concurrent.locks.ReentrantLock;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
import static java.lang.Thread.sleep;
|
|
import static java.lang.Thread.sleep;
|
|
@@ -57,6 +58,10 @@ public class WeChatProfitSharingService {
|
|
|
private AppProfitSharingInfoMapper appProfitSharingInfoMapper;
|
|
private AppProfitSharingInfoMapper appProfitSharingInfoMapper;
|
|
|
@Resource
|
|
@Resource
|
|
|
private ShopMoneyMapper shopMoneyMapper;
|
|
private ShopMoneyMapper shopMoneyMapper;
|
|
|
|
|
+
|
|
|
|
|
+ // 声明一个可重入锁
|
|
|
|
|
+ private final ReentrantLock lock = new ReentrantLock();
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 添加分账接收方
|
|
* 添加分账接收方
|
|
|
*
|
|
*
|
|
@@ -90,7 +95,7 @@ public class WeChatProfitSharingService {
|
|
|
"limit 1"));
|
|
"limit 1"));
|
|
|
List<AppOrderProInfo> orderProInfoList = appOrderProInfoMapper.selectList(Wrappers.lambdaQuery(AppOrderProInfo.class).eq(AppOrderProInfo::getOrderId, appOrder.getId()).eq(AppOrderProInfo::getType, CommonConstant.ORDER_PRO_INFO_TYPE_6));
|
|
List<AppOrderProInfo> orderProInfoList = appOrderProInfoMapper.selectList(Wrappers.lambdaQuery(AppOrderProInfo.class).eq(AppOrderProInfo::getOrderId, appOrder.getId()).eq(AppOrderProInfo::getType, CommonConstant.ORDER_PRO_INFO_TYPE_6));
|
|
|
BigDecimal insurePrice = BigDecimal.ZERO;
|
|
BigDecimal insurePrice = BigDecimal.ZERO;
|
|
|
- if (CollUtil.isNotEmpty(orderProInfoList)){
|
|
|
|
|
|
|
+ if (CollUtil.isNotEmpty(orderProInfoList)) {
|
|
|
BigDecimal reduce = orderProInfoList.stream().map(AppOrderProInfo::getPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
BigDecimal reduce = orderProInfoList.stream().map(AppOrderProInfo::getPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
insurePrice = insurePrice.add(reduce);
|
|
insurePrice = insurePrice.add(reduce);
|
|
|
}
|
|
}
|
|
@@ -119,7 +124,7 @@ public class WeChatProfitSharingService {
|
|
|
List<Receiver> receivers = new ArrayList<>();
|
|
List<Receiver> receivers = new ArrayList<>();
|
|
|
//查询当前订单的分账接收方列表
|
|
//查询当前订单的分账接收方列表
|
|
|
for (AppProfitSharingInfo receiverRecord : partyFunding) {
|
|
for (AppProfitSharingInfo receiverRecord : partyFunding) {
|
|
|
- if (receiverRecord.getPreAmount() != 0){
|
|
|
|
|
|
|
+ if (receiverRecord.getPreAmount() != 0) {
|
|
|
Receiver receiver = new Receiver();
|
|
Receiver receiver = new Receiver();
|
|
|
receiver.setType("MERCHANT_ID")
|
|
receiver.setType("MERCHANT_ID")
|
|
|
.setAccount(receiverRecord.getMchId())
|
|
.setAccount(receiverRecord.getMchId())
|
|
@@ -187,7 +192,8 @@ public class WeChatProfitSharingService {
|
|
|
//List<WechatReceiver> wechatReceivers = (List<WechatReceiver>) res.get("receivers");
|
|
//List<WechatReceiver> wechatReceivers = (List<WechatReceiver>) res.get("receivers");
|
|
|
Gson gson = new Gson();
|
|
Gson gson = new Gson();
|
|
|
// 定义目标类型的TypeToken
|
|
// 定义目标类型的TypeToken
|
|
|
- Type receiverListType = new TypeToken<List<WechatReceiver>>() {}.getType();
|
|
|
|
|
|
|
+ Type receiverListType = new TypeToken<List<WechatReceiver>>() {
|
|
|
|
|
+ }.getType();
|
|
|
// 转换
|
|
// 转换
|
|
|
List<WechatReceiver> wechatReceivers = gson.fromJson(
|
|
List<WechatReceiver> wechatReceivers = gson.fromJson(
|
|
|
// 将receivers转为JSON字符串
|
|
// 将receivers转为JSON字符串
|
|
@@ -222,12 +228,12 @@ public class WeChatProfitSharingService {
|
|
|
* @return JSONObject
|
|
* @return JSONObject
|
|
|
* @throws Exception
|
|
* @throws Exception
|
|
|
*/
|
|
*/
|
|
|
- public JSONObject profitSharings(String orderCode,String s) throws Exception {
|
|
|
|
|
|
|
+ public JSONObject profitSharings(String orderCode, String s) throws Exception {
|
|
|
AppOrder appOrder = appOrderMapper.selectOne(Wrappers.lambdaQuery(AppOrder.class).eq(AppOrder::getOrderCode, orderCode).last(
|
|
AppOrder appOrder = appOrderMapper.selectOne(Wrappers.lambdaQuery(AppOrder.class).eq(AppOrder::getOrderCode, orderCode).last(
|
|
|
"limit 1"));
|
|
"limit 1"));
|
|
|
List<AppOrderProInfo> orderProInfoList = appOrderProInfoMapper.selectList(Wrappers.lambdaQuery(AppOrderProInfo.class).eq(AppOrderProInfo::getOrderId, appOrder.getId()).eq(AppOrderProInfo::getType, CommonConstant.ORDER_PRO_INFO_TYPE_6));
|
|
List<AppOrderProInfo> orderProInfoList = appOrderProInfoMapper.selectList(Wrappers.lambdaQuery(AppOrderProInfo.class).eq(AppOrderProInfo::getOrderId, appOrder.getId()).eq(AppOrderProInfo::getType, CommonConstant.ORDER_PRO_INFO_TYPE_6));
|
|
|
BigDecimal insurePrice = BigDecimal.ZERO;
|
|
BigDecimal insurePrice = BigDecimal.ZERO;
|
|
|
- if (CollUtil.isNotEmpty(orderProInfoList)){
|
|
|
|
|
|
|
+ if (CollUtil.isNotEmpty(orderProInfoList)) {
|
|
|
BigDecimal reduce = orderProInfoList.stream().map(AppOrderProInfo::getPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
BigDecimal reduce = orderProInfoList.stream().map(AppOrderProInfo::getPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
insurePrice = insurePrice.add(reduce);
|
|
insurePrice = insurePrice.add(reduce);
|
|
|
}
|
|
}
|
|
@@ -256,7 +262,7 @@ public class WeChatProfitSharingService {
|
|
|
List<Receiver> receivers = new ArrayList<>();
|
|
List<Receiver> receivers = new ArrayList<>();
|
|
|
//查询当前订单的分账接收方列表
|
|
//查询当前订单的分账接收方列表
|
|
|
for (AppProfitSharingInfo receiverRecord : partyFunding) {
|
|
for (AppProfitSharingInfo receiverRecord : partyFunding) {
|
|
|
- if (receiverRecord.getPreAmount() != 0){
|
|
|
|
|
|
|
+ if (receiverRecord.getPreAmount() != 0) {
|
|
|
Receiver receiver = new Receiver();
|
|
Receiver receiver = new Receiver();
|
|
|
receiver.setType("MERCHANT_ID")
|
|
receiver.setType("MERCHANT_ID")
|
|
|
.setAccount(receiverRecord.getMchId())
|
|
.setAccount(receiverRecord.getMchId())
|
|
@@ -310,7 +316,8 @@ public class WeChatProfitSharingService {
|
|
|
//List<WechatReceiver> wechatReceivers = (List<WechatReceiver>) res.get("receivers");
|
|
//List<WechatReceiver> wechatReceivers = (List<WechatReceiver>) res.get("receivers");
|
|
|
Gson gson = new Gson();
|
|
Gson gson = new Gson();
|
|
|
// 定义目标类型的TypeToken
|
|
// 定义目标类型的TypeToken
|
|
|
- Type receiverListType = new TypeToken<List<WechatReceiver>>() {}.getType();
|
|
|
|
|
|
|
+ Type receiverListType = new TypeToken<List<WechatReceiver>>() {
|
|
|
|
|
+ }.getType();
|
|
|
// 转换
|
|
// 转换
|
|
|
List<WechatReceiver> wechatReceivers = gson.fromJson(
|
|
List<WechatReceiver> wechatReceivers = gson.fromJson(
|
|
|
gson.toJson(res.get("receivers")), // 将receivers转为JSON字符串
|
|
gson.toJson(res.get("receivers")), // 将receivers转为JSON字符串
|
|
@@ -387,7 +394,8 @@ public class WeChatProfitSharingService {
|
|
|
if (ObjectUtil.isNotEmpty(res.get("receivers"))) {
|
|
if (ObjectUtil.isNotEmpty(res.get("receivers"))) {
|
|
|
Gson gson = new Gson();
|
|
Gson gson = new Gson();
|
|
|
// 定义目标类型的TypeToken
|
|
// 定义目标类型的TypeToken
|
|
|
- Type receiverListType = new TypeToken<List<WechatReceiver>>() {}.getType();
|
|
|
|
|
|
|
+ Type receiverListType = new TypeToken<List<WechatReceiver>>() {
|
|
|
|
|
+ }.getType();
|
|
|
// 转换
|
|
// 转换
|
|
|
List<WechatReceiver> wechatReceivers = gson.fromJson(
|
|
List<WechatReceiver> wechatReceivers = gson.fromJson(
|
|
|
// 将receivers转为JSON字符串
|
|
// 将receivers转为JSON字符串
|
|
@@ -438,7 +446,7 @@ public class WeChatProfitSharingService {
|
|
|
map.put("out_return_no", "T" + orderCode);
|
|
map.put("out_return_no", "T" + orderCode);
|
|
|
map.put("return_mchid", receiverRecord.getMchId());
|
|
map.put("return_mchid", receiverRecord.getMchId());
|
|
|
map.put("amount", receiverRecord.getAmount());
|
|
map.put("amount", receiverRecord.getAmount());
|
|
|
- map.put("description", receiverRecord.getMchName() +"分账订单:"+ orderCode + "退还金额:" + receiverRecord.getAmount());
|
|
|
|
|
|
|
+ map.put("description", receiverRecord.getMchName() + "分账订单:" + orderCode + "退还金额:" + receiverRecord.getAmount());
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
JSONObject res = wechatPayV3Utils.sendPost(WechatUrlConstants.PAY_V3_RETURN_ORDER, JSONObject.from(map));
|
|
JSONObject res = wechatPayV3Utils.sendPost(WechatUrlConstants.PAY_V3_RETURN_ORDER, JSONObject.from(map));
|
|
@@ -483,31 +491,37 @@ public class WeChatProfitSharingService {
|
|
|
public Map<String, Object> wxPayRefundCallback(HttpServletRequest request, HttpServletResponse response, WechatRefundCallback refundCallback) {
|
|
public Map<String, Object> wxPayRefundCallback(HttpServletRequest request, HttpServletResponse response, WechatRefundCallback refundCallback) {
|
|
|
|
|
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
- // 2.签名验证
|
|
|
|
|
- //验签及解析返回数据
|
|
|
|
|
- JSONObject res = wechatPayV3Utils.getCallbackData(request);
|
|
|
|
|
- if (res == null) {
|
|
|
|
|
|
|
+ if (lock.tryLock()) {
|
|
|
|
|
+ // 2.签名验证
|
|
|
|
|
+ //验签及解析返回数据
|
|
|
|
|
+ JSONObject res = wechatPayV3Utils.getCallbackData(request);
|
|
|
|
|
+ if (res == null) {
|
|
|
|
|
+ result.put("code", "FAIL");
|
|
|
|
|
+ result.put("message", "失败");
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+ log.info("最终拿到的微信支付通知数据:" + res);
|
|
|
|
|
+
|
|
|
|
|
+ // 4.封装微信返回的数据
|
|
|
|
|
+ WechatCallbackRefundData refundData = getRefundCallbackData(res);
|
|
|
|
|
+ if ("SUCCESS".equals(refundData.getStatus())) {
|
|
|
|
|
+ // 执行业务逻辑
|
|
|
|
|
+ refundCallback.success(refundData);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 特殊情况退款失败业务处理,退款到银行发现用户的卡作废或者冻结了,导致原路退款银行卡失败,可前往商户平台-交易中心,手动处理此笔退款
|
|
|
|
|
+ refundCallback.fail(refundData);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 5.成功应答
|
|
|
|
|
+ response.setStatus(200);
|
|
|
|
|
+ result.put("code", "SUCCESS");
|
|
|
|
|
+ result.put("message", "成功");
|
|
|
|
|
+ return result;
|
|
|
|
|
+ } else {
|
|
|
result.put("code", "FAIL");
|
|
result.put("code", "FAIL");
|
|
|
result.put("message", "失败");
|
|
result.put("message", "失败");
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
- log.info("最终拿到的微信支付通知数据:" + res);
|
|
|
|
|
-
|
|
|
|
|
- // 4.封装微信返回的数据
|
|
|
|
|
- WechatCallbackRefundData refundData = getRefundCallbackData(res);
|
|
|
|
|
- if ("SUCCESS".equals(refundData.getStatus())) {
|
|
|
|
|
- // 执行业务逻辑
|
|
|
|
|
- refundCallback.success(refundData);
|
|
|
|
|
- } else {
|
|
|
|
|
- // 特殊情况退款失败业务处理,退款到银行发现用户的卡作废或者冻结了,导致原路退款银行卡失败,可前往商户平台-交易中心,手动处理此笔退款
|
|
|
|
|
- refundCallback.fail(refundData);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 5.成功应答
|
|
|
|
|
- response.setStatus(200);
|
|
|
|
|
- result.put("code", "SUCCESS");
|
|
|
|
|
- result.put("message", "成功");
|
|
|
|
|
- return result;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private static WechatCallbackRefundData getRefundCallbackData(JSONObject res) {
|
|
private static WechatCallbackRefundData getRefundCallbackData(JSONObject res) {
|