From 6fb083aeea02ba2c5fb05e6d12195640d9f21eae Mon Sep 17 00:00:00 2001 From: shouyuwang <93957183+shouyuwang@users.noreply.github.com> Date: Thu, 6 Jan 2022 14:48:32 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E3=80=90=E5=BE=AE=E4=BF=A1=E6=94=AF?= =?UTF-8?q?=E4=BB=98=E3=80=91=E6=94=AF=E4=BB=98=E5=88=86=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/PayScoreServiceImpl.java | 55 ++++++++++++++----- 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/PayScoreServiceImpl.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/PayScoreServiceImpl.java index 0b237fda3..4181e74f2 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/PayScoreServiceImpl.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/PayScoreServiceImpl.java @@ -10,6 +10,7 @@ import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.service.PayScoreService; import com.github.binarywang.wxpay.service.WxPayService; import com.github.binarywang.wxpay.v3.util.AesUtils; +import com.google.common.base.Strings; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import lombok.RequiredArgsConstructor; @@ -38,17 +39,23 @@ public class PayScoreServiceImpl implements PayScoreService { public WxPayScoreResult permissions(WxPayScoreRequest request) throws WxPayException { WxPayConfig config = this.payService.getConfig(); String url = this.payService.getPayBaseUrl() + "/v3/payscore/permissions"; - request.setAppid(config.getAppId()); - request.setServiceId(config.getServiceId()); - String permissionNotifyUrl = config.getPayScorePermissionNotifyUrl(); - if (StringUtils.isBlank(permissionNotifyUrl)) { - throw new WxPayException("授权回调地址未配置"); + if(Strings.isNullOrEmpty(request.getAppid())){ + request.setAppid(config.getAppId()); + } + if(Strings.isNullOrEmpty(request.getServiceId())){ + request.setServiceId(config.getServiceId()); + } + if(Strings.isNullOrEmpty(request.getNotifyUrl())){ + String permissionNotifyUrl = config.getPayScorePermissionNotifyUrl(); + if (StringUtils.isBlank(permissionNotifyUrl)) { + throw new WxPayException("授权回调地址未配置"); + } + request.setNotifyUrl(permissionNotifyUrl); } String authorizationCode = request.getAuthorizationCode(); if (StringUtils.isBlank(authorizationCode)) { throw new WxPayException("authorizationCode不允许为空"); } - request.setNotifyUrl(permissionNotifyUrl); String result = this.payService.postV3(url, request.toJson()); return WxPayScoreResult.fromJson(result); @@ -139,9 +146,15 @@ public class PayScoreServiceImpl implements PayScoreService { boolean needUserConfirm = request.getNeedUserConfirm(); WxPayConfig config = this.payService.getConfig(); String url = this.payService.getPayBaseUrl() + "/v3/payscore/serviceorder"; - request.setAppid(config.getAppId()); - request.setServiceId(config.getServiceId()); - request.setNotifyUrl(config.getPayScoreNotifyUrl()); + if(Strings.isNullOrEmpty(request.getAppid())){ + request.setAppid(config.getAppId()); + } + if(Strings.isNullOrEmpty(request.getServiceId())){ + request.setServiceId(config.getServiceId()); + } + if(Strings.isNullOrEmpty(request.getNotifyUrl())){ + request.setNotifyUrl(config.getPayScoreNotifyUrl()); + } String result = this.payService.postV3(url, request.toJson()); WxPayScoreResult wxPayScoreCreateResult = WxPayScoreResult.fromJson(result); @@ -213,8 +226,12 @@ public class PayScoreServiceImpl implements PayScoreService { WxPayConfig config = this.payService.getConfig(); String outOrderNo = request.getOutOrderNo(); String url = String.format("%s/v3/payscore/serviceorder/%s/modify", this.payService.getPayBaseUrl(), outOrderNo); - request.setAppid(config.getAppId()); - request.setServiceId(config.getServiceId()); + if(Strings.isNullOrEmpty(request.getAppid())){ + request.setAppid(config.getAppId()); + } + if(Strings.isNullOrEmpty(config.getServiceId())){ + request.setServiceId(config.getServiceId()); + } request.setOutOrderNo(null); String result = payService.postV3(url, request.toJson()); return WxPayScoreResult.fromJson(result); @@ -225,8 +242,12 @@ public class PayScoreServiceImpl implements PayScoreService { WxPayConfig config = this.payService.getConfig(); String outOrderNo = request.getOutOrderNo(); String url = String.format("%s/v3/payscore/serviceorder/%s/complete", this.payService.getPayBaseUrl(), outOrderNo); - request.setAppid(config.getAppId()); - request.setServiceId(config.getServiceId()); + if(Strings.isNullOrEmpty(request.getAppid())){ + request.setAppid(config.getAppId()); + } + if(Strings.isNullOrEmpty(request.getServiceId())){ + request.setServiceId(config.getServiceId()); + } request.setOutOrderNo(null); String result = payService.postV3(url, request.toJson()); return WxPayScoreResult.fromJson(result); @@ -248,8 +269,12 @@ public class PayScoreServiceImpl implements PayScoreService { WxPayConfig config = this.payService.getConfig(); String outOrderNo = request.getOutOrderNo(); String url = String.format("%s/v3/payscore/serviceorder/%s/sync", this.payService.getPayBaseUrl(), outOrderNo); - request.setAppid(config.getAppId()); - request.setServiceId(config.getServiceId()); + if(Strings.isNullOrEmpty(request.getAppid())){ + request.setAppid(config.getAppId()); + } + if(Strings.isNullOrEmpty(request.getServiceId())){ + request.setServiceId(config.getServiceId()); + } request.setOutOrderNo(null); String result = payService.postV3(url, request.toJson()); return WxPayScoreResult.fromJson(result);