Browse Source

:art: #1585 微信支付结果异步通知的解析方法增加可以自行指定signType的重载方法

Binary Wang 5 years ago
parent
commit
da0ce15da6

+ 11 - 0
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java

@@ -304,6 +304,17 @@ public interface WxPayService {
   WxPayOrderNotifyResult parseOrderNotifyResult(String xmlData) throws WxPayException;
 
   /**
+   * 解析支付结果通知.
+   * 详见https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_7
+   *
+   * @param xmlData  the xml data
+   * @param signType 签名类型
+   * @return the wx pay order notify result
+   * @throws WxPayException the wx pay exception
+   */
+  WxPayOrderNotifyResult parseOrderNotifyResult(String xmlData, String signType) throws WxPayException;
+
+  /**
    * 解析退款结果通知
    * 详见https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_16&index=9
    *

+ 10 - 1
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java

@@ -154,11 +154,20 @@ public abstract class BaseWxPayServiceImpl implements WxPayService {
 
   @Override
   public WxPayOrderNotifyResult parseOrderNotifyResult(String xmlData) throws WxPayException {
+    return this.parseOrderNotifyResult(xmlData, null);
+  }
+
+  @Override
+  public WxPayOrderNotifyResult parseOrderNotifyResult(String xmlData, String signType) throws WxPayException {
     try {
       log.debug("微信支付异步通知请求参数:{}", xmlData);
       WxPayOrderNotifyResult result = WxPayOrderNotifyResult.fromXML(xmlData);
+      if (result.getSignType() != null) {
+        // 如果解析的通知对象中signType有值,则使用它进行验签
+        signType = result.getSignType();
+      }
       log.debug("微信支付异步通知请求解析后的对象:{}", result);
-      result.checkResult(this, result.getSignType(), false);
+      result.checkResult(this, signType, false);
       return result;
     } catch (WxPayException e) {
       throw e;