1
1
package com .github .binarywang .wxpay .service .impl ;
2
2
3
3
import 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 .*;
8
5
import com .github .binarywang .wxpay .config .WxPayConfig ;
9
6
import com .github .binarywang .wxpay .exception .WxPayException ;
10
7
import com .github .binarywang .wxpay .service .PartnerPayScoreService ;
@@ -41,22 +38,24 @@ public WxPartnerPayScoreResult permissions(WxPartnerPayScoreRequest request) thr
41
38
request .setAppid (request .getAppid ());
42
39
request .setServiceId (request .getServiceId ());
43
40
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 ());
47
43
}
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 ())) {
50
51
throw new WxPayException ("authorizationCode不允许为空" );
51
52
}
52
- request .setNotifyUrl (permissionNotifyUrl );
53
53
String result = this .payService .postV3 (url , request .toJson ());
54
54
return WxPartnerPayScoreResult .fromJson (result );
55
55
}
56
56
57
57
@ 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 {
60
59
if (StringUtils .isBlank (authorizationCode )) {
61
60
throw new WxPayException ("authorizationCode不允许为空" );
62
61
}
@@ -163,7 +162,15 @@ public WxPartnerPayScoreResult createServiceOrder(WxPartnerPayScoreRequest reque
163
162
String url = this .payService .getPayBaseUrl () + "/v3/payscore/partner/serviceorder" ;
164
163
165
164
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
+ }
167
174
String result = this .payService .postV3 (url , request .toJson ());
168
175
169
176
return WxPartnerPayScoreResult .fromJson (result );
@@ -229,10 +236,14 @@ public WxPartnerPayScoreResult modifyServiceOrder(WxPartnerPayScoreRequest reque
229
236
public void completeServiceOrder (WxPartnerPayScoreRequest request ) throws WxPayException {
230
237
String outOrderNo = request .getOutOrderNo ();
231
238
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
+ }
234
246
request .setOutOrderNo (null );
235
- request .setSubMchid (request .getSubMchid ());
236
247
this .payService .postV3 (url , request .toJson ());
237
248
}
238
249
@@ -254,7 +265,9 @@ public WxPartnerPayScoreResult payServiceOrder(String serviceId, String appId, S
254
265
public WxPartnerPayScoreResult syncServiceOrder (WxPartnerPayScoreRequest request ) throws WxPayException {
255
266
String outOrderNo = request .getOutOrderNo ();
256
267
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
+ }
258
271
request .setOutOrderNo (null );
259
272
String result = payService .postV3 (url , request .toJson ());
260
273
return WxPartnerPayScoreResult .fromJson (result );
@@ -284,7 +297,7 @@ public WxPartnerPayScoreResult queryServiceAccountState(String outApplyNo) throw
284
297
}
285
298
286
299
@ Override
287
- public UserAuthorizationStatusNotifyResult parseUserAuthorizationStatusNotifyResult (String notifyData , SignatureHeader header ) throws WxPayException {
300
+ public WxPartnerUserAuthorizationStatusNotifyResult parseUserAuthorizationStatusNotifyResult (String notifyData , SignatureHeader header ) throws WxPayException {
288
301
PayScoreNotifyData response = parseNotifyData (notifyData , header );
289
302
PayScoreNotifyData .Resource resource = response .getResource ();
290
303
String cipherText = resource .getCipherText ();
@@ -293,7 +306,7 @@ public UserAuthorizationStatusNotifyResult parseUserAuthorizationStatusNotifyRes
293
306
String apiV3Key = this .payService .getConfig ().getApiV3Key ();
294
307
try {
295
308
String result = AesUtils .decryptToString (associatedData , nonce , cipherText , apiV3Key );
296
- UserAuthorizationStatusNotifyResult notifyResult = GSON .fromJson (result , UserAuthorizationStatusNotifyResult .class );
309
+ WxPartnerUserAuthorizationStatusNotifyResult notifyResult = GSON .fromJson (result , WxPartnerUserAuthorizationStatusNotifyResult .class );
297
310
notifyResult .setRawData (response );
298
311
return notifyResult ;
299
312
} catch (GeneralSecurityException | IOException e ) {
0 commit comments