From 9bc2eceebf43204d127864ce7f2587200bea93c6 Mon Sep 17 00:00:00 2001 From: xiafang Date: Wed, 2 Dec 2020 18:21:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +- .../wechat/WechatPayConfiguration.java | 6 +- .../wechat/enumeration/WechatPayV3Type.java | 9 ++- .../payment/wechat/v3/WechatMarketingApi.java | 75 +++++++++++-------- .../payment/wechat/v3/WechatPayCallback.java | 16 +++- 5 files changed, 72 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index 50e358b..9bf6ce6 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ public class PayConfig { WechatMarketingApi wchatMarketingApi; ``` ###### V3 -例如V3 APP 支付 +例如V3 查询商户下的优惠券 ```java // 查询商户下的优惠券 @@ -74,7 +74,7 @@ public class PayConfig { StocksQueryParams params = new StocksQueryParams(); params.setOffset(0); params.setLimit(10); - WechatResponseEntity objectNodeWechatResponseEntity = wechatPayV3Api.queryStocksByMch(params); + WechatResponseEntity objectNodeWechatResponseEntity = wchatMarketingApi.queryStocksByMch(params); System.out.println("objectNodeWechatResponseEntity = " + objectNodeWechatResponseEntity); } ``` diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/WechatPayConfiguration.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/WechatPayConfiguration.java index 801dd6f..c5ee4fb 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/WechatPayConfiguration.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/WechatPayConfiguration.java @@ -58,7 +58,7 @@ public class WechatPayConfiguration { } /** - * Wechat pay v3 api. + * 微信支付API. * * @param wechatPayClient the wechat pay v 3 client * @param wechatMetaBean the wechat meta bean @@ -70,7 +70,7 @@ public class WechatPayConfiguration { } /** - * Wechat marketing api wechat marketing api. + * 微信营销API. * * @param wechatPayClient the wechat pay client * @param wechatMetaBean the wechat meta bean @@ -82,7 +82,7 @@ public class WechatPayConfiguration { } /** - * Wechat pay callback. + * 微信支付回调工具. * * @param signatureProvider the signature provider * @return the wechat pay callback 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 884f71d..1c5e7ee 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 @@ -44,13 +44,18 @@ public enum WechatPayV3Type { */ MARKETING_FAVOR_STOCKS_START(HttpMethod.POST,"%s/v3/marketing/favor/stocks/{stock_id}/start"), /** - * 重启代金券 + * 暂停代金券批次API. */ - MARKETING_FAVOR_STOCKS_RESTART(HttpMethod.POST,"%s/v3/marketing/favor/stocks/{stock_id}/restart"), + MARKETING_FAVOR_STOCKS_PAUSE(HttpMethod.POST,"%s/v3/marketing/favor/stocks/{stock_id}/pause"), + /** * 发放代金券API & 根据商户号查用户的券. */ MARKETING_FAVOR_USERS_COUPONS(HttpMethod.POST,"%s/v3/marketing/favor/users/{openid}/coupons"), + /** + * 重启代金券 + */ + MARKETING_FAVOR_STOCKS_RESTART(HttpMethod.POST,"%s/v3/marketing/favor/stocks/{stock_id}/restart"), /** * 查询代金券可用商户. */ diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatMarketingApi.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatMarketingApi.java index 707c0a4..755f346 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatMarketingApi.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatMarketingApi.java @@ -79,12 +79,54 @@ public class WechatMarketingApi extends AbstractApi { public WechatResponseEntity startStock(String stockId) { WechatResponseEntity wechatResponseEntity = new WechatResponseEntity<>(); this.client().withType(WechatPayV3Type.MARKETING_FAVOR_STOCKS_START, stockId) - .function(this::startAndRestartStockFunction) + .function(this::startAndRestartAndPauseStockFunction) .consumer(wechatResponseEntity::convert) .request(); return wechatResponseEntity; } + + /** + * 发放代金券API. + * + * @param params the params + * @return the wechat response entity + */ + public WechatResponseEntity sendStock(StocksSendParams params) { + WechatResponseEntity wechatResponseEntity = new WechatResponseEntity<>(); + this.client().withType(WechatPayV3Type.MARKETING_FAVOR_USERS_COUPONS, params) + .function(this::sendStocksFunction) + .consumer(wechatResponseEntity::convert) + .request(); + return wechatResponseEntity; + } + + + private RequestEntity sendStocksFunction(WechatPayV3Type type, StocksSendParams params) { + WechatPayProperties.V3 v3 = this.meta().getWechatPayProperties().getV3(); + // 服务号 + params.setAppid(v3.getMp().getAppId()); + params.setStockCreatorMchid(v3.getMchId()); + String httpUrl = type.uri(WeChatServer.CHINA); + URI uri = UriComponentsBuilder.fromHttpUrl(httpUrl).build().expand(params.getOpenid()).toUri(); + params.setOpenid(null); + return post(uri, params); + } + + /** + * 暂停代金券批次API. + * + * @param stockId the stock id + * @return the wechat response entity + */ + public WechatResponseEntity pauseStock(String stockId) { + WechatResponseEntity wechatResponseEntity = new WechatResponseEntity<>(); + this.client().withType(WechatPayV3Type.MARKETING_FAVOR_STOCKS_PAUSE, stockId) + .function(this::startAndRestartAndPauseStockFunction) + .consumer(wechatResponseEntity::convert) + .request(); + return wechatResponseEntity; + } /** * 重启代金券批次API. * @@ -94,13 +136,13 @@ public class WechatMarketingApi extends AbstractApi { public WechatResponseEntity restartStock(String stockId) { WechatResponseEntity wechatResponseEntity = new WechatResponseEntity<>(); this.client().withType(WechatPayV3Type.MARKETING_FAVOR_STOCKS_RESTART, stockId) - .function(this::startAndRestartStockFunction) + .function(this::startAndRestartAndPauseStockFunction) .consumer(wechatResponseEntity::convert) .request(); return wechatResponseEntity; } - private RequestEntity startAndRestartStockFunction(WechatPayV3Type type, String stockId) { + private RequestEntity startAndRestartAndPauseStockFunction(WechatPayV3Type type, String stockId) { WechatPayProperties.V3 v3 = this.meta().getWechatPayProperties().getV3(); String mchId = v3.getMchId(); Map body = new HashMap<>(); @@ -212,33 +254,6 @@ public class WechatMarketingApi extends AbstractApi { return RequestEntity.get(uri).build(); } - /** - * 发放代金券API. - * - * @param params the params - * @return the wechat response entity - */ - public WechatResponseEntity sendStock(StocksSendParams params) { - WechatResponseEntity wechatResponseEntity = new WechatResponseEntity<>(); - this.client().withType(WechatPayV3Type.MARKETING_FAVOR_USERS_COUPONS, params) - .function(this::sendStocksFunction) - .consumer(wechatResponseEntity::convert) - .request(); - return wechatResponseEntity; - } - - - private RequestEntity sendStocksFunction(WechatPayV3Type type, StocksSendParams params) { - WechatPayProperties.V3 v3 = this.meta().getWechatPayProperties().getV3(); - // 服务号 - params.setAppid(v3.getMp().getAppId()); - params.setStockCreatorMchid(v3.getMchId()); - String httpUrl = type.uri(WeChatServer.CHINA); - URI uri = UriComponentsBuilder.fromHttpUrl(httpUrl).build().expand(params.getOpenid()).toUri(); - params.setOpenid(null); - return post(uri, params); - } - /** * 营销图片上传API. * diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatPayCallback.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatPayCallback.java index b56dcb5..2cdf3f4 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatPayCallback.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatPayCallback.java @@ -16,8 +16,10 @@ import java.util.Map; import java.util.function.Consumer; /** + * The type Wechat pay callback. + * * @author Dax - * @since 10:21 + * @since 10 :21 */ @Slf4j public class WechatPayCallback { @@ -29,11 +31,23 @@ public class WechatPayCallback { MAPPER.setSerializationInclusion(JsonInclude.Include.NON_NULL); } + /** + * Instantiates a new Wechat pay callback. + * + * @param signatureProvider the signature provider + */ public WechatPayCallback(SignatureProvider signatureProvider) { this.signatureProvider = signatureProvider; } + /** + * 微信支付代金券核销回调工具. + * + * @param params the params + * @param couponConsumeDataConsumer the coupon consume data consumer + * @return the map + */ @SneakyThrows public Map wechatPayCouponCallback(ResponseSignVerifyParams params, Consumer couponConsumeDataConsumer) {