图片上传bugfix

This commit is contained in:
felord.cn
2020-12-13 13:44:40 +08:00
parent 495f56365c
commit 6fe24b770a
5 changed files with 74 additions and 31 deletions

View File

@@ -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)

View File

@@ -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

View File

@@ -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<ObjectNode> queryStocksByMch(StocksQueryParams params) {
WechatResponseEntity<ObjectNode> 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<String, String> 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
* <p>
@@ -361,15 +351,37 @@ public class WechatMarketingFavorApi extends AbstractApi {
* @param params the params
* @return the wechat response entity
*/
public WechatResponseEntity<ObjectNode> queryMerchantsByStockId(StocksQueryParams params) {
public WechatResponseEntity<ObjectNode> queryMerchantsByStockId(MchQueryParams params) {
WechatResponseEntity<ObjectNode> 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<String, String> 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
* <p>
@@ -378,10 +390,10 @@ public class WechatMarketingFavorApi extends AbstractApi {
* @param params the params
* @return the wechat response entity
*/
public WechatResponseEntity<ObjectNode> queryStockItems(StocksQueryParams params) {
public WechatResponseEntity<ObjectNode> queryStockItems(MchQueryParams params) {
WechatResponseEntity<ObjectNode> 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<String, Object> 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)

View File

@@ -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;
}

View File

@@ -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;
/**
* 查询参数,适用以下接口:
* <p>
* 条件查询批次列表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而定
* <p>
* 批次ID对条件查询批次列表API{@link WechatMarketingFavorApi#queryStocksByMch(StocksQueryParams)}无效。
*/
private String stockId;
* 批次ID
*//*
private String stockId;*/
/**
* 选填
* <p>
@@ -57,7 +56,7 @@ public class StocksQueryParams {
/**
* 根据API而定
* <p>
* 批次状态只对条件查询批次列表API{@link WechatMarketingFavorApi#queryStocksByMch(StocksQueryParams)}有效。
* 批次状态
*/
private StockStatus status;
}