Skip to content

Commit

Permalink
🆕 #1725 微信支付分增加免确认模式(预授权方式)相关接口支持
Browse files Browse the repository at this point in the history
  • Loading branch information
spvycf committed Oct 15, 2020
1 parent 5599c0d commit 7c9e2e4
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,7 @@ public String toJson() {
private String type;
@SerializedName("detail")
private Detail detail;
@SerializedName("authorization_code")
private String authorizationCode;

}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,22 @@ public static WxPayScoreResult fromJson(String json) {
@SerializedName("payScoreSignInfo")
private Map<String, String> 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;


/**
* 收款信息
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ public class WxPayConfig {
*/
private String payScoreNotifyUrl;


/**
* 微信支付分授权回调地址
*/
private String payScorePermissionNotifyUrl;


private CloseableHttpClient apiV3HttpClient;
/**
* 私钥信息
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,91 @@
* @author doger.wang
*/
public interface PayScoreService {



/**
* <pre>
* 支付分商户预授权API
* 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/payscore/chapter5_1.shtml
* 接口链接:https://api.mch.weixin.qq.com/v3/payscore/permissions
* </pre>
*
* @param request 请求对象
* @return WxPayScoreResult wx pay score result
* @throws WxPayException the wx pay exception
*/
WxPayScoreResult permissions(WxPayScoreRequest request) throws WxPayException;


/**
* <pre>
* 支付分查询与用户授权记录(授权协议号)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}
* </pre>
*
* @param authorizationCode
* @return WxPayScoreResult wx pay score result
* @throws WxPayException the wx pay exception
*/
WxPayScoreResult permissionsQueryByAuthorizationCode(String authorizationCode) throws WxPayException;



/**
* <pre>
* 解除用户授权关系(授权协议号)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
* </pre>
*
* @param authorizationCode
* @param reason
* @return WxPayScoreResult wx pay score result
* @throws WxPayException the wx pay exception
*/
WxPayScoreResult permissionsTerminateByAuthorizationCode(String authorizationCode,String reason) throws WxPayException;





/**
* <pre>
* 支付分查询与用户授权记录(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}
* </pre>
*
* @param openId
* @return WxPayScoreResult wx pay score result
* @throws WxPayException the wx pay exception
*/
WxPayScoreResult permissionsQueryByOpenId(String openId) throws WxPayException;





/**
* <pre>
* 解除用户授权关系(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
* </pre>
*
* @param openId
* @param reason
* @return WxPayScoreResult wx pay score result
* @throws WxPayException the wx pay exception
*/
WxPayScoreResult permissionsTerminateByOpenId(String openId,String reason) throws WxPayException;





/**
* <pre>
* 支付分创建订单API.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,106 @@
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<String, Object> 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<String, Object> 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();
Expand Down

0 comments on commit 7c9e2e4

Please sign in to comment.