wangming 1 month ago
parent
commit
ede69e8757

+ 2 - 1
yami-shop-wx/src/main/java/com/yami/shop/wx/service/impl/WxProviderServiceImpl.java

@@ -489,7 +489,7 @@ public class WxProviderServiceImpl implements WxProviderService {
             try {
                 // 解密resource中的通知数据
                 String resource = bodyJson.getString("resource");
-                JSONObject resourceJson = WechatPayValidator.decryptFromResource(resource, WxConstants.API_V3_KEY, 2);
+                JSONObject resourceJson = WechatPayValidator.decryptFromResource(resource, WxConstants.API_V3_KEY);
                 log.info("  =================== 服务商小程序支付回调解密resource中的通知数据 ===================\n" + resourceJson);
                 Integer trans = statusTrans(resourceJson.getString("trade_state"));
                 JSONObject attach = resourceJson.getJSONObject("attach");
@@ -499,6 +499,7 @@ public class WxProviderServiceImpl implements WxProviderService {
                     return successJson;
                 } else {
                     System.err.println("支付失败...");
+                    return bodyJson;
                 }
             } finally {
                 lock.unlock();

+ 3 - 6
yami-shop-wx/src/main/java/com/yami/shop/wx/utils/WechatPayValidator.java

@@ -113,13 +113,10 @@ public class WechatPayValidator {
      *
      * @param resource 加密数据
      * @param apiV3Key apiV3密钥
-     * @param type     1-支付,2-退款
      * @return
      */
-    public static JSONObject decryptFromResource(String resource, String apiV3Key, Integer type) {
-
-        String msg = type == 1 ? "支付成功" : "退款成功";
-        log.info(msg + ",回调通知,密文解密");
+    public static JSONObject decryptFromResource(String resource, String apiV3Key) {
+        log.info("回调通知,密文解密");
         try {
             //通知数据
             JSONObject jsonObject = JSONObject.parseObject(resource);
@@ -134,7 +131,7 @@ public class WechatPayValidator {
             String resourceStr = aesUtil.decryptToString(associatedData.getBytes(StandardCharsets.UTF_8),
                     nonce.getBytes(StandardCharsets.UTF_8),
                     ciphertext);
-            log.info(msg + "回调通知,解密结果 : {}", resourceStr);
+            log.info("回调通知,解密结果 : {}", resourceStr);
             return JSONObject.parseObject(resourceStr);
         } catch (Exception e) {
             throw new RuntimeException("回调参数,解密失败!");