Skip to content

Commit 6fb083a

Browse files
authored
🎨 【微信支付】支付分请求接口代码优化
1 parent bb9a185 commit 6fb083a

1 file changed

Lines changed: 40 additions & 15 deletions

File tree

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/PayScoreServiceImpl.java

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.github.binarywang.wxpay.service.PayScoreService;
1111
import com.github.binarywang.wxpay.service.WxPayService;
1212
import com.github.binarywang.wxpay.v3.util.AesUtils;
13+
import com.google.common.base.Strings;
1314
import com.google.gson.Gson;
1415
import com.google.gson.GsonBuilder;
1516
import lombok.RequiredArgsConstructor;
@@ -38,17 +39,23 @@ public class PayScoreServiceImpl implements PayScoreService {
3839
public WxPayScoreResult permissions(WxPayScoreRequest request) throws WxPayException {
3940
WxPayConfig config = this.payService.getConfig();
4041
String url = this.payService.getPayBaseUrl() + "/v3/payscore/permissions";
41-
request.setAppid(config.getAppId());
42-
request.setServiceId(config.getServiceId());
43-
String permissionNotifyUrl = config.getPayScorePermissionNotifyUrl();
44-
if (StringUtils.isBlank(permissionNotifyUrl)) {
45-
throw new WxPayException("授权回调地址未配置");
42+
if(Strings.isNullOrEmpty(request.getAppid())){
43+
request.setAppid(config.getAppId());
44+
}
45+
if(Strings.isNullOrEmpty(request.getServiceId())){
46+
request.setServiceId(config.getServiceId());
47+
}
48+
if(Strings.isNullOrEmpty(request.getNotifyUrl())){
49+
String permissionNotifyUrl = config.getPayScorePermissionNotifyUrl();
50+
if (StringUtils.isBlank(permissionNotifyUrl)) {
51+
throw new WxPayException("授权回调地址未配置");
52+
}
53+
request.setNotifyUrl(permissionNotifyUrl);
4654
}
4755
String authorizationCode = request.getAuthorizationCode();
4856
if (StringUtils.isBlank(authorizationCode)) {
4957
throw new WxPayException("authorizationCode不允许为空");
5058
}
51-
request.setNotifyUrl(permissionNotifyUrl);
5259
String result = this.payService.postV3(url, request.toJson());
5360
return WxPayScoreResult.fromJson(result);
5461

@@ -139,9 +146,15 @@ public WxPayScoreResult createServiceOrder(WxPayScoreRequest request) throws WxP
139146
boolean needUserConfirm = request.getNeedUserConfirm();
140147
WxPayConfig config = this.payService.getConfig();
141148
String url = this.payService.getPayBaseUrl() + "/v3/payscore/serviceorder";
142-
request.setAppid(config.getAppId());
143-
request.setServiceId(config.getServiceId());
144-
request.setNotifyUrl(config.getPayScoreNotifyUrl());
149+
if(Strings.isNullOrEmpty(request.getAppid())){
150+
request.setAppid(config.getAppId());
151+
}
152+
if(Strings.isNullOrEmpty(request.getServiceId())){
153+
request.setServiceId(config.getServiceId());
154+
}
155+
if(Strings.isNullOrEmpty(request.getNotifyUrl())){
156+
request.setNotifyUrl(config.getPayScoreNotifyUrl());
157+
}
145158
String result = this.payService.postV3(url, request.toJson());
146159
WxPayScoreResult wxPayScoreCreateResult = WxPayScoreResult.fromJson(result);
147160

@@ -213,8 +226,12 @@ public WxPayScoreResult modifyServiceOrder(WxPayScoreRequest request) throws WxP
213226
WxPayConfig config = this.payService.getConfig();
214227
String outOrderNo = request.getOutOrderNo();
215228
String url = String.format("%s/v3/payscore/serviceorder/%s/modify", this.payService.getPayBaseUrl(), outOrderNo);
216-
request.setAppid(config.getAppId());
217-
request.setServiceId(config.getServiceId());
229+
if(Strings.isNullOrEmpty(request.getAppid())){
230+
request.setAppid(config.getAppId());
231+
}
232+
if(Strings.isNullOrEmpty(config.getServiceId())){
233+
request.setServiceId(config.getServiceId());
234+
}
218235
request.setOutOrderNo(null);
219236
String result = payService.postV3(url, request.toJson());
220237
return WxPayScoreResult.fromJson(result);
@@ -225,8 +242,12 @@ public WxPayScoreResult completeServiceOrder(WxPayScoreRequest request) throws W
225242
WxPayConfig config = this.payService.getConfig();
226243
String outOrderNo = request.getOutOrderNo();
227244
String url = String.format("%s/v3/payscore/serviceorder/%s/complete", this.payService.getPayBaseUrl(), outOrderNo);
228-
request.setAppid(config.getAppId());
229-
request.setServiceId(config.getServiceId());
245+
if(Strings.isNullOrEmpty(request.getAppid())){
246+
request.setAppid(config.getAppId());
247+
}
248+
if(Strings.isNullOrEmpty(request.getServiceId())){
249+
request.setServiceId(config.getServiceId());
250+
}
230251
request.setOutOrderNo(null);
231252
String result = payService.postV3(url, request.toJson());
232253
return WxPayScoreResult.fromJson(result);
@@ -248,8 +269,12 @@ public WxPayScoreResult syncServiceOrder(WxPayScoreRequest request) throws WxPay
248269
WxPayConfig config = this.payService.getConfig();
249270
String outOrderNo = request.getOutOrderNo();
250271
String url = String.format("%s/v3/payscore/serviceorder/%s/sync", this.payService.getPayBaseUrl(), outOrderNo);
251-
request.setAppid(config.getAppId());
252-
request.setServiceId(config.getServiceId());
272+
if(Strings.isNullOrEmpty(request.getAppid())){
273+
request.setAppid(config.getAppId());
274+
}
275+
if(Strings.isNullOrEmpty(request.getServiceId())){
276+
request.setServiceId(config.getServiceId());
277+
}
253278
request.setOutOrderNo(null);
254279
String result = payService.postV3(url, request.toJson());
255280
return WxPayScoreResult.fromJson(result);

0 commit comments

Comments
 (0)