From 7d51de65e326295b5a7716076f813e607af94716 Mon Sep 17 00:00:00 2001 From: Element Date: Thu, 17 Aug 2017 15:24:40 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=9B=B4=E6=96=B0messageSend=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=90=91wxCpConfigStorage=E9=87=8C=E8=8E=B7=E5=8F=96a?= =?UTF-8?q?gentId?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/cp/api/impl/WxCpServiceAbstractImpl.java | 4 ++++ .../java/me/chanjar/weixin/cp/api/WxCpMessageAPITest.java | 8 +++++--- 2 files changed, 9 insertions(+), 3 deletions(-) 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(); From 4622ca92c1d74f56a1c0c711efbbc0e3a1696984 Mon Sep 17 00:00:00 2001 From: Element Date: Fri, 18 Aug 2017 11:01:15 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=B0=8F=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=E8=AF=B7=E6=B1=82=E4=BA=8C=E7=BB=B4=E7=A0=81=E6=97=B6?= =?UTF-8?q?=E5=AF=B9=E9=94=99=E8=AF=AF=E7=B1=BB=E5=9E=8B=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=EF=BC=88text/plain=20=E6=94=B9=E4=B8=BA=20app/json=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../binarywang/wx/miniapp/util/http/QrCodeRequestExecutor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/util/http/QrCodeRequestExecutor.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/util/http/QrCodeRequestExecutor.java index dc482dff25..3c026f4a18 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/util/http/QrCodeRequestExecutor.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/util/http/QrCodeRequestExecutor.java @@ -48,7 +48,7 @@ public File execute(String uri, WxMaQrcodeWrapper ticket) throws WxErrorExceptio InputStream inputStream = InputStreamResponseHandler.INSTANCE.handleResponse(response);) { Header[] contentTypeHeader = response.getHeaders("Content-Type"); if (contentTypeHeader != null && contentTypeHeader.length > 0 - && ContentType.TEXT_PLAIN.getMimeType().equals(contentTypeHeader[0].getValue())) { + && ContentType.APPLICATION_JSON.getMimeType().equals(contentTypeHeader[0].getValue())) { String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response); throw new WxErrorException(WxError.fromJson(responseContent)); } From 6ea951a956b45602bc7f14dcdcaedf4485651511 Mon Sep 17 00:00:00 2001 From: Element Date: Fri, 18 Aug 2017 11:01:15 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=B0=8F=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=E8=AF=B7=E6=B1=82=E4=BA=8C=E7=BB=B4=E7=A0=81=E6=97=B6?= =?UTF-8?q?=E5=AF=B9=E9=94=99=E8=AF=AF=E7=B1=BB=E5=9E=8B=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=EF=BC=88text/plain=20=E6=94=B9=E4=B8=BA=20app/json=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../binarywang/wx/miniapp/util/http/QrCodeRequestExecutor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/util/http/QrCodeRequestExecutor.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/util/http/QrCodeRequestExecutor.java index dc482dff25..3c026f4a18 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/util/http/QrCodeRequestExecutor.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/util/http/QrCodeRequestExecutor.java @@ -48,7 +48,7 @@ public File execute(String uri, WxMaQrcodeWrapper ticket) throws WxErrorExceptio InputStream inputStream = InputStreamResponseHandler.INSTANCE.handleResponse(response);) { Header[] contentTypeHeader = response.getHeaders("Content-Type"); if (contentTypeHeader != null && contentTypeHeader.length > 0 - && ContentType.TEXT_PLAIN.getMimeType().equals(contentTypeHeader[0].getValue())) { + && ContentType.APPLICATION_JSON.getMimeType().equals(contentTypeHeader[0].getValue())) { String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response); throw new WxErrorException(WxError.fromJson(responseContent)); }