From 6c31059020e2ccf47102057386a26026806291c7 Mon Sep 17 00:00:00 2001 From: f00lish Date: Sun, 13 Sep 2020 09:26:54 +0800 Subject: [PATCH] =?UTF-8?q?:new:=20#1758=20=E5=BE=AE=E4=BF=A1=E6=94=AF?= =?UTF-8?q?=E4=BB=98=E5=A2=9E=E5=8A=A0=E7=94=B5=E5=95=86=E6=94=B6=E4=BB=98?= =?UTF-8?q?=E9=80=9A=E6=9C=8D=E5=8A=A1=E5=95=86=E5=92=8C=E4=BA=8C=E7=BA=A7?= =?UTF-8?q?=E5=95=86=E6=88=B7=E4=BD=99=E9=A2=9D=E6=9F=A5=E8=AF=A2=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bean/ecommerce/FundBalanceResult.java | 57 +++++++++++++++++++ .../ecommerce/enums/SpAccountTypeEnum.java | 32 +++++++++++ .../wxpay/service/EcommerceService.java | 47 +++++++++++++++ .../service/impl/EcommerceServiceImpl.java | 33 +++++++++++ 4 files changed, 169 insertions(+) create mode 100644 weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/FundBalanceResult.java create mode 100644 weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/enums/SpAccountTypeEnum.java diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/FundBalanceResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/FundBalanceResult.java new file mode 100644 index 0000000000..e53b480c3f --- /dev/null +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/FundBalanceResult.java @@ -0,0 +1,57 @@ +package com.github.binarywang.wxpay.bean.ecommerce; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @author: f00lish + * @date: 2020/09/12 + */ +@Data +@NoArgsConstructor +public class FundBalanceResult { + /** + *
+   * 字段名:二级商户号
+   * 变量名:sub_mchid
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:
+   *  电商平台二级商户号,由微信支付生成并下发。
+   *  示例值:1900000109
+   * 
+ */ + @SerializedName("sub_mchid") + private String subMchid; + + /** + *
+   * 字段名:可用余额
+   * 变量名:available_amount
+   * 是否必填:是
+   * 类型:int64
+   * 描述:
+   *  可用余额(单位:分),此余额可做提现操作。
+   *  示例值:100
+   * 
+ */ + @SerializedName("available_amount") + private Integer availableAmount; + + /** + *
+   * 字段名:不可用余额
+   * 变量名:pending_amount
+   * 是否必填:否
+   * 类型:int64
+   * 描述:
+   *  不可用余额(单位:分)。
+   *  示例值:100
+   * 
+ */ + @SerializedName("pending_amount") + private Integer pendingAmount; + + +} diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/enums/SpAccountTypeEnum.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/enums/SpAccountTypeEnum.java new file mode 100644 index 0000000000..2d7067804e --- /dev/null +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/enums/SpAccountTypeEnum.java @@ -0,0 +1,32 @@ +package com.github.binarywang.wxpay.bean.ecommerce.enums; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * 服务商账户类型 + * @author: f00lish + * @date: 2020/09/12 + */ +@Getter +@AllArgsConstructor +public enum SpAccountTypeEnum { + + /** + * 基本账户 + */ + BASIC("BASIC"), + /** + * 运营账户 + */ + OPERATION("OPERATION"), + /** + * 手续费账户 + */ + FEES("FEES"); + + /** + * 账户类型 + */ + private final String value; +} diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/EcommerceService.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/EcommerceService.java index 67038a8890..095865067e 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/EcommerceService.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/EcommerceService.java @@ -1,6 +1,7 @@ package com.github.binarywang.wxpay.service; import com.github.binarywang.wxpay.bean.ecommerce.*; +import com.github.binarywang.wxpay.bean.ecommerce.enums.SpAccountTypeEnum; import com.github.binarywang.wxpay.bean.ecommerce.enums.TradeTypeEnum; import com.github.binarywang.wxpay.exception.WxPayException; @@ -127,4 +128,50 @@ public interface EcommerceService { * @return 解密后通知数据 */ PartnerTransactionsNotifyResult parsePartnerNotifyResult(String notifyData, SignatureHeader header) throws WxPayException; + + /** + *
+   * 服务商账户实时余额
+   * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pages/amount.shtml
+   * 
+ * + * @param accountType 服务商账户类型 + * @return 返回数据 + */ + FundBalanceResult spNowBalance(SpAccountTypeEnum accountType) throws WxPayException; + + /** + *
+   * 服务商账户日终余额
+   * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pages/amount.shtml
+   * 
+ * + * @param accountType 服务商账户类型 + * @param date 查询日期 2020-09-11 + * @return 返回数据 + */ + FundBalanceResult spDayEndBalance(SpAccountTypeEnum accountType, String date) throws WxPayException; + + /** + *
+   * 二级商户号账户实时余额
+   * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pages/amount.shtml
+   * 
+ * + * @param subMchid 二级商户号 + * @return 返回数据 + */ + FundBalanceResult subNowBalance(String subMchid) throws WxPayException; + + /** + *
+   * 二级商户号账户日终余额
+   * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pages/amount.shtml
+   * 
+ * + * @param subMchid 二级商户号 + * @param date 查询日期 2020-09-11 + * @return 返回数据 + */ + FundBalanceResult subDayEndBalance(String subMchid, String date) throws WxPayException; } diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/EcommerceServiceImpl.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/EcommerceServiceImpl.java index 4dc535b0fe..c0d45e87e5 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/EcommerceServiceImpl.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/EcommerceServiceImpl.java @@ -1,6 +1,7 @@ package com.github.binarywang.wxpay.service.impl; import com.github.binarywang.wxpay.bean.ecommerce.*; +import com.github.binarywang.wxpay.bean.ecommerce.enums.SpAccountTypeEnum; import com.github.binarywang.wxpay.bean.ecommerce.enums.TradeTypeEnum; import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.service.EcommerceService; @@ -115,6 +116,38 @@ public PartnerTransactionsNotifyResult parsePartnerNotifyResult(String notifyDat } } + @Override + public FundBalanceResult spNowBalance(SpAccountTypeEnum accountType) throws WxPayException { + String url = String.format("%s/v3/merchant/fund/balance/%s", this.payService.getPayBaseUrl(), accountType); + URI uri = URI.create(url); + String response = this.payService.getV3(uri); + return GSON.fromJson(response, FundBalanceResult.class); + } + + @Override + public FundBalanceResult spDayEndBalance(SpAccountTypeEnum accountType, String date) throws WxPayException { + String url = String.format("%s/v3/merchant/fund/dayendbalance/%s?date=%s", this.payService.getPayBaseUrl(), accountType, date); + URI uri = URI.create(url); + String response = this.payService.getV3(uri); + return GSON.fromJson(response, FundBalanceResult.class); + } + + @Override + public FundBalanceResult subNowBalance(String subMchid) throws WxPayException { + String url = String.format("%s/v3/ecommerce/fund/balance/%s", this.payService.getPayBaseUrl(), subMchid); + URI uri = URI.create(url); + String response = this.payService.getV3(uri); + return GSON.fromJson(response, FundBalanceResult.class); + } + + @Override + public FundBalanceResult subDayEndBalance(String subMchid, String date) throws WxPayException { + String url = String.format("%s/v3/ecommerce/fund/enddaybalance/%s?date=%s", this.payService.getPayBaseUrl(), subMchid, date); + URI uri = URI.create(url); + String response = this.payService.getV3(uri); + return GSON.fromJson(response, FundBalanceResult.class); + } + private boolean verifyNotifySign(SignatureHeader header, String data) { String beforeSign = String.format("%s\n%s\n%s\n", header.getTimeStamp(),