Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 31, 2025

The current WxPayCodepayRequest class only supports direct merchant mode but lacks support for service provider mode, which requires the sub_mch_id parameter. When using the codepay interface in service provider mode, users encounter the error:

受理机构必须传入sub_mch_id

This PR adds service provider mode support by:

  1. Adding service provider fields to WxPayCodepayRequest:

    • sp_appid - Service provider application ID
    • sp_mchid - Service provider merchant ID
    • sub_appid - Sub-merchant application ID
    • sub_mchid - Sub-merchant ID (the key field that was missing)
  2. Updating the service implementation to handle both modes:

    • Auto-detects service provider mode when any of sp_appid, sp_mchid, or sub_mchid is set
    • Uses partner API endpoint /v3/pay/partner/transactions/codepay for service provider mode
    • Uses direct API endpoint /v3/pay/transactions/codepay for direct merchant mode
    • Automatically fills missing fields from WxPayConfig

The implementation maintains backward compatibility - existing direct merchant mode usage continues to work unchanged. The new service provider mode can be used like this:

WxPayCodepayRequest request = new WxPayCodepayRequest();
request.setSpMchid("17085xxxxx");
request.setSubMchid("1230000109");  // This was the missing field causing the error
request.setDescription("订单支付");
request.setOutTradeNo("1234567890");
// ... other fields

WxPayCodepayResult result = wxPayService.codepay(request);

Fixes #3676.


💡 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.

Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] 微信支付在服务商模式下使用codepay接口时,会报缺少sub_mch_id参数错误 Add service provider mode support for WeChat Pay codepay interface Aug 31, 2025
@Copilot Copilot AI requested a review from binarywang August 31, 2025 14:59
Copilot finished work on behalf of binarywang August 31, 2025 14:59
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.

微信支付在服务商模式下使用codepay接口时,会报缺少sub_mch_id参数错误
2 participants