Skip to content
Prev Previous commit
Next Next commit
Merge remote-tracking branch 'origin/develop' into develop
# Conflicts:
#	weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceApacheHttpImpl.java
  • Loading branch information
SynchPj committed May 12, 2025
commit cee794bd70dfd22c092efd0db078212d4109fe5d
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,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";
private static final String WECHAT_PAY_SERIAL = "Wechatpay-Serial";

@Override
public byte[] postForBytes(String url, String requestStr, boolean useKey) throws WxPayException {
Expand Down Expand Up @@ -100,11 +100,13 @@ public String post(String url, String requestStr, boolean useKey) throws WxPayEx
@Override
public String postV3(String url, String requestStr) throws WxPayException {
HttpPost httpPost = this.createHttpPost(url, requestStr);
httpPost.addHeader(ACCEPT, APPLICATION_JSON);
httpPost.addHeader(CONTENT_TYPE, APPLICATION_JSON);
String serialNumber = getWechatpaySerial(getConfig());
httpPost.addHeader(WECHATPAY_SERIAL, serialNumber);
try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
this.configureRequest(httpPost);
return this.requestV3(url, requestStr, httpPost);
}

private String requestV3(String url, String requestStr, HttpRequestBase httpRequestBase) throws WxPayException {
try (CloseableHttpClient httpClient = this.createApiV3HttpClient();
CloseableHttpResponse response = httpClient.execute(httpRequestBase)) {
//v3已经改为通过状态码判断200 204 成功
int statusCode = response.getStatusLine().getStatusCode();
//post方法有可能会没有返回值的情况
Expand Down Expand Up @@ -132,8 +134,6 @@ public String postV3(String url, String requestStr) throws WxPayException {
@Override
public String patchV3(String url, String requestStr) throws WxPayException {
HttpPatch httpPatch = new HttpPatch(url);
String serialNumber = getWechatpaySerial(getConfig());
httpPatch.addHeader(WECHATPAY_SERIAL, serialNumber);
httpPatch.setEntity(this.createEntry(requestStr));
return this.requestV3(url, requestStr, httpPatch);
}
Expand Down Expand Up @@ -170,8 +170,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);
String serialNumber = getWechatPaySerial(getConfig());
httpPost.addHeader(WECHAT_PAY_SERIAL, serialNumber);
return this.requestV3(url, httpPost);
}

Expand Down Expand Up @@ -211,30 +211,23 @@ public String getV3(String url) throws WxPayException {
return getV3WithWechatPaySerial(url);
}
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);
}

@Override
public String getV3WithWechatPaySerial(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);
}

@Override
public InputStream downloadV3(String url) throws WxPayException {
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)) {
String serialNumber = getWechatPaySerial(getConfig());
httpGet.addHeader(WECHAT_PAY_SERIAL, serialNumber);
try (CloseableHttpClient httpClient = this.createApiV3HttpClient();
CloseableHttpResponse response = httpClient.execute(httpGet)) {
//v3已经改为通过状态码判断200 204 成功
int statusCode = response.getStatusLine().getStatusCode();
Header contentType = response.getFirstHeader(HttpHeaders.CONTENT_TYPE);
Expand Down Expand Up @@ -263,20 +256,12 @@ public String putV3(String url, String requestStr) throws WxPayException {
HttpPut httpPut = new HttpPut(url);
StringEntity entity = this.createEntry(requestStr);
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);
}

@Override
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
You are viewing a condensed version of this merge commit. You can view the full changes here.