Skip to content

Commit

Permalink
binarywang#315 修改messageSend方法,自动从wxCpConfigStorage获取agentId
Browse files Browse the repository at this point in the history
  • Loading branch information
forfuns authored and binarywang committed Aug 17, 2017
1 parent 92947b3 commit f0d3a1a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ public WxJsapiSignature createJsapiSignature(String url) throws WxErrorException
@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()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
public class WxCpMessageAPITest {

@Inject
protected WxCpServiceImpl wxService;
protected WxCpService wxService;

private ApiTestModule.WxXmlCpInMemoryConfigStorage configStorage;

@BeforeTest
Expand All @@ -30,7 +31,7 @@ public void setup() {

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>");
Expand All @@ -43,10 +44,11 @@ public void testSendMessage() throws WxErrorException {
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();
Expand Down

0 comments on commit f0d3a1a

Please sign in to comment.