8000 修复POST请求签名错误问题 by SynchPj · Pull Request #3586 · binarywang/WxJava · GitHub
[go: up one dir, main page]

Skip to content

修复POST请求签名错误问题 #3586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 14, 2025
Next Next commit
🎨 【微信支付】v3请求统一加上Wechatpay-Serial请求头
  • Loading branch information
SynchPj committed Apr 15, 2025
commit dfc685e0f9ef3c65b7cbf055d1786c8a3e885286
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class WxPayServiceApacheHttpImpl extends BaseWxPayServiceImpl {
private static final String ACCEPT = "Accept";
private static final String CONTENT_TYPE = "Content-Type";
private static final String APPLICATION_JSON = "application/json";
private static final String WECHATPAY_SERIAL = "Wechatpay-Serial";

@Override
public byte[] postForBytes(String url, String requestStr, boolean useKey) throws WxPayException {
Expand Down Expand Up @@ -101,7 +102,7 @@ public String postV3(String url, String requestStr) throws WxPayException {
httpPost.addHeader(ACCEPT, APPLICATION_JSON);
httpPost.addHeader(CONTENT_TYPE, APPLICATION_JSON);
String serialNumber = getWechatpaySerial(getConfig());
httpPost.addHeader("Wechatpay-Serial", serialNumber);
httpPost.addHeader(WECHATPAY_SERIAL, serialNumber);
try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
//v3已经改为通过状态码判断200 204 成功
int statusCode = response.getStatusLine().getStatusCode();
Expand Down Expand Up @@ -133,6 +134,8 @@ public String postV3(String url, String requestStr) throws WxPayException {
public String patchV3(String url, String requestStr) throws WxPayException {
CloseableHttpClient httpClient = this.createApiV3HttpClient();
HttpPatch httpPatch = new HttpPatch(url);
String serialNumber = getWechatpaySerial(getConfig());
httpPatch.addHeader(WECHATPAY_SERIAL, serialNumber);
httpPatch.setEntity(this.createEntry(requestStr));

httpPatch.setConfig(RequestConfig.custom()
Expand Down Expand Up @@ -204,6 +207,8 @@ public String postV3WithWechatpaySerial(String url, String requestStr) throws Wx

@Override
public String postV3(String url, HttpPost httpPost) throws WxPayException {
String serialNumber = getWechatpaySerial(getConfig());
httpPost.addHeader(WECHATPAY_SERIAL, serialNumber);
return this.requestV3(url, httpPost);
}

Expand Down Expand Up @@ -246,6 +251,8 @@ public String getV3(String url) throws WxPayException {
HttpGet httpGet = new HttpGet(url);
httpGet.addHeader(ACCEPT, APPLICATION_JSON);
httpGet.addHeader(CONTENT_TYPE, APPLICATION_JSON);
String serialNumber = getWechatpaySerial(getConfig());
httpGet.addHeader(WECHATPAY_SERIAL, serialNumber);
return this.requestV3(url, httpGet);
}

Expand All @@ -255,7 +262,7 @@ public String getV3WithWechatPaySerial(String url) throws WxPayException {
httpGet.addHeader(ACCEPT, APPLICATION_JSON);
httpGet.addHeader(CONTENT_TYPE, APPLICATION_JSON);
String serialNumber = getWechatpaySerial(getConfig());
httpGet.addHeader("Wechatpay-Serial", serialNumber);
httpGet.addHeader(WECHATPAY_SERIAL, serialNumber);
return this.requestV3(url, httpGet);
}

Expand All @@ -264,6 +271,8 @@ public InputStream downloadV3(String url) throws WxPayException {
CloseableHttpClient httpClient = this.createApiV3HttpClient();
HttpGet httpGet = new WxPayV3DownloadHttpGet(url);
httpGet.addHeader(ACCEPT, ContentType.WILDCARD.getMimeType());
String serialNumber = getWechatpaySerial(getConfig());
httpGet.addHeader(WECHATPAY_SERIAL, serialNumber);
try (CloseableHttpResponse response = httpClient.execute(httpGet)) {
//v3已经改为通过状态码判断200 204 成功
int statusCode = response.getStatusLine().getStatusCode();
Expand Down Expand Up @@ -295,6 +304,8 @@ public String putV3(String url, String requestStr) throws WxPayException {
httpPut.setEntity(entity);
httpPut.addHeader(ACCEPT, APPLICATION_JSON);
httpPut.addHeader(CONTENT_TYPE, APPLICATION_JSON);
String serialNumber = getWechatpaySerial(getConfig());
httpPut.addHeader(WECHATPAY_SERIAL, serialNumber);
return requestV3(url, httpPut);
}

Expand All @@ -303,6 +314,8 @@ public String deleteV3(String url) throws WxPayException {
HttpDelete httpDelete = new HttpDelete(url);
httpDelete.addHeader(ACCEPT, APPLICATION_JSON);
httpDelete.addHeader(CONTENT_TYPE, APPLICATION_JSON);
String serialNumber = getWechatpaySerial(getConfig());
httpDelete.addHeader(WECHATPAY_SERIAL, serialNumber);
return requestV3(url, httpDelete);
}

Expand Down
0