mirror of
https://github.com/dromara/payment-spring-boot.git
synced 2026-03-14 05:43:46 +08:00
图片上传bugfix
This commit is contained in:
@@ -8,7 +8,8 @@
|
|||||||
- 配置简单、只依赖 Spring 框架
|
- 配置简单、只依赖 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)
|
[技术博客](https://felord.cn)
|
||||||
[快速开始](README.md)
|
[快速开始](README.md)
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ wechat:
|
|||||||
# 微信支付商户号 必填
|
# 微信支付商户号 必填
|
||||||
mch-id: xxxxxxx
|
mch-id: xxxxxxx
|
||||||
# 商户服务器域名 用于回调 需要放开回调接口的安全策略 必填
|
# 商户服务器域名 用于回调 需要放开回调接口的安全策略 必填
|
||||||
domain: https://xxxx.xxx.com
|
domain: https://felord.cn
|
||||||
# 商户 api 证书路径 必填 填写classpath路径 位于 maven项目的resources文件下
|
# 商户 api 证书路径 必填 填写classpath路径 位于 maven项目的resources文件下
|
||||||
cert-path: apiclient_cert.p12
|
cert-path: apiclient_cert.p12
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import org.springframework.util.LinkedMultiValueMap;
|
|||||||
import org.springframework.util.MultiValueMap;
|
import org.springframework.util.MultiValueMap;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
import org.springframework.web.util.UriComponents;
|
|
||||||
import org.springframework.web.util.UriComponentsBuilder;
|
import org.springframework.web.util.UriComponentsBuilder;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
@@ -215,14 +214,12 @@ public class WechatMarketingFavorApi extends AbstractApi {
|
|||||||
public WechatResponseEntity<ObjectNode> queryStocksByMch(StocksQueryParams params) {
|
public WechatResponseEntity<ObjectNode> queryStocksByMch(StocksQueryParams params) {
|
||||||
WechatResponseEntity<ObjectNode> wechatResponseEntity = new WechatResponseEntity<>();
|
WechatResponseEntity<ObjectNode> wechatResponseEntity = new WechatResponseEntity<>();
|
||||||
this.client().withType(WechatPayV3Type.MARKETING_FAVOR_STOCKS, params)
|
this.client().withType(WechatPayV3Type.MARKETING_FAVOR_STOCKS, params)
|
||||||
.function(this::queryStocksFunction)
|
.function(this::queryStocksByMchFunction)
|
||||||
.consumer(wechatResponseEntity::convert)
|
.consumer(wechatResponseEntity::convert)
|
||||||
.request();
|
.request();
|
||||||
|
|
||||||
return wechatResponseEntity;
|
return wechatResponseEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query stocks function request entity.
|
* Query stocks function request entity.
|
||||||
*
|
*
|
||||||
@@ -230,7 +227,7 @@ public class WechatMarketingFavorApi extends AbstractApi {
|
|||||||
* @param params the params
|
* @param params the params
|
||||||
* @return the request entity
|
* @return the request entity
|
||||||
*/
|
*/
|
||||||
private RequestEntity<?> queryStocksFunction(WechatPayV3Type type, StocksQueryParams params) {
|
private RequestEntity<?> queryStocksByMchFunction(WechatPayV3Type type, StocksQueryParams params) {
|
||||||
|
|
||||||
MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<>();
|
MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<>();
|
||||||
queryParams.add("offset", String.valueOf(params.getOffset()));
|
queryParams.add("offset", String.valueOf(params.getOffset()));
|
||||||
@@ -251,24 +248,17 @@ public class WechatMarketingFavorApi extends AbstractApi {
|
|||||||
.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME));
|
.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME));
|
||||||
}
|
}
|
||||||
StockStatus status = params.getStatus();
|
StockStatus status = params.getStatus();
|
||||||
if (Objects.nonNull(status) && Objects.equals(WechatPayV3Type.MARKETING_FAVOR_STOCKS, type)) {
|
if (Objects.nonNull(status)) {
|
||||||
queryParams.add("status", status.value());
|
queryParams.add("status", status.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
String stockId = params.getStockId();
|
URI uri = UriComponentsBuilder.fromHttpUrl(type.uri(WeChatServer.CHINA))
|
||||||
|
|
||||||
UriComponents uriComponents = UriComponentsBuilder.fromHttpUrl(type.uri(WeChatServer.CHINA))
|
|
||||||
.queryParams(queryParams)
|
.queryParams(queryParams)
|
||||||
.build();
|
.build().toUri();
|
||||||
|
|
||||||
if (StringUtils.hasText(stockId) && !Objects.equals(WechatPayV3Type.MARKETING_FAVOR_STOCKS, type)) {
|
|
||||||
uriComponents = uriComponents.expand(stockId);
|
|
||||||
}
|
|
||||||
|
|
||||||
URI uri = uriComponents.toUri();
|
|
||||||
return Get(uri);
|
return Get(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询批次详情API
|
* 查询批次详情API
|
||||||
* <p>
|
* <p>
|
||||||
@@ -361,15 +351,37 @@ public class WechatMarketingFavorApi extends AbstractApi {
|
|||||||
* @param params the params
|
* @param params the params
|
||||||
* @return the wechat response entity
|
* @return the wechat response entity
|
||||||
*/
|
*/
|
||||||
public WechatResponseEntity<ObjectNode> queryMerchantsByStockId(StocksQueryParams params) {
|
public WechatResponseEntity<ObjectNode> queryMerchantsByStockId(MchQueryParams params) {
|
||||||
WechatResponseEntity<ObjectNode> wechatResponseEntity = new WechatResponseEntity<>();
|
WechatResponseEntity<ObjectNode> wechatResponseEntity = new WechatResponseEntity<>();
|
||||||
this.client().withType(WechatPayV3Type.MARKETING_FAVOR_STOCKS_MERCHANTS, params)
|
this.client().withType(WechatPayV3Type.MARKETING_FAVOR_STOCKS_MERCHANTS, params)
|
||||||
.function(this::queryStocksFunction)
|
.function(this::queryMerchantsByStockIdFunction)
|
||||||
.consumer(wechatResponseEntity::convert)
|
.consumer(wechatResponseEntity::convert)
|
||||||
.request();
|
.request();
|
||||||
return wechatResponseEntity;
|
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
|
* 查询代金券可用单品API
|
||||||
* <p>
|
* <p>
|
||||||
@@ -378,10 +390,10 @@ public class WechatMarketingFavorApi extends AbstractApi {
|
|||||||
* @param params the params
|
* @param params the params
|
||||||
* @return the wechat response entity
|
* @return the wechat response entity
|
||||||
*/
|
*/
|
||||||
public WechatResponseEntity<ObjectNode> queryStockItems(StocksQueryParams params) {
|
public WechatResponseEntity<ObjectNode> queryStockItems(MchQueryParams params) {
|
||||||
WechatResponseEntity<ObjectNode> wechatResponseEntity = new WechatResponseEntity<>();
|
WechatResponseEntity<ObjectNode> wechatResponseEntity = new WechatResponseEntity<>();
|
||||||
this.client().withType(WechatPayV3Type.MARKETING_FAVOR_STOCKS_ITEMS, params)
|
this.client().withType(WechatPayV3Type.MARKETING_FAVOR_STOCKS_ITEMS, params)
|
||||||
.function(this::queryStocksFunction)
|
.function(this::queryMerchantsByStockIdFunction)
|
||||||
.consumer(wechatResponseEntity::convert)
|
.consumer(wechatResponseEntity::convert)
|
||||||
.request();
|
.request();
|
||||||
|
|
||||||
@@ -538,7 +550,10 @@ public class WechatMarketingFavorApi extends AbstractApi {
|
|||||||
private RequestEntity<?> marketingImageUploadFunction(WechatPayV3Type type, MultipartFile file) {
|
private RequestEntity<?> marketingImageUploadFunction(WechatPayV3Type type, MultipartFile file) {
|
||||||
|
|
||||||
Map<String, Object> meta = new LinkedHashMap<>(2);
|
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());
|
byte[] digest = SHA256.Digest.getInstance("SHA-256").digest(file.getBytes());
|
||||||
meta.put("sha256", Hex.toHexString(digest));
|
meta.put("sha256", Hex.toHexString(digest));
|
||||||
@@ -549,7 +564,6 @@ public class WechatMarketingFavorApi extends AbstractApi {
|
|||||||
String metaStr = this.getMapper().writeValueAsString(meta);
|
String metaStr = this.getMapper().writeValueAsString(meta);
|
||||||
|
|
||||||
URI uri = UriComponentsBuilder.fromHttpUrl(type.uri(WeChatServer.CHINA))
|
URI uri = UriComponentsBuilder.fromHttpUrl(type.uri(WeChatServer.CHINA))
|
||||||
.queryParam("pay_tenantId", this.tenantId())
|
|
||||||
.build()
|
.build()
|
||||||
.toUri();
|
.toUri();
|
||||||
return RequestEntity.post(uri)
|
return RequestEntity.post(uri)
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
package cn.felord.payment.wechat.v3.model;
|
package cn.felord.payment.wechat.v3.model;
|
||||||
|
|
||||||
import cn.felord.payment.wechat.enumeration.StockStatus;
|
import cn.felord.payment.wechat.enumeration.StockStatus;
|
||||||
import cn.felord.payment.wechat.v3.WechatMarketingFavorApi;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.time.OffsetDateTime;
|
import java.time.OffsetDateTime;
|
||||||
@@ -9,7 +8,7 @@ import java.time.OffsetDateTime;
|
|||||||
/**
|
/**
|
||||||
* 查询参数,适用以下接口:
|
* 查询参数,适用以下接口:
|
||||||
* <p>
|
* <p>
|
||||||
* 条件查询批次列表API、查询代金券可用商户API、查询代金券可用单品API
|
* 条件查询批次列表API
|
||||||
*
|
*
|
||||||
* @author felord.cn
|
* @author felord.cn
|
||||||
* @since 1.0.0.RELEASE
|
* @since 1.0.0.RELEASE
|
||||||
@@ -36,12 +35,12 @@ public class StocksQueryParams {
|
|||||||
* 查询代金券可用单品API 最大100。
|
* 查询代金券可用单品API 最大100。
|
||||||
*/
|
*/
|
||||||
private Integer limit = 10;
|
private Integer limit = 10;
|
||||||
/**
|
/* *//**
|
||||||
* 根据API而定
|
* 根据API而定
|
||||||
* <p>
|
* <p>
|
||||||
* 批次ID,对条件查询批次列表API{@link WechatMarketingFavorApi#queryStocksByMch(StocksQueryParams)}无效。
|
* 批次ID
|
||||||
*/
|
*//*
|
||||||
private String stockId;
|
private String stockId;*/
|
||||||
/**
|
/**
|
||||||
* 选填
|
* 选填
|
||||||
* <p>
|
* <p>
|
||||||
@@ -57,7 +56,7 @@ public class StocksQueryParams {
|
|||||||
/**
|
/**
|
||||||
* 根据API而定
|
* 根据API而定
|
||||||
* <p>
|
* <p>
|
||||||
* 批次状态,只对条件查询批次列表API{@link WechatMarketingFavorApi#queryStocksByMch(StocksQueryParams)}有效。
|
* 批次状态
|
||||||
*/
|
*/
|
||||||
private StockStatus status;
|
private StockStatus status;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user