🆕 #1725 微信支付分增加免确认模式(预授权方式)相关接口支持

This commit is contained in:
spvycf 2020-10-15 13:39:54 +08:00 committed by GitHub
parent 5599c0d833
commit 7c9e2e4a12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 210 additions and 0 deletions

View File

@ -80,5 +80,7 @@ public class WxPayScoreRequest implements Serializable {
private String type;
@SerializedName("detail")
private Detail detail;
@SerializedName("authorization_code")
private String authorizationCode;
}

View File

@ -85,6 +85,22 @@ public class WxPayScoreResult implements Serializable {
@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;
/**
* 收款信息
*/

View File

@ -126,6 +126,13 @@ public class WxPayConfig {
*/
private String payScoreNotifyUrl;
/**
* 微信支付分授权回调地址
*/
private String payScorePermissionNotifyUrl;
private CloseableHttpClient apiV3HttpClient;
/**
* 私钥信息

View File

@ -18,6 +18,91 @@ import com.github.binarywang.wxpay.exception.WxPayException;
* @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>
* 支付分查询与用户授权记录openidAPI
* 文档详见: 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>
* 解除用户授权关系openidAPI
* 文档详见: 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.

View File

@ -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<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();