Repository navigation
支持微信支付 V3 SM2/SM3 签名与验签 - #4151
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bae282bbce
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
🟡 Changes recommended
Signature types are not propagated through the certificate wrapper and notification verification paths, causing valid SM2 signatures to be incorrectly verified as RSA and fail.
2 open issues
What changed in this PR
本 PR 为 WxJava 微信支付 V3 的请求签名和响应验签增加 SM2/SM3 支持,对应 #4141,并保留现有 RSA 行为。
变更:
- 新增统一签名算法工具,支持 SM2/SM3、指定用户 ID 和动态认证类型。
- 根据响应签名类型选择验签算法,并扩展 PEM 工具以解析 EC 密钥。
- 新增 SM2 签名、验签、密钥解析及 RSA 兼容性测试,并注册到 TestNG 套件。
验证范围:已静态核查相关差异和调用链,未执行构建或测试。
| File | Description |
|---|---|
weixin-java-pay/src/test/resources/testng.xml |
注册新增 SM2 测试类。 |
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/v3/auth/Sm2SignatureTest.java |
覆盖 SM2 功能及 RSA 兼容性。 |
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/v3/util/PemUtils.java |
增加 EC 私钥和公钥解析。 |
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/v3/auth/WxPayValidator.java |
读取并校验响应签名类型,传入验证器。 |
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/v3/auth/WxPayCredentials.java |
从签名器获取认证类型。 |
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/v3/auth/WechatPaySignature.java |
集中创建 RSA、SM2 签名对象并设置用户 ID。 |
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/v3/auth/Verifier.java |
增加带签名类型的验签重载。 |
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/v3/auth/Signer.java |
增加默认 RSA 认证类型接口。 |
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/v3/auth/PublicCertificateVerifier.java |
支持按指定算法进行公钥验签和证书委托。 |
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/v3/auth/PrivateKeySigner.java |
根据私钥类型选择签名算法和认证类型。 |
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/v3/auth/CertificatesVerifier.java |
增加按指定算法进行证书验签的路径。 |
Review effort: Balanced
|
|
||
| @Override | ||
| public boolean verify(String serialNumber, byte[] message, String signature) { | ||
| return verify(serialNumber, message, signature, WechatPaySignature.RSA_TYPE); |
Keep RSA defaults and add regression coverage for certificate verification. Document the preloaded SM2 platform certificate path tested offline. Refs #4151.
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Keep RSA defaults and add regression coverage for certificate verification. Document the preloaded SM2 platform certificate path tested offline. Refs #4151.
生产代码使用 bcprov,证书构造依赖仅用于测试。保留 RSA 旧验签分派,校验 SM2 曲线参数,并补充回归测试。Java 8 下 40 项定向测试通过。
06269cf to
11b19d9
Compare

微信支付 API v3 增加国密签名支持,按官方规则使用 SM2-with-SM3、指定用户 ID,并通过
Wechatpay-Signature-Type区分响应签名算法。WECHATPAY2-SM2-WITH-SM3;RSA 签名保持原有行为。