姜永辉 1 год назад
Родитель
Сommit
fdf2f792c6

+ 34 - 0
src/main/java/com/dk/oauth/controller/wxapi/basic/WechatPayController.java

@@ -87,5 +87,39 @@ public class WechatPayController {
         return WxPayNotifyResponse.success("成功");
     }
 
+    /**
+     * @desc : 退款的回调
+     * @author : 姜永辉
+     * @date : 2024/03/06 11:20
+     */
+    @PostMapping("/refund/order/{appId}")
+    public String parseRefundNotifyResult(@PathVariable(value = "appId") String appId, @RequestBody String xmlData)
+            throws WxPayException {
+        log.info("parseOrderNotifyResult--0" + appId + "---" + xmlData);
+        WxPayService wxPayService = wechatPayService.getWxPayService();
+        final WxPayOrderNotifyResult notifyResult = wxPayService.parseOrderNotifyResult(xmlData);
+        // 另起线程处理业务
+        executorService.execute(new Runnable() {
+            @Override
+            public void run() {
+                String resultCode = notifyResult.getResultCode();
+                log.info("parseOrderNotifyResult--1" + resultCode );
+                // 支付成功
+                if (resultCode.equals("SUCCESS")) {
+                    // 处理支付成功逻辑
+                    try {
+                        wechatPayService.notifyWechatPay(notifyResult);
+                    } catch (Exception e) {
+                        log.error("微信回调业务处理报错,params:" + notifyResult, e);
+                    }
+                } else {
+                    log.error("没有处理微信回调业务,交易状态:{},params:{}", resultCode, JSONObject.toJSON(notifyResult));
+                }
+            }
+        });
+        log.info("parseOrderNotifyResult--10000-成功"  );
+        return WxPayNotifyResponse.success("成功");
+    }
+
 
 }

+ 4 - 0
src/main/java/com/dk/oauth/service/wxapi/basic/WechatPayService.java

@@ -24,6 +24,7 @@ import com.github.binarywang.wxpay.service.WxPayService;
 import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.io.ClassPathResource;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -161,6 +162,9 @@ public class WechatPayService {
         payConfig.setMchKey(StringUtils.trimToNull(wechatPayConfigInfo.getMchKey()));
 //        payConfig.setSubAppId(null);
 //        payConfig.setSubMchId(null);
+        ClassPathResource classPathResource = new ClassPathResource("apiclient_cert.p12");
+        payConfig.setKeyPath(StringUtils.trimToNull(classPathResource.getPath()));
+        log.info("getWxPayService=>" + classPathResource.toString());
 //        payConfig.setKeyPath(StringUtils.trimToNull(wechatPayConfigInfo.getKeyPath()));
         // 可以指定是否使用沙箱环境
         payConfig.setUseSandboxEnv(false);

+ 3 - 1
src/main/resources/test/bootstrap.yml

@@ -115,9 +115,11 @@ wx:
     # 支付密钥
     mchKey: 399e76d7db9511ee9c24fa163eacb119
     # 证书路径
-    keyPath: /mnt/cert/2021/05/11/404727f0-e5be-424e-b009-59f1ec8d102e.p12
+    keyPath: /mnt/cert/2024/05/01/apiclient_cert.p12
     # 小程序支付的回调接口地址
     wechatNotifyUrl: https://s.dev01.dkiboss.com:7000/api/oauth-server/wxapi/basic/wechat/pay/notify/order
+    # 小程序退款的回调接口地址
+    refundNotifyUrl: https://s.dev01.dkiboss.com:7000/api/oauth-server/wxapi/basic/wechat/pay/refund/order
 
 upload:
   server: https://s.dev01.dkiboss.com:7000/api/file