Browse Source

微信支付接口增加日志

master
Binary Wang 8 years ago
parent
commit
4fa672d46c
2 changed files with 14 additions and 5 deletions
  1. +13
    -4
      weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java
  2. +1
    -1
      weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java

+ 13
- 4
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java View File

@@ -25,6 +25,8 @@ import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContexts;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.net.ssl.SSLContext;
import java.io.File;
@@ -40,6 +42,8 @@ import java.util.*;
*/
public class WxMpPayServiceImpl implements WxMpPayService {

protected final Logger log = LoggerFactory.getLogger(this.getClass());

private static final String PAY_BASE_URL = "https://api.mch.weixin.qq.com";
private static final String[] TRADE_TYPES = new String[]{"JSAPI","NATIVE", "APP"};
private static final String[] REFUND_ACCOUNT = new String[]{"REFUND_SOURCE_RECHARGE_FUNDS",
@@ -269,7 +273,7 @@ public class WxMpPayServiceImpl implements WxMpPayService {
String responseContent = this.executeRequest(url, xstream.toXML(request));
WxPayUnifiedOrderResult result = (WxPayUnifiedOrderResult) xstream
.fromXML(responseContent);
if ("FAIL".equals(result.getResultCode())) {
if ("FAIL".equals(result.getResultCode()) || "FAIL".equals(result.getReturnCode())) {
throw new WxErrorException(WxError.newBuilder()
.setErrorMsg(result.getErrCode() + ":" + result.getErrCodeDes())
.build());
@@ -390,9 +394,12 @@ public class WxMpPayServiceImpl implements WxMpPayService {
httpPost.setEntity(new StringEntity(new String(requestStr.getBytes("UTF-8"), "ISO-8859-1")));

try (CloseableHttpResponse response = httpclient.execute(httpPost)) {
return EntityUtils.toString(response.getEntity(), Consts.UTF_8);
String result = EntityUtils.toString(response.getEntity(), Consts.UTF_8);
this.log.debug("\n[URL]: {}\n[PARAMS]: {}\n[RESPONSE]: {}",url, requestStr, result);
return result;
}
} catch (IOException e) {
this.log.error("\n[URL]: {}\n[PARAMS]: {}\n[EXCEPTION]: {}", url, requestStr, e.getMessage());
throw new WxErrorException(WxError.newBuilder().setErrorMsg(e.getMessage()).build(), e);
}finally {
httpPost.releaseConnection();
@@ -400,7 +407,6 @@ public class WxMpPayServiceImpl implements WxMpPayService {
}

private String executeRequestWithKeyFile( String url, File keyFile, String requestStr, String mchId) throws WxErrorException {

try (FileInputStream inputStream = new FileInputStream(keyFile)) {
KeyStore keyStore = KeyStore.getInstance("PKCS12");
keyStore.load(inputStream, mchId.toCharArray());
@@ -417,12 +423,15 @@ public class WxMpPayServiceImpl implements WxMpPayService {
try (CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build()) {
httpPost.setEntity(new StringEntity(new String(requestStr.getBytes("UTF-8"), "ISO-8859-1")));
try (CloseableHttpResponse response = httpclient.execute(httpPost)) {
return EntityUtils.toString(response.getEntity(), Consts.UTF_8);
String result = EntityUtils.toString(response.getEntity(), Consts.UTF_8);
this.log.debug("\n[URL]: {}\n[PARAMS]: {}\n[RESPONSE]: {}",url, requestStr, result);
return result;
}
}finally {
httpPost.releaseConnection();
}
} catch (Exception e) {
this.log.error("\n[URL]: {}\n[PARAMS]: {}\n[EXCEPTION]: {}", url, requestStr, e.getMessage());
throw new WxErrorException(WxError.newBuilder().setErrorMsg(e.getMessage()).build(), e);
}
}


+ 1
- 1
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java View File

@@ -33,7 +33,7 @@ public class WxMpServiceImpl implements WxMpService {

private static final JsonParser JSON_PARSER = new JsonParser();

protected final Logger log = LoggerFactory.getLogger(WxMpServiceImpl.class);
protected final Logger log = LoggerFactory.getLogger(this.getClass());

/**
* 全局的是否正在刷新access token的锁


Loading…
Cancel
Save