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 2c5d82f59..fae0a6a0d 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.common.error.WxErrorException; 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 308d89920..07824c218 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.api.WxCpService;
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 class WxCpMessageServiceImpl implements WxCpMessageService {
}
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 class WxCpMessageServiceImpl implements WxCpMessageService {
}
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 000000000..fa14d15e8
--- /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 62d466b9a..6fd219ff0 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 final class WxCpApiPathConsts {
*/
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 8f02df1fc..3a1e5460f 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.api.WxCpService;
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 org.testng.annotations.Test;
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 @@ import static org.testng.Assert.assertNotNull;
* @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 class WxCpMessageServiceImplTest {
}
@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 e2d6199cd..ca283c4af 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 @@ import com.github.binarywang.wxpay.exception.WxPayException;
*
*
* @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 + ** * @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;* 服务商模式普通支付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; @@ -136,7 +146,8 @@ public interface EcommerceService { ** 服务商模式普通支付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; @@ -124,8 +133,9 @@ public interface EcommerceService { *