mirror of
https://github.com/dromara/payment-spring-boot.git
synced 2026-03-14 05:43:46 +08:00
完善营销API
This commit is contained in:
@@ -53,13 +53,9 @@ public enum WechatPayV3Type {
|
|||||||
*/
|
*/
|
||||||
MARKETING_FAVOR_USERS_COUPONS(HttpMethod.POST,"%s/v3/marketing/favor/users/{openid}/coupons"),
|
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_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.
|
* 条件查询批次列表API.
|
||||||
*/
|
*/
|
||||||
@@ -68,6 +64,18 @@ public enum WechatPayV3Type {
|
|||||||
* 查询批次详情API.
|
* 查询批次详情API.
|
||||||
*/
|
*/
|
||||||
MARKETING_FAVOR_STOCKS_DETAIL(HttpMethod.GET, "%s/v3/marketing/favor/stocks/{stock_id}"),
|
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.
|
* 营销图片上传API.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import cn.felord.payment.wechat.WechatPayProperties;
|
|||||||
import cn.felord.payment.wechat.enumeration.StockStatus;
|
import cn.felord.payment.wechat.enumeration.StockStatus;
|
||||||
import cn.felord.payment.wechat.enumeration.WeChatServer;
|
import cn.felord.payment.wechat.enumeration.WeChatServer;
|
||||||
import cn.felord.payment.wechat.enumeration.WechatPayV3Type;
|
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.StocksCreateParams;
|
||||||
import cn.felord.payment.wechat.v3.model.StocksQueryParams;
|
import cn.felord.payment.wechat.v3.model.StocksQueryParams;
|
||||||
import cn.felord.payment.wechat.v3.model.StocksSendParams;
|
import cn.felord.payment.wechat.v3.model.StocksSendParams;
|
||||||
@@ -64,8 +65,9 @@ public class WechatMarketingApi extends AbstractApi {
|
|||||||
private RequestEntity<?> createStocksFunction(WechatPayV3Type type, StocksCreateParams params) {
|
private RequestEntity<?> createStocksFunction(WechatPayV3Type type, StocksCreateParams params) {
|
||||||
WechatPayProperties.V3 v3 = this.meta().getWechatPayProperties().getV3();
|
WechatPayProperties.V3 v3 = this.meta().getWechatPayProperties().getV3();
|
||||||
String mchId = v3.getMchId();
|
String mchId = v3.getMchId();
|
||||||
String httpUrl = type.uri(WeChatServer.CHINA);
|
URI uri = UriComponentsBuilder.fromHttpUrl(type.uri(WeChatServer.CHINA))
|
||||||
URI uri = UriComponentsBuilder.fromHttpUrl(httpUrl).build().toUri();
|
.build()
|
||||||
|
.toUri();
|
||||||
params.setBelongMerchant(mchId);
|
params.setBelongMerchant(mchId);
|
||||||
return post(uri, params);
|
return post(uri, params);
|
||||||
}
|
}
|
||||||
@@ -107,8 +109,10 @@ public class WechatMarketingApi extends AbstractApi {
|
|||||||
// 服务号
|
// 服务号
|
||||||
params.setAppid(v3.getMp().getAppId());
|
params.setAppid(v3.getMp().getAppId());
|
||||||
params.setStockCreatorMchid(v3.getMchId());
|
params.setStockCreatorMchid(v3.getMchId());
|
||||||
String httpUrl = type.uri(WeChatServer.CHINA);
|
URI uri = UriComponentsBuilder.fromHttpUrl(type.uri(WeChatServer.CHINA))
|
||||||
URI uri = UriComponentsBuilder.fromHttpUrl(httpUrl).build().expand(params.getOpenid()).toUri();
|
.build()
|
||||||
|
.expand(params.getOpenid())
|
||||||
|
.toUri();
|
||||||
params.setOpenid(null);
|
params.setOpenid(null);
|
||||||
return post(uri, params);
|
return post(uri, params);
|
||||||
}
|
}
|
||||||
@@ -127,6 +131,7 @@ public class WechatMarketingApi extends AbstractApi {
|
|||||||
.request();
|
.request();
|
||||||
return wechatResponseEntity;
|
return wechatResponseEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 重启代金券批次API.
|
* 重启代金券批次API.
|
||||||
*
|
*
|
||||||
@@ -147,59 +152,16 @@ public class WechatMarketingApi extends AbstractApi {
|
|||||||
String mchId = v3.getMchId();
|
String mchId = v3.getMchId();
|
||||||
Map<String, String> body = new HashMap<>();
|
Map<String, String> body = new HashMap<>();
|
||||||
body.put("stock_creator_mchid", mchId);
|
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);
|
return post(uri, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询批次详情API.
|
* 条件查询批次列表API.
|
||||||
*
|
|
||||||
* @param stockId the stock id
|
|
||||||
* @return the wechat response entity
|
|
||||||
*/
|
|
||||||
public WechatResponseEntity<ObjectNode> queryStockDetail(String stockId) {
|
|
||||||
WechatResponseEntity<ObjectNode> 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<String, String> 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<ObjectNode> queryMerchantsByStockId(StocksQueryParams params) {
|
|
||||||
WechatResponseEntity<ObjectNode> wechatResponseEntity = new WechatResponseEntity<>();
|
|
||||||
this.client().withType(WechatPayV3Type.MARKETING_FAVOR_STOCKS_MERCHANTS, params)
|
|
||||||
.function(this::queryStocksFunction)
|
|
||||||
.consumer(wechatResponseEntity::convert)
|
|
||||||
.request();
|
|
||||||
|
|
||||||
return wechatResponseEntity;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 分页查询商户下的代金券批次.
|
|
||||||
*
|
*
|
||||||
* @param params the params
|
* @param params the params
|
||||||
* @return the wechat response entity
|
* @return the wechat response entity
|
||||||
@@ -254,6 +216,120 @@ public class WechatMarketingApi extends AbstractApi {
|
|||||||
return RequestEntity.get(uri).build();
|
return RequestEntity.get(uri).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询批次详情API.
|
||||||
|
*
|
||||||
|
* @param stockId the stock id
|
||||||
|
* @return the wechat response entity
|
||||||
|
*/
|
||||||
|
public WechatResponseEntity<ObjectNode> queryStockDetail(String stockId) {
|
||||||
|
WechatResponseEntity<ObjectNode> 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<String, String> 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<ObjectNode> queryCouponDetails(CouponDetailsQueryParams params) {
|
||||||
|
WechatResponseEntity<ObjectNode> 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<String, String> queryParams = new LinkedMultiValueMap<>();
|
||||||
|
queryParams.add("appid", v3.getMp().getAppId());
|
||||||
|
|
||||||
|
MultiValueMap<String, String> 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<ObjectNode> queryMerchantsByStockId(StocksQueryParams params) {
|
||||||
|
WechatResponseEntity<ObjectNode> 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<ObjectNode> queryStockItems(StocksQueryParams params) {
|
||||||
|
WechatResponseEntity<ObjectNode> 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<ObjectNode> queryUserCouponsByMchId(StocksQueryParams params) {
|
||||||
|
WechatResponseEntity<ObjectNode> wechatResponseEntity = new WechatResponseEntity<>();
|
||||||
|
this.client().withType(WechatPayV3Type.MARKETING_FAVOR_STOCKS_ITEMS, params)
|
||||||
|
.function(this::queryStocksFunction)
|
||||||
|
.consumer(wechatResponseEntity::convert)
|
||||||
|
.request();
|
||||||
|
|
||||||
|
return wechatResponseEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 营销图片上传API.
|
* 营销图片上传API.
|
||||||
*
|
*
|
||||||
@@ -287,7 +363,7 @@ public class WechatMarketingApi extends AbstractApi {
|
|||||||
String metaStr = this.getMapper().writeValueAsString(meta);
|
String metaStr = this.getMapper().writeValueAsString(meta);
|
||||||
return RequestEntity.post(uri)
|
return RequestEntity.post(uri)
|
||||||
.header("Content-Type", MediaType.MULTIPART_FORM_DATA_VALUE)
|
.header("Content-Type", MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||||
.header("Meta-Info",metaStr)
|
.header("Meta-Info", metaStr)
|
||||||
.body(body);
|
.body(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user