From 6c31059020e2ccf47102057386a26026806291c7 Mon Sep 17 00:00:00 2001 From: f00lish Date: Sun, 13 Sep 2020 09:26:54 +0800 Subject: [PATCH 1/4] =?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(), From 91d484f7305b15f6bd5afea4492e1b27da8f1cb2 Mon Sep 17 00:00:00 2001 From: f00lish Date: Sun, 13 Sep 2020 09:28:43 +0800 Subject: [PATCH 2/4] =?UTF-8?q?:new:=20#1759=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=E8=AF=B7=E6=B1=82=E5=88=86=E8=B4=A6=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 增加微信收付通请求分账接口 --- .../bean/ecommerce/ProfitSharingRequest.java | 192 ++++++++++++++++++ .../bean/ecommerce/ProfitSharingResult.java | 71 +++++++ .../wxpay/service/EcommerceService.java | 12 ++ .../service/impl/EcommerceServiceImpl.java | 7 + 4 files changed, 282 insertions(+) create mode 100644 weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/ProfitSharingRequest.java create mode 100644 weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/ProfitSharingResult.java 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/service/EcommerceService.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/EcommerceService.java index 095865067e..e2d6199cd6 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 @@ -174,4 +174,16 @@ public interface EcommerceService { * @return 返回数据 */ 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 返回数据 + */ + 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 c0d45e87e5..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 @@ -148,6 +148,13 @@ public FundBalanceResult subDayEndBalance(String subMchid, String date) throws W 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(), From 37a009c7908c576e7310b5c5b10621620dfbe8d4 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Sun, 13 Sep 2020 09:51:40 +0800 Subject: [PATCH 3/4] =?UTF-8?q?:new:=20#1723=20=E4=BC=81=E4=B8=9A=E5=BE=AE?= =?UTF-8?q?=E4=BF=A1=E5=A2=9E=E5=8A=A0=E6=9F=A5=E8=AF=A2=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E5=8F=91=E9=80=81=E7=BB=9F=E8=AE=A1=E7=9A=84?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/cp/api/WxCpMessageService.java | 16 +++++ .../cp/api/impl/WxCpMessageServiceImpl.java | 15 ++++- .../message/WxCpMessageSendStatistics.java | 43 ++++++++++++++ .../weixin/cp/constant/WxCpApiPathConsts.java | 5 ++ .../api/impl/WxCpMessageServiceImplTest.java | 21 ++++++- .../wxpay/service/EcommerceService.java | 59 ++++++++++++------- 6 files changed, 131 insertions(+), 28 deletions(-) create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/message/WxCpMessageSendStatistics.java diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageService.java index 2c5d82f597..fae0a6a0d6 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageService.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageService.java @@ -4,6 +4,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; /** * 消息推送接口. @@ -24,6 +25,21 @@ public interface WxCpMessageService { */ WxCpMessageSendResult send(WxCpMessage message) throws WxErrorException; + /** + *
+   * 查询应用消息发送统计
+   * 请求方式: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-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 e2d6199cd6..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
@@ -12,7 +12,7 @@
  * 
