mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-08-24 16:18:51 +08:00
🆕 #1725 微信支付分增加免确认模式(预授权方式)相关接口支持
This commit is contained in:
parent
5599c0d833
commit
7c9e2e4a12
@ -80,5 +80,7 @@ public class WxPayScoreRequest implements Serializable {
|
|||||||
private String type;
|
private String type;
|
||||||
@SerializedName("detail")
|
@SerializedName("detail")
|
||||||
private Detail detail;
|
private Detail detail;
|
||||||
|
@SerializedName("authorization_code")
|
||||||
|
private String authorizationCode;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -85,6 +85,22 @@ public class WxPayScoreResult implements Serializable {
|
|||||||
@SerializedName("payScoreSignInfo")
|
@SerializedName("payScoreSignInfo")
|
||||||
private Map<String, String> 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;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 收款信息
|
* 收款信息
|
||||||
*/
|
*/
|
||||||
|
@ -126,6 +126,13 @@ public class WxPayConfig {
|
|||||||
*/
|
*/
|
||||||
private String payScoreNotifyUrl;
|
private String payScoreNotifyUrl;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 微信支付分授权回调地址
|
||||||
|
*/
|
||||||
|
private String payScorePermissionNotifyUrl;
|
||||||
|
|
||||||
|
|
||||||
private CloseableHttpClient apiV3HttpClient;
|
private CloseableHttpClient apiV3HttpClient;
|
||||||
/**
|
/**
|
||||||
* 私钥信息
|
* 私钥信息
|
||||||
|
@ -18,6 +18,91 @@ import com.github.binarywang.wxpay.exception.WxPayException;
|
|||||||
* @author doger.wang
|
* @author doger.wang
|
||||||
*/
|
*/
|
||||||
public interface PayScoreService {
|
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>
|
* <pre>
|
||||||
* 支付分创建订单API.
|
* 支付分创建订单API.
|
||||||
|
@ -27,6 +27,106 @@ import java.util.Map;
|
|||||||
public class PayScoreServiceImpl implements PayScoreService {
|
public class PayScoreServiceImpl implements PayScoreService {
|
||||||
private final WxPayService payService;
|
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
|
@Override
|
||||||
public WxPayScoreResult createServiceOrder(WxPayScoreRequest request) throws WxPayException {
|
public WxPayScoreResult createServiceOrder(WxPayScoreRequest request) throws WxPayException {
|
||||||
boolean needUserConfirm = request.isNeedUserConfirm();
|
boolean needUserConfirm = request.isNeedUserConfirm();
|
||||||
|
Loading…
Reference in New Issue
Block a user