@@ -1201,15 +1201,40 @@ public WxPayMicropayResult micropay(WxPayMicropayRequest request) throws WxPayEx
12011201
12021202 @ Override
12031203 public WxPayCodepayResult codepay (WxPayCodepayRequest request ) throws WxPayException {
1204- if (StringUtils .isBlank (request .getAppid ())) {
1205- request .setAppid (this .getConfig ().getAppId ());
1206- }
1207- if (StringUtils .isBlank (request .getMchid ())) {
1208- request .setMchid (this .getConfig ().getMchId ());
1204+ // 判断是否为服务商模式:如果设置了sp_appid或sp_mchid或sub_mchid中的任何一个,则认为是服务商模式
1205+ boolean isPartnerMode = StringUtils .isNotBlank (request .getSpAppid ())
1206+ || StringUtils .isNotBlank (request .getSpMchid ())
1207+ || StringUtils .isNotBlank (request .getSubMchid ());
1208+
1209+ if (isPartnerMode ) {
1210+ // 服务商模式
1211+ if (StringUtils .isBlank (request .getSpAppid ())) {
1212+ request .setSpAppid (this .getConfig ().getAppId ());
1213+ }
1214+ if (StringUtils .isBlank (request .getSpMchid ())) {
1215+ request .setSpMchid (this .getConfig ().getMchId ());
1216+ }
1217+ if (StringUtils .isBlank (request .getSubAppid ())) {
1218+ request .setSubAppid (this .getConfig ().getSubAppId ());
1219+ }
1220+ if (StringUtils .isBlank (request .getSubMchid ())) {
1221+ request .setSubMchid (this .getConfig ().getSubMchId ());
1222+ }
1223+ String url = String .format ("%s/v3/pay/partner/transactions/codepay" , this .getPayBaseUrl ());
1224+ String body = this .postV3WithWechatpaySerial (url , GSON .toJson (request ));
1225+ return GSON .fromJson (body , WxPayCodepayResult .class );
1226+ } else {
1227+ // 直连商户模式
1228+ if (StringUtils .isBlank (request .getAppid ())) {
1229+ request .setAppid (this .getConfig ().getAppId ());
1230+ }
1231+ if (StringUtils .isBlank (request .getMchid ())) {
1232+ request .setMchid (this .getConfig ().getMchId ());
1233+ }
1234+ String url = String .format ("%s/v3/pay/transactions/codepay" , this .getPayBaseUrl ());
1235+ String body = this .postV3WithWechatpaySerial (url , GSON .toJson (request ));
1236+ return GSON .fromJson (body , WxPayCodepayResult .class );
12091237 }
1210- String url = String .format ("%s/v3/pay/transactions/codepay" , this .getPayBaseUrl ());
1211- String body = this .postV3WithWechatpaySerial (url , GSON .toJson (request ));
1212- return GSON .fromJson (body , WxPayCodepayResult .class );
12131238 }
12141239
12151240 @ Override
0 commit comments