WxJava
WxJava copied to clipboard
Add service provider mode support for WeChat Pay codepay interface
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:
-
Adding service provider fields to
WxPayCodepayRequest:sp_appid- Service provider application IDsp_mchid- Service provider merchant IDsub_appid- Sub-merchant application IDsub_mchid- Sub-merchant ID (the key field that was missing)
-
Updating the service implementation to handle both modes:
- Auto-detects service provider mode when any of
sp_appid,sp_mchid, orsub_mchidis set - Uses partner API endpoint
/v3/pay/partner/transactions/codepayfor service provider mode - Uses direct API endpoint
/v3/pay/transactions/codepayfor direct merchant mode - Automatically fills missing fields from
WxPayConfig
- Auto-detects service provider mode when any of
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.