diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceAbstractImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceAbstractImpl.java
index a1f07e68cc..43c3415ef1 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceAbstractImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceAbstractImpl.java
@@ -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()));
}
diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMessageAPITest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMessageAPITest.java
index 1e0d40b05b..0cecc01588 100644
--- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMessageAPITest.java
+++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMessageAPITest.java
@@ -20,7 +20,8 @@
public class WxCpMessageAPITest {
@Inject
- protected WxCpServiceImpl wxService;
+ protected WxCpService wxService;
+
private ApiTestModule.WxXmlCpInMemoryConfigStorage configStorage;
@BeforeTest
@@ -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超链接:Hello World");
@@ -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超链接:Hello World")
.build();