diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/goldplan/GoldPlanResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/goldplan/GoldPlanResult.java new file mode 100644 index 000000000..9ab72f917 --- /dev/null +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/goldplan/GoldPlanResult.java @@ -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; +} diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/GoldPlanService.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/GoldPlanService.java new file mode 100644 index 000000000..a02e7b21d --- /dev/null +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/GoldPlanService.java @@ -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; + +/** + * 点金计划 接口 + *

+ * 产品介绍 + *

+ * + * @author zhangyl + * @since 2026-08-22 + */ +public interface GoldPlanService { + + /** + * 为特约商户开通点金计划 + *

+ * 接口文档 + *

+ * + * @param subMchId 特约商户号 + * @param operationPayScene 支付场景,可选值为JSAPI_AND_MINIPROGRAM、JSAPI、MINIPROGRAM;不传时默认为JSAPI + * @return 点金计划操作结果 + * @throws WxPayException 微信支付请求异常 + */ + GoldPlanResult openGoldPlan(String subMchId, String operationPayScene) throws WxPayException; + + /** + * 为特约商户关闭点金计划 + *

+ * 接口文档 + *

+ * + * @param subMchId 特约商户号 + * @param operationPayScene 支付场景,可选值为JSAPI_AND_MINIPROGRAM、JSAPI、MINIPROGRAM;不传时默认为JSAPI + * @return 点金计划操作结果 + * @throws WxPayException 微信支付请求异常 + */ + GoldPlanResult closeGoldPlan(String subMchId, String operationPayScene) throws WxPayException; + + /** + * 为特约商户开通商家小票 + *

+ * 接口文档 + *

+ * + * @param subMchId 特约商户号 + * @return 商家小票操作结果 + * @throws WxPayException 微信支付请求异常 + */ + GoldPlanResult openCustomPage(String subMchId) throws WxPayException; + + /** + * 为特约商户关闭商家小票 + *

+ * 接口文档 + *

+ * + * @param subMchId 特约商户号 + * @return 商家小票操作结果 + * @throws WxPayException 微信支付请求异常 + */ + GoldPlanResult closeCustomPage(String subMchId) throws WxPayException; + + /** + * 设置特约商户的点金计划同业过滤标签 + *

+ * 接口文档 + *

+ * + * @param subMchId 特约商户号 + * @param advertisingIndustryFilters 同业过滤标签,最少一个,最多三个 + * @throws WxPayException 微信支付请求异常 + */ + void setAdvertisingIndustryFilter(String subMchId, List advertisingIndustryFilters) throws WxPayException; + + /** + * 为特约商户的点金计划页面开通广告展示 + *

+ * 接口文档 + *

+ * + * @param subMchId 特约商户号 + * @param advertisingIndustryFilters 同业过滤标签,可选,最多三个 + * @throws WxPayException 微信支付请求异常 + */ + void openAdvertisingShow(String subMchId, List advertisingIndustryFilters) throws WxPayException; + + /** + * 为特约商户的点金计划页面关闭广告展示 + *

+ * 接口文档 + *

+ * + * @param subMchId 特约商户号 + * @throws WxPayException 微信支付请求异常 + */ + void closeAdvertisingShow(String subMchId) throws WxPayException; + +} diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java index 2aec71183..d0d43285d 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java @@ -408,6 +408,13 @@ public interface WxPayService { */ MerchantLimitationService getMerchantLimitationService(); + /** + * 获取点金计划服务类 + * + * @return 点金计划服务 + */ + GoldPlanService getGoldPlanService(); + /** * 获取服务商电子发票服务类。 * diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java index 8489f8062..18e9b05b1 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java @@ -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); diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/GoldPlanServiceImpl.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/GoldPlanServiceImpl.java new file mode 100644 index 000000000..801ed6a26 --- /dev/null +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/GoldPlanServiceImpl.java @@ -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 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 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 advertisingIndustryFilters) + throws WxPayException { + String url = String.format("%s/v3/goldplan/merchants/set-advertising-industry-filter", + this.payService.getPayBaseUrl()); + Map 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 advertisingIndustryFilters) throws WxPayException { + String url = String.format("%s/v3/goldplan/merchants/open-advertising-show", this.payService.getPayBaseUrl()); + Map 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 request = new HashMap<>(1); + request.put("sub_mchid", subMchId); + this.payService.postV3(url, GSON.toJson(request)); + } +} diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceApacheHttpImpl.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceApacheHttpImpl.java index 5926bbacf..69a67ca0b 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceApacheHttpImpl.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceApacheHttpImpl.java @@ -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); } diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceHttpComponentsImpl.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceHttpComponentsImpl.java index 837587e76..d28cbc890 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceHttpComponentsImpl.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceHttpComponentsImpl.java @@ -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); }