11package com .github .binarywang .wxpay .service .impl ;
22
33import com .github .binarywang .wxpay .bean .ecommerce .SignatureHeader ;
4- import com .github .binarywang .wxpay .bean .payscore .PayScoreNotifyData ;
5- import com .github .binarywang .wxpay .bean .payscore .UserAuthorizationStatusNotifyResult ;
6- import com .github .binarywang .wxpay .bean .payscore .WxPartnerPayScoreRequest ;
7- import com .github .binarywang .wxpay .bean .payscore .WxPartnerPayScoreResult ;
4+ import com .github .binarywang .wxpay .bean .payscore .*;
85import com .github .binarywang .wxpay .config .WxPayConfig ;
96import com .github .binarywang .wxpay .exception .WxPayException ;
107import com .github .binarywang .wxpay .service .PartnerPayScoreService ;
@@ -41,22 +38,24 @@ public WxPartnerPayScoreResult permissions(WxPartnerPayScoreRequest request) thr
4138 request .setAppid (request .getAppid ());
4239 request .setServiceId (request .getServiceId ());
4340 WxPayConfig config = this .payService .getConfig ();
44- String permissionNotifyUrl = config .getPayScorePermissionNotifyUrl ();
45- if (StringUtils .isBlank (permissionNotifyUrl )) {
46- throw new WxPayException ("授权回调地址未配置" );
41+ if (StringUtils .isBlank (request .getAppid ())){
42+ request .setAppid (config .getAppId ());
4743 }
48- String authorizationCode = request .getAuthorizationCode ();
49- if (StringUtils .isBlank (authorizationCode )) {
44+ if (StringUtils .isBlank ((request .getServiceId ()))){
45+ request .setServiceId (config .getServiceId ());
46+ }
47+ if (StringUtils .isBlank (request .getNotifyUrl ())) {
48+ request .setNotifyUrl (config .getPayScorePermissionNotifyUrl ());
49+ }
50+ if (StringUtils .isBlank (request .getAuthorizationCode ())) {
5051 throw new WxPayException ("authorizationCode不允许为空" );
5152 }
52- request .setNotifyUrl (permissionNotifyUrl );
5353 String result = this .payService .postV3 (url , request .toJson ());
5454 return WxPartnerPayScoreResult .fromJson (result );
5555 }
5656
5757 @ Override
58- public WxPartnerPayScoreResult permissionsQueryByAuthorizationCode (String serviceId , String subMchid , String authorizationCode )
59- throws WxPayException {
58+ public WxPartnerPayScoreResult permissionsQueryByAuthorizationCode (String serviceId , String subMchid , String authorizationCode ) throws WxPayException {
6059 if (StringUtils .isBlank (authorizationCode )) {
6160 throw new WxPayException ("authorizationCode不允许为空" );
6261 }
@@ -163,7 +162,15 @@ public WxPartnerPayScoreResult createServiceOrder(WxPartnerPayScoreRequest reque
163162 String url = this .payService .getPayBaseUrl () + "/v3/payscore/partner/serviceorder" ;
164163
165164 WxPayConfig config = this .payService .getConfig ();
166- request .setNotifyUrl (config .getPayScoreNotifyUrl ());
165+ if (StringUtils .isBlank (request .getAppid ())){
166+ request .setAppid (config .getAppId ());
167+ }
168+ if (StringUtils .isBlank ((request .getServiceId ()))){
169+ request .setServiceId (config .getServiceId ());
170+ }
171+ if (StringUtils .isBlank ((request .getNotifyUrl ()))){
172+ request .setNotifyUrl (config .getPayScoreNotifyUrl ());
173+ }
167174 String result = this .payService .postV3 (url , request .toJson ());
168175
169176 return WxPartnerPayScoreResult .fromJson (result );
@@ -229,10 +236,14 @@ public WxPartnerPayScoreResult modifyServiceOrder(WxPartnerPayScoreRequest reque
229236 public void completeServiceOrder (WxPartnerPayScoreRequest request ) throws WxPayException {
230237 String outOrderNo = request .getOutOrderNo ();
231238 String url = String .format ("%s/v3/payscore/partner/serviceorder/%s/complete" , this .payService .getPayBaseUrl (), outOrderNo );
232- request .setAppid (request .getAppid ());
233- request .setServiceId (request .getServiceId ());
239+ WxPayConfig config = this .payService .getConfig ();
240+ if (StringUtils .isBlank (request .getServiceId ())) {
241+ request .setServiceId (config .getServiceId ());
242+ }
243+ if (StringUtils .isBlank (request .getSubMchid ())) {
244+ request .setSubMchid (config .getSubMchId ());
245+ }
234246 request .setOutOrderNo (null );
235- request .setSubMchid (request .getSubMchid ());
236247 this .payService .postV3 (url , request .toJson ());
237248 }
238249
@@ -254,7 +265,9 @@ public WxPartnerPayScoreResult payServiceOrder(String serviceId, String appId, S
254265 public WxPartnerPayScoreResult syncServiceOrder (WxPartnerPayScoreRequest request ) throws WxPayException {
255266 String outOrderNo = request .getOutOrderNo ();
256267 String url = String .format ("%s/v3/payscore/partner/serviceorder/%s/sync" , this .payService .getPayBaseUrl (), outOrderNo );
257- request .setAppid (this .payService .getConfig ().getAppId ());
268+ if (StringUtils .isBlank (request .getAppid ())) {
269+ request .setAppid (this .payService .getConfig ().getAppId ());
270+ }
258271 request .setOutOrderNo (null );
259272 String result = payService .postV3 (url , request .toJson ());
260273 return WxPartnerPayScoreResult .fromJson (result );
@@ -284,7 +297,7 @@ public WxPartnerPayScoreResult queryServiceAccountState(String outApplyNo) throw
284297 }
285298
286299 @ Override
287- public UserAuthorizationStatusNotifyResult parseUserAuthorizationStatusNotifyResult (String notifyData , SignatureHeader header ) throws WxPayException {
300+ public WxPartnerUserAuthorizationStatusNotifyResult parseUserAuthorizationStatusNotifyResult (String notifyData , SignatureHeader header ) throws WxPayException {
288301 PayScoreNotifyData response = parseNotifyData (notifyData , header );
289302 PayScoreNotifyData .Resource resource = response .getResource ();
290303 String cipherText = resource .getCipherText ();
@@ -293,7 +306,7 @@ public UserAuthorizationStatusNotifyResult parseUserAuthorizationStatusNotifyRes
293306 String apiV3Key = this .payService .getConfig ().getApiV3Key ();
294307 try {
295308 String result = AesUtils .decryptToString (associatedData , nonce , cipherText , apiV3Key );
296- UserAuthorizationStatusNotifyResult notifyResult = GSON .fromJson (result , UserAuthorizationStatusNotifyResult .class );
309+ WxPartnerUserAuthorizationStatusNotifyResult notifyResult = GSON .fromJson (result , WxPartnerUserAuthorizationStatusNotifyResult .class );
297310 notifyResult .setRawData (response );
298311 return notifyResult ;
299312 } catch (GeneralSecurityException | IOException e ) {
0 commit comments