* * @author cloudX - * @date 2020/08/17 + * @date 2020 /08/17 */ public interface EcommerceService { /** @@ -63,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; @@ -75,9 +76,11 @@ public interface EcommerceService { * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pages/e-combine.shtml * * + * @param the type parameter * @param tradeType 支付方式 - * @param request 请求对象 - * @return 调起支付需要的参数 + * @param request 请求对象 + * @return 调起支付需要的参数 t + * @throws WxPayException the wx pay exception */ T combineTransactions(TradeTypeEnum tradeType, CombineTransactionsRequest request) throws WxPayException; @@ -88,32 +91,38 @@ public interface EcommerceService { * * * @param notifyData 通知数据 - * @param header 通知头部数据,不传则表示不校验头 - * @return 解密后通知数据 + * @param header 通知头部数据,不传则表示不校验头 + * @return 解密后通知数据 combine transactions notify result + * @throws WxPayException the wx pay exception */ CombineTransactionsNotifyResult parseCombineNotifyResult(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
    *  
+ * * @param tradeType 支付方式 - * @param request 请求对象 - * @return 调起支付需要的参数 + * @param request 请求对象 + * @return 调起支付需要的参数 transactions result + * @throws WxPayException the wx pay exception */ TransactionsResult partner(TradeTypeEnum tradeType, PartnerTransactionsRequest request) 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
    *  
+ * + * @param the 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; @@ -124,8 +133,9 @@ public interface EcommerceService { *
* * @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; @@ -136,7 +146,8 @@ public interface EcommerceService { *
* * @param accountType 服务商账户类型 - * @return 返回数据 + * @return 返回数据 fund balance result + * @throws WxPayException the wx pay exception */ FundBalanceResult spNowBalance(SpAccountTypeEnum accountType) throws WxPayException; @@ -147,8 +158,9 @@ public interface EcommerceService { * * * @param accountType 服务商账户类型 - * @param date 查询日期 2020-09-11 - * @return 返回数据 + * @param date 查询日期 2020-09-11 + * @return 返回数据 fund balance result + * @throws WxPayException the wx pay exception */ FundBalanceResult spDayEndBalance(SpAccountTypeEnum accountType, String date) throws WxPayException; @@ -159,7 +171,8 @@ public interface EcommerceService { * * * @param subMchid 二级商户号 - * @return 返回数据 + * @return 返回数据 fund balance result + * @throws WxPayException the wx pay exception */ FundBalanceResult subNowBalance(String subMchid) throws WxPayException; @@ -170,8 +183,9 @@ public interface EcommerceService { * * * @param subMchid 二级商户号 - * @param date 查询日期 2020-09-11 - * @return 返回数据 + * @param date 查询日期 2020-09-11 + * @return 返回数据 fund balance result + * @throws WxPayException the wx pay exception */ FundBalanceResult subDayEndBalance(String subMchid, String date) throws WxPayException; @@ -182,7 +196,8 @@ public interface EcommerceService { * * * @param request 分账请求 - * @return 返回数据 + * @return 返回数据 profit sharing result + * @throws WxPayException the wx pay exception */ ProfitSharingResult profitSharing(ProfitSharingRequest request) throws WxPayException; From cc83bcb4158028e7286b26f7dc7937bf7a6f99ab Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Sun, 13 Sep 2020 10:11:14 +0800 Subject: [PATCH 4/4] =?UTF-8?q?:bookmark:=20=E5=8F=91=E5=B8=83=203.9.2.B?= =?UTF-8?q?=20=E6=B5=8B=E8=AF=95=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- spring-boot-starters/pom.xml | 2 +- .../wx-java-miniapp-spring-boot-starter/pom.xml | 2 +- spring-boot-starters/wx-java-mp-spring-boot-starter/pom.xml | 2 +- spring-boot-starters/wx-java-open-spring-boot-starter/pom.xml | 2 +- spring-boot-starters/wx-java-pay-spring-boot-starter/pom.xml | 2 +- weixin-graal/pom.xml | 2 +- weixin-java-common/pom.xml | 2 +- weixin-java-cp/pom.xml | 2 +- weixin-java-miniapp/pom.xml | 2 +- weixin-java-mp/pom.xml | 2 +- weixin-java-open/pom.xml | 2 +- weixin-java-pay/pom.xml | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/pom.xml b/pom.xml index c87072185d..ada8d65a03 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ 4.0.0 com.github.binarywang wx-java - 3.9.1.B + 3.9.2.B pom WxJava - Weixin/Wechat Java SDK 微信开发Java SDK diff --git a/spring-boot-starters/pom.xml b/spring-boot-starters/pom.xml index 05f5414423..ef5681e5c1 100644 --- a/spring-boot-starters/pom.xml +++ b/spring-boot-starters/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang wx-java - 3.9.1.B + 3.9.2.B pom wx-java-spring-boot-starters diff --git a/spring-boot-starters/wx-java-miniapp-spring-boot-starter/pom.xml b/spring-boot-starters/wx-java-miniapp-spring-boot-starter/pom.xml index 72513a80db..894de14c96 100644 --- a/spring-boot-starters/wx-java-miniapp-spring-boot-starter/pom.xml +++ b/spring-boot-starters/wx-java-miniapp-spring-boot-starter/pom.xml @@ -5,7 +5,7 @@ wx-java-spring-boot-starters com.github.binarywang - 3.9.1.B + 3.9.2.B 4.0.0 diff --git a/spring-boot-starters/wx-java-mp-spring-boot-starter/pom.xml b/spring-boot-starters/wx-java-mp-spring-boot-starter/pom.xml index 623c2147e0..e28fb5adc1 100644 --- a/spring-boot-starters/wx-java-mp-spring-boot-starter/pom.xml +++ b/spring-boot-starters/wx-java-mp-spring-boot-starter/pom.xml @@ -5,7 +5,7 @@ wx-java-spring-boot-starters com.github.binarywang - 3.9.1.B + 3.9.2.B 4.0.0 diff --git a/spring-boot-starters/wx-java-open-spring-boot-starter/pom.xml b/spring-boot-starters/wx-java-open-spring-boot-starter/pom.xml index 3d7cabcbec..83e07d221e 100644 --- a/spring-boot-starters/wx-java-open-spring-boot-starter/pom.xml +++ b/spring-boot-starters/wx-java-open-spring-boot-starter/pom.xml @@ -5,7 +5,7 @@ wx-java-spring-boot-starters com.github.binarywang - 3.9.1.B + 3.9.2.B 4.0.0 diff --git a/spring-boot-starters/wx-java-pay-spring-boot-starter/pom.xml b/spring-boot-starters/wx-java-pay-spring-boot-starter/pom.xml index e4cffe7d92..a6239501d7 100644 --- a/spring-boot-starters/wx-java-pay-spring-boot-starter/pom.xml +++ b/spring-boot-starters/wx-java-pay-spring-boot-starter/pom.xml @@ -5,7 +5,7 @@ wx-java-spring-boot-starters com.github.binarywang - 3.9.1.B + 3.9.2.B 4.0.0 diff --git a/weixin-graal/pom.xml b/weixin-graal/pom.xml index d28ffff26a..a0c352ff78 100644 --- a/weixin-graal/pom.xml +++ b/weixin-graal/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang wx-java - 3.9.1.B + 3.9.2.B weixin-graal diff --git a/weixin-java-common/pom.xml b/weixin-java-common/pom.xml index 16abcf236e..aeb9649fb8 100644 --- a/weixin-java-common/pom.xml +++ b/weixin-java-common/pom.xml @@ -6,7 +6,7 @@ com.github.binarywang wx-java - 3.9.1.B + 3.9.2.B weixin-java-common diff --git a/weixin-java-cp/pom.xml b/weixin-java-cp/pom.xml index 4c0c2e9eac..acad7bb5f5 100644 --- a/weixin-java-cp/pom.xml +++ b/weixin-java-cp/pom.xml @@ -7,7 +7,7 @@ com.github.binarywang wx-java - 3.9.1.B + 3.9.2.B weixin-java-cp 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