Explorar el Código

:art: #3586 【微信支付】修复资源上传接口使用POST请求Content-Type不正确导致签名错误的问题

SynchPj hace 2 días
padre
commit
47051bdf31

+ 5 - 4
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceApacheHttpImpl.java

@@ -65,7 +65,7 @@ public class WxPayServiceApacheHttpImpl extends BaseWxPayServiceImpl {
         httpPost.releaseConnection();
       }
     } catch (Exception e) {
-      this.logError( url, requestStr, e);
+      this.logError(url, requestStr, e);
       wxApiData.set(new WxPayApiData(url, requestStr, null, e.getMessage()));
       throw new WxPayException(e.getMessage(), e);
     }
@@ -170,8 +170,6 @@ public class WxPayServiceApacheHttpImpl extends BaseWxPayServiceImpl {
 
   @Override
   public String postV3(String url, HttpPost httpPost) throws WxPayException {
-    String serialNumber = getWechatPaySerial(getConfig());
-    httpPost.addHeader(WECHAT_PAY_SERIAL, serialNumber);
     return this.requestV3(url, httpPost);
   }
 
@@ -264,8 +262,11 @@ public class WxPayServiceApacheHttpImpl extends BaseWxPayServiceImpl {
 
   private void configureRequest(HttpRequestBase request) {
     String serialNumber = getWechatPaySerial(getConfig());
+    String method = request.getMethod();
     request.addHeader(ACCEPT, APPLICATION_JSON);
-    request.addHeader(CONTENT_TYPE, APPLICATION_JSON);
+    if (!method.equals("POST")) {
+      request.addHeader(CONTENT_TYPE, APPLICATION_JSON);
+    }
     request.addHeader(WECHAT_PAY_SERIAL, serialNumber);
 
     request.setConfig(RequestConfig.custom()