diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/enumeration/WechatPayV3Type.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/enumeration/WechatPayV3Type.java index c62871d..2195a86 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/enumeration/WechatPayV3Type.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/enumeration/WechatPayV3Type.java @@ -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. * diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatDirectPayApi.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatDirectPayApi.java index 3814f6a..fb53076 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatDirectPayApi.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatDirectPayApi.java @@ -56,12 +56,29 @@ public class WechatDirectPayApi extends AbstractApi { super(wechatPayClient, tenantId); } - /** - * APP下单API - * - * @param payParams the pay params - * @return the wechat response entity - */ + public WechatResponseEntity codePay(PayParams payParams) { + WechatResponseEntity 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 + * + * @param payParams the pay params + * @return the wechat response entity + */ public WechatResponseEntity appPay(PayParams payParams) { WechatResponseEntity wechatResponseEntity = new WechatResponseEntity<>(); this.client().withType(WechatPayV3Type.APP, payParams) @@ -185,8 +202,10 @@ public class WechatDirectPayApi extends AbstractApi { WechatPayProperties.V3 v3 = this.wechatMetaBean().getV3(); payParams.setAppid(v3.getAppId()); payParams.setMchid(v3.getMchId()); - String notifyUrl = v3.getDomain().concat(payParams.getNotifyUrl()); - payParams.setNotifyUrl(notifyUrl); + 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 reverse(String outTradeNo) { + WechatResponseEntity 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 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 * diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/Payer.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/Payer.java index 1b29fc4..b928056 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/Payer.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/Payer.java @@ -38,4 +38,6 @@ public class Payer { * 用户子标识 */ private String subOpenid; + + private String authCode; }