Skip to content

Conversation

@lianup
Copy link
Contributor

@lianup lianup commented Jan 19, 2022

No description provided.

throw new IllegalArgumentException("serialNumber为空");
}
if (message == null || message.length == 0) {
throw new IllegalArgumentException("message为空");
Copy link
Contributor

Choose a reason for hiding this comment

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

这种都是实时的外部不可控输入,不应该用IllegalArgumentException这样的 RuntimeException 的,而是 ValidationException 的。切记不能因为外部输入导致程序直接异常呀。

Copy link
Contributor

Choose a reason for hiding this comment

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

另外,如果只能从 builder 构造,参数检查不是做过一遍了吗?很多参数都是自己可控的,难道你是想别人扩展NotifyHandler 吗

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已修改参数校验

@@ -0,0 +1,75 @@
package com.wechat.pay.contrib.apache.httpclient.auth;
Copy link
Contributor

Choose a reason for hiding this comment

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

感觉不应该放在 auth 下,只是 auth 的一个应用场景 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

可以新建notify,放到notify下

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已修改

/**
* @author lianup
*/
public class WechatPayNotifyHandler {
Copy link
Contributor

Choose a reason for hiding this comment

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

名字要加 wechatpay 前缀吗,除了最外层的 builder 其他地方都没加呢

Copy link
Contributor

Choose a reason for hiding this comment

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

我觉得应该叫做 NotificationHandler

Copy link
Contributor Author

Choose a reason for hiding this comment

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

移动到notify,前缀可去掉

Copy link
Contributor

Choose a reason for hiding this comment

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

用名词notification

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this.verifyMessage = verifyMessage;
this.body = body;
// 获取请求体需要信息
parseBody();
Copy link
Contributor

Choose a reason for hiding this comment

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

先验签再解析吧,只有是微信支付的回调,才有解析的意义

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已修改

/**
* @author lianup
*/
public class WechatPayNotifyRequest {
Copy link
Contributor

Choose a reason for hiding this comment

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

我担心这样直接暴露实现给开发者,不利于未来的扩展,就像图片上传一样。而是提供 interface,interface只包含验签所需要的字段,即

  • serialno
  • message
  • signature

而没有timestampnonce

再针对接口提供实现会更好。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

可以修改为:

  1. 增加Request接口,包括getSerialNumber()、getMessage()、getSignature()方法。
  2. 增加NotifyRequest类,实现Request接口。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

1还可以增加getBody()方法,也属于request的一部分。

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 569e513 to e502cdf Compare January 20, 2022 08:00
Copy link
Contributor

@xy-peng xy-peng left a comment

Choose a reason for hiding this comment

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

配套的readme呢?

getAssociatedData, new String(bodyNonce), ciphertext);
throw new DecryptionException(errorMessage, e);
}
return data;
Copy link
Contributor

Choose a reason for hiding this comment

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

这里返回一个完整的回调结构体,而不仅仅是加密的部分吧。还有id/type/summary等等对商户可能有价值信息。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

可以返回一个parseResult,包括id、create_time、event_type、data(解密后的数据)、summary。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已添加

package com.wechat.pay.contrib.apache.httpclient.notification;

/**
* @author lianup
Copy link
Contributor

Choose a reason for hiding this comment

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

对外接口加一些注释?

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
Copy link
Contributor Author

lianup commented Jan 20, 2022

配套的readme呢?

打算在bump version时添加

@lianup lianup force-pushed the master branch 4 times, most recently from d2e41a5 to 04e2e82 Compare January 21, 2022 04:34
}

@Override
public String toString() {
Copy link
Contributor

Choose a reason for hiding this comment

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

使用 ObjectMapper 来代替手写?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

此处用到toString的地方为拼接错误信息,在错误中抛出,商户测试和使用时也可以直接用toString打印。

private String decryptData;

@Override
public String toString() {
Copy link
Contributor

Choose a reason for hiding this comment

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

使用 ObjectMapper 来代替手写?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

此处用到toString的地方为拼接错误信息,在错误中抛出,商户测试和使用时也可以直接用toString打印。

try {
decryptData = aesUtil.decryptToString(associatedData, bodyNonce, ciphertext);
} catch (GeneralSecurityException e) {
String errorMessage = String.format("aes解密失败 apiV3Key[%s], associatedData[%s] bodyNonce[%s] ciphertext[%s]",
Copy link
Contributor

Choose a reason for hiding this comment

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

Resource也有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.

已修改。

@lianup lianup force-pushed the master branch 2 times, most recently from 2fbcd18 to 72fbae1 Compare January 21, 2022 10:06
@lianup lianup merged commit c5d89c7 into wechatpay-apiv3:master Jan 23, 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.

建议直接在sdk中封装一个对微信支付请求的验签(直接封装进行就不用用户自己封装了)

4 participants