Skip to content

修复V3新商户完全公钥模式下publicKey为空的问题#3775

Merged
binarywang merged 3 commits into
developfrom
copilot/fix-public-key-issue
Nov 28, 2025
Merged

修复V3新商户完全公钥模式下publicKey为空的问题#3775
binarywang merged 3 commits into
developfrom
copilot/fix-public-key-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Nov 28, 2025

V3新商户使用完全公钥模式(fullPublicKeyModel=true)时,若只配置了 publicKeyId 而未配置公钥文件,publicKey 会是 null,导致验证器初始化失败且无明确错误提示。

修改内容

  • WxPayConfig.initApiV3HttpClient() 的完全公钥模式分支增加 null 检查,配置缺失时抛出明确异常
if (this.fullPublicKeyModel) {
  if (publicKey == null) {
    throw new WxPayException("完全公钥模式下,请确保公钥配置(publicKeyPath/publicKeyString/publicKeyContent)及publicKeyId已设置");
  }
  certificatesVerifier = VerifierBuilder.buildPublicCertVerifier(this.publicKeyId, publicKey);
}

正确配置示例

payConfig.setFullPublicKeyModel(true);
payConfig.setPublicKeyId("YOUR_PUBLIC_KEY_ID");
payConfig.setPublicKeyPath("/path/to/pub_key.pem");  // 必须配置公钥文件
Original prompt

This section details on the original issue you should resolve

<issue_title>v3新商户,只有公钥。没有公钥证书,会导致publicKey为空。</issue_title>
<issue_description>Image

这是我的config

@bean
@ConditionalOnMissingBean
public WxPayService wxService() {
WxPayConfig payConfig = new WxPayConfig();
payConfig.setAppId(StringUtils.trimToNull(this.properties.getAppId()));//V3商户模式需要
payConfig.setMchId(StringUtils.trimToNull(this.properties.getMchId()));//V3商户模式需要
payConfig.setMchKey(StringUtils.trimToNull(this.properties.getMchKey()));
payConfig.setKeyPath(StringUtils.trimToNull(this.properties.getKeyPath()));
payConfig.setApiV3Key(StringUtils.trimToNull(this.properties.getApiV3Key()));//V3商户模式需要
payConfig.setCertSerialNo(StringUtils.trimToNull(this.properties.getCertSerialNo()));//V3商户模式需要
payConfig.setPrivateCertPath(StringUtils.trimToNull(this.properties.getPrivateCertPath()));//V3商户模式需要
payConfig.setPrivateKeyPath(StringUtils.trimToNull(this.properties.getPrivateKeyPath()));//V3商户模式需要
payConfig.setPublicKeyId(StringUtils.trimToNull(this.properties.getPublicKeyId()));//V3商户模式需要

payConfig.setFullPublicKeyModel(true);
payConfig.setStrictlyNeedWechatPaySerial(true);


WxPayService wxPayService = new WxPayServiceImpl();
wxPayService.setConfig(payConfig);
return wxPayService;

}</issue_description>

Comments on the Issue (you are @copilot in this section)

Custom agent used: 自定义的
需要用中文


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits November 28, 2025 02:05
Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix publicKey not set for v3 merchants without certificate 修复V3新商户完全公钥模式下publicKey为空的问题 Nov 28, 2025
Copilot AI requested a review from binarywang November 28, 2025 02:08
@binarywang binarywang marked this pull request as ready for review November 28, 2025 03:20
@binarywang binarywang merged commit f6d9e8b into develop Nov 28, 2025
1 check passed
@binarywang binarywang deleted the copilot/fix-public-key-issue branch November 28, 2025 03:20
@binarywang binarywang added this to the 4.7.9 milestone Nov 28, 2025
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.

v3新商户,只有公钥。没有公钥证书,会导致publicKey为空。

2 participants