From 6fe24b770ad5a90c582e5b8e5256b2a4059e53b6 Mon Sep 17 00:00:00 2001 From: "felord.cn" Date: Sun, 13 Dec 2020 13:44:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BE=E7=89=87=E4=B8=8A=E4=BC=A0bugfix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/_coverpage.md | 3 +- docs/quick_start.md | 2 +- .../wechat/v3/WechatMarketingFavorApi.java | 58 ++++++++++++------- .../wechat/v3/model/MchQueryParams.java | 29 ++++++++++ .../wechat/v3/model/StocksQueryParams.java | 13 ++--- 5 files changed, 74 insertions(+), 31 deletions(-) create mode 100644 payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/MchQueryParams.java diff --git a/docs/_coverpage.md b/docs/_coverpage.md index 3595831..d2fb743 100644 --- a/docs/_coverpage.md +++ b/docs/_coverpage.md @@ -8,7 +8,8 @@ - 配置简单、只依赖 Spring 框架 -[Star](https://github.com/NotFound403/payment-spring-boot) +[GitHub](https://github.com/NotFound403/payment-spring-boot) +[示例项目](https://github.com/NotFound403/payment-spring-boot-samples) [技术博客](https://felord.cn) [快速开始](README.md) diff --git a/docs/quick_start.md b/docs/quick_start.md index e42d164..b8104e7 100644 --- a/docs/quick_start.md +++ b/docs/quick_start.md @@ -51,7 +51,7 @@ wechat: # 微信支付商户号 必填 mch-id: xxxxxxx # 商户服务器域名 用于回调 需要放开回调接口的安全策略 必填 - domain: https://xxxx.xxx.com + domain: https://felord.cn # 商户 api 证书路径 必填 填写classpath路径 位于 maven项目的resources文件下 cert-path: apiclient_cert.p12 diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatMarketingFavorApi.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatMarketingFavorApi.java index e724e50..bfa7cbe 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatMarketingFavorApi.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatMarketingFavorApi.java @@ -15,7 +15,6 @@ import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.util.StringUtils; import org.springframework.web.multipart.MultipartFile; -import org.springframework.web.util.UriComponents; import org.springframework.web.util.UriComponentsBuilder; import java.net.URI; @@ -215,14 +214,12 @@ public class WechatMarketingFavorApi extends AbstractApi { public WechatResponseEntity queryStocksByMch(StocksQueryParams params) { WechatResponseEntity wechatResponseEntity = new WechatResponseEntity<>(); this.client().withType(WechatPayV3Type.MARKETING_FAVOR_STOCKS, params) - .function(this::queryStocksFunction) + .function(this::queryStocksByMchFunction) .consumer(wechatResponseEntity::convert) .request(); return wechatResponseEntity; } - - /** * Query stocks function request entity. * @@ -230,7 +227,7 @@ public class WechatMarketingFavorApi extends AbstractApi { * @param params the params * @return the request entity */ - private RequestEntity queryStocksFunction(WechatPayV3Type type, StocksQueryParams params) { + private RequestEntity queryStocksByMchFunction(WechatPayV3Type type, StocksQueryParams params) { MultiValueMap queryParams = new LinkedMultiValueMap<>(); queryParams.add("offset", String.valueOf(params.getOffset())); @@ -251,24 +248,17 @@ public class WechatMarketingFavorApi extends AbstractApi { .format(DateTimeFormatter.ISO_OFFSET_DATE_TIME)); } StockStatus status = params.getStatus(); - if (Objects.nonNull(status) && Objects.equals(WechatPayV3Type.MARKETING_FAVOR_STOCKS, type)) { + if (Objects.nonNull(status)) { queryParams.add("status", status.value()); } - String stockId = params.getStockId(); - - UriComponents uriComponents = UriComponentsBuilder.fromHttpUrl(type.uri(WeChatServer.CHINA)) + URI uri = UriComponentsBuilder.fromHttpUrl(type.uri(WeChatServer.CHINA)) .queryParams(queryParams) - .build(); - - if (StringUtils.hasText(stockId) && !Objects.equals(WechatPayV3Type.MARKETING_FAVOR_STOCKS, type)) { - uriComponents = uriComponents.expand(stockId); - } - - URI uri = uriComponents.toUri(); + .build().toUri(); return Get(uri); } + /** * 查询批次详情API *

@@ -361,15 +351,37 @@ public class WechatMarketingFavorApi extends AbstractApi { * @param params the params * @return the wechat response entity */ - public WechatResponseEntity queryMerchantsByStockId(StocksQueryParams params) { + public WechatResponseEntity queryMerchantsByStockId(MchQueryParams params) { WechatResponseEntity wechatResponseEntity = new WechatResponseEntity<>(); this.client().withType(WechatPayV3Type.MARKETING_FAVOR_STOCKS_MERCHANTS, params) - .function(this::queryStocksFunction) + .function(this::queryMerchantsByStockIdFunction) .consumer(wechatResponseEntity::convert) .request(); return wechatResponseEntity; } + /** + * Query stocks function request entity. + * + * @param type the type + * @param params the params + * @return the request entity + */ + private RequestEntity queryMerchantsByStockIdFunction(WechatPayV3Type type, MchQueryParams params) { + MultiValueMap queryParams = new LinkedMultiValueMap<>(); + queryParams.add("offset", String.valueOf(params.getOffset())); + queryParams.add("limit", String.valueOf(params.getLimit())); + WechatPayProperties.V3 v3 = this.wechatMetaBean().getV3(); + queryParams.add("stock_creator_mchid", v3.getMchId()); + String stockId = params.getStockId(); + URI uri = UriComponentsBuilder.fromHttpUrl(type.uri(WeChatServer.CHINA)) + .queryParams(queryParams) + .build() + .expand(stockId) + .toUri(); + return Get(uri); + } + /** * 查询代金券可用单品API *

@@ -378,10 +390,10 @@ public class WechatMarketingFavorApi extends AbstractApi { * @param params the params * @return the wechat response entity */ - public WechatResponseEntity queryStockItems(StocksQueryParams params) { + public WechatResponseEntity queryStockItems(MchQueryParams params) { WechatResponseEntity wechatResponseEntity = new WechatResponseEntity<>(); this.client().withType(WechatPayV3Type.MARKETING_FAVOR_STOCKS_ITEMS, params) - .function(this::queryStocksFunction) + .function(this::queryMerchantsByStockIdFunction) .consumer(wechatResponseEntity::convert) .request(); @@ -538,7 +550,10 @@ public class WechatMarketingFavorApi extends AbstractApi { private RequestEntity marketingImageUploadFunction(WechatPayV3Type type, MultipartFile file) { Map meta = new LinkedHashMap<>(2); - meta.put("filename", file.getOriginalFilename()); + + String originalFilename = file.getOriginalFilename(); + String filename = StringUtils.hasText(originalFilename)? originalFilename :file.getName(); + meta.put("filename", filename); byte[] digest = SHA256.Digest.getInstance("SHA-256").digest(file.getBytes()); meta.put("sha256", Hex.toHexString(digest)); @@ -549,7 +564,6 @@ public class WechatMarketingFavorApi extends AbstractApi { String metaStr = this.getMapper().writeValueAsString(meta); URI uri = UriComponentsBuilder.fromHttpUrl(type.uri(WeChatServer.CHINA)) - .queryParam("pay_tenantId", this.tenantId()) .build() .toUri(); return RequestEntity.post(uri) diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/MchQueryParams.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/MchQueryParams.java new file mode 100644 index 0000000..a053d3e --- /dev/null +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/MchQueryParams.java @@ -0,0 +1,29 @@ +package cn.felord.payment.wechat.v3.model; + +import lombok.Data; + +/** + * 查询代金券可用商户. + * + * @author felord.cn + * @since 1.0.0.RELEASE + */ +@Data +public class MchQueryParams { + /** + * 必填 + * + * 查询代金券可用商户API 分页页码,最大1000。 + */ + private Integer offset = 0; + /** + * 必填 + * + * 查询代金券可用商户API 最大50。 + */ + private Integer limit = 10; + /** + * 批次ID + */ + private String stockId; +} diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/StocksQueryParams.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/StocksQueryParams.java index 33ff758..b09d797 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/StocksQueryParams.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/StocksQueryParams.java @@ -1,7 +1,6 @@ package cn.felord.payment.wechat.v3.model; import cn.felord.payment.wechat.enumeration.StockStatus; -import cn.felord.payment.wechat.v3.WechatMarketingFavorApi; import lombok.Data; import java.time.OffsetDateTime; @@ -9,7 +8,7 @@ import java.time.OffsetDateTime; /** * 查询参数,适用以下接口: *

- * 条件查询批次列表API、查询代金券可用商户API、查询代金券可用单品API + * 条件查询批次列表API * * @author felord.cn * @since 1.0.0.RELEASE @@ -36,12 +35,12 @@ public class StocksQueryParams { * 查询代金券可用单品API 最大100。 */ private Integer limit = 10; - /** +/* *//** * 根据API而定 *

- * 批次ID,对条件查询批次列表API{@link WechatMarketingFavorApi#queryStocksByMch(StocksQueryParams)}无效。 - */ - private String stockId; + * 批次ID + *//* + private String stockId;*/ /** * 选填 *

@@ -57,7 +56,7 @@ public class StocksQueryParams { /** * 根据API而定 *

- * 批次状态,只对条件查询批次列表API{@link WechatMarketingFavorApi#queryStocksByMch(StocksQueryParams)}有效。 + * 批次状态 */ private StockStatus status; }