mirror of
https://github.com/dromara/payment-spring-boot.git
synced 2026-03-13 21:33:41 +08:00
✨ 增加微信商户模式下V3接口的付款码支付与对应的撤销
This commit is contained in:
@@ -66,6 +66,13 @@ public enum WechatPayV3Type {
|
||||
MERCHANT_MEDIA_VIDEO(HttpMethod.POST, "%s/v3/merchant/media/video_upload"),
|
||||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
/**
|
||||
* 付款码支付
|
||||
*
|
||||
* @since 1.0.0.RELEASE
|
||||
*/
|
||||
CODE(HttpMethod.POST, "%s/v3/pay/transactions/codepay"),
|
||||
|
||||
/**
|
||||
* 微信公众号支付或者小程序支付.
|
||||
*
|
||||
@@ -99,6 +106,13 @@ public enum WechatPayV3Type {
|
||||
* @since 1.0.0.RELEASE
|
||||
*/
|
||||
CLOSE(HttpMethod.POST, "%s/v3/pay/transactions/out-trade-no/{out_trade_no}/close"),
|
||||
/**
|
||||
* 关闭订单.
|
||||
*
|
||||
* @since 1.0.0.RELEASE
|
||||
*/
|
||||
REVERSE(HttpMethod.POST, "%s/v3/pay/transactions/out-trade-no/{out_trade_no}/reverse"),
|
||||
|
||||
/**
|
||||
* 微信支付订单号查询API.
|
||||
*
|
||||
@@ -633,6 +647,7 @@ public enum WechatPayV3Type {
|
||||
|
||||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
/**
|
||||
* 服务商APP下单API.
|
||||
*
|
||||
|
||||
@@ -56,6 +56,23 @@ public class WechatDirectPayApi extends AbstractApi {
|
||||
super(wechatPayClient, tenantId);
|
||||
}
|
||||
|
||||
public WechatResponseEntity<ObjectNode> codePay(PayParams payParams) {
|
||||
WechatResponseEntity<ObjectNode> wechatResponseEntity = new WechatResponseEntity<>();
|
||||
this.client().withType(WechatPayV3Type.CODE, payParams)
|
||||
.function(this::payFunction)
|
||||
.consumer(responseEntity -> {
|
||||
ObjectNode body = responseEntity.getBody();
|
||||
if (Objects.isNull(body)) {
|
||||
throw new PayException("response body cannot be resolved");
|
||||
}
|
||||
wechatResponseEntity.setHttpStatus(responseEntity.getStatusCodeValue());
|
||||
wechatResponseEntity.setBody(body);
|
||||
})
|
||||
.request();
|
||||
return wechatResponseEntity;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* APP下单API
|
||||
*
|
||||
@@ -185,8 +202,10 @@ public class WechatDirectPayApi extends AbstractApi {
|
||||
WechatPayProperties.V3 v3 = this.wechatMetaBean().getV3();
|
||||
payParams.setAppid(v3.getAppId());
|
||||
payParams.setMchid(v3.getMchId());
|
||||
if (!type.equals(WechatPayV3Type.CODE)){
|
||||
String notifyUrl = v3.getDomain().concat(payParams.getNotifyUrl());
|
||||
payParams.setNotifyUrl(notifyUrl);
|
||||
}
|
||||
URI uri = UriComponentsBuilder.fromHttpUrl(type.uri(WeChatServer.CHINA))
|
||||
.build()
|
||||
.toUri();
|
||||
@@ -252,6 +271,21 @@ public class WechatDirectPayApi extends AbstractApi {
|
||||
return wechatResponseEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
* 撤销API
|
||||
*
|
||||
* @param outTradeNo the out trade no
|
||||
* @return the wechat response entity
|
||||
*/
|
||||
public WechatResponseEntity<ObjectNode> reverse(String outTradeNo) {
|
||||
WechatResponseEntity<ObjectNode> wechatResponseEntity = new WechatResponseEntity<>();
|
||||
this.client().withType(WechatPayV3Type.REVERSE, outTradeNo)
|
||||
.function(this::reverseOutTradeNoFunction)
|
||||
.consumer(wechatResponseEntity::convert)
|
||||
.request();
|
||||
return wechatResponseEntity;
|
||||
}
|
||||
|
||||
private RequestEntity<?> closeByOutTradeNoFunction(WechatPayV3Type type, String outTradeNo) {
|
||||
WechatPayProperties.V3 v3 = this.wechatMetaBean().getV3();
|
||||
|
||||
@@ -265,6 +299,20 @@ public class WechatDirectPayApi extends AbstractApi {
|
||||
return Post(uri, queryParams);
|
||||
}
|
||||
|
||||
private RequestEntity<?> reverseOutTradeNoFunction(WechatPayV3Type type, String outTradeNo) {
|
||||
WechatPayProperties.V3 v3 = this.wechatMetaBean().getV3();
|
||||
|
||||
Map<String, String> queryParams = new HashMap<>(1);
|
||||
queryParams.put("mchid", v3.getMchId());
|
||||
queryParams.put("appid", v3.getAppId());
|
||||
|
||||
URI uri = UriComponentsBuilder.fromHttpUrl(type.uri(WeChatServer.CHINA))
|
||||
.build()
|
||||
.expand(outTradeNo)
|
||||
.toUri();
|
||||
return Post(uri, queryParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* 申请退款API
|
||||
*
|
||||
|
||||
@@ -38,4 +38,6 @@ public class Payer {
|
||||
* 用户子标识
|
||||
*/
|
||||
private String subOpenid;
|
||||
|
||||
private String authCode;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user