GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — 微信支付付款码支付接口添加服务商模式支持 by Copilot · Pull Request #3686 · binarywang/WxJava Conversation
|
There was an error while loading. Please reload this page.
|
@copilot 请用中文改下描述文字,包括PR的标题 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
已将PR描述更新为中文。关于PR标题,由于工具限制无法直接修改,需要您手动将标题改为:「微信支付付款码支付接口添加服务商模式支持」 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
本 PR 为微信支付付款码支付接口添加服务商模式支持,解决了在服务商模式下缺少 sub_mch_id 参数导致的 "受理机构必须传入sub_mch_id" 错误(issue #3676)。
主要变更:
WxPayCodepayRequest 类中新增服务商模式所需的四个字段(sp_appid、sp_mchid、sub_appid、sub_mchid)BaseWxPayServiceImpl.codepay() 方法中实现模式自动检测逻辑,根据服务商字段是否存在来选择调用直连商户或服务商 API 端点Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayCodepayRequest.java | 添加服务商模式所需的四个字段(sp_appid、sp_mchid、sub_appid、sub_mchid),包含完整的中文文档注释 |
| weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java | 修改 codepay 方法实现,增加服务商模式检测逻辑,根据检测结果调用不同的 API 端点并自动填充配置字段 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| public WxPayCodepayResult codepay(WxPayCodepayRequest request) throws WxPayException { | ||
| if (StringUtils.isBlank(request.getAppid())) { | ||
| request.setAppid(this.getConfig().getAppId()); | ||
| } | ||
| if (StringUtils.isBlank(request.getMchid())) { | ||
| request.setMchid(this.getConfig().getMchId()); | ||
| // 判断是否为服务商模式:如果设置了sp_appid或sp_mchid或sub_mchid中的任何一个,则认为是服务商模式 | ||
| boolean isPartnerMode = StringUtils.isNotBlank(request.getSpAppid()) | ||
| || StringUtils.isNotBlank(request.getSpMchid()) | ||
| || StringUtils.isNotBlank(request.getSubMchid()); | ||
|
|
||
| if (isPartnerMode) { | ||
| // 服务商模式 | ||
| if (StringUtils.isBlank(request.getSpAppid())) { | ||
| request.setSpAppid(this.getConfig().getAppId()); | ||
| } | ||
| if (StringUtils.isBlank(request.getSpMchid())) { | ||
| request.setSpMchid(this.getConfig().getMchId()); | ||
| } | ||
| if (StringUtils.isBlank(request.getSubAppid())) { | ||
| request.setSubAppid(this.getConfig().getSubAppId()); | ||
| } | ||
| if (StringUtils.isBlank(request.getSubMchid())) { | ||
| request.setSubMchid(this.getConfig().getSubMchId()); | ||
| } | ||
| String url = String.format("%s/v3/pay/partner/transactions/codepay", this.getPayBaseUrl()); | ||
| String body = this.postV3WithWechatpaySerial(url, GSON.toJson(request)); | ||
| return GSON.fromJson(body, WxPayCodepayResult.class); | ||
| } else { | ||
| // 直连商户模式 | ||
| if (StringUtils.isBlank(request.getAppid())) { | ||
| request.setAppid(this.getConfig().getAppId()); | ||
| } | ||
| if (StringUtils.isBlank(request.getMchid())) { | ||
| request.setMchid(this.getConfig().getMchId()); | ||
| } | ||
| String url = String.format("%s/v3/pay/transactions/codepay", this.getPayBaseUrl()); | ||
| String body = this.postV3WithWechatpaySerial(url, GSON.toJson(request)); | ||
| return GSON.fromJson(body, WxPayCodepayResult.class); | ||
| } | ||
| String url = String.format("%s/v3/pay/transactions/codepay", this.getPayBaseUrl()); | ||
| String body = this.postV3WithWechatpaySerial(url, GSON.toJson(request)); | ||
| return GSON.fromJson(body, WxPayCodepayResult.class); | ||
| } |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
此实现偏离了项目中处理服务商模式的既定模式。现有的服务商模式实现(如 queryPartnerOrderV3、closePartnerOrderV3、unifiedPartnerOrderV3 等)使用单独的方法,而不是在同一方法中自动检测模式。建议考虑创建单独的 codepayPartner 方法以保持 API 设计的一致性,或者如果自动检测是有意的设计决策,请在代码注释中说明原因。
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| || StringUtils.isNotBlank(request.getSpMchid()) | ||
| || StringUtils.isNotBlank(request.getSubMchid()); | ||
|
|
||
| if (isPartnerMode) { | ||
| // 服务商模式 | ||
| if (StringUtils.isBlank(request.getSpAppid())) { | ||
| request.setSpAppid(this.getConfig().getAppId()); | ||
| } | ||
| if (StringUtils.isBlank(request.getSpMchid())) { | ||
| request.setSpMchid(this.getConfig().getMchId()); | ||
| } |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
如果字段名从 spMchid 更改为 spMchId 以保持一致性,此处的方法调用也需要相应更新为 request.getSpMchId() 和 request.setSpMchId()。
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| || StringUtils.isNotBlank(request.getSubMchid()); | ||
|
|
||
| if (isPartnerMode) { | ||
| // 服务商模式 | ||
| if (StringUtils.isBlank(request.getSpAppid())) { | ||
| request.setSpAppid(this.getConfig().getAppId()); | ||
| } | ||
| if (StringUtils.isBlank(request.getSpMchid())) { | ||
| request.setSpMchid(this.getConfig().getMchId()); | ||
| } | ||
| if (StringUtils.isBlank(request.getSubAppid())) { | ||
| request.setSubAppid(this.getConfig().getSubAppId()); | ||
| } | ||
| if (StringUtils.isBlank(request.getSubMchid())) { | ||
| request.setSubMchid(this.getConfig().getSubMchId()); | ||
| } |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
如果字段名从 subMchid 更改为 subMchId 以保持一致性,此处的方法调用也需要相应更新为 request.getSubMchId() 和 request.setSubMchId()。
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| * </pre> | ||
| */ | ||
| @SerializedName(value = "sp_mchid") | ||
| protected String spMchid; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
字段命名与现有的服务商请求类不一致。在 WxPayPartnerUnifiedOrderV3Request 中,对应字段命名为 spMchId(Id 的 'I' 大写),而此处使用 spMchid(全小写)。为保持代码库的一致性,建议将字段名改为 spMchId 以匹配现有模式。
| protected String spMchid; | |
| protected String spMchId; |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| * </pre> | ||
| */ | ||
| @SerializedName(value = "sub_mchid") | ||
| protected String subMchid; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
字段命名与现有的服务商请求类不一致。在 WxPayPartnerUnifiedOrderV3Request 中,对应字段命名为 subMchId(Id 的 'I' 大写),而此处使用 subMchid(全小写)。为保持代码库的一致性,建议将字段名改为 subMchId 以匹配现有模式。
| protected String subMchid; | |
| protected String subMchId; |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
微信支付在服务商模式下使用codepay接口时,会报缺少sub_mch_id参数错误
There was an error while loading. Please reload this page.