diff --git a/pom.xml b/pom.xml
index c87072185d..ada8d65a03 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
+ * 查询应用消息发送统计 + * 请求方式:POST(HTTPS) + * 请求地址:https://qyapi.weixin.qq.com/cgi-bin/message/get_statistics?access_token=ACCESS_TOKEN + * + * 详情请见: https://work.weixin.qq.com/api/doc/90000/90135/92369 + *+ * + * @param timeType 查询哪天的数据,0:当天;1:昨天。默认为0。 + * @return 统计结果 + * @throws WxErrorException the wx error exception + */ + WxCpMessageSendStatistics getStatistics(int timeType) throws WxErrorException; + /** *
* 互联企业的应用支持推送文本、图片、视频、文件、图文等类型。
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMessageServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMessageServiceImpl.java
index 308d899201..07824c2183 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMessageServiceImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMessageServiceImpl.java
@@ -1,5 +1,6 @@
package me.chanjar.weixin.cp.api.impl;
+import com.google.common.collect.ImmutableMap;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.api.WxCpMessageService;
@@ -7,7 +8,9 @@
import me.chanjar.weixin.cp.bean.message.WxCpLinkedCorpMessage;
import me.chanjar.weixin.cp.bean.message.WxCpMessage;
import me.chanjar.weixin.cp.bean.message.WxCpMessageSendResult;
-import me.chanjar.weixin.cp.constant.WxCpApiPathConsts;
+import me.chanjar.weixin.cp.bean.message.WxCpMessageSendStatistics;
+import me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Message;
+import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
/**
* 消息推送接口实现类.
@@ -27,7 +30,13 @@ public WxCpMessageSendResult send(WxCpMessage message) throws WxErrorException {
}
return WxCpMessageSendResult.fromJson(this.cpService.post(this.cpService.getWxCpConfigStorage()
- .getApiUrl(WxCpApiPathConsts.Message.MESSAGE_SEND), message.toJson()));
+ .getApiUrl(Message.MESSAGE_SEND), message.toJson()));
+ }
+
+ @Override
+ public WxCpMessageSendStatistics getStatistics(int timeType) throws WxErrorException {
+ return WxCpMessageSendStatistics.fromJson(this.cpService.post(this.cpService.getWxCpConfigStorage().getApiUrl(Message.GET_STATISTICS),
+ WxCpGsonBuilder.create().toJson(ImmutableMap.of("time_type", timeType))));
}
@Override
@@ -38,6 +47,6 @@ public WxCpMessageSendResult sendLinkedCorpMessage(WxCpLinkedCorpMessage message
}
return WxCpMessageSendResult.fromJson(this.cpService.post(this.cpService.getWxCpConfigStorage()
- .getApiUrl(WxCpApiPathConsts.Message.LINKEDCORP_MESSAGE_SEND), message.toJson()));
+ .getApiUrl(Message.LINKEDCORP_MESSAGE_SEND), message.toJson()));
}
}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/message/WxCpMessageSendStatistics.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/message/WxCpMessageSendStatistics.java
new file mode 100644
index 0000000000..fa14d15e89
--- /dev/null
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/message/WxCpMessageSendStatistics.java
@@ -0,0 +1,43 @@
+package me.chanjar.weixin.cp.bean.message;
+
+import com.google.gson.annotations.SerializedName;
+import lombok.Data;
+import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
+
+import java.util.List;
+
+/**
+ * 应用消息发送统计信息.
+ *
+ * @author Binary Wang
+ * @date 2020-09-13
+ */
+@Data
+public class WxCpMessageSendStatistics {
+ public static WxCpMessageSendStatistics fromJson(String json) {
+ return WxCpGsonBuilder.create().fromJson(json, WxCpMessageSendStatistics.class);
+ }
+
+ private List statistics;
+
+ @Data
+ public static class StatisticItem {
+ /**
+ * 应用名
+ */
+ @SerializedName("app_name")
+ private String appName;
+
+ /**
+ * 应用id
+ */
+ @SerializedName("agentid")
+ private Integer agentId;
+
+ /**
+ * 发消息成功人次
+ */
+ @SerializedName("count")
+ private Integer count;
+ }
+}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java
index 62d466b9aa..6fd219ff06 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java
@@ -36,6 +36,11 @@ public static class Message {
*/
public static final String MESSAGE_SEND = "/cgi-bin/message/send";
+ /**
+ * 查询应用消息发送统计
+ */
+ public static final String GET_STATISTICS = "/cgi-bin/message/get_statistics";
+
/**
* 互联企业发送应用消息
*/
diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpMessageServiceImplTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpMessageServiceImplTest.java
index 8f02df1fc6..3a1e5460fa 100644
--- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpMessageServiceImplTest.java
+++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpMessageServiceImplTest.java
@@ -12,6 +12,7 @@
import me.chanjar.weixin.cp.bean.message.WxCpLinkedCorpMessage;
import me.chanjar.weixin.cp.bean.message.WxCpMessage;
import me.chanjar.weixin.cp.bean.message.WxCpMessageSendResult;
+import me.chanjar.weixin.cp.bean.message.WxCpMessageSendStatistics;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Guice;
@@ -20,6 +21,7 @@
import static com.github.dreamhead.moco.Moco.file;
import static com.github.dreamhead.moco.MocoJsonRunner.jsonHttpServer;
import static me.chanjar.weixin.cp.api.ApiTestModuleWithMockServer.mockServerPort;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.testng.Assert.assertNotNull;
/**
@@ -29,8 +31,8 @@
* @date 2020-08-30
*/
@Test
-@Guice(modules = ApiTestModuleWithMockServer.class)
-//@Guice(modules = ApiTestModule.class)
+//@Guice(modules = ApiTestModuleWithMockServer.class)
+@Guice(modules = ApiTestModule.class)
public class WxCpMessageServiceImplTest {
@Inject
protected WxCpService wxService;
@@ -154,11 +156,24 @@ public void testSendMessage_miniProgram_notice() throws WxErrorException {
}
@Test
- public void testLinkedCorpMessageSend() throws WxErrorException {
+ public void testSendLinkedCorpMessage() throws WxErrorException {
this.wxService.getMessageService().sendLinkedCorpMessage(WxCpLinkedCorpMessage.builder()
.msgType(WxConsts.KefuMsgType.TEXT)
.toUsers(new String[]{configStorage.getUserId()})
.content("欢迎欢迎,热烈欢迎\n换行测试\n超链接:Hello World")
.build());
}
+
+ @Test
+ public void testSend() {
+ // see other test methods
+ }
+
+ @Test
+ public void testGetStatistics() throws WxErrorException {
+ final WxCpMessageSendStatistics statistics = this.wxService.getMessageService().getStatistics(1);
+ assertNotNull(statistics);
+ assertThat(statistics.getStatistics()).isNotNull();
+ }
+
}
diff --git a/weixin-java-miniapp/pom.xml b/weixin-java-miniapp/pom.xml
index d708de8a98..41ddb0a636 100644
--- a/weixin-java-miniapp/pom.xml
+++ b/weixin-java-miniapp/pom.xml
@@ -7,7 +7,7 @@
com.github.binarywang
wx-java
- 3.9.1.B
+ 3.9.2.B
weixin-java-miniapp
diff --git a/weixin-java-mp/pom.xml b/weixin-java-mp/pom.xml
index f1fad08a81..d1f1ac0fd0 100644
--- a/weixin-java-mp/pom.xml
+++ b/weixin-java-mp/pom.xml
@@ -7,7 +7,7 @@
com.github.binarywang
wx-java
- 3.9.1.B
+ 3.9.2.B
weixin-java-mp
diff --git a/weixin-java-open/pom.xml b/weixin-java-open/pom.xml
index 8001b4ab8d..19d188ac16 100644
--- a/weixin-java-open/pom.xml
+++ b/weixin-java-open/pom.xml
@@ -7,7 +7,7 @@
com.github.binarywang
wx-java
- 3.9.1.B
+ 3.9.2.B
weixin-java-open
diff --git a/weixin-java-pay/pom.xml b/weixin-java-pay/pom.xml
index bfc41e3546..629c6fc654 100644
--- a/weixin-java-pay/pom.xml
+++ b/weixin-java-pay/pom.xml
@@ -5,7 +5,7 @@
com.github.binarywang
wx-java
- 3.9.1.B
+ 3.9.2.B
4.0.0
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/ProfitSharingRequest.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/ProfitSharingRequest.java
new file mode 100644
index 0000000000..aaec33bd07
--- /dev/null
+++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/ProfitSharingRequest.java
@@ -0,0 +1,192 @@
+package com.github.binarywang.wxpay.bean.ecommerce;
+
+import com.google.gson.annotations.SerializedName;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.io.Serializable;
+
+/**
+ * 请求分账 对象
+ *
+ * 文档地址:https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/profitsharing/chapter3_1.shtml
+ *
+ * @author: f00lish
+ * @date: 2020/09/12
+ */
+@Data
+@NoArgsConstructor
+public class ProfitSharingRequest implements Serializable {
+
+ private static final long serialVersionUID = -8662837652326828377L;
+ /**
+ *
+ * 字段名:公众账号ID
+ * 变量名:appid
+ * 是否必填:是
+ * 类型:string(32)
+ * 描述:
+ * 微信分配的公众账号ID。
+ * 示例值:wx8888888888888888
+ *
+ */
+ @SerializedName(value = "appid")
+ private String appid;
+
+ /**
+ *
+ * 字段名:二级商户号
+ * 变量名:sub_mchid
+ * 是否必填:是
+ * 类型:string(32)
+ * 描述:
+ * 分账出资的电商平台二级商户,填写微信支付分配的商户号。
+ * 示例值:1900000109
+ *
+ */
+ @SerializedName(value = "sub_mchid")
+ private String subMchid;
+
+ /**
+ *
+ * 字段名:微信订单号
+ * 变量名:transaction_id
+ * 是否必填:是
+ * 类型:string(32)
+ * 描述:
+ * 微信支付订单号。
+ * 示例值:4208450740201411110007820472
+ *
+ */
+ @SerializedName(value = "transaction_id")
+ private String transactionId;
+
+ /**
+ *
+ * 字段名:商户分账单号
+ * 变量名:out_order_no
+ * 是否必填:是
+ * 类型:string(64)
+ * 描述:
+ * 商户系统内部的分账单号,在商户系统内部唯一(单次分账、多次分账、完结分账应使用不同的商户分账单号),同一分账单号多次请求等同一次。
+ * 示例值:P20150806125346
+ *
+ */
+ @SerializedName(value = "out_order_no")
+ private String outOrderNo;
+
+ /**
+ *
+ * 字段名:分账接收方列表
+ * 变量名:receivers
+ * 是否必填:是
+ * 类型:array
+ * 描述:
+ * 分账接收方列表,支持设置出资商户作为分账接收方,单次分账最多可有5个分账接收方
+ *
+ */
+ @SerializedName(value = "receivers")
+ private Receiver[] receivers;
+
+ /**
+ *
+ * 字段名:是否分账完成
+ * 变量名:finish
+ * 是否必填:是
+ * 类型:bool
+ * 描述:
+ * 是否完成分账
+ * 1、如果为true,该笔订单剩余未分账的金额会解冻回电商平台二级商户;
+ * 2、如果为false,该笔订单剩余未分账的金额不会解冻回电商平台二级商户,可以对该笔订单再次进行分账。
+ * 示例值:true
+ *
+ */
+ @SerializedName(value = "finish")
+ private Boolean finish;
+
+ @Data
+ @NoArgsConstructor
+ public static class Receiver implements Serializable {
+
+ private static final long serialVersionUID = 8995144356011793136L;
+
+ /**
+ *
+ * 字段名:分账接收方类型
+ * 变量名:type
+ * 是否必填:否
+ * 类型:string(32)
+ * 描述:
+ * 分账接收方类型,枚举值:
+ * MERCHANT_ID:商户
+ * PERSONAL_OPENID:个人
+ * 示例值:MERCHANT_ID
+ *
+ */
+ @SerializedName(value = "type")
+ private String type;
+
+ /**
+ *
+ * 字段名:分账接收方账号
+ * 变量名:receiver_account
+ * 是否必填:是
+ * 类型:string(32)
+ * 描述:
+ * 分账接收方账号:
+ * 类型是MERCHANT_ID时,是商户ID
+ * 类型是PERSONAL_OPENID时,是个人openid,openid获取方法 https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/guide/chapter2_1.shtml#menu1
+ * 示例值:1900000109
+ *
+ */
+ @SerializedName(value = "receiver_account")
+ private String receiverAccount;
+
+ /**
+ *
+ * 字段名:分账金额
+ * 变量名:amount
+ * 是否必填:是
+ * 类型:int
+ * 描述:
+ * 分账金额,单位为分,只能为整数,不能超过原订单支付金额及最大分账比例金额。
+ * 示例值:190
+ *
+ */
+ @SerializedName(value = "amount")
+ private Integer amount;
+
+ /**
+ *
+ * 字段名:分账描述
+ * 变量名:description
+ * 是否必填:是
+ * 类型:string(180)
+ * 描述:
+ * 分账的原因描述,分账账单中需要体现。
+ * 示例值:分给商户1900000109
+ *
+ */
+ @SerializedName(value = "description")
+ private String description;
+
+ /**
+ *
+ * 字段名:分账个人姓名
+ * 变量名:receiver_name
+ * 是否必填:否
+ * 类型:string(10240)
+ * 描述:
+ * 可选项,在接收方类型为个人的时可选填,若有值,会检查与 receiver_name 是否实名匹配,不匹配会拒绝分账请求
+ * 1、分账接收方类型是PERSONAL_OPENID时,是个人姓名的密文(选传,传则校验) 此字段的加密方法详见:敏感信息加密说明
+ * 2、使用微信支付平台证书中的公钥
+ * 3、使用RSAES-OAEP算法进行加密
+ * 4、将请求中HTTP头部的Wechatpay-Serial设置为证书序列号
+ * 示例值:hu89ohu89ohu89o
+ *
+ */
+ @SerializedName(value = "receiver_name")
+ private String receiverName;
+
+ }
+}
diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/ProfitSharingResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/ProfitSharingResult.java
new file mode 100644
index 0000000000..4a79586654
--- /dev/null
+++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/ProfitSharingResult.java
@@ -0,0 +1,71 @@
+package com.github.binarywang.wxpay.bean.ecommerce;
+
+import com.google.gson.annotations.SerializedName;
+
+import java.io.Serializable;
+
+/**
+ * 请求分账 结果响应
+ * @author: f00lish
+ * @date: 2020/09/12
+ */
+public class ProfitSharingResult implements Serializable {
+
+ private static final long serialVersionUID = 9026456165403642050L;
+ /**
+ *
+ * 字段名:二级商户号
+ * 变量名:sub_mchid
+ * 是否必填:是
+ * 类型:string(32)
+ * 描述:
+ * 分账出资的电商平台二级商户,填写微信支付分配的商户号。
+ * 示例值:1900000109
+ *
+ */
+ @SerializedName(value = "sub_mchid")
+ private String subMchid;
+
+ /**
+ *
+ * 字段名:微信订单号
+ * 变量名:transaction_id
+ * 是否必填:是
+ * 类型:string(32)
+ * 描述:
+ * 微信支付订单号。
+ * 示例值:4208450740201411110007820472
+ *
+ */
+ @SerializedName(value = "transaction_id")
+ private String transactionId;
+
+ /**
+ *
+ * 字段名:商户分账单号
+ * 变量名:out_order_no
+ * 是否必填:是
+ * 类型:string(64)
+ * 描述:
+ * 商户系统内部的分账单号,在商户系统内部唯一(单次分账、多次分账、完结分账应使用不同的商户分账单号),同一分账单号多次请求等同一次。
+ * 示例值:P20150806125346
+ *
+ */
+ @SerializedName(value = "out_order_no")
+ private String outOrderNo;
+
+ /**
+ *
+ * 字段名:微信分账单号
+ * 变量名:order_id
+ * 是否必填:是
+ * 类型:string (64)
+ * 描述:
+ * 微信分账单号,微信系统返回的唯一标识。
+ * 示例值:6754760740201411110007865434
+ *
+ */
+ @SerializedName(value = "order_id")
+ private String orderId;
+
+}
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..ca283c4af9 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;
@@ -11,7 +12,7 @@
*
*
* @author cloudX
- * @date 2020/08/17
+ * @date 2020 /08/17
*/
public interface EcommerceService {
/**
@@ -62,8 +63,9 @@ public interface EcommerceService {
*
*
* @param tradeType 支付方式
- * @param request 请求对象
- * @return 微信合单支付返回
+ * @param request 请求对象
+ * @return 微信合单支付返回 transactions result
+ * @throws WxPayException the wx pay exception
*/
TransactionsResult combine(TradeTypeEnum tradeType, CombineTransactionsRequest request) throws WxPayException;
@@ -74,9 +76,11 @@ public interface EcommerceService {
* 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pages/e-combine.shtml
*
*
+ * @param + ** 服务商模式普通支付API(APP支付、JSAPI支付、H5支付、NATIVE支付). * 请求URL:https://api.mch.weixin.qq.com/v3/pay/partner/transactions/jsapi * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pages/transactions_sl.shtml *+ * * @param tradeType 支付方式 - * @param request 请求对象 - * @return 调起支付需要的参数 + * @param request 请求对象 + * @return 调起支付需要的参数 transactions result + * @throws WxPayException the wx pay exception */ TransactionsResult partner(TradeTypeEnum tradeType, PartnerTransactionsRequest request) throws WxPayException; /** - *+ ** * @param notifyData 通知数据 - * @param header 通知头部数据,不传则表示不校验头 - * @return 解密后通知数据 + * @param header 通知头部数据,不传则表示不校验头 + * @return 解密后通知数据 partner transactions notify result + * @throws WxPayException the wx pay exception */ PartnerTransactionsNotifyResult parsePartnerNotifyResult(String notifyData, SignatureHeader header) throws WxPayException; + + /** + ** 服务商模式普通支付API(APP支付、JSAPI支付、H5支付、NATIVE支付). * 请求URL:https://api.mch.weixin.qq.com/v3/pay/partner/transactions/jsapi * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pages/transactions_sl.shtml *+ * + * @paramthe type parameter * @param tradeType 支付方式 - * @param request 请求对象 - * @return 调起支付需要的参数 + * @param request 请求对象 + * @return 调起支付需要的参数 t + * @throws WxPayException the wx pay exception */ T partnerTransactions(TradeTypeEnum tradeType, PartnerTransactionsRequest request) throws WxPayException; @@ -123,8 +133,72 @@ public interface EcommerceService { * + * 服务商账户实时余额 + * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pages/amount.shtml + *+ * + * @param accountType 服务商账户类型 + * @return 返回数据 fund balance result + * @throws WxPayException the wx pay exception + */ + 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 返回数据 fund balance result + * @throws WxPayException the wx pay exception + */ + FundBalanceResult spDayEndBalance(SpAccountTypeEnum accountType, String date) throws WxPayException; + + /** + *+ * 二级商户号账户实时余额 + * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pages/amount.shtml + *+ * + * @param subMchid 二级商户号 + * @return 返回数据 fund balance result + * @throws WxPayException the wx pay exception + */ + 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 返回数据 fund balance result + * @throws WxPayException the wx pay exception + */ + FundBalanceResult subDayEndBalance(String subMchid, String date) throws WxPayException; + + /** + *+ * 请求分账API + * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/profitsharing/chapter3_1.shtml + *+ * + * @param request 分账请求 + * @return 返回数据 profit sharing result + * @throws WxPayException the wx pay exception + */ + ProfitSharingResult profitSharing(ProfitSharingRequest request) 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..07cd559cfd 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,45 @@ 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); + } + + @Override + public ProfitSharingResult profitSharing(ProfitSharingRequest request) throws WxPayException { + String url = String.format("%s/v3/ecommerce/profitsharing/orders", this.payService.getPayBaseUrl()); + String response = this.payService.postV3(url, GSON.toJson(request)); + return GSON.fromJson(response, ProfitSharingResult.class); + } + private boolean verifyNotifySign(SignatureHeader header, String data) { String beforeSign = String.format("%s\n%s\n%s\n", header.getTimeStamp(),