@@ -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
@@ -249,6 +254,8 @@ public String getV3(String url) throws WxPayException {
249254 HttpGet httpGet = new HttpGet (url );
250255 httpGet .addHeader (ACCEPT , APPLICATION_JSON );
251256 httpGet .addHeader (CONTENT_TYPE , APPLICATION_JSON );
257+ String serialNumber = getWechatpaySerial (getConfig ());
258+ httpGet .addHeader (WECHATPAY_SERIAL , serialNumber );
252259 return this .requestV3 (url , httpGet );
253260 }
254261
@@ -258,7 +265,7 @@ public String getV3WithWechatPaySerial(String url) throws WxPayException {
258265 httpGet .addHeader (ACCEPT , APPLICATION_JSON );
259266 httpGet .addHeader (CONTENT_TYPE , APPLICATION_JSON );
260267 String serialNumber = getWechatpaySerial (getConfig ());
261- httpGet .addHeader ("Wechatpay-Serial" , serialNumber );
268+ httpGet .addHeader (WECHATPAY_SERIAL , serialNumber );
262269 return this .requestV3 (url , httpGet );
263270 }
264271
@@ -267,6 +274,8 @@ public InputStream downloadV3(String url) throws WxPayException {
267274 CloseableHttpClient httpClient = this .createApiV3HttpClient ();
268275 HttpGet httpGet = new WxPayV3DownloadHttpGet (url );
269276 httpGet .addHeader (ACCEPT , ContentType .WILDCARD .getMimeType ());
277+ String serialNumber = getWechatpaySerial (getConfig ());
278+ httpGet .addHeader (WECHATPAY_SERIAL , serialNumber );
270279 try (CloseableHttpResponse response = httpClient .execute (httpGet )) {
271280 //v3已经改为通过状态码判断200 204 成功
272281 int statusCode = response .getStatusLine ().getStatusCode ();
@@ -298,6 +307,8 @@ public String putV3(String url, String requestStr) throws WxPayException {
298307 httpPut .setEntity (entity );
299308 httpPut .addHeader (ACCEPT , APPLICATION_JSON );
300309 httpPut .addHeader (CONTENT_TYPE , APPLICATION_JSON );
310+ String serialNumber = getWechatpaySerial (getConfig ());
311+ httpPut .addHeader (WECHATPAY_SERIAL , serialNumber );
301312 return requestV3 (url , httpPut );
302313 }
303314
@@ -306,6 +317,8 @@ public String deleteV3(String url) throws WxPayException {
306317 HttpDelete httpDelete = new HttpDelete (url );
307318 httpDelete .addHeader (ACCEPT , APPLICATION_JSON );
308319 httpDelete .addHeader (CONTENT_TYPE , APPLICATION_JSON );
320+ String serialNumber = getWechatpaySerial (getConfig ());
321+ httpDelete .addHeader (WECHATPAY_SERIAL , serialNumber );
309322 return requestV3 (url , httpDelete );
310323 }
311324
0 commit comments