Skip to content

Commit 92ac532

Browse files
authored
🆕 #4107 【微信支付】新增服务商点金计划接口,并修复patchV3缺失Http头问题
1 parent 0122878 commit 92ac532

7 files changed

Lines changed: 251 additions & 0 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.github.binarywang.wxpay.bean.goldplan;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Data;
5+
6+
import java.io.Serializable;
7+
8+
/**
9+
* 点金计划操作结果
10+
*
11+
* @author zhangyl
12+
*/
13+
@Data
14+
public class GoldPlanResult implements Serializable {
15+
private static final long serialVersionUID = 1L;
16+
17+
/**
18+
* 特约商户号
19+
*/
20+
@SerializedName("sub_mchid")
21+
private String subMchId;
22+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package com.github.binarywang.wxpay.service;
2+
3+
import com.github.binarywang.wxpay.bean.goldplan.GoldPlanResult;
4+
import com.github.binarywang.wxpay.exception.WxPayException;
5+
6+
import java.util.List;
7+
8+
/**
9+
* 点金计划 接口
10+
* <p>
11+
* <a href="https://pay.weixin.qq.com/doc/v3/partner/4012072130">产品介绍</a>
12+
* </p>
13+
*
14+
* @author zhangyl
15+
* @since 2026-08-22
16+
*/
17+
public interface GoldPlanService {
18+
19+
/**
20+
* 为特约商户开通点金计划
21+
* <p>
22+
* <a href="https://pay.weixin.qq.com/doc/v3/partner/4012473796">接口文档</a>
23+
* </p>
24+
*
25+
* @param subMchId 特约商户号
26+
* @param operationPayScene 支付场景,可选值为JSAPI_AND_MINIPROGRAM、JSAPI、MINIPROGRAM;不传时默认为JSAPI
27+
* @return 点金计划操作结果
28+
* @throws WxPayException 微信支付请求异常
29+
*/
30+
GoldPlanResult openGoldPlan(String subMchId, String operationPayScene) throws WxPayException;
31+
32+
/**
33+
* 为特约商户关闭点金计划
34+
* <p>
35+
* <a href="https://pay.weixin.qq.com/doc/v3/partner/4012473796">接口文档</a>
36+
* </p>
37+
*
38+
* @param subMchId 特约商户号
39+
* @param operationPayScene 支付场景,可选值为JSAPI_AND_MINIPROGRAM、JSAPI、MINIPROGRAM;不传时默认为JSAPI
40+
* @return 点金计划操作结果
41+
* @throws WxPayException 微信支付请求异常
42+
*/
43+
GoldPlanResult closeGoldPlan(String subMchId, String operationPayScene) throws WxPayException;
44+
45+
/**
46+
* 为特约商户开通商家小票
47+
* <p>
48+
* <a href="https://pay.weixin.qq.com/doc/v3/partner/4012473788">接口文档</a>
49+
* </p>
50+
*
51+
* @param subMchId 特约商户号
52+
* @return 商家小票操作结果
53+
* @throws WxPayException 微信支付请求异常
54+
*/
55+
GoldPlanResult openCustomPage(String subMchId) throws WxPayException;
56+
57+
/**
58+
* 为特约商户关闭商家小票
59+
* <p>
60+
* <a href="https://pay.weixin.qq.com/doc/v3/partner/4012473788">接口文档</a>
61+
* </p>
62+
*
63+
* @param subMchId 特约商户号
64+
* @return 商家小票操作结果
65+
* @throws WxPayException 微信支付请求异常
66+
*/
67+
GoldPlanResult closeCustomPage(String subMchId) throws WxPayException;
68+
69+
/**
70+
* 设置特约商户的点金计划同业过滤标签
71+
* <p>
72+
* <a href="https://pay.weixin.qq.com/doc/v3/partner/4012473784">接口文档</a>
73+
* </p>
74+
*
75+
* @param subMchId 特约商户号
76+
* @param advertisingIndustryFilters 同业过滤标签,最少一个,最多三个
77+
* @throws WxPayException 微信支付请求异常
78+
*/
79+
void setAdvertisingIndustryFilter(String subMchId, List<String> advertisingIndustryFilters) throws WxPayException;
80+
81+
/**
82+
* 为特约商户的点金计划页面开通广告展示
83+
* <p>
84+
* <a href="https://pay.weixin.qq.com/doc/v3/partner/4012473794">接口文档</a>
85+
* </p>
86+
*
87+
* @param subMchId 特约商户号
88+
* @param advertisingIndustryFilters 同业过滤标签,可选,最多三个
89+
* @throws WxPayException 微信支付请求异常
90+
*/
91+
void openAdvertisingShow(String subMchId, List<String> advertisingIndustryFilters) throws WxPayException;
92+
93+
/**
94+
* 为特约商户的点金计划页面关闭广告展示
95+
* <p>
96+
* <a href="https://pay.weixin.qq.com/doc/v3/partner/4012473781">接口文档</a>
97+
* </p>
98+
*
99+
* @param subMchId 特约商户号
100+
* @throws WxPayException 微信支付请求异常
101+
*/
102+
void closeAdvertisingShow(String subMchId) throws WxPayException;
103+
104+
}

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,13 @@ default WxPayService switchoverTo(String mchIdOrConfigKey) {
408408
*/
409409
MerchantLimitationService getMerchantLimitationService();
410410

411+
/**
412+
* 获取点金计划服务类
413+
*
414+
* @return 点金计划服务
415+
*/
416+
GoldPlanService getGoldPlanService();
417+
411418
/**
412419
* 获取服务商电子发票服务类。
413420
*

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ public abstract class BaseWxPayServiceImpl implements WxPayService {
148148
@Getter
149149
private final MerchantLimitationService merchantLimitationService = new MerchantLimitationServiceImpl(this);
150150

151+
@Getter
152+
private final GoldPlanService goldPlanService = new GoldPlanServiceImpl(this);
153+
151154
@Getter
152155
private final PartnerInvoiceService partnerInvoiceService = new PartnerInvoiceServiceImpl(this);
153156

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
package com.github.binarywang.wxpay.service.impl;
2+
3+
import com.github.binarywang.wxpay.bean.goldplan.GoldPlanResult;
4+
import com.github.binarywang.wxpay.exception.WxPayException;
5+
import com.github.binarywang.wxpay.service.GoldPlanService;
6+
import com.github.binarywang.wxpay.service.WxPayService;
7+
import com.google.gson.Gson;
8+
import com.google.gson.GsonBuilder;
9+
import lombok.RequiredArgsConstructor;
10+
11+
import java.util.HashMap;
12+
import java.util.List;
13+
import java.util.Map;
14+
15+
/**
16+
* 点金计划 接口实现
17+
*
18+
* @author zhangyl
19+
* @since 2026-08-22
20+
*/
21+
@RequiredArgsConstructor
22+
public class GoldPlanServiceImpl implements GoldPlanService {
23+
private static final Gson GSON = new GsonBuilder().create();
24+
private static final String OPEN = "OPEN";
25+
private static final String CLOSE = "CLOSE";
26+
27+
private final WxPayService payService;
28+
29+
@Override
30+
public GoldPlanResult openGoldPlan(String subMchId, String operationPayScene) throws WxPayException {
31+
return changeGoldPlanStatus(subMchId, OPEN, operationPayScene);
32+
}
33+
34+
/**
35+
* 调用微信支付接口开通或关闭点金计划
36+
*
37+
* @param subMchId 特约商户号
38+
* @param operationType 操作类型
39+
* @param operationPayScene 支付场景
40+
* @return 点金计划操作结果
41+
* @throws WxPayException 微信支付请求异常
42+
*/
43+
private GoldPlanResult changeGoldPlanStatus(String subMchId, String operationType,
44+
String operationPayScene) throws WxPayException {
45+
String url = String.format("%s/v3/goldplan/merchants/changegoldplanstatus", this.payService.getPayBaseUrl());
46+
Map<String, Object> request = new HashMap<>(4);
47+
request.put("sub_mchid", subMchId);
48+
request.put("operation_type", operationType);
49+
request.put("operation_pay_scene", operationPayScene);
50+
String result = this.payService.postV3(url, GSON.toJson(request));
51+
return GSON.fromJson(result, GoldPlanResult.class);
52+
}
53+
54+
@Override
55+
public GoldPlanResult closeGoldPlan(String subMchId, String operationPayScene) throws WxPayException {
56+
return changeGoldPlanStatus(subMchId, CLOSE, operationPayScene);
57+
}
58+
59+
@Override
60+
public GoldPlanResult openCustomPage(String subMchId) throws WxPayException {
61+
return changeCustomPageStatus(subMchId, OPEN);
62+
}
63+
64+
/**
65+
* 调用微信支付接口开通或关闭商家小票
66+
*
67+
* @param subMchId 特约商户号
68+
* @param operationType 操作类型
69+
* @return 商家小票操作结果
70+
* @throws WxPayException 微信支付请求异常
71+
*/
72+
private GoldPlanResult changeCustomPageStatus(String subMchId, String operationType) throws WxPayException {
73+
String url = String.format("%s/v3/goldplan/merchants/changecustompagestatus", this.payService.getPayBaseUrl());
74+
Map<String, String> request = new HashMap<>(2);
75+
request.put("sub_mchid", subMchId);
76+
request.put("operation_type", operationType);
77+
String result = this.payService.postV3(url, GSON.toJson(request));
78+
return GSON.fromJson(result, GoldPlanResult.class);
79+
}
80+
81+
@Override
82+
public GoldPlanResult closeCustomPage(String subMchId) throws WxPayException {
83+
return changeCustomPageStatus(subMchId, CLOSE);
84+
}
85+
86+
@Override
87+
public void setAdvertisingIndustryFilter(String subMchId, List<String> advertisingIndustryFilters)
88+
throws WxPayException {
89+
String url = String.format("%s/v3/goldplan/merchants/set-advertising-industry-filter",
90+
this.payService.getPayBaseUrl());
91+
Map<String, Object> request = new HashMap<>(2);
92+
request.put("sub_mchid", subMchId);
93+
request.put("advertising_industry_filters", advertisingIndustryFilters);
94+
this.payService.postV3(url, GSON.toJson(request));
95+
}
96+
97+
@Override
98+
public void openAdvertisingShow(String subMchId, List<String> advertisingIndustryFilters) throws WxPayException {
99+
String url = String.format("%s/v3/goldplan/merchants/open-advertising-show", this.payService.getPayBaseUrl());
100+
Map<String, Object> request = new HashMap<>(2);
101+
request.put("sub_mchid", subMchId);
102+
request.put("advertising_industry_filters", advertisingIndustryFilters);
103+
this.payService.patchV3(url, GSON.toJson(request));
104+
}
105+
106+
@Override
107+
public void closeAdvertisingShow(String subMchId) throws WxPayException {
108+
String url = String.format("%s/v3/goldplan/merchants/close-advertising-show", this.payService.getPayBaseUrl());
109+
Map<String, String> request = new HashMap<>(1);
110+
request.put("sub_mchid", subMchId);
111+
this.payService.postV3(url, GSON.toJson(request));
112+
}
113+
}

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceApacheHttpImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ private String requestV3(String url, String requestStr, HttpRequestBase httpRequ
159159
public String patchV3(String url, String requestStr) throws WxPayException {
160160
HttpPatch httpPatch = new HttpPatch(url);
161161
httpPatch.setEntity(createEntry(requestStr));
162+
this.configureRequest(httpPatch);
162163
return this.requestV3(url, requestStr, httpPatch);
163164
}
164165

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceHttpComponentsImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ private String requestV3(String url, String requestStr, HttpRequestBase httpRequ
156156
public String patchV3(String url, String requestStr) throws WxPayException {
157157
HttpPatch httpPatch = new HttpPatch(url);
158158
httpPatch.setEntity(createEntry(requestStr));
159+
this.configureRequest(httpPatch);
159160
return this.requestV3(url, requestStr, httpPatch);
160161
}
161162

0 commit comments

Comments
 (0)