Skip to content

微信服务商模式请求付款码V3接口状态码返回202,导致返回响应异常 #4050

Description

@wdmic

简要描述

微信服务商模式,付款码v3接口请求报错,状态码返回202,但是交易状态是USERPAYING,导致直接返回异常

模块版本情况

  • WxJava 模块名: weixin-java-pay
  • WxJava 版本号: 4.8.4.B

详细描述

微信服务商模式下,请求付款码V3接口,由于微信状态码返回202,交易状态为:USERPAYING,当前处于用户输入密码阶段。但是当前版本是通过状态码200或204判断成功的,导致直接返回异常了。

@OverRide
public String postV3WithWechatpaySerial(String url, String requestStr) throws WxPayException {
HttpPost httpPost = this.createHttpPost(url, requestStr);
this.configureRequest(httpPost);
CloseableHttpClient httpClient = this.createApiV3HttpClient();
try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
//v3已经改为通过状态码判断200 204 成功
int statusCode = response.getStatusLine().getStatusCode();
String responseString = "{}";
HttpEntity entity = response.getEntity();
if (entity != null) {
responseString = EntityUtils.toString(entity, StandardCharsets.UTF_8);
}
if (HttpStatus.SC_OK == statusCode || HttpStatus.SC_NO_CONTENT == statusCode) {
this.logRequestAndResponse(url, requestStr, responseString);
return responseString;
}
//有错误提示信息返回
JsonObject jsonObject = GsonParser.parse(responseString);
throw convertException(jsonObject);
} catch (Exception e) {
this.logError(url, requestStr, e);
throw (e instanceof WxPayException) ? (WxPayException) e : new WxPayException(e.getMessage(), e);
} finally {
httpPost.releaseConnection();
}
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions