From 9570d5a642c669f3b430c77812720892830128eb Mon Sep 17 00:00:00 2001
From: rk <94314517@qq.com>
Date: 星期五, 22 八月 2025 10:29:59 +0800
Subject: [PATCH] 111
---
server/admin/src/main/java/com/doumee/api/business/PaymentCallback.java | 69 ++++++++++++++++++++++++++--------
1 files changed, 53 insertions(+), 16 deletions(-)
diff --git a/server/admin/src/main/java/com/doumee/api/business/PaymentCallback.java b/server/admin/src/main/java/com/doumee/api/business/PaymentCallback.java
index 33f43ee..8539e1c 100644
--- a/server/admin/src/main/java/com/doumee/api/business/PaymentCallback.java
+++ b/server/admin/src/main/java/com/doumee/api/business/PaymentCallback.java
@@ -3,10 +3,12 @@
import com.alibaba.fastjson.JSON;
import com.doumee.config.wx.TransferDetailEntityNew;
import com.doumee.config.wx.WxMiniConfig;
+import com.doumee.core.constants.Constants;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.model.ApiResponse;
import com.doumee.service.business.OrdersService;
+import com.doumee.service.business.WithdrawalOrdersService;
import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import com.wechat.pay.java.core.RSAPublicKeyConfig;
@@ -16,6 +18,7 @@
import com.wechat.pay.java.service.partnerpayments.jsapi.model.Transaction;
import com.wechat.pay.java.service.refund.model.RefundNotification;
import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.mgt.DefaultSecurityManager;
import org.springframework.beans.factory.annotation.Autowired;
@@ -45,6 +48,9 @@
@Autowired
private OrdersService ordersService;
+
+ @Autowired
+ private WithdrawalOrdersService withdrawalOrdersService;
/**
* 銆愬井淇℃敮浠樸�戝紓姝ラ�氱煡
@@ -77,9 +83,17 @@
.body(body)
.build();
- NotificationConfig config = new RSAAutoCertificateConfig.Builder()
+ NotificationConfig config = /*new RSAAutoCertificateConfig.Builder()
.merchantId(WxMiniConfig.wxProperties.getMchId())
.privateKeyFromPath(WxMiniConfig.wxProperties.getPrivateKeyPath())
+ .merchantSerialNumber(WxMiniConfig.wxProperties.getSerialNumer())
+ .apiV3Key(WxMiniConfig.wxProperties.getApiV3Key())
+ .build(); */
+ new RSAPublicKeyConfig.Builder()
+ .merchantId(WxMiniConfig.wxProperties.getMchId())
+ .privateKeyFromPath(WxMiniConfig.wxProperties.getPrivateKeyPath())
+ .publicKeyFromPath(WxMiniConfig.wxProperties.getPubKeyPath())
+ .publicKeyId(WxMiniConfig.wxProperties.getPayPublicKeyId())
.merchantSerialNumber(WxMiniConfig.wxProperties.getSerialNumer())
.apiV3Key(WxMiniConfig.wxProperties.getApiV3Key())
.build();
@@ -146,13 +160,20 @@
.body(body)
.build();
- NotificationConfig config = new RSAAutoCertificateConfig.Builder()
+ NotificationConfig config = /*new RSAAutoCertificateConfig.Builder()
.merchantId(WxMiniConfig.wxProperties.getMchId())
.privateKeyFromPath(WxMiniConfig.wxProperties.getPrivateKeyPath())
.merchantSerialNumber(WxMiniConfig.wxProperties.getSerialNumer())
.apiV3Key(WxMiniConfig.wxProperties.getApiV3Key())
+ .build();*/
+ new RSAPublicKeyConfig.Builder()
+ .merchantId(WxMiniConfig.wxProperties.getMchId())
+ .privateKeyFromPath(WxMiniConfig.wxProperties.getPrivateKeyPath())
+ .publicKeyFromPath(WxMiniConfig.wxProperties.getPubKeyPath())
+ .publicKeyId(WxMiniConfig.wxProperties.getPayPublicKeyId())
+ .merchantSerialNumber(WxMiniConfig.wxProperties.getSerialNumer())
+ .apiV3Key(WxMiniConfig.wxProperties.getApiV3Key())
.build();
-
NotificationParser parser = new NotificationParser(config);
RefundNotification result = parser.parse(requestParam, RefundNotification.class);
@@ -177,14 +198,30 @@
* @return
*/
@PostMapping(value = "/web/wechat/transferNotify")
- public ApiResponse wxPayCallback( HttpServletRequest request) {
+ public ApiResponse transferNotify( HttpServletRequest request) {
Map<String,String> errMap = new HashMap<>();
try {
- log.info("寰俊鍟嗘埛闆剁嚎杞处 - 鍥炶皟閫氱煡 /wxpay/callback");
- TransferDetailEntityNew entity = wxPaySuccessCallback(request);
- log.info("transfer ok.{}",entity);
+ log.error("寰俊鍟嗘埛闆剁嚎杞处 - 鍥炶皟閫氱煡 /wxpay/callback");
+
+ Config config = new RSAPublicKeyConfig.Builder()
+ .merchantId(WxMiniConfig.wxProperties.getSubMchId()) //寰俊鏀粯鐨勫晢鎴峰彿
+ .privateKeyFromPath(WxMiniConfig.wxProperties.getWechatPrivateKeyPath()) // 鍟嗘埛API璇佷功绉侀挜鐨勫瓨鏀捐矾寰�
+ .publicKeyFromPath(WxMiniConfig.wxProperties.getWechatPubKeyPath()) //寰俊鏀粯鍏挜鐨勫瓨鏀捐矾寰�
+ .publicKeyId(WxMiniConfig.wxProperties.getWechatPayPublicKeyId()) //寰俊鏀粯鍏挜ID
+ .merchantSerialNumber(WxMiniConfig.wxProperties.getWechatSerialNumer()) //鍟嗘埛API璇佷功搴忓垪鍙�
+ .apiV3Key(WxMiniConfig.wxProperties.getWechatApiV3Key()) //APIv3瀵嗛挜
+ .build();
+
+ TransferDetailEntityNew entity = wxSuccessCallback(request,config);
+ log.error("transfer ok.{}",entity);
//鍥炶皟鎴愬姛鍚庡鐞嗚嚜宸辩殑涓氬姟
if(entity != null){
+ if((entity.getState().equals(Constants.SUCCESS)
+ || entity.getState().equals(Constants.CANCELLED)
+ || entity.getState().equals(Constants.FAIL))
+ && StringUtils.isNotBlank(entity.getOutBillNo())){
+ withdrawalOrdersService.transferSuccess(entity.getOutBillNo(),entity.getState().equals(Constants.SUCCESS)?true:false);
+ }
}
return ApiResponse.success("澶勭悊鎴愬姛");
} catch (Exception e) {
@@ -195,7 +232,7 @@
}
}
- public TransferDetailEntityNew wxPaySuccessCallback(HttpServletRequest request) throws IOException {
+ public TransferDetailEntityNew wxSuccessCallback(HttpServletRequest request,Config config) throws IOException {
String requestBody = getBodyString(request, "UTF-8");
//璇佷功搴忓垪鍙凤紙寰俊骞冲彴锛� 楠岀鐨勨�滃井淇℃敮浠樺钩鍙拌瘉涔︹�濇墍瀵瑰簲鐨勫钩鍙拌瘉涔﹀簭鍒楀彿
String wechatPaySerial = request.getHeader("Wechatpay-Serial");
@@ -214,14 +251,14 @@
.body(requestBody)
.build();
// 2. 鏋勫缓Config RSAPublicKeyConfig
- Config config = new RSAPublicKeyConfig.Builder()
- .merchantId(WxMiniConfig.wxProperties.getMchId()) //寰俊鏀粯鐨勫晢鎴峰彿
- .privateKeyFromPath(WxMiniConfig.wxProperties.getPrivateKeyPath()) // 鍟嗘埛API璇佷功绉侀挜鐨勫瓨鏀捐矾寰�
- .publicKeyFromPath(WxMiniConfig.wxProperties.getWechatPubKeyPath()) //寰俊鏀粯鍏挜鐨勫瓨鏀捐矾寰�
- .publicKeyId(WxMiniConfig.wxProperties.getWechatPayPublicKeyId()) //寰俊鏀粯鍏挜ID
- .merchantSerialNumber(WxMiniConfig.wxProperties.getSerialNumer()) //鍟嗘埛API璇佷功搴忓垪鍙�
- .apiV3Key("") //APIv3瀵嗛挜
- .build();
+// Config config = new RSAPublicKeyConfig.Builder()
+// .merchantId(WxMiniConfig.wxProperties.getMchId()) //寰俊鏀粯鐨勫晢鎴峰彿
+// .privateKeyFromPath(WxMiniConfig.wxProperties.getPrivateKeyPath()) // 鍟嗘埛API璇佷功绉侀挜鐨勫瓨鏀捐矾寰�
+// .publicKeyFromPath(WxMiniConfig.wxProperties.getWechatPubKeyPath()) //寰俊鏀粯鍏挜鐨勫瓨鏀捐矾寰�
+// .publicKeyId(WxMiniConfig.wxProperties.getWechatPayPublicKeyId()) //寰俊鏀粯鍏挜ID
+// .merchantSerialNumber(WxMiniConfig.wxProperties.getSerialNumer()) //鍟嗘埛API璇佷功搴忓垪鍙�
+// .apiV3Key("") //APIv3瀵嗛挜
+// .build();
log.info("WxPayService.wxPaySuccessCallback request : wechatPaySerial is [{}] , wechatSignature is [{}] , wechatTimestamp is [{}] , wechatpayNonce is [{}] , requestBody is [{}]",wechatPaySerial,wechatSignature,wechatTimestamp,wechatpayNonce,requestBody);
// 3. 鍒濆鍖� NotificationParser
NotificationParser parser = new NotificationParser((NotificationConfig) config);
--
Gitblit v1.9.3