mirror of
https://github.com/dromara/payment-spring-boot.git
synced 2026-03-13 21:33:41 +08:00
代金券发放API优化
This commit is contained in:
@@ -52,20 +52,20 @@ public class WechatPayConfiguration {
|
||||
* @return the wechat pay service
|
||||
*/
|
||||
@Bean
|
||||
public WechatPayV3Client wechatPayService(SignatureProvider signatureProvider) {
|
||||
return new WechatPayV3Client(signatureProvider);
|
||||
public WechatPayClient wechatPayService(SignatureProvider signatureProvider) {
|
||||
return new WechatPayClient(signatureProvider);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wechat pay v3 api.
|
||||
*
|
||||
* @param wechatPayV3Client the wechat pay v 3 client
|
||||
* @param wechatPayClient the wechat pay v 3 client
|
||||
* @param wechatMetaBean the wechat meta bean
|
||||
* @return the wechat pay v 3 api
|
||||
*/
|
||||
@Bean
|
||||
public WechatPayApi wechatPayApi(WechatPayV3Client wechatPayV3Client, WechatMetaBean wechatMetaBean) {
|
||||
return new WechatPayApi(wechatPayV3Client,wechatMetaBean);
|
||||
public WechatPayApi wechatPayApi(WechatPayClient wechatPayClient, WechatMetaBean wechatMetaBean) {
|
||||
return new WechatPayApi(wechatPayClient,wechatMetaBean);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.enongm.dianji.payment.wechat.enumeration;
|
||||
import org.springframework.http.HttpMethod;
|
||||
|
||||
/**
|
||||
* The enum Pay type.
|
||||
* The Wechat Pay V3 type.
|
||||
*
|
||||
* @author Dax
|
||||
* @since 14 :25
|
||||
@@ -62,7 +62,7 @@ public enum WechatPayV3Type {
|
||||
/**
|
||||
* 营销图片上传API.
|
||||
*/
|
||||
IMAGE_UPLOAD(HttpMethod.POST, "%s/v3/marketing/favor/media/image-upload");
|
||||
MARKETING_IMAGE_UPLOAD(HttpMethod.POST, "%s/v3/marketing/favor/media/image-upload");
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ import java.util.Objects;
|
||||
*/
|
||||
public class WechatPayApi {
|
||||
private static final ObjectMapper MAPPER = new ObjectMapper();
|
||||
private final WechatPayV3Client wechatPayV3Client;
|
||||
private final WechatPayClient wechatPayClient;
|
||||
private final WechatMetaBean wechatMetaBean;
|
||||
|
||||
static {
|
||||
@@ -49,11 +49,11 @@ public class WechatPayApi {
|
||||
/**
|
||||
* Wechat Pay V3 Api.
|
||||
*
|
||||
* @param wechatPayV3Client the wechat pay v 3 client
|
||||
* @param wechatMetaBean the wechat meta bean
|
||||
* @param wechatPayClient the wechat pay v 3 client
|
||||
* @param wechatMetaBean the wechat meta bean
|
||||
*/
|
||||
public WechatPayApi(WechatPayV3Client wechatPayV3Client, WechatMetaBean wechatMetaBean) {
|
||||
this.wechatPayV3Client = wechatPayV3Client;
|
||||
public WechatPayApi(WechatPayClient wechatPayClient, WechatMetaBean wechatMetaBean) {
|
||||
this.wechatPayClient = wechatPayClient;
|
||||
this.wechatMetaBean = wechatMetaBean;
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ public class WechatPayApi {
|
||||
*/
|
||||
public WechatResponseEntity<ObjectNode> createStock(StocksCreateParams params) {
|
||||
WechatResponseEntity<ObjectNode> wechatResponseEntity = new WechatResponseEntity<>();
|
||||
wechatPayV3Client.withType(WechatPayV3Type.MARKETING_FAVOR_STOCKS_COUPON_STOCKS, params)
|
||||
wechatPayClient.withType(WechatPayV3Type.MARKETING_FAVOR_STOCKS_COUPON_STOCKS, params)
|
||||
.function(this::createStocksFunction)
|
||||
.consumer(wechatResponseEntity::convert)
|
||||
.request();
|
||||
@@ -96,7 +96,7 @@ public class WechatPayApi {
|
||||
*/
|
||||
public WechatResponseEntity<ObjectNode> startStock(String stockId) {
|
||||
WechatResponseEntity<ObjectNode> wechatResponseEntity = new WechatResponseEntity<>();
|
||||
wechatPayV3Client.withType(WechatPayV3Type.MARKETING_FAVOR_STOCKS_START, stockId)
|
||||
wechatPayClient.withType(WechatPayV3Type.MARKETING_FAVOR_STOCKS_START, stockId)
|
||||
.function(this::startStockFunction)
|
||||
.consumer(wechatResponseEntity::convert)
|
||||
.request();
|
||||
@@ -128,7 +128,7 @@ public class WechatPayApi {
|
||||
*/
|
||||
public WechatResponseEntity<ObjectNode> queryStockDetail(String stockId) {
|
||||
WechatResponseEntity<ObjectNode> wechatResponseEntity = new WechatResponseEntity<>();
|
||||
wechatPayV3Client.withType(WechatPayV3Type.MARKETING_FAVOR_STOCKS_DETAIL, stockId)
|
||||
wechatPayClient.withType(WechatPayV3Type.MARKETING_FAVOR_STOCKS_DETAIL, stockId)
|
||||
.function(this::stockDetailFunction)
|
||||
.consumer(wechatResponseEntity::convert)
|
||||
.request();
|
||||
@@ -157,7 +157,7 @@ public class WechatPayApi {
|
||||
*/
|
||||
public WechatResponseEntity<ObjectNode> queryMerchantsByStockId(StocksQueryParams params) {
|
||||
WechatResponseEntity<ObjectNode> wechatResponseEntity = new WechatResponseEntity<>();
|
||||
wechatPayV3Client.withType(WechatPayV3Type.MARKETING_FAVOR_STOCKS_MERCHANTS, params)
|
||||
wechatPayClient.withType(WechatPayV3Type.MARKETING_FAVOR_STOCKS_MERCHANTS, params)
|
||||
.function(this::queryStocksFunction)
|
||||
.consumer(wechatResponseEntity::convert)
|
||||
.request();
|
||||
@@ -174,7 +174,7 @@ public class WechatPayApi {
|
||||
*/
|
||||
public WechatResponseEntity<ObjectNode> queryStocksByMch(StocksQueryParams params) {
|
||||
WechatResponseEntity<ObjectNode> wechatResponseEntity = new WechatResponseEntity<>();
|
||||
wechatPayV3Client.withType(WechatPayV3Type.MARKETING_FAVOR_STOCKS, params)
|
||||
wechatPayClient.withType(WechatPayV3Type.MARKETING_FAVOR_STOCKS, params)
|
||||
.function(this::queryStocksFunction)
|
||||
.consumer(wechatResponseEntity::convert)
|
||||
.request();
|
||||
@@ -231,7 +231,7 @@ public class WechatPayApi {
|
||||
*/
|
||||
public WechatResponseEntity<ObjectNode> sendStocks(StocksSendParams params) {
|
||||
WechatResponseEntity<ObjectNode> wechatResponseEntity = new WechatResponseEntity<>();
|
||||
wechatPayV3Client.withType(WechatPayV3Type.MARKETING_FAVOR_USERS_COUPONS, params)
|
||||
wechatPayClient.withType(WechatPayV3Type.MARKETING_FAVOR_USERS_COUPONS, params)
|
||||
.function(this::sendStocksFunction)
|
||||
.consumer(wechatResponseEntity::convert)
|
||||
.request();
|
||||
@@ -264,7 +264,7 @@ public class WechatPayApi {
|
||||
*/
|
||||
public WechatResponseEntity<ObjectNode> appPay(AppPayParams payParams) {
|
||||
WechatResponseEntity<ObjectNode> wechatResponseEntity = new WechatResponseEntity<>();
|
||||
wechatPayV3Client.withType(WechatPayV3Type.APP, payParams)
|
||||
wechatPayClient.withType(WechatPayV3Type.APP, payParams)
|
||||
.function(this::appPayFunction)
|
||||
.consumer(wechatResponseEntity::convert)
|
||||
.request();
|
||||
|
||||
@@ -18,7 +18,7 @@ import java.util.function.Consumer;
|
||||
* @author Dax
|
||||
* @since 11 :43
|
||||
*/
|
||||
public class WechatPayV3Client {
|
||||
public class WechatPayClient {
|
||||
private final PayFilterChain payFilterChain;
|
||||
|
||||
/**
|
||||
@@ -26,10 +26,11 @@ public class WechatPayV3Client {
|
||||
*
|
||||
* @param signatureProvider the signature provider
|
||||
*/
|
||||
public WechatPayV3Client(SignatureProvider signatureProvider) {
|
||||
public WechatPayClient(SignatureProvider signatureProvider) {
|
||||
DefaultPayFilterChain defaultPayFilterChain = new DefaultPayFilterChain();
|
||||
// 构造私钥签名
|
||||
defaultPayFilterChain.register(new HeaderFilter(signatureProvider));
|
||||
// 向微信支付服务器发起请求
|
||||
defaultPayFilterChain.register(new HttpRequestFilter(signatureProvider));
|
||||
this.payFilterChain = defaultPayFilterChain;
|
||||
}
|
||||
@@ -38,9 +39,9 @@ public class WechatPayV3Client {
|
||||
/**
|
||||
* 构造 {@link WechatRequestEntity}.
|
||||
*
|
||||
* @param <M> the type parameter
|
||||
* @param <M> the type parameter
|
||||
* @param wechatPayV3Type the v 3 pay type
|
||||
* @param m the m
|
||||
* @param m the m
|
||||
* @return the executor
|
||||
*/
|
||||
public <M> Executor<M> withType(WechatPayV3Type wechatPayV3Type, M m) {
|
||||
@@ -57,7 +58,7 @@ public class WechatPayV3Client {
|
||||
/**
|
||||
* The V 3 pay type.
|
||||
*/
|
||||
private final WechatPayV3Type wechatPayV3Type;
|
||||
private final WechatPayV3Type wechatPayV3Type;
|
||||
|
||||
/**
|
||||
* The Pay filter chain.
|
||||
@@ -78,9 +79,9 @@ public class WechatPayV3Client {
|
||||
/**
|
||||
* Instantiates a new Executor.
|
||||
*
|
||||
* @param wechatPayV3Type the v 3 pay type
|
||||
* @param model the model
|
||||
* @param payFilterChain the pay filter chain
|
||||
* @param wechatPayV3Type the v 3 pay type
|
||||
* @param model the model
|
||||
* @param payFilterChain the pay filter chain
|
||||
*/
|
||||
public Executor(WechatPayV3Type wechatPayV3Type,
|
||||
M model,
|
||||
@@ -46,17 +46,17 @@ public class HeaderFilter implements PayFilter {
|
||||
String body = requestEntity.hasBody() ? Objects.requireNonNull(requestEntity.getBody()).toString() : "";
|
||||
String authorization = signatureProvider.requestSign(httpMethod.name(), canonicalUrl, body);
|
||||
|
||||
HttpHeaders headers = requestEntity.getHeaders();
|
||||
|
||||
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
|
||||
HttpHeaders httpHeaders = new HttpHeaders();
|
||||
httpHeaders.addAll(requestEntity.getHeaders());
|
||||
httpHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
|
||||
// 兼容图片上传,自定义优先级最高
|
||||
if (Objects.isNull(headers.getContentType())) {
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
if (Objects.isNull(httpHeaders.getContentType())) {
|
||||
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
|
||||
}
|
||||
headers.add("Authorization", authorization);
|
||||
headers.add("User-Agent", "X-Pay-Service");
|
||||
httpHeaders.add("Authorization", authorization);
|
||||
httpHeaders.add("User-Agent", "X-Pay-Service");
|
||||
|
||||
chain.doChain(requestEntity.headers(headers));
|
||||
chain.doChain(requestEntity.headers(httpHeaders));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user