Skip to content

增加日志打印 #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

Merged
merged 1 commit into from
Apr 22, 2022
Merged

增加日志打印 #133

merged 1 commit into from
Apr 22, 2022

Conversation

lianup
Copy link
Contributor

@lianup lianup commented Apr 20, 2022

No description provided.

@lianup lianup changed the title 增加debug日志 增加日志打印 Apr 20, 2022
// 错误应答需要打日志
log.error("request header[{}]", Arrays.toString(request.getAllHeaders()));
HttpEntity entity = getRequestEntity(request);
if (entity != null && !isUploadHttpPost(request)) {
Copy link
Contributor

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(...)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好像没有其他地方用到,是否现在没有抽象成Util的必要

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是apache httpclient 本来就提供了 toString 方法……

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get,已改

@xy-peng
Copy link
Contributor

xy-peng commented Apr 21, 2022

@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()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

header → headers。
日志这里加上具体的错误信息,不只是给headers。

Copy link
Contributor Author

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"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

日志这里加上具体的错误信息,不只是给headers。

Copy link
Contributor Author

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 用英文描述。
  2. 加上什么上下文信息(什么情况下找不到)。
  3. 这应该是个error log,不是debug log?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

其他日志都用中文,这里用中文比较统一

@lianup lianup force-pushed the master branch 2 times, most recently from abb16bc to 0227fad Compare April 22, 2022 05:28
@lianup lianup merged commit 7a9ba38 into wechatpay-apiv3:master Apr 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants