增加微信商户模式下V3接口的付款码支付与对应的撤销

This commit is contained in:
xucun
2025-06-11 18:05:54 +08:00
parent 7388a75455
commit 7be5971ae3
3 changed files with 73 additions and 8 deletions

View File

@@ -66,6 +66,13 @@ public enum WechatPayV3Type {
MERCHANT_MEDIA_VIDEO(HttpMethod.POST, "%s/v3/merchant/media/video_upload"), 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 * @since 1.0.0.RELEASE
*/ */
CLOSE(HttpMethod.POST, "%s/v3/pay/transactions/out-trade-no/{out_trade_no}/close"), 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. * 微信支付订单号查询API.
* *
@@ -633,6 +647,7 @@ public enum WechatPayV3Type {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/** /**
* 服务商APP下单API. * 服务商APP下单API.
* *

View File

@@ -56,12 +56,29 @@ public class WechatDirectPayApi extends AbstractApi {
super(wechatPayClient, tenantId); super(wechatPayClient, tenantId);
} }
/** public WechatResponseEntity<ObjectNode> codePay(PayParams payParams) {
* APP下单API WechatResponseEntity<ObjectNode> wechatResponseEntity = new WechatResponseEntity<>();
* this.client().withType(WechatPayV3Type.CODE, payParams)
* @param payParams the pay params .function(this::payFunction)
* @return the wechat response entity .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
*
* @param payParams the pay params
* @return the wechat response entity
*/
public WechatResponseEntity<ObjectNode> appPay(PayParams payParams) { public WechatResponseEntity<ObjectNode> appPay(PayParams payParams) {
WechatResponseEntity<ObjectNode> wechatResponseEntity = new WechatResponseEntity<>(); WechatResponseEntity<ObjectNode> wechatResponseEntity = new WechatResponseEntity<>();
this.client().withType(WechatPayV3Type.APP, payParams) this.client().withType(WechatPayV3Type.APP, payParams)
@@ -185,8 +202,10 @@ public class WechatDirectPayApi extends AbstractApi {
WechatPayProperties.V3 v3 = this.wechatMetaBean().getV3(); WechatPayProperties.V3 v3 = this.wechatMetaBean().getV3();
payParams.setAppid(v3.getAppId()); payParams.setAppid(v3.getAppId());
payParams.setMchid(v3.getMchId()); payParams.setMchid(v3.getMchId());
String notifyUrl = v3.getDomain().concat(payParams.getNotifyUrl()); if (!type.equals(WechatPayV3Type.CODE)){
payParams.setNotifyUrl(notifyUrl); String notifyUrl = v3.getDomain().concat(payParams.getNotifyUrl());
payParams.setNotifyUrl(notifyUrl);
}
URI uri = UriComponentsBuilder.fromHttpUrl(type.uri(WeChatServer.CHINA)) URI uri = UriComponentsBuilder.fromHttpUrl(type.uri(WeChatServer.CHINA))
.build() .build()
.toUri(); .toUri();
@@ -252,6 +271,21 @@ public class WechatDirectPayApi extends AbstractApi {
return wechatResponseEntity; 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) { private RequestEntity<?> closeByOutTradeNoFunction(WechatPayV3Type type, String outTradeNo) {
WechatPayProperties.V3 v3 = this.wechatMetaBean().getV3(); WechatPayProperties.V3 v3 = this.wechatMetaBean().getV3();
@@ -265,6 +299,20 @@ public class WechatDirectPayApi extends AbstractApi {
return Post(uri, queryParams); 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 * 申请退款API
* *

View File

@@ -38,4 +38,6 @@ public class Payer {
* 用户子标识 * 用户子标识
*/ */
private String subOpenid; private String subOpenid;
private String authCode;
} }