#315 修改messageSend方法,自动从wxCpConfigStorage获取agentId

This commit is contained in:
forfuns 2017-08-17 15:33:45 +08:00 committed by Binary Wang
parent 92947b344a
commit f0d3a1af73
2 changed files with 9 additions and 3 deletions

View File

@ -131,6 +131,10 @@ public abstract class WxCpServiceAbstractImpl<H, P> implements WxCpService, Requ
@Override
public WxCpMessageSendResult messageSend(WxCpMessage message) throws WxErrorException {
String url = "https://qyapi.weixin.qq.com/cgi-bin/message/send";
Integer agentId = message.getAgentId();
if(null == agentId){
message.setAgentId(this.getWxCpConfigStorage().getAgentId());
}
return WxCpMessageSendResult.fromJson(this.post(url, message.toJson()));
}

View File

@ -20,7 +20,8 @@ import static org.testng.Assert.*;
public class WxCpMessageAPITest {
@Inject
protected WxCpServiceImpl wxService;
protected WxCpService wxService;
private ApiTestModule.WxXmlCpInMemoryConfigStorage configStorage;
@BeforeTest
@ -30,7 +31,7 @@ public class WxCpMessageAPITest {
public void testSendMessage() throws WxErrorException {
WxCpMessage message = new WxCpMessage();
message.setAgentId(configStorage.getAgentId());
// message.setAgentId(configStorage.getAgentId());
message.setMsgType(WxConsts.CUSTOM_MSG_TEXT);
message.setToUser(configStorage.getUserId());
message.setContent("欢迎欢迎,热烈欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>");
@ -43,10 +44,11 @@ public class WxCpMessageAPITest {
System.out.println(messageSendResult.getInvalidTagList());
}
@Test
public void testSendMessage1() throws WxErrorException {
WxCpMessage message = WxCpMessage
.TEXT()
.agentId(configStorage.getAgentId())
// .agentId(configStorage.getAgentId())
.toUser(configStorage.getUserId())
.content("欢迎欢迎,热烈欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>")
.build();