From 2fd5a26a5e847a0654be1fc01e429248e8370506 Mon Sep 17 00:00:00 2001 From: xiafang Date: Wed, 2 Dec 2020 19:31:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E8=90=A5=E9=94=80API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wechat/enumeration/WechatPayV3Type.java | 18 +- .../payment/wechat/v3/WechatMarketingApi.java | 184 +++++++++++++----- .../v3/model/CouponDetailsQueryParams.java | 22 +++ .../v3/model/UserCouponsQueryParams.java | 48 +++++ 4 files changed, 213 insertions(+), 59 deletions(-) create mode 100644 payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/CouponDetailsQueryParams.java create mode 100644 payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/UserCouponsQueryParams.java 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 1c5e7ee..a28ea45 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 @@ -53,13 +53,9 @@ public enum WechatPayV3Type { */ MARKETING_FAVOR_USERS_COUPONS(HttpMethod.POST,"%s/v3/marketing/favor/users/{openid}/coupons"), /** - * 重启代金券 + * 重启代金券API */ MARKETING_FAVOR_STOCKS_RESTART(HttpMethod.POST,"%s/v3/marketing/favor/stocks/{stock_id}/restart"), - /** - * 查询代金券可用商户. - */ - MARKETING_FAVOR_STOCKS_MERCHANTS(HttpMethod.GET, "%s/v3/marketing/favor/stocks/{stock_id}/merchants"), /** * 条件查询批次列表API. */ @@ -68,6 +64,18 @@ public enum WechatPayV3Type { * 查询批次详情API. */ MARKETING_FAVOR_STOCKS_DETAIL(HttpMethod.GET, "%s/v3/marketing/favor/stocks/{stock_id}"), + /** + * 查询代金券详情API + */ + MARKETING_FAVOR_USERS_COUPONS_DETAIL(HttpMethod.GET, "%s/v3/marketing/favor/users/{openid}/coupons/{coupon_id}"), + /** + * 查询代金券可用商户API. + */ + MARKETING_FAVOR_STOCKS_MERCHANTS(HttpMethod.GET, "%s/v3/marketing/favor/stocks/{stock_id}/merchants"), + /** + * 查询代金券可用单品API. + */ + MARKETING_FAVOR_STOCKS_ITEMS(HttpMethod.GET, "%s/v3/marketing/favor/stocks/{stock_id}/items"), /** * 营销图片上传API. */ 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 755f346..492529f 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 @@ -4,6 +4,7 @@ import cn.felord.payment.wechat.WechatPayProperties; import cn.felord.payment.wechat.enumeration.StockStatus; import cn.felord.payment.wechat.enumeration.WeChatServer; import cn.felord.payment.wechat.enumeration.WechatPayV3Type; +import cn.felord.payment.wechat.v3.model.CouponDetailsQueryParams; import cn.felord.payment.wechat.v3.model.StocksCreateParams; import cn.felord.payment.wechat.v3.model.StocksQueryParams; import cn.felord.payment.wechat.v3.model.StocksSendParams; @@ -64,8 +65,9 @@ public class WechatMarketingApi extends AbstractApi { private RequestEntity createStocksFunction(WechatPayV3Type type, StocksCreateParams params) { WechatPayProperties.V3 v3 = this.meta().getWechatPayProperties().getV3(); String mchId = v3.getMchId(); - String httpUrl = type.uri(WeChatServer.CHINA); - URI uri = UriComponentsBuilder.fromHttpUrl(httpUrl).build().toUri(); + URI uri = UriComponentsBuilder.fromHttpUrl(type.uri(WeChatServer.CHINA)) + .build() + .toUri(); params.setBelongMerchant(mchId); return post(uri, params); } @@ -107,8 +109,10 @@ public class WechatMarketingApi extends AbstractApi { // 服务号 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(); + URI uri = UriComponentsBuilder.fromHttpUrl(type.uri(WeChatServer.CHINA)) + .build() + .expand(params.getOpenid()) + .toUri(); params.setOpenid(null); return post(uri, params); } @@ -127,6 +131,7 @@ public class WechatMarketingApi extends AbstractApi { .request(); return wechatResponseEntity; } + /** * 重启代金券批次API. * @@ -147,59 +152,16 @@ public class WechatMarketingApi extends AbstractApi { String mchId = v3.getMchId(); Map body = new HashMap<>(); body.put("stock_creator_mchid", mchId); - String httpUrl = type.uri(WeChatServer.CHINA); - URI uri = UriComponentsBuilder.fromHttpUrl(httpUrl).build().expand(stockId).toUri(); + + URI uri = UriComponentsBuilder.fromHttpUrl(type.uri(WeChatServer.CHINA)) + .build() + .expand(stockId) + .toUri(); return post(uri, body); } /** - * 查询批次详情API. - * - * @param stockId the stock id - * @return the wechat response entity - */ - public WechatResponseEntity queryStockDetail(String stockId) { - WechatResponseEntity wechatResponseEntity = new WechatResponseEntity<>(); - this.client().withType(WechatPayV3Type.MARKETING_FAVOR_STOCKS_DETAIL, stockId) - .function(this::stockDetailFunction) - .consumer(wechatResponseEntity::convert) - .request(); - return wechatResponseEntity; - } - - - private RequestEntity stockDetailFunction(WechatPayV3Type type, String stockId) { - WechatPayProperties.V3 v3 = this.meta().getWechatPayProperties().getV3(); - - String httpUrl = type.uri(WeChatServer.CHINA); - - MultiValueMap queryParams = new LinkedMultiValueMap<>(); - queryParams.add("stock_creator_mchid", v3.getMchId()); - URI uri = UriComponentsBuilder.fromHttpUrl(httpUrl).queryParams(queryParams).build().expand(stockId).toUri(); - return RequestEntity.get(uri).build(); - - } - - - /** - * 查询该代金券可用的商户 - * - * @param params the params - * @return the wechat response entity - */ - public WechatResponseEntity queryMerchantsByStockId(StocksQueryParams params) { - WechatResponseEntity wechatResponseEntity = new WechatResponseEntity<>(); - this.client().withType(WechatPayV3Type.MARKETING_FAVOR_STOCKS_MERCHANTS, params) - .function(this::queryStocksFunction) - .consumer(wechatResponseEntity::convert) - .request(); - - return wechatResponseEntity; - } - - - /** - * 分页查询商户下的代金券批次. + * 条件查询批次列表API. * * @param params the params * @return the wechat response entity @@ -254,6 +216,120 @@ public class WechatMarketingApi extends AbstractApi { return RequestEntity.get(uri).build(); } + /** + * 查询批次详情API. + * + * @param stockId the stock id + * @return the wechat response entity + */ + public WechatResponseEntity queryStockDetail(String stockId) { + WechatResponseEntity wechatResponseEntity = new WechatResponseEntity<>(); + this.client().withType(WechatPayV3Type.MARKETING_FAVOR_STOCKS_DETAIL, stockId) + .function(this::stockDetailFunction) + .consumer(wechatResponseEntity::convert) + .request(); + return wechatResponseEntity; + } + + + private RequestEntity stockDetailFunction(WechatPayV3Type type, String stockId) { + WechatPayProperties.V3 v3 = this.meta().getWechatPayProperties().getV3(); + + MultiValueMap queryParams = new LinkedMultiValueMap<>(); + queryParams.add("stock_creator_mchid", v3.getMchId()); + + URI uri = UriComponentsBuilder.fromHttpUrl(type.uri(WeChatServer.CHINA)) + .queryParams(queryParams) + .build() + .expand(stockId) + .toUri(); + return RequestEntity.get(uri).build(); + + } + + /** + * 查询代金券详情API + * + * @param params the params + * @return the wechat response entity + */ + public WechatResponseEntity queryCouponDetails(CouponDetailsQueryParams params) { + WechatResponseEntity wechatResponseEntity = new WechatResponseEntity<>(); + this.client().withType(WechatPayV3Type.MARKETING_FAVOR_USERS_COUPONS_DETAIL, params) + .function(this::couponDetailFunction) + .consumer(wechatResponseEntity::convert) + .request(); + return wechatResponseEntity; + } + + + private RequestEntity couponDetailFunction(WechatPayV3Type type, CouponDetailsQueryParams params) { + + WechatPayProperties.V3 v3 = this.meta().getWechatPayProperties().getV3(); + + MultiValueMap queryParams = new LinkedMultiValueMap<>(); + queryParams.add("appid", v3.getMp().getAppId()); + + MultiValueMap pathParams = new LinkedMultiValueMap<>(); + pathParams.add("openid", params.getOpenId()); + pathParams.add("coupon_id", params.getCouponId()); + URI uri = UriComponentsBuilder.fromHttpUrl(type.uri(WeChatServer.CHINA)) + .queryParams(queryParams) + .build() + .expand(pathParams) + .toUri(); + return RequestEntity.get(uri).build(); + + } + + /** + * 查询代金券可用商户API + * + * @param params the params + * @return the wechat response entity + */ + public WechatResponseEntity queryMerchantsByStockId(StocksQueryParams params) { + WechatResponseEntity wechatResponseEntity = new WechatResponseEntity<>(); + this.client().withType(WechatPayV3Type.MARKETING_FAVOR_STOCKS_MERCHANTS, params) + .function(this::queryStocksFunction) + .consumer(wechatResponseEntity::convert) + .request(); + return wechatResponseEntity; + } + + /** + * 查询代金券可用单品API + * + * @param params the params + * @return the wechat response entity + */ + public WechatResponseEntity queryStockItems(StocksQueryParams params) { + WechatResponseEntity wechatResponseEntity = new WechatResponseEntity<>(); + this.client().withType(WechatPayV3Type.MARKETING_FAVOR_STOCKS_ITEMS, params) + .function(this::queryStocksFunction) + .consumer(wechatResponseEntity::convert) + .request(); + + return wechatResponseEntity; + } + + /** + * 根据商户号查用户的券API + * + * @param params the params + * @return the wechat response entity + */ + public WechatResponseEntity queryUserCouponsByMchId(StocksQueryParams params) { + WechatResponseEntity wechatResponseEntity = new WechatResponseEntity<>(); + this.client().withType(WechatPayV3Type.MARKETING_FAVOR_STOCKS_ITEMS, params) + .function(this::queryStocksFunction) + .consumer(wechatResponseEntity::convert) + .request(); + + return wechatResponseEntity; + } + + /** * 营销图片上传API. * @@ -287,7 +363,7 @@ public class WechatMarketingApi extends AbstractApi { String metaStr = this.getMapper().writeValueAsString(meta); return RequestEntity.post(uri) .header("Content-Type", MediaType.MULTIPART_FORM_DATA_VALUE) - .header("Meta-Info",metaStr) + .header("Meta-Info", metaStr) .body(body); } diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/CouponDetailsQueryParams.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/CouponDetailsQueryParams.java new file mode 100644 index 0000000..e60a044 --- /dev/null +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/CouponDetailsQueryParams.java @@ -0,0 +1,22 @@ +package cn.felord.payment.wechat.v3.model; + +import lombok.Data; + +/** + * 查询代金券详情API参数 + * + * @author Dax + * @since 18 :51 + */ +@Data +public class CouponDetailsQueryParams { + /** + * 用户在公众号服务号配置{@link cn.felord.payment.wechat.WechatPayProperties.Mp}下授权得到的openid + * 参考发券 + */ + private String openId; + /** + * 代金券id + */ + private String couponId; +} diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/UserCouponsQueryParams.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/UserCouponsQueryParams.java new file mode 100644 index 0000000..329c916 --- /dev/null +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/UserCouponsQueryParams.java @@ -0,0 +1,48 @@ +package cn.felord.payment.wechat.v3.model; + +import cn.felord.payment.wechat.enumeration.CouponStatus; +import lombok.Data; + +/** + * @author Dax + * @since 19:19 + */ +@Data +public class UserCouponsQueryParams { + /** + * 用户公众号服务号标识 + */ + private String openId; + /** + * 公众服务号ID + */ + private String appId; + /** + * 批次号 + */ + private String stockId; + /** + * 券状态 null 不生效 + */ + private CouponStatus status; + /** + * 创建批次的商户号 + */ + private String creatorMchId; + /** + * 批次发放商户号 + */ + private String senderMchId; + /** + * 可用商户号 + */ + private String availableMchId; + /** + * 分页页码 + */ + private int offset = 0; + /** + * 分页大小 + */ + private int limit = 20; +}