1
0
mirror of synced 2026-10-07 23:39:43 +08:00

🆕 #4107 【微信支付】新增服务商点金计划接口,并修复patchV3缺失Http头问题

This commit is contained in:
buaazyl
2026-08-22 21:54:42 +08:00
committed by GitHub
parent 0122878b14
commit 92ac532377
7 changed files with 251 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
package com.github.binarywang.wxpay.bean.goldplan;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import java.io.Serializable;
/**
* 点金计划操作结果
*
* @author zhangyl
*/
@Data
public class GoldPlanResult implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 特约商户号
*/
@SerializedName("sub_mchid")
private String subMchId;
}

View File

@@ -0,0 +1,104 @@
package com.github.binarywang.wxpay.service;
import com.github.binarywang.wxpay.bean.goldplan.GoldPlanResult;
import com.github.binarywang.wxpay.exception.WxPayException;
import java.util.List;
/**
* 点金计划 接口
* <p>
* <a href="https://pay.weixin.qq.com/doc/v3/partner/4012072130">产品介绍</a>
* </p>
*
* @author zhangyl
* @since 2026-08-22
*/
public interface GoldPlanService {
/**
* 为特约商户开通点金计划
* <p>
* <a href="https://pay.weixin.qq.com/doc/v3/partner/4012473796">接口文档</a>
* </p>
*
* @param subMchId 特约商户号
* @param operationPayScene 支付场景,可选值为JSAPI_AND_MINIPROGRAM、JSAPI、MINIPROGRAM;不传时默认为JSAPI
* @return 点金计划操作结果
* @throws WxPayException 微信支付请求异常
*/
GoldPlanResult openGoldPlan(String subMchId, String operationPayScene) throws WxPayException;
/**
* 为特约商户关闭点金计划
* <p>
* <a href="https://pay.weixin.qq.com/doc/v3/partner/4012473796">接口文档</a>
* </p>
*
* @param subMchId 特约商户号
* @param operationPayScene 支付场景,可选值为JSAPI_AND_MINIPROGRAM、JSAPI、MINIPROGRAM;不传时默认为JSAPI
* @return 点金计划操作结果
* @throws WxPayException 微信支付请求异常
*/
GoldPlanResult closeGoldPlan(String subMchId, String operationPayScene) throws WxPayException;
/**
* 为特约商户开通商家小票
* <p>
* <a href="https://pay.weixin.qq.com/doc/v3/partner/4012473788">接口文档</a>
* </p>
*
* @param subMchId 特约商户号
* @return 商家小票操作结果
* @throws WxPayException 微信支付请求异常
*/
GoldPlanResult openCustomPage(String subMchId) throws WxPayException;
/**
* 为特约商户关闭商家小票
* <p>
* <a href="https://pay.weixin.qq.com/doc/v3/partner/4012473788">接口文档</a>
* </p>
*
* @param subMchId 特约商户号
* @return 商家小票操作结果
* @throws WxPayException 微信支付请求异常
*/
GoldPlanResult closeCustomPage(String subMchId) throws WxPayException;
/**
* 设置特约商户的点金计划同业过滤标签
* <p>
* <a href="https://pay.weixin.qq.com/doc/v3/partner/4012473784">接口文档</a>
* </p>
*
* @param subMchId 特约商户号
* @param advertisingIndustryFilters 同业过滤标签,最少一个,最多三个
* @throws WxPayException 微信支付请求异常
*/
void setAdvertisingIndustryFilter(String subMchId, List<String> advertisingIndustryFilters) throws WxPayException;
/**
* 为特约商户的点金计划页面开通广告展示
* <p>
* <a href="https://pay.weixin.qq.com/doc/v3/partner/4012473794">接口文档</a>
* </p>
*
* @param subMchId 特约商户号
* @param advertisingIndustryFilters 同业过滤标签,可选,最多三个
* @throws WxPayException 微信支付请求异常
*/
void openAdvertisingShow(String subMchId, List<String> advertisingIndustryFilters) throws WxPayException;
/**
* 为特约商户的点金计划页面关闭广告展示
* <p>
* <a href="https://pay.weixin.qq.com/doc/v3/partner/4012473781">接口文档</a>
* </p>
*
* @param subMchId 特约商户号
* @throws WxPayException 微信支付请求异常
*/
void closeAdvertisingShow(String subMchId) throws WxPayException;
}

View File

@@ -408,6 +408,13 @@ public interface WxPayService {
*/
MerchantLimitationService getMerchantLimitationService();
/**
* 获取点金计划服务类
*
* @return 点金计划服务
*/
GoldPlanService getGoldPlanService();
/**
* 获取服务商电子发票服务类。
*

View File

@@ -148,6 +148,9 @@ public abstract class BaseWxPayServiceImpl implements WxPayService {
@Getter
private final MerchantLimitationService merchantLimitationService = new MerchantLimitationServiceImpl(this);
@Getter
private final GoldPlanService goldPlanService = new GoldPlanServiceImpl(this);
@Getter
private final PartnerInvoiceService partnerInvoiceService = new PartnerInvoiceServiceImpl(this);

View File

@@ -0,0 +1,113 @@
package com.github.binarywang.wxpay.service.impl;
import com.github.binarywang.wxpay.bean.goldplan.GoldPlanResult;
import com.github.binarywang.wxpay.exception.WxPayException;
import com.github.binarywang.wxpay.service.GoldPlanService;
import com.github.binarywang.wxpay.service.WxPayService;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import lombok.RequiredArgsConstructor;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 点金计划 接口实现
*
* @author zhangyl
* @since 2026-08-22
*/
@RequiredArgsConstructor
public class GoldPlanServiceImpl implements GoldPlanService {
private static final Gson GSON = new GsonBuilder().create();
private static final String OPEN = "OPEN";
private static final String CLOSE = "CLOSE";
private final WxPayService payService;
@Override
public GoldPlanResult openGoldPlan(String subMchId, String operationPayScene) throws WxPayException {
return changeGoldPlanStatus(subMchId, OPEN, operationPayScene);
}
/**
* 调用微信支付接口开通或关闭点金计划
*
* @param subMchId 特约商户号
* @param operationType 操作类型
* @param operationPayScene 支付场景
* @return 点金计划操作结果
* @throws WxPayException 微信支付请求异常
*/
private GoldPlanResult changeGoldPlanStatus(String subMchId, String operationType,
String operationPayScene) throws WxPayException {
String url = String.format("%s/v3/goldplan/merchants/changegoldplanstatus", this.payService.getPayBaseUrl());
Map<String, Object> request = new HashMap<>(4);
request.put("sub_mchid", subMchId);
request.put("operation_type", operationType);
request.put("operation_pay_scene", operationPayScene);
String result = this.payService.postV3(url, GSON.toJson(request));
return GSON.fromJson(result, GoldPlanResult.class);
}
@Override
public GoldPlanResult closeGoldPlan(String subMchId, String operationPayScene) throws WxPayException {
return changeGoldPlanStatus(subMchId, CLOSE, operationPayScene);
}
@Override
public GoldPlanResult openCustomPage(String subMchId) throws WxPayException {
return changeCustomPageStatus(subMchId, OPEN);
}
/**
* 调用微信支付接口开通或关闭商家小票
*
* @param subMchId 特约商户号
* @param operationType 操作类型
* @return 商家小票操作结果
* @throws WxPayException 微信支付请求异常
*/
private GoldPlanResult changeCustomPageStatus(String subMchId, String operationType) throws WxPayException {
String url = String.format("%s/v3/goldplan/merchants/changecustompagestatus", this.payService.getPayBaseUrl());
Map<String, String> request = new HashMap<>(2);
request.put("sub_mchid", subMchId);
request.put("operation_type", operationType);
String result = this.payService.postV3(url, GSON.toJson(request));
return GSON.fromJson(result, GoldPlanResult.class);
}
@Override
public GoldPlanResult closeCustomPage(String subMchId) throws WxPayException {
return changeCustomPageStatus(subMchId, CLOSE);
}
@Override
public void setAdvertisingIndustryFilter(String subMchId, List<String> advertisingIndustryFilters)
throws WxPayException {
String url = String.format("%s/v3/goldplan/merchants/set-advertising-industry-filter",
this.payService.getPayBaseUrl());
Map<String, Object> request = new HashMap<>(2);
request.put("sub_mchid", subMchId);
request.put("advertising_industry_filters", advertisingIndustryFilters);
this.payService.postV3(url, GSON.toJson(request));
}
@Override
public void openAdvertisingShow(String subMchId, List<String> advertisingIndustryFilters) throws WxPayException {
String url = String.format("%s/v3/goldplan/merchants/open-advertising-show", this.payService.getPayBaseUrl());
Map<String, Object> request = new HashMap<>(2);
request.put("sub_mchid", subMchId);
request.put("advertising_industry_filters", advertisingIndustryFilters);
this.payService.patchV3(url, GSON.toJson(request));
}
@Override
public void closeAdvertisingShow(String subMchId) throws WxPayException {
String url = String.format("%s/v3/goldplan/merchants/close-advertising-show", this.payService.getPayBaseUrl());
Map<String, String> request = new HashMap<>(1);
request.put("sub_mchid", subMchId);
this.payService.postV3(url, GSON.toJson(request));
}
}

View File

@@ -159,6 +159,7 @@ public class WxPayServiceApacheHttpImpl extends BaseWxPayServiceImpl {
public String patchV3(String url, String requestStr) throws WxPayException {
HttpPatch httpPatch = new HttpPatch(url);
httpPatch.setEntity(createEntry(requestStr));
this.configureRequest(httpPatch);
return this.requestV3(url, requestStr, httpPatch);
}

View File

@@ -156,6 +156,7 @@ public class WxPayServiceHttpComponentsImpl extends BaseWxPayServiceImpl {
public String patchV3(String url, String requestStr) throws WxPayException {
HttpPatch httpPatch = new HttpPatch(url);
httpPatch.setEntity(createEntry(requestStr));
this.configureRequest(httpPatch);
return this.requestV3(url, requestStr, httpPatch);
}