Skip to content

Commit dfc685e

Browse files
author
SynchPj
committed
🎨 【微信支付】v3请求统一加上Wechatpay-Serial请求头
1 parent 89280ab commit dfc685e

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public class WxPayServiceApacheHttpImpl extends BaseWxPayServiceImpl {
4444
private static final String ACCEPT = "Accept";
4545
private static final String CONTENT_TYPE = "Content-Type";
4646
private static final String APPLICATION_JSON = "application/json";
47+
private static final String WECHATPAY_SERIAL = "Wechatpay-Serial";
4748

4849
@Override
4950
public byte[] postForBytes(String url, String requestStr, boolean useKey) throws WxPayException {
@@ -101,7 +102,7 @@ public String postV3(String url, String requestStr) throws WxPayException {
101102
httpPost.addHeader(ACCEPT, APPLICATION_JSON);
102103
httpPost.addHeader(CONTENT_TYPE, APPLICATION_JSON);
103104
String serialNumber = getWechatpaySerial(getConfig());
104-
httpPost.addHeader("Wechatpay-Serial", serialNumber);
105+
httpPost.addHeader(WECHATPAY_SERIAL, serialNumber);
105106
try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
106107
//v3已经改为通过状态码判断200 204 成功
107108
int statusCode = response.getStatusLine().getStatusCode();
@@ -133,6 +134,8 @@ public String postV3(String url, String requestStr) throws WxPayException {
133134
public String patchV3(String url, String requestStr) throws WxPayException {
134135
CloseableHttpClient httpClient = this.createApiV3HttpClient();
135136
HttpPatch httpPatch = new HttpPatch(url);
137+
String serialNumber = getWechatpaySerial(getConfig());
138+
httpPatch.addHeader(WECHATPAY_SERIAL, serialNumber);
136139
httpPatch.setEntity(this.createEntry(requestStr));
137140

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

205208
@Override
206209
public String postV3(String url, HttpPost httpPost) throws WxPayException {
210+
String serialNumber = getWechatpaySerial(getConfig());
211+
httpPost.addHeader(WECHATPAY_SERIAL, serialNumber);
207212
return this.requestV3(url, httpPost);
208213
}
209214

@@ -246,6 +251,8 @@ public String getV3(String url) throws WxPayException {
246251
HttpGet httpGet = new HttpGet(url);
247252
httpGet.addHeader(ACCEPT, APPLICATION_JSON);
248253
httpGet.addHeader(CONTENT_TYPE, APPLICATION_JSON);
254+
String serialNumber = getWechatpaySerial(getConfig());
255+
httpGet.addHeader(WECHATPAY_SERIAL, serialNumber);
249256
return this.requestV3(url, httpGet);
250257
}
251258

@@ -255,7 +262,7 @@ public String getV3WithWechatPaySerial(String url) throws WxPayException {
255262
httpGet.addHeader(ACCEPT, APPLICATION_JSON);
256263
httpGet.addHeader(CONTENT_TYPE, APPLICATION_JSON);
257264
String serialNumber = getWechatpaySerial(getConfig());
258-
httpGet.addHeader("Wechatpay-Serial", serialNumber);
265+
httpGet.addHeader(WECHATPAY_SERIAL, serialNumber);
259266
return this.requestV3(url, httpGet);
260267
}
261268

@@ -264,6 +271,8 @@ public InputStream downloadV3(String url) throws WxPayException {
264271
CloseableHttpClient httpClient = this.createApiV3HttpClient();
265272
HttpGet httpGet = new WxPayV3DownloadHttpGet(url);
266273
httpGet.addHeader(ACCEPT, ContentType.WILDCARD.getMimeType());
274+
String serialNumber = getWechatpaySerial(getConfig());
275+
httpGet.addHeader(WECHATPAY_SERIAL, serialNumber);
267276
try (CloseableHttpResponse response = httpClient.execute(httpGet)) {
268277
//v3已经改为通过状态码判断200 204 成功
269278
int statusCode = response.getStatusLine().getStatusCode();
@@ -295,6 +304,8 @@ public String putV3(String url, String requestStr) throws WxPayException {
295304
httpPut.setEntity(entity);
296305
httpPut.addHeader(ACCEPT, APPLICATION_JSON);
297306
httpPut.addHeader(CONTENT_TYPE, APPLICATION_JSON);
307+
String serialNumber = getWechatpaySerial(getConfig());
308+
httpPut.addHeader(WECHATPAY_SERIAL, serialNumber);
298309
return requestV3(url, httpPut);
299310
}
300311

@@ -303,6 +314,8 @@ public String deleteV3(String url) throws WxPayException {
303314
HttpDelete httpDelete = new HttpDelete(url);
304315
httpDelete.addHeader(ACCEPT, APPLICATION_JSON);
305316
httpDelete.addHeader(CONTENT_TYPE, APPLICATION_JSON);
317+
String serialNumber = getWechatpaySerial(getConfig());
318+
httpDelete.addHeader(WECHATPAY_SERIAL, serialNumber);
306319
return requestV3(url, httpDelete);
307320
}
308321

0 commit comments

Comments
 (0)