-
Notifications
You must be signed in to change notification settings - Fork 254
增加日志打印 #133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
增加日志打印 #133
Conversation
src/main/java/com/wechat/pay/contrib/apache/httpclient/auth/CertificatesVerifier.java
Outdated
Show resolved
Hide resolved
src/main/java/com/wechat/pay/contrib/apache/httpclient/WechatPayUploadHttpPost.java
Outdated
Show resolved
Hide resolved
src/main/java/com/wechat/pay/contrib/apache/httpclient/SignatureExec.java
Outdated
Show resolved
Hide resolved
// 错误应答需要打日志 | ||
log.error("request header[{}]", Arrays.toString(request.getAllHeaders())); | ||
HttpEntity entity = getRequestEntity(request); | ||
if (entity != null && !isUploadHttpPost(request)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if isEntityEnclosing && !isUploadHttpPost {
entity = request.getentity()
EntityUtils.toString(entity)
log.error(...)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好像没有其他地方用到,是否现在没有抽象成Util的必要
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是apache httpclient 本来就提供了 toString 方法……
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get,已改
@lianup 顺便修复下README-开始的 typo 吧 import com.wechat.pay.contrib.apache.httpclient.WechatPayHttpClientBuilder;
//...
WechatPayHttpClientBuilder builder = WechatPayHttpClientBuilder.create()
.withMerchant(merchantId, merchantSerialNumber, merchantPrivateKey)
.withWechatPay(wechatpayCertificates);
// ... 接下来,你仍然可以通过builder设置各种参数,来配置你的HttpClient
// 通过WechatPayHttpClientBuilder构造的HttpClient,会自动的处理签名和验签
CloseableHttpClient httpClient = builder.build();
// 后面跟使用Apache HttpClient一样
ClosableHttpResponse response = httpClient.execute(...);
^^^
CloseableHttpClient,少了个e |
// 对成功应答验签 | ||
StatusLine statusLine = response.getStatusLine(); | ||
if (statusLine.getStatusCode() >= SC_OK && statusLine.getStatusCode() < SC_MULTIPLE_CHOICES) { | ||
convertToRepeatableResponseEntity(response); | ||
if (!validator.validate(response)) { | ||
throw new HttpException("应答的微信支付签名验证失败"); | ||
} | ||
} else { | ||
// 错误应答需要打日志 | ||
log.error("request header[{}]", Arrays.toString(request.getAllHeaders())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
header → headers。
日志这里加上具体的错误信息,不只是给headers。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已改
HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity(); | ||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); | ||
entity.writeTo(outputStream); | ||
log.error("request body[{}]", outputStream.toString("UTF-8")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
日志这里加上具体的错误信息,不只是给headers。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已改
@@ -57,7 +60,11 @@ protected boolean verify(X509Certificate certificate, byte[] message, String sig | |||
public boolean verify(String serialNumber, byte[] message, String signature) { | |||
BigInteger val = new BigInteger(serialNumber, 16); | |||
X509Certificate cert = certificates.get(val); | |||
return cert != null && verify(cert, message, signature); | |||
if (cert == null) { | |||
log.debug("找不到证书序列号对应的证书,序列号:{}", serialNumber); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 用英文描述。
- 加上什么上下文信息(什么情况下找不到)。
- 这应该是个error log,不是debug log?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
其他日志都用中文,这里用中文比较统一
abb16bc
to
0227fad
Compare
No description provided.