From 7c9e2e4a12cd2f308b1c8a722969722d6549d1c0 Mon Sep 17 00:00:00 2001 From: spvycf <545997765@qq.com> Date: Thu, 15 Oct 2020 13:39:54 +0800 Subject: [PATCH] =?UTF-8?q?:new:=20#1725=20=E5=BE=AE=E4=BF=A1=E6=94=AF?= =?UTF-8?q?=E4=BB=98=E5=88=86=E5=A2=9E=E5=8A=A0=E5=85=8D=E7=A1=AE=E8=AE=A4?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=EF=BC=88=E9=A2=84=E6=8E=88=E6=9D=83=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=EF=BC=89=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3=E6=94=AF?= =?UTF-8?q?=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bean/payscore/WxPayScoreRequest.java | 2 + .../wxpay/bean/payscore/WxPayScoreResult.java | 16 +++ .../binarywang/wxpay/config/WxPayConfig.java | 7 ++ .../wxpay/service/PayScoreService.java | 85 +++++++++++++++ .../service/impl/PayScoreServiceImpl.java | 100 ++++++++++++++++++ 5 files changed, 210 insertions(+) diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/payscore/WxPayScoreRequest.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/payscore/WxPayScoreRequest.java index c4fd49438..6091df26f 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/payscore/WxPayScoreRequest.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/payscore/WxPayScoreRequest.java @@ -80,5 +80,7 @@ public class WxPayScoreRequest implements Serializable { private String type; @SerializedName("detail") private Detail detail; + @SerializedName("authorization_code") + private String authorizationCode; } diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/payscore/WxPayScoreResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/payscore/WxPayScoreResult.java index 58665bf55..266440d21 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/payscore/WxPayScoreResult.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/payscore/WxPayScoreResult.java @@ -85,6 +85,22 @@ public class WxPayScoreResult implements Serializable { @SerializedName("payScoreSignInfo") private Map payScoreSignInfo; + @SerializedName("apply_permissions_token") + private String applyPermissionsToken; + + @SerializedName("authorization_code") + private String authorizationCode; + + @SerializedName("authorization_state") + private String authorizationState; + + @SerializedName("cancel_authorization_time") + private String cancelAuthorizationTime; + + @SerializedName("authorization_success_time") + private String authorizationSuccessTime; + + /** * 收款信息 */ diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/config/WxPayConfig.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/config/WxPayConfig.java index 1f012ed2f..258608819 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/config/WxPayConfig.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/config/WxPayConfig.java @@ -126,6 +126,13 @@ public class WxPayConfig { */ private String payScoreNotifyUrl; + + /** + * 微信支付分授权回调地址 + */ + private String payScorePermissionNotifyUrl; + + private CloseableHttpClient apiV3HttpClient; /** * 私钥信息 diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/PayScoreService.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/PayScoreService.java index ff6aafe9f..d92a2b20e 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/PayScoreService.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/PayScoreService.java @@ -18,6 +18,91 @@ import com.github.binarywang.wxpay.exception.WxPayException; * @author doger.wang */ public interface PayScoreService { + + + + /** + *
+   * 支付分商户预授权API
+   * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/payscore/chapter5_1.shtml
+   * 接口链接:https://api.mch.weixin.qq.com/v3/payscore/permissions
+   * 
+ * + * @param request 请求对象 + * @return WxPayScoreResult wx pay score result + * @throws WxPayException the wx pay exception + */ + WxPayScoreResult permissions(WxPayScoreRequest request) throws WxPayException; + + + /** + *
+   * 支付分查询与用户授权记录(授权协议号)API
+   * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/payscore/chapter5_2.shtml
+   * 接口链接:https://api.mch.weixin.qq.com/v3/payscore/permissions/authorization-code/{authorization_code}
+   * 
+ * + * @param authorizationCode + * @return WxPayScoreResult wx pay score result + * @throws WxPayException the wx pay exception + */ + WxPayScoreResult permissionsQueryByAuthorizationCode(String authorizationCode) throws WxPayException; + + + + /** + *
+   * 解除用户授权关系(授权协议号)API
+   * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/payscore/chapter5_3.shtml
+   * 接口链接:https://api.mch.weixin.qq.com/v3/payscore/permissions/authorization-code/{authorization_code}/terminate
+   * 
+ * + * @param authorizationCode + * @param reason + * @return WxPayScoreResult wx pay score result + * @throws WxPayException the wx pay exception + */ + WxPayScoreResult permissionsTerminateByAuthorizationCode(String authorizationCode,String reason) throws WxPayException; + + + + + + /** + *
+   * 支付分查询与用户授权记录(openid)API
+   * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/payscore/chapter5_4shtml
+   * 接口链接:https://api.mch.weixin.qq.com/v3/payscore/permissions/openid/{openid}
+   * 
+ * + * @param openId + * @return WxPayScoreResult wx pay score result + * @throws WxPayException the wx pay exception + */ + WxPayScoreResult permissionsQueryByOpenId(String openId) throws WxPayException; + + + + + + /** + *
+   * 解除用户授权关系(openid)API
+   * 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/payscore/chapter5_5.shtml
+   * 接口链接:https://api.mch.weixin.qq.com/v3/payscore/permissions/openid/{openid}/terminate
+   * 
+ * + * @param openId + * @param reason + * @return WxPayScoreResult wx pay score result + * @throws WxPayException the wx pay exception + */ + WxPayScoreResult permissionsTerminateByOpenId(String openId,String reason) throws WxPayException; + + + + + /** *
    * 支付分创建订单API.
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 7fa7efa58..221128c29 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
@@ -27,6 +27,106 @@ import java.util.Map;
 public class PayScoreServiceImpl implements PayScoreService {
   private final WxPayService payService;
 
+  @Override
+  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("授权回调地址未配置");
+    }
+    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);
+
+  }
+
+  @Override
+  public WxPayScoreResult permissionsQueryByAuthorizationCode(String authorizationCode) throws WxPayException {
+    WxPayConfig config = this.payService.getConfig();
+    if (StringUtils.isBlank(authorizationCode)){
+      throw new WxPayException("authorizationCode不允许为空");
+    }
+    String url = String.format("%s/v3/payscore/permissions/authorization-code/%s", this.payService.getPayBaseUrl(), authorizationCode);
+    URIBuilder uriBuilder;
+    try {
+      uriBuilder = new URIBuilder(url);
+    } catch (URISyntaxException e) {
+      throw new WxPayException("未知异常!", e);
+    }
+
+    uriBuilder.setParameter("service_id", config.getServiceId());
+    try {
+      String result = payService.getV3(uriBuilder.build());
+      return WxPayScoreResult.fromJson(result);
+    } catch (URISyntaxException e) {
+      throw new WxPayException("未知异常!", e);
+    }
+
+  }
+
+  @Override
+  public WxPayScoreResult permissionsTerminateByAuthorizationCode(String authorizationCode,String reason) throws WxPayException {
+    WxPayConfig config = this.payService.getConfig();
+    if (StringUtils.isBlank(authorizationCode)){
+      throw new WxPayException("authorizationCode不允许为空");
+    }
+    String url = String.format("%s/v3/payscore/permissions/authorization-code/%s/terminate", this.payService.getPayBaseUrl(), authorizationCode);
+    Map map = new HashMap<>(4);
+    map.put("service_id", config.getServiceId());
+    map.put("reason", reason);
+    String result = payService.postV3(url, WxGsonBuilder.create().toJson(map));
+    return WxPayScoreResult.fromJson(result);
+
+  }
+
+  @Override
+  public WxPayScoreResult permissionsQueryByOpenId(String openId) throws WxPayException {
+    WxPayConfig config = this.payService.getConfig();
+    if (StringUtils.isBlank(openId)){
+      throw new WxPayException("openId不允许为空");
+    }
+    String url = String.format("%s/v3/payscore/permissions/openid/%s", this.payService.getPayBaseUrl(), openId);
+    URIBuilder uriBuilder;
+    try {
+      uriBuilder = new URIBuilder(url);
+    } catch (URISyntaxException e) {
+      throw new WxPayException("未知异常!", e);
+    }
+
+    uriBuilder.setParameter("appid", config.getAppId());
+    uriBuilder.setParameter("service_id", config.getServiceId());
+    try {
+      String result = payService.getV3(uriBuilder.build());
+      return WxPayScoreResult.fromJson(result);
+    } catch (URISyntaxException e) {
+      throw new WxPayException("未知异常!", e);
+    }
+
+  }
+
+  @Override
+  public WxPayScoreResult permissionsTerminateByOpenId(String openId, String reason) throws WxPayException {
+    WxPayConfig config = this.payService.getConfig();
+    if (StringUtils.isBlank(openId)){
+      throw new WxPayException("openId不允许为空");
+    }
+    String url = String.format("%s/v3/payscore/permissions/openid/%s/terminate", this.payService.getPayBaseUrl(), openId);
+    Map map = new HashMap<>(4);
+    map.put("service_id", config.getServiceId());
+    map.put("appid", config.getAppId());
+    map.put("reason", reason);
+    String result = payService.postV3(url, WxGsonBuilder.create().toJson(map));
+    return WxPayScoreResult.fromJson(result);
+
+  }
+
   @Override
   public WxPayScoreResult createServiceOrder(WxPayScoreRequest request) throws WxPayException {
     boolean needUserConfirm = request.isNeedUserConfirm();