mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-04-05 17:38:05 +08:00
🆕 #1723 企业微信增加查询应用消息发送统计的接口
This commit is contained in:
parent
91d484f730
commit
37a009c790
@ -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.WxCpLinkedCorpMessage;
|
||||||
import me.chanjar.weixin.cp.bean.message.WxCpMessage;
|
import me.chanjar.weixin.cp.bean.message.WxCpMessage;
|
||||||
import me.chanjar.weixin.cp.bean.message.WxCpMessageSendResult;
|
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;
|
WxCpMessageSendResult send(WxCpMessage message) throws WxErrorException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <pre>
|
||||||
|
* 查询应用消息发送统计
|
||||||
|
* 请求方式: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
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @param timeType 查询哪天的数据,0:当天;1:昨天。默认为0。
|
||||||
|
* @return 统计结果
|
||||||
|
* @throws WxErrorException the wx error exception
|
||||||
|
*/
|
||||||
|
WxCpMessageSendStatistics getStatistics(int timeType) throws WxErrorException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <pre>
|
* <pre>
|
||||||
* 互联企业的应用支持推送文本、图片、视频、文件、图文等类型。
|
* 互联企业的应用支持推送文本、图片、视频、文件、图文等类型。
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package me.chanjar.weixin.cp.api.impl;
|
package me.chanjar.weixin.cp.api.impl;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import me.chanjar.weixin.common.error.WxErrorException;
|
import me.chanjar.weixin.common.error.WxErrorException;
|
||||||
import me.chanjar.weixin.cp.api.WxCpMessageService;
|
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.WxCpLinkedCorpMessage;
|
||||||
import me.chanjar.weixin.cp.bean.message.WxCpMessage;
|
import me.chanjar.weixin.cp.bean.message.WxCpMessage;
|
||||||
import me.chanjar.weixin.cp.bean.message.WxCpMessageSendResult;
|
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()
|
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
|
@Override
|
||||||
@ -38,6 +47,6 @@ public class WxCpMessageServiceImpl implements WxCpMessageService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return WxCpMessageSendResult.fromJson(this.cpService.post(this.cpService.getWxCpConfigStorage()
|
return WxCpMessageSendResult.fromJson(this.cpService.post(this.cpService.getWxCpConfigStorage()
|
||||||
.getApiUrl(WxCpApiPathConsts.Message.LINKEDCORP_MESSAGE_SEND), message.toJson()));
|
.getApiUrl(Message.LINKEDCORP_MESSAGE_SEND), message.toJson()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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 <a href="https://github.com/binarywang">Binary Wang</a>
|
||||||
|
* @date 2020-09-13
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class WxCpMessageSendStatistics {
|
||||||
|
public static WxCpMessageSendStatistics fromJson(String json) {
|
||||||
|
return WxCpGsonBuilder.create().fromJson(json, WxCpMessageSendStatistics.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<StatisticItem> statistics;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class StatisticItem {
|
||||||
|
/**
|
||||||
|
* 应用名
|
||||||
|
*/
|
||||||
|
@SerializedName("app_name")
|
||||||
|
private String appName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 应用id
|
||||||
|
*/
|
||||||
|
@SerializedName("agentid")
|
||||||
|
private Integer agentId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发消息成功人次
|
||||||
|
*/
|
||||||
|
@SerializedName("count")
|
||||||
|
private Integer count;
|
||||||
|
}
|
||||||
|
}
|
@ -36,6 +36,11 @@ public final class WxCpApiPathConsts {
|
|||||||
*/
|
*/
|
||||||
public static final String MESSAGE_SEND = "/cgi-bin/message/send";
|
public static final String MESSAGE_SEND = "/cgi-bin/message/send";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询应用消息发送统计
|
||||||
|
*/
|
||||||
|
public static final String GET_STATISTICS = "/cgi-bin/message/get_statistics";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 互联企业发送应用消息
|
* 互联企业发送应用消息
|
||||||
*/
|
*/
|
||||||
|
@ -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.WxCpLinkedCorpMessage;
|
||||||
import me.chanjar.weixin.cp.bean.message.WxCpMessage;
|
import me.chanjar.weixin.cp.bean.message.WxCpMessage;
|
||||||
import me.chanjar.weixin.cp.bean.message.WxCpMessageSendResult;
|
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.AfterTest;
|
||||||
import org.testng.annotations.BeforeTest;
|
import org.testng.annotations.BeforeTest;
|
||||||
import org.testng.annotations.Guice;
|
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.Moco.file;
|
||||||
import static com.github.dreamhead.moco.MocoJsonRunner.jsonHttpServer;
|
import static com.github.dreamhead.moco.MocoJsonRunner.jsonHttpServer;
|
||||||
import static me.chanjar.weixin.cp.api.ApiTestModuleWithMockServer.mockServerPort;
|
import static me.chanjar.weixin.cp.api.ApiTestModuleWithMockServer.mockServerPort;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.testng.Assert.assertNotNull;
|
import static org.testng.Assert.assertNotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -29,8 +31,8 @@ import static org.testng.Assert.assertNotNull;
|
|||||||
* @date 2020-08-30
|
* @date 2020-08-30
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@Guice(modules = ApiTestModuleWithMockServer.class)
|
//@Guice(modules = ApiTestModuleWithMockServer.class)
|
||||||
//@Guice(modules = ApiTestModule.class)
|
@Guice(modules = ApiTestModule.class)
|
||||||
public class WxCpMessageServiceImplTest {
|
public class WxCpMessageServiceImplTest {
|
||||||
@Inject
|
@Inject
|
||||||
protected WxCpService wxService;
|
protected WxCpService wxService;
|
||||||
@ -154,11 +156,24 @@ public class WxCpMessageServiceImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLinkedCorpMessageSend() throws WxErrorException {
|
public void testSendLinkedCorpMessage() throws WxErrorException {
|
||||||
this.wxService.getMessageService().sendLinkedCorpMessage(WxCpLinkedCorpMessage.builder()
|
this.wxService.getMessageService().sendLinkedCorpMessage(WxCpLinkedCorpMessage.builder()
|
||||||
.msgType(WxConsts.KefuMsgType.TEXT)
|
.msgType(WxConsts.KefuMsgType.TEXT)
|
||||||
.toUsers(new String[]{configStorage.getUserId()})
|
.toUsers(new String[]{configStorage.getUserId()})
|
||||||
.content("欢迎欢迎,热烈欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>")
|
.content("欢迎欢迎,热烈欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>")
|
||||||
.build());
|
.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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ import com.github.binarywang.wxpay.exception.WxPayException;
|
|||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @author cloudX
|
* @author cloudX
|
||||||
* @date 2020/08/17
|
* @date 2020 /08/17
|
||||||
*/
|
*/
|
||||||
public interface EcommerceService {
|
public interface EcommerceService {
|
||||||
/**
|
/**
|
||||||
@ -63,8 +63,9 @@ public interface EcommerceService {
|
|||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @param tradeType 支付方式
|
* @param tradeType 支付方式
|
||||||
* @param request 请求对象
|
* @param request 请求对象
|
||||||
* @return 微信合单支付返回
|
* @return 微信合单支付返回 transactions result
|
||||||
|
* @throws WxPayException the wx pay exception
|
||||||
*/
|
*/
|
||||||
TransactionsResult combine(TradeTypeEnum tradeType, CombineTransactionsRequest request) throws WxPayException;
|
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
|
* 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pages/e-combine.shtml
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
|
* @param <T> the type parameter
|
||||||
* @param tradeType 支付方式
|
* @param tradeType 支付方式
|
||||||
* @param request 请求对象
|
* @param request 请求对象
|
||||||
* @return 调起支付需要的参数
|
* @return 调起支付需要的参数 t
|
||||||
|
* @throws WxPayException the wx pay exception
|
||||||
*/
|
*/
|
||||||
<T> T combineTransactions(TradeTypeEnum tradeType, CombineTransactionsRequest request) throws WxPayException;
|
<T> T combineTransactions(TradeTypeEnum tradeType, CombineTransactionsRequest request) throws WxPayException;
|
||||||
|
|
||||||
@ -88,32 +91,38 @@ public interface EcommerceService {
|
|||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @param notifyData 通知数据
|
* @param notifyData 通知数据
|
||||||
* @param header 通知头部数据,不传则表示不校验头
|
* @param header 通知头部数据,不传则表示不校验头
|
||||||
* @return 解密后通知数据
|
* @return 解密后通知数据 combine transactions notify result
|
||||||
|
* @throws WxPayException the wx pay exception
|
||||||
*/
|
*/
|
||||||
CombineTransactionsNotifyResult parseCombineNotifyResult(String notifyData, SignatureHeader header) throws WxPayException;
|
CombineTransactionsNotifyResult parseCombineNotifyResult(String notifyData, SignatureHeader header) throws WxPayException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <pre>
|
* <pre>
|
||||||
* 服务商模式普通支付API(APP支付、JSAPI支付、H5支付、NATIVE支付).
|
* 服务商模式普通支付API(APP支付、JSAPI支付、H5支付、NATIVE支付).
|
||||||
* 请求URL:https://api.mch.weixin.qq.com/v3/pay/partner/transactions/jsapi
|
* 请求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
|
* 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pages/transactions_sl.shtml
|
||||||
* </pre>
|
* </pre>
|
||||||
|
*
|
||||||
* @param tradeType 支付方式
|
* @param tradeType 支付方式
|
||||||
* @param request 请求对象
|
* @param request 请求对象
|
||||||
* @return 调起支付需要的参数
|
* @return 调起支付需要的参数 transactions result
|
||||||
|
* @throws WxPayException the wx pay exception
|
||||||
*/
|
*/
|
||||||
TransactionsResult partner(TradeTypeEnum tradeType, PartnerTransactionsRequest request) throws WxPayException;
|
TransactionsResult partner(TradeTypeEnum tradeType, PartnerTransactionsRequest request) throws WxPayException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <pre>
|
* <pre>
|
||||||
* 服务商模式普通支付API(APP支付、JSAPI支付、H5支付、NATIVE支付).
|
* 服务商模式普通支付API(APP支付、JSAPI支付、H5支付、NATIVE支付).
|
||||||
* 请求URL:https://api.mch.weixin.qq.com/v3/pay/partner/transactions/jsapi
|
* 请求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
|
* 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pages/transactions_sl.shtml
|
||||||
* </pre>
|
* </pre>
|
||||||
|
*
|
||||||
|
* @param <T> the type parameter
|
||||||
* @param tradeType 支付方式
|
* @param tradeType 支付方式
|
||||||
* @param request 请求对象
|
* @param request 请求对象
|
||||||
* @return 调起支付需要的参数
|
* @return 调起支付需要的参数 t
|
||||||
|
* @throws WxPayException the wx pay exception
|
||||||
*/
|
*/
|
||||||
<T> T partnerTransactions(TradeTypeEnum tradeType, PartnerTransactionsRequest request) throws WxPayException;
|
<T> T partnerTransactions(TradeTypeEnum tradeType, PartnerTransactionsRequest request) throws WxPayException;
|
||||||
|
|
||||||
@ -124,8 +133,9 @@ public interface EcommerceService {
|
|||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @param notifyData 通知数据
|
* @param notifyData 通知数据
|
||||||
* @param header 通知头部数据,不传则表示不校验头
|
* @param header 通知头部数据,不传则表示不校验头
|
||||||
* @return 解密后通知数据
|
* @return 解密后通知数据 partner transactions notify result
|
||||||
|
* @throws WxPayException the wx pay exception
|
||||||
*/
|
*/
|
||||||
PartnerTransactionsNotifyResult parsePartnerNotifyResult(String notifyData, SignatureHeader header) throws WxPayException;
|
PartnerTransactionsNotifyResult parsePartnerNotifyResult(String notifyData, SignatureHeader header) throws WxPayException;
|
||||||
|
|
||||||
@ -136,7 +146,8 @@ public interface EcommerceService {
|
|||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @param accountType 服务商账户类型
|
* @param accountType 服务商账户类型
|
||||||
* @return 返回数据
|
* @return 返回数据 fund balance result
|
||||||
|
* @throws WxPayException the wx pay exception
|
||||||
*/
|
*/
|
||||||
FundBalanceResult spNowBalance(SpAccountTypeEnum accountType) throws WxPayException;
|
FundBalanceResult spNowBalance(SpAccountTypeEnum accountType) throws WxPayException;
|
||||||
|
|
||||||
@ -147,8 +158,9 @@ public interface EcommerceService {
|
|||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @param accountType 服务商账户类型
|
* @param accountType 服务商账户类型
|
||||||
* @param date 查询日期 2020-09-11
|
* @param date 查询日期 2020-09-11
|
||||||
* @return 返回数据
|
* @return 返回数据 fund balance result
|
||||||
|
* @throws WxPayException the wx pay exception
|
||||||
*/
|
*/
|
||||||
FundBalanceResult spDayEndBalance(SpAccountTypeEnum accountType, String date) throws WxPayException;
|
FundBalanceResult spDayEndBalance(SpAccountTypeEnum accountType, String date) throws WxPayException;
|
||||||
|
|
||||||
@ -159,7 +171,8 @@ public interface EcommerceService {
|
|||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @param subMchid 二级商户号
|
* @param subMchid 二级商户号
|
||||||
* @return 返回数据
|
* @return 返回数据 fund balance result
|
||||||
|
* @throws WxPayException the wx pay exception
|
||||||
*/
|
*/
|
||||||
FundBalanceResult subNowBalance(String subMchid) throws WxPayException;
|
FundBalanceResult subNowBalance(String subMchid) throws WxPayException;
|
||||||
|
|
||||||
@ -170,8 +183,9 @@ public interface EcommerceService {
|
|||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @param subMchid 二级商户号
|
* @param subMchid 二级商户号
|
||||||
* @param date 查询日期 2020-09-11
|
* @param date 查询日期 2020-09-11
|
||||||
* @return 返回数据
|
* @return 返回数据 fund balance result
|
||||||
|
* @throws WxPayException the wx pay exception
|
||||||
*/
|
*/
|
||||||
FundBalanceResult subDayEndBalance(String subMchid, String date) throws WxPayException;
|
FundBalanceResult subDayEndBalance(String subMchid, String date) throws WxPayException;
|
||||||
|
|
||||||
@ -182,7 +196,8 @@ public interface EcommerceService {
|
|||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @param request 分账请求
|
* @param request 分账请求
|
||||||
* @return 返回数据
|
* @return 返回数据 profit sharing result
|
||||||
|
* @throws WxPayException the wx pay exception
|
||||||
*/
|
*/
|
||||||
ProfitSharingResult profitSharing(ProfitSharingRequest request) throws WxPayException;
|
ProfitSharingResult profitSharing(ProfitSharingRequest request) throws WxPayException;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user