mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-03-10 00:13:40 +08:00
🆕 #2097 【微信支付】增加微信商户平台商家券相关业务接口
This commit is contained in:
@@ -0,0 +1,250 @@
|
||||
package com.github.binarywang.wxpay.service;
|
||||
|
||||
import com.github.binarywang.wxpay.bean.marketing.*;
|
||||
import com.github.binarywang.wxpay.exception.WxPayException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 微信支付营销商家券接口
|
||||
* </pre>
|
||||
*
|
||||
* @author yujam
|
||||
*/
|
||||
public interface MarketingBusiFavorService {
|
||||
/**
|
||||
* <pre>
|
||||
* 商家券接口-创建商家券API
|
||||
* 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_2_1.shtml
|
||||
* 接口链接:https://api.mch.weixin.qq.com/v3/marketing/busifavor/stocks
|
||||
* </pre>
|
||||
*
|
||||
* @param request 请求对象 {@link BusiFavorStocksCreateRequest}
|
||||
* @return FavorStocksResult 微信返回的批次号信息。
|
||||
* @throws WxPayException the wx pay exception
|
||||
*/
|
||||
BusiFavorStocksCreateResult createBusiFavorStocksV3(BusiFavorStocksCreateRequest request) throws WxPayException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 商家券接口-查询商家券详情API
|
||||
* 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_2_2.shtml
|
||||
* 接口链接:https://api.mch.weixin.qq.com/v3/marketing/busifavor/stocks/{stock_id}
|
||||
* </pre>
|
||||
*
|
||||
* @param stockId 微信为每个商家券批次分配的唯一ID
|
||||
* @return BusiFavorStocksGetResult 微信返回的批次号信息。 {@link BusiFavorStocksGetResult}
|
||||
* @throws WxPayException the wx pay exception
|
||||
*/
|
||||
BusiFavorStocksGetResult getBusiFavorStocksV3(String stockId) throws WxPayException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 商家券接口-核销用户券API
|
||||
* 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_2_3.shtml
|
||||
* 接口链接:https://api.mch.weixin.qq.com/v3/marketing/busifavor/coupons/use
|
||||
* </pre>
|
||||
*
|
||||
* @param request 请求对象 {@link BusiFavorCouponsUseRequest}
|
||||
* @return BusiFavorCouponsUseResult 微信返回的信息。
|
||||
* @throws WxPayException the wx pay exception
|
||||
*/
|
||||
BusiFavorCouponsUseResult verifyBusiFavorCouponsUseV3(BusiFavorCouponsUseRequest request) throws WxPayException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 商家券接口-H5发券API
|
||||
* 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_4_1.shtml
|
||||
* 接口链接:https://action.weixin.qq.com/busifavor/getcouponinfo
|
||||
* </pre>
|
||||
*
|
||||
* @param request 请求对象 {@link BusiFavorCouponsUrlRequest}
|
||||
* @return String H5领券地址
|
||||
* @throws WxPayException the wx pay exception
|
||||
*/
|
||||
String buildBusiFavorCouponinfoUrl(BusiFavorCouponsUrlRequest request) throws WxPayException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 商家券接口-根据过滤条件查询用户券API
|
||||
* 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_2_4.shtml
|
||||
* 接口链接:https://api.mch.weixin.qq.com/v3/marketing/busifavor/users/{openid}/coupons
|
||||
* </pre>
|
||||
*
|
||||
* @param request 请求对象 {@link BusiFavorQueryUserCouponsRequest}
|
||||
* @return BusiFavorQueryUserCouponsResult
|
||||
* @throws WxPayException the wx pay exception
|
||||
*/
|
||||
BusiFavorQueryUserCouponsResult queryBusiFavorUsersCoupons(BusiFavorQueryUserCouponsRequest request) throws WxPayException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 商家券接口-查询用户单张券详情API
|
||||
* 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_2_5.shtml
|
||||
* 接口链接:https://api.mch.weixin.qq.com/v3/marketing/busifavor/users/{openid}/coupons/{coupon_code}/appids/{appid}
|
||||
* </pre>
|
||||
*
|
||||
* @param request 请求对象 {@link BusiFavorQueryOneUserCouponsResult}
|
||||
* @return BusiFavorQueryOneUserCouponsRequest
|
||||
* @throws WxPayException the wx pay exception
|
||||
*/
|
||||
BusiFavorQueryOneUserCouponsResult queryOneBusiFavorUsersCoupons(BusiFavorQueryOneUserCouponsRequest request) throws WxPayException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 商家券接口-上传预存code API
|
||||
* 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_2_6.shtml
|
||||
* 接口链接:https://api.mch.weixin.qq.com/v3/marketing/busifavor/stocks/{stock_id}/couponcodes
|
||||
* </pre>
|
||||
*
|
||||
* @param stockId 批次号
|
||||
* @param request 请求对象 {@link BusiFavorCouponCodeRequest}
|
||||
* @return BusiFavorCouponCodeResult
|
||||
* @throws WxPayException the wx pay exception
|
||||
*/
|
||||
BusiFavorCouponCodeResult uploadBusiFavorCouponCodes(String stockId, BusiFavorCouponCodeRequest request) throws WxPayException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 商家券接口-设置商家券事件通知地址 API
|
||||
* 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_2_7.shtml
|
||||
* 接口链接:https://api.mch.weixin.qq.com/v3/marketing/busifavor/callbacks
|
||||
* </pre>
|
||||
*
|
||||
* @param request 请求对象 {@link BusiFavorCallbacksRequest}
|
||||
* @return BusiFavorCallbacksResult
|
||||
* @throws WxPayException the wx pay exception
|
||||
*/
|
||||
BusiFavorCallbacksResult createBusiFavorCallbacks(BusiFavorCallbacksRequest request) throws WxPayException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 商家券接口-查询商家券事件通知地址 API
|
||||
* 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_2_8.shtml
|
||||
* 接口链接:https://api.mch.weixin.qq.com/v3/marketing/busifavor/callbacks
|
||||
* </pre>
|
||||
*
|
||||
* @param request 请求对象 {@link BusiFavorCallbacksRequest}
|
||||
* @return BusiFavorCallbacksResult
|
||||
* @throws WxPayException the wx pay exception
|
||||
*/
|
||||
BusiFavorCallbacksResult queryBusiFavorCallbacks(BusiFavorCallbacksRequest request) throws WxPayException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 商家券接口-关联订单信息 API
|
||||
* 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_2_9.shtml
|
||||
* 接口链接:https://api.mch.weixin.qq.com/v3/marketing/busifavor/coupons/associate
|
||||
* </pre>
|
||||
*
|
||||
* @param request 请求对象 {@link BusiFavorCouponsAssociateRequest}
|
||||
* @return BusiFavorCouponsAssociateResult
|
||||
* @throws WxPayException the wx pay exception
|
||||
*/
|
||||
BusiFavorCouponsAssociateResult queryBusiFavorCouponsAssociate(BusiFavorCouponsAssociateRequest request) throws WxPayException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 商家券接口-取消关联订单信息 API
|
||||
* 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_2_10.shtml
|
||||
* 接口链接:https://api.mch.weixin.qq.com/v3/marketing/busifavor/coupons/disassociate
|
||||
* </pre>
|
||||
*
|
||||
* @param request 请求对象 {@link BusiFavorCouponsAssociateRequest}
|
||||
* @return BusiFavorCouponsAssociateResult
|
||||
* @throws WxPayException the wx pay exception
|
||||
*/
|
||||
BusiFavorCouponsAssociateResult queryBusiFavorCouponsDisAssociate(BusiFavorCouponsAssociateRequest request) throws WxPayException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 商家券接口-修改批次预算 API
|
||||
* 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_2_11.shtml
|
||||
* 接口链接:https://api.mch.weixin.qq.com/v3/marketing/busifavor/stocks/{stock_id}/budget
|
||||
* </pre>
|
||||
*
|
||||
* @param stockId 批次号
|
||||
* @param request 请求对象 {@link BusiFavorStocksBudgetRequest}
|
||||
* @return BusiFavorStocksBudgetResult
|
||||
* @throws WxPayException the wx pay exception
|
||||
*/
|
||||
BusiFavorStocksBudgetResult updateBusiFavorStocksBudget(String stockId, BusiFavorStocksBudgetRequest request) throws WxPayException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 商家券接口-创建商家券API
|
||||
* 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_2_12.shtml
|
||||
* 接口链接:https://api.mch.weixin.qq.com/v3/marketing/busifavor/stocks/{stock_id}
|
||||
* </pre>
|
||||
*
|
||||
* @param stockId 批次号
|
||||
* @param request 请求对象 {@link BusiFavorStocksCreateRequest}
|
||||
* @return String 处理成功 应答无内容。
|
||||
* @throws WxPayException the wx pay exception
|
||||
*/
|
||||
String updateBusiFavorStocksV3(String stockId, BusiFavorStocksCreateRequest request) throws WxPayException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 商家券接口-申请退款API
|
||||
* 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_2_13.shtml
|
||||
* 接口链接:https://api.mch.weixin.qq.com/v3/marketing/busifavor/coupons/return
|
||||
* </pre>
|
||||
*
|
||||
* @param request 请求对象 {@link BusiFavorCouponsReturnRequest}
|
||||
* @return BusiFavorCouponsReturnResult
|
||||
* @throws WxPayException the wx pay exception
|
||||
*/
|
||||
BusiFavorCouponsReturnResult returnBusiFavorCoupons(BusiFavorCouponsReturnRequest request) throws WxPayException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 商家券接口-使券失效API
|
||||
* 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_2_15.shtml
|
||||
* 接口链接:https://api.mch.weixin.qq.com/v3/marketing/busifavor/coupons/deactivate
|
||||
* </pre>
|
||||
*
|
||||
* @param request 请求对象 {@link BusiFavorCouponsDeactivateRequest}
|
||||
* @return BusiFavorCouponsDeactivateResult
|
||||
* @throws WxPayException the wx pay exception
|
||||
*/
|
||||
BusiFavorCouponsDeactivateResult deactiveBusiFavorCoupons(BusiFavorCouponsDeactivateRequest request) throws WxPayException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 商家券接口-营销补差付款API
|
||||
* 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_2_16.shtml
|
||||
* 接口链接:https://api.mch.weixin.qq.com/v3/marketing/busifavor/subsidy/pay-receipts
|
||||
* </pre>
|
||||
*
|
||||
* @param request 请求对象 {@link BusiFavorSubsidyResult}
|
||||
* @return BusiFavorSubsidyRequest
|
||||
* @throws WxPayException the wx pay exception
|
||||
*/
|
||||
BusiFavorSubsidyResult subsidyBusiFavorPayReceipts(BusiFavorSubsidyRequest request) throws WxPayException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 商家券接口-查询营销补差付款单详情API
|
||||
* 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_2_17.shtml
|
||||
* 接口链接:https://api.mch.weixin.qq.com/v3/marketing/busifavor/subsidy/pay-receipts/{subsidy_receipt_id}
|
||||
* </pre>
|
||||
*
|
||||
* @param subsidyReceiptId 补差付款唯一单号
|
||||
* @return BusiFavorSubsidyRequest
|
||||
* @throws WxPayException the wx pay exception
|
||||
*/
|
||||
BusiFavorSubsidyResult queryBusiFavorSubsidyPayReceipts(String subsidyReceiptId) throws WxPayException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 商家券接口-领券事件回调通知API
|
||||
* 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_2_15.shtml
|
||||
* </pre>
|
||||
*
|
||||
* @param url 回调地址
|
||||
* @param request 领券事件回调通知请求对象
|
||||
* @return BusiFavorNotifyResult
|
||||
* @throws WxPayException the wx pay exception
|
||||
*/
|
||||
BusiFavorNotifyResult notifyBusiFavor(String url, BusiFavorNotifyRequest request) throws WxPayException;
|
||||
}
|
||||
@@ -38,7 +38,7 @@ public interface WxPayService {
|
||||
/**
|
||||
* Map里 加入新的 {@link WxPayConfig},适用于动态添加新的微信公众号配置.
|
||||
*
|
||||
* @param mchId 商户号id
|
||||
* @param mchId 商户号id
|
||||
* @param wxPayConfig 新的微信配置
|
||||
*/
|
||||
void addConfig(String mchId, WxPayConfig wxPayConfig);
|
||||
@@ -62,7 +62,7 @@ public interface WxPayService {
|
||||
* 注入多个 {@link WxPayConfig} 的实现. 并为每个 {@link WxPayConfig} 赋予不同的 {@link String label} 值
|
||||
*
|
||||
* @param wxPayConfigs WxPayConfig map
|
||||
* @param defaultMchId 设置一个{@link WxPayConfig} 所对应的{@link String mchId}进行Http初始化
|
||||
* @param defaultMchId 设置一个{@link WxPayConfig} 所对应的{@link String mchId}进行Http初始化
|
||||
*/
|
||||
void setMultiConfig(Map<String, WxPayConfig> wxPayConfigs, String defaultMchId);
|
||||
|
||||
@@ -114,6 +114,16 @@ public interface WxPayService {
|
||||
*/
|
||||
String postV3(String url, String requestStr) throws WxPayException;
|
||||
|
||||
/**
|
||||
* 发送patch请求,得到响应字符串.
|
||||
*
|
||||
* @param url 请求地址
|
||||
* @param requestStr 请求信息
|
||||
* @return 返回请求结果字符串 string
|
||||
* @throws WxPayException the wx pay exception
|
||||
*/
|
||||
String patchV3(String url, String requestStr) throws WxPayException;
|
||||
|
||||
/**
|
||||
* 发送post请求,得到响应字符串.
|
||||
* <p>
|
||||
@@ -139,7 +149,7 @@ public interface WxPayService {
|
||||
/**
|
||||
* 发送http请求,得到响应字符串.
|
||||
*
|
||||
* @param url 请求地址
|
||||
* @param url 请求地址
|
||||
* @param httpRequest 请求信息,可以是put,post,get,delete等请求
|
||||
* @return 返回请求结果字符串 string
|
||||
* @throws WxPayException the wx pay exception
|
||||
@@ -228,6 +238,13 @@ public interface WxPayService {
|
||||
*/
|
||||
MarketingFavorService getMarketingFavorService();
|
||||
|
||||
/**
|
||||
* 获取微信支付营销商家券服务类
|
||||
*
|
||||
* @return the marketing favor service
|
||||
*/
|
||||
MarketingBusiFavorService getMarketingBusiFavorService();
|
||||
|
||||
/**
|
||||
* 设置企业付款服务类,允许开发者自定义实现类.
|
||||
*
|
||||
@@ -350,7 +367,7 @@ public interface WxPayService {
|
||||
* @param request 请求对象,注意一些参数如appid、mchid等不用设置,方法内会自动从配置对象中获取到(前提是对应配置中已经设置)
|
||||
* @return the pay info
|
||||
* @throws WxPayException the wx pay exception
|
||||
* @deprecated 建议使用 {@link com.github.binarywang.wxpay.service.WxPayService#createOrder(WxPayUnifiedOrderRequest)}
|
||||
* @deprecated 建议使用 {@link WxPayService#createOrder(WxPayUnifiedOrderRequest)}
|
||||
*/
|
||||
@Deprecated
|
||||
Map<String, String> getPayInfo(WxPayUnifiedOrderRequest request) throws WxPayException;
|
||||
|
||||
@@ -66,6 +66,7 @@ public abstract class BaseWxPayServiceImpl implements WxPayService {
|
||||
private final MerchantMediaService merchantMediaService = new MerchantMediaServiceImpl(this);
|
||||
private final MarketingMediaService marketingMediaService = new MarketingMediaServiceImpl(this);
|
||||
private final MarketingFavorService marketingFavorService = new MarketingFavorServiceImpl(this);
|
||||
private final MarketingBusiFavorService marketingBusiFavorService = new MarketingBusiFavorServiceImpl(this);
|
||||
|
||||
protected Map<String, WxPayConfig> configMap;
|
||||
|
||||
@@ -114,6 +115,11 @@ public abstract class BaseWxPayServiceImpl implements WxPayService {
|
||||
return this.marketingFavorService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarketingBusiFavorService getMarketingBusiFavorService() {
|
||||
return this.marketingBusiFavorService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEntPayService(EntPayService entPayService) {
|
||||
this.entPayService = entPayService;
|
||||
|
||||
@@ -0,0 +1,190 @@
|
||||
package com.github.binarywang.wxpay.service.impl;
|
||||
|
||||
import com.github.binarywang.wxpay.bean.marketing.*;
|
||||
import com.github.binarywang.wxpay.constant.WxPayConstants;
|
||||
import com.github.binarywang.wxpay.exception.WxPayException;
|
||||
import com.github.binarywang.wxpay.service.MarketingBusiFavorService;
|
||||
import com.github.binarywang.wxpay.service.WxPayService;
|
||||
import com.github.binarywang.wxpay.util.SignUtils;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 微信支付-营销商家券接口
|
||||
*
|
||||
* @author yujam
|
||||
*/
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class MarketingBusiFavorServiceImpl implements MarketingBusiFavorService {
|
||||
|
||||
private static final Gson GSON = new GsonBuilder().create();
|
||||
private final WxPayService payService;
|
||||
|
||||
@Override
|
||||
public BusiFavorStocksCreateResult createBusiFavorStocksV3(BusiFavorStocksCreateRequest request) throws WxPayException {
|
||||
String url = String.format("%s/v3/marketing/busifavor/stocks", this.payService.getPayBaseUrl());
|
||||
String result = this.payService.postV3WithWechatpaySerial(url, GSON.toJson(request));
|
||||
return GSON.fromJson(result, BusiFavorStocksCreateResult.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BusiFavorStocksGetResult getBusiFavorStocksV3(String stockId) throws WxPayException {
|
||||
String url = String.format("%s/v3/marketing/busifavor/stocks/%s", this.payService.getPayBaseUrl(), stockId);
|
||||
String result = this.payService.getV3(url);
|
||||
return GSON.fromJson(result, BusiFavorStocksGetResult.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BusiFavorCouponsUseResult verifyBusiFavorCouponsUseV3(BusiFavorCouponsUseRequest request) throws WxPayException {
|
||||
String url = String.format("%s/v3/marketing/busifavor/coupons/use", this.payService.getPayBaseUrl());
|
||||
String result = this.payService.postV3WithWechatpaySerial(url, GSON.toJson(request));
|
||||
return GSON.fromJson(result, BusiFavorCouponsUseResult.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String buildBusiFavorCouponinfoUrl(BusiFavorCouponsUrlRequest request) throws WxPayException {
|
||||
Map<String, String> signMap = new HashMap<>(8);
|
||||
signMap.put("out_request_no", request.getOutRequestNo());
|
||||
signMap.put("stock_id", request.getStockId());
|
||||
signMap.put("send_coupon_merchant", request.getSendCouponMerchant());
|
||||
signMap.put("open_id", request.getOpenid());
|
||||
|
||||
String sign = SignUtils.createSign(signMap, WxPayConstants.SignType.HMAC_SHA256, this.payService.getConfig().getMchKey(), null);
|
||||
String actionBaseUrl = "https://action.weixin.qq.com";
|
||||
return String.format("%s/busifavor/getcouponinfo?stock_id=%s&out_request_no=%s&sign=%s&send_coupon_merchant=%s&open_id=%s#wechat_redirect",
|
||||
actionBaseUrl, request.getStockId(), request.getOutRequestNo(), sign, request.getSendCouponMerchant(), request.getOpenid());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BusiFavorQueryUserCouponsResult queryBusiFavorUsersCoupons(BusiFavorQueryUserCouponsRequest request) throws WxPayException {
|
||||
String url = String.format("%s/v3/marketing/busifavor/users/%s/coupons", this.payService.getPayBaseUrl(), request.getOpenid());
|
||||
|
||||
if (request.getOffset() == null) {
|
||||
request.setOffset(0);
|
||||
}
|
||||
|
||||
if (request.getLimit() == null || request.getLimit() <= 0) {
|
||||
request.setLimit(20);
|
||||
}
|
||||
|
||||
String query = String.format("?appid=%s&offset=%s&limit=%s", request.getAppid(), request.getOffset(), request.getLimit());
|
||||
|
||||
if (StringUtils.isNotBlank(request.getStockId())) {
|
||||
query += "&stock_id=" + request.getStockId();
|
||||
}
|
||||
if (StringUtils.isNotBlank(request.getCouponState())) {
|
||||
query += "&coupon_state=" + request.getCouponState();
|
||||
}
|
||||
if (StringUtils.isNotBlank(request.getCreatorMerchant())) {
|
||||
query += "&creator_merchant=" + request.getCreatorMerchant();
|
||||
}
|
||||
if (StringUtils.isNotBlank(request.getBelongMerchant())) {
|
||||
query += "&belong_merchant=" + request.getBelongMerchant();
|
||||
}
|
||||
if (StringUtils.isNotBlank(request.getSenderMerchant())) {
|
||||
query += "&sender_merchant=" + request.getSenderMerchant();
|
||||
}
|
||||
|
||||
String result = this.payService.getV3(url + query);
|
||||
return GSON.fromJson(result, BusiFavorQueryUserCouponsResult.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BusiFavorQueryOneUserCouponsResult queryOneBusiFavorUsersCoupons(BusiFavorQueryOneUserCouponsRequest request) throws WxPayException {
|
||||
String url = String.format("%s/v3/marketing/busifavor/users/%s/coupons/%s/appids/%s", this.payService.getPayBaseUrl(), request.getOpenid(), request.getCouponCode(), request.getAppid());
|
||||
String result = this.payService.getV3(url);
|
||||
return GSON.fromJson(result, BusiFavorQueryOneUserCouponsResult.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BusiFavorCouponCodeResult uploadBusiFavorCouponCodes(String stockId, BusiFavorCouponCodeRequest request) throws WxPayException {
|
||||
String url = String.format("%s/v3/marketing/busifavor/stocks/%s/couponcodes", this.payService.getPayBaseUrl(), stockId);
|
||||
String result = this.payService.postV3WithWechatpaySerial(url, GSON.toJson(request));
|
||||
return GSON.fromJson(result, BusiFavorCouponCodeResult.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BusiFavorCallbacksResult createBusiFavorCallbacks(BusiFavorCallbacksRequest request) throws WxPayException {
|
||||
String url = String.format("%s/v3/marketing/busifavor/callbacks", this.payService.getPayBaseUrl());
|
||||
String result = this.payService.postV3WithWechatpaySerial(url, GSON.toJson(request));
|
||||
return GSON.fromJson(result, BusiFavorCallbacksResult.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BusiFavorCallbacksResult queryBusiFavorCallbacks(BusiFavorCallbacksRequest request) throws WxPayException {
|
||||
String url = String.format("%s/v3/marketing/busifavor/callbacks", this.payService.getPayBaseUrl());
|
||||
if (StringUtils.isNotBlank(request.getMchid())) {
|
||||
url += "?mchid=" + request.getMchid();
|
||||
}
|
||||
String result = this.payService.getV3(url);
|
||||
return GSON.fromJson(result, BusiFavorCallbacksResult.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BusiFavorCouponsAssociateResult queryBusiFavorCouponsAssociate(BusiFavorCouponsAssociateRequest request) throws WxPayException {
|
||||
String url = String.format("%s/v3/marketing/busifavor/coupons/associate", this.payService.getPayBaseUrl());
|
||||
String result = this.payService.postV3WithWechatpaySerial(url, GSON.toJson(request));
|
||||
return GSON.fromJson(result, BusiFavorCouponsAssociateResult.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BusiFavorCouponsAssociateResult queryBusiFavorCouponsDisAssociate(BusiFavorCouponsAssociateRequest request) throws WxPayException {
|
||||
String url = String.format("%s/v3/marketing/busifavor/coupons/disassociate", this.payService.getPayBaseUrl());
|
||||
String result = this.payService.postV3WithWechatpaySerial(url, GSON.toJson(request));
|
||||
return GSON.fromJson(result, BusiFavorCouponsAssociateResult.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BusiFavorStocksBudgetResult updateBusiFavorStocksBudget(String stockId, BusiFavorStocksBudgetRequest request) throws WxPayException {
|
||||
String url = String.format("%s/v3/marketing/busifavor/stocks/%s/budget", this.payService.getPayBaseUrl(), stockId);
|
||||
String result = payService.patchV3(url, GSON.toJson(request));
|
||||
return GSON.fromJson(result, BusiFavorStocksBudgetResult.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String updateBusiFavorStocksV3(String stockId, BusiFavorStocksCreateRequest request) throws WxPayException {
|
||||
String url = String.format("%s/v3/marketing/busifavor/stocks/%s", this.payService.getPayBaseUrl(), stockId);
|
||||
return this.payService.patchV3(url, GSON.toJson(request));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BusiFavorCouponsReturnResult returnBusiFavorCoupons(BusiFavorCouponsReturnRequest request) throws WxPayException {
|
||||
String url = String.format("%s/v3/marketing/busifavor/coupons/return", this.payService.getPayBaseUrl());
|
||||
String result = this.payService.postV3WithWechatpaySerial(url, GSON.toJson(request));
|
||||
return GSON.fromJson(result, BusiFavorCouponsReturnResult.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BusiFavorCouponsDeactivateResult deactiveBusiFavorCoupons(BusiFavorCouponsDeactivateRequest request) throws WxPayException {
|
||||
String url = String.format("%s/v3/marketing/busifavor/coupons/deactivate", this.payService.getPayBaseUrl());
|
||||
String result = this.payService.postV3WithWechatpaySerial(url, GSON.toJson(request));
|
||||
return GSON.fromJson(result, BusiFavorCouponsDeactivateResult.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BusiFavorSubsidyResult subsidyBusiFavorPayReceipts(BusiFavorSubsidyRequest request) throws WxPayException {
|
||||
String url = String.format("%s/v3/marketing/busifavor/subsidy/pay-receipts", this.payService.getPayBaseUrl());
|
||||
String result = this.payService.postV3WithWechatpaySerial(url, GSON.toJson(request));
|
||||
return GSON.fromJson(result, BusiFavorSubsidyResult.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BusiFavorSubsidyResult queryBusiFavorSubsidyPayReceipts(String subsidyReceiptId) throws WxPayException {
|
||||
String url = String.format("%s/v3/marketing/busifavor/subsidy/pay-receipts/%s", this.payService.getPayBaseUrl(), subsidyReceiptId);
|
||||
String result = this.payService.getV3(url);
|
||||
return GSON.fromJson(result, BusiFavorSubsidyResult.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BusiFavorNotifyResult notifyBusiFavor(String url, BusiFavorNotifyRequest request) throws WxPayException {
|
||||
String result = this.payService.postV3WithWechatpaySerial(url, GSON.toJson(request));
|
||||
return GSON.fromJson(result, BusiFavorNotifyResult.class);
|
||||
}
|
||||
}
|
||||
@@ -13,10 +13,7 @@ import org.apache.http.auth.AuthScope;
|
||||
import org.apache.http.auth.UsernamePasswordCredentials;
|
||||
import org.apache.http.client.CredentialsProvider;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.client.methods.HttpRequestBase;
|
||||
import org.apache.http.client.methods.*;
|
||||
import org.apache.http.conn.ssl.DefaultHostnameVerifier;
|
||||
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
|
||||
import org.apache.http.entity.ContentType;
|
||||
@@ -125,6 +122,46 @@ public class WxPayServiceApacheHttpImpl extends BaseWxPayServiceImpl {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String patchV3(String url, String requestStr) throws WxPayException {
|
||||
CloseableHttpClient httpClient = this.createApiV3HttpClient();
|
||||
HttpPatch httpPatch = new HttpPatch(url);
|
||||
httpPatch.setEntity(this.createEntry(requestStr));
|
||||
|
||||
httpPatch.setConfig(RequestConfig.custom()
|
||||
.setConnectionRequestTimeout(this.getConfig().getHttpConnectionTimeout())
|
||||
.setConnectTimeout(this.getConfig().getHttpConnectionTimeout())
|
||||
.setSocketTimeout(this.getConfig().getHttpTimeout())
|
||||
.build());
|
||||
|
||||
httpPatch.addHeader("Accept", "application/json");
|
||||
httpPatch.addHeader("Content-Type", "application/json");
|
||||
try (CloseableHttpResponse response = httpClient.execute(httpPatch)) {
|
||||
//v3已经改为通过状态码判断200 204 成功
|
||||
int statusCode = response.getStatusLine().getStatusCode();
|
||||
//post方法有可能会没有返回值的情况
|
||||
String responseString;
|
||||
if (response.getEntity() == null) {
|
||||
responseString = null;
|
||||
} else {
|
||||
responseString = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
|
||||
}
|
||||
if (HttpStatus.SC_OK == statusCode || HttpStatus.SC_NO_CONTENT == statusCode) {
|
||||
this.log.info("\n【请求地址】:{}\n【请求数据】:{}\n【响应数据】:{}", url, requestStr, responseString);
|
||||
return responseString;
|
||||
} else {
|
||||
//有错误提示信息返回
|
||||
JsonObject jsonObject = GsonParser.parse(responseString);
|
||||
throw convertException(jsonObject);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
this.log.error("\n【请求地址】:{}\n【请求数据】:{}\n【异常信息】:{}", url, requestStr, e.getMessage());
|
||||
throw (e instanceof WxPayException) ? (WxPayException) e : new WxPayException(e.getMessage(), e);
|
||||
} finally {
|
||||
httpPatch.releaseConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String postV3WithWechatpaySerial(String url, String requestStr) throws WxPayException {
|
||||
CloseableHttpClient httpClient = this.createApiV3HttpClient();
|
||||
|
||||
@@ -66,6 +66,11 @@ public class WxPayServiceJoddHttpImpl extends BaseWxPayServiceImpl {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String patchV3(String url, String requestStr) throws WxPayException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String postV3WithWechatpaySerial(String url, String requestStr) throws WxPayException {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user