From a8f5d07ff3982bdfa885c90c3631f8350e139d12 Mon Sep 17 00:00:00 2001 From: Daniel Qian Date: Wed, 22 Oct 2014 10:29:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86=E5=8F=8A=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- weixin-java-enterprise/pom.xml => pom.xml | 116 ++++--- weixin-java-common/pom.xml | 68 ++++ .../weixin/common}/bean/WxAccessToken.java | 6 +- .../chanjar/weixin/common}/bean/WxMenu.java | 8 +- .../weixin/common/bean/result/WxError.java | 13 +- .../bean/result/WxMediaUploadResult.java | 12 +- .../common}/exception/WxErrorException.java | 2 +- .../weixin/common}/util/crypto/ByteGroup.java | 10 +- .../common}/util/crypto/PKCS7Encoder.java | 10 +- .../weixin/common}/util/crypto/SHA1.java | 2 +- .../common}/util/crypto/WxCryptUtil.java | 63 ++-- .../weixin/common/util/fs}/FileUtils.java | 2 +- .../util/http/InputStreamResponseHandler.java | 2 +- .../http/MediaDownloadRequestExecutor.java | 22 +- .../util/http/MediaUploadRequestExecutor.java | 6 +- .../common}/util/http/RequestExecutor.java | 4 +- .../util/http/SimpleGetRequestExecutor.java | 4 +- .../util/http/SimplePostRequestExecutor.java | 4 +- .../util/http/Utf8ResponseHandler.java | 2 +- .../weixin/common/util/json}/GsonHelper.java | 2 +- .../util/json/WxAccessTokenAdapter.java | 4 +- .../common}/util/json/WxErrorAdapter.java | 4 +- .../common/util/json/WxGsonBuilder.java | 26 ++ .../util/json/WxMediaUploadResultAdapter.java | 4 +- .../common}/util/json/WxMenuGsonAdapter.java | 6 +- .../weixin/common/util/xml}/AdapterCDATA.java | 2 +- .../common/util/xml}/MediaIdMarshaller.java | 2 +- .../weixin/common/bean/WxAccessTokenTest.java | 1 - .../weixin/common}/bean/WxErrorTest.java | 7 +- .../weixin/common}/bean/WxMenuTest.java | 6 +- .../common}/util/crypto/WxCryptUtilTest.java | 6 +- .../src/test/resources/testng.xml | 12 + .../LICENSE | 0 weixin-java-cp/README.md | 46 +++ weixin-java-cp/pom.xml | 73 ++++ .../weixin/cp}/api/WxCpConfigStorage.java | 4 +- .../me/chanjar/weixin/cp}/api/WxCpConsts.java | 5 +- .../cp/api/WxCpInMemoryConfigStorage.java | 8 +- .../weixin/cp}/api/WxCpMessageHandler.java | 6 +- .../cp}/api/WxCpMessageInterceptor.java | 4 +- .../weixin/cp}/api/WxCpMessageRouter.java | 96 +++--- .../chanjar/weixin/cp}/api/WxCpService.java | 19 +- .../weixin/cp}/api/WxCpServiceImpl.java | 39 +-- .../chanjar/weixin/cp}/bean/WxCpDepart.java | 4 +- .../chanjar/weixin/cp}/bean/WxCpMessage.java | 18 +- .../me/chanjar/weixin/cp}/bean/WxCpTag.java | 11 +- .../me/chanjar/weixin/cp}/bean/WxCpUser.java | 5 +- .../weixin/cp}/bean/WxCpXmlMessage.java | 37 +- .../cp}/bean/WxCpXmlOutImageMessage.java | 6 +- .../weixin/cp}/bean/WxCpXmlOutMessage.java | 20 +- .../cp}/bean/WxCpXmlOutMewsMessage.java | 6 +- .../cp}/bean/WxCpXmlOutTextMessage.java | 6 +- .../cp}/bean/WxCpXmlOutVideoMessage.java | 6 +- .../cp}/bean/WxCpXmlOutVoiceMessage.java | 6 +- .../cp}/bean/messagebuilder/BaseBuilder.java | 4 +- .../cp}/bean/messagebuilder/FileBuilder.java | 6 +- .../cp}/bean/messagebuilder/ImageBuilder.java | 6 +- .../cp}/bean/messagebuilder/NewsBuilder.java | 6 +- .../cp}/bean/messagebuilder/TextBuilder.java | 6 +- .../cp}/bean/messagebuilder/VideoBuilder.java | 6 +- .../cp}/bean/messagebuilder/VoiceBuilder.java | 6 +- .../cp}/bean/outxmlbuilder/BaseBuilder.java | 4 +- .../cp}/bean/outxmlbuilder/ImageBuilder.java | 4 +- .../cp}/bean/outxmlbuilder/NewsBuilder.java | 6 +- .../cp}/bean/outxmlbuilder/TextBuilder.java | 4 +- .../cp}/bean/outxmlbuilder/VideoBuilder.java | 4 +- .../cp}/bean/outxmlbuilder/VoiceBuilder.java | 4 +- .../weixin/cp/util/crypto/WxCpCryptUtil.java | 43 +++ .../cp}/util/json/WxCpDepartGsonAdapter.java | 6 +- .../weixin/cp}/util/json/WxCpGsonBuilder.java | 12 +- .../cp}/util/json/WxCpMessageGsonAdapter.java | 10 +- .../cp}/util/json/WxCpTagGsonAdapter.java | 10 +- .../cp}/util/json/WxCpUserGsonAdapter.java | 6 +- .../weixin/cp/util/xml}/XmlTransformer.java | 4 +- .../chanjar/weixin/cp}/api/ApiTestModule.java | 6 +- .../weixin/cp}/api/WxCpBaseAPITest.java | 4 +- .../weixin/cp}/api/WxCpDepartAPITest.java | 6 +- .../weixin/cp}/api/WxCpMediaAPITest.java | 6 +- .../weixin/cp}/api/WxCpMessageAPITest.java | 8 +- .../weixin/cp}/api/WxCpMessageRouterTest.java | 6 +- .../weixin/cp}/api/WxCpTagAPITest.java | 10 +- .../weixin/cp}/api/WxCpUserAPITest.java | 8 +- .../chanjar/weixin/cp}/api/WxMenuAPITest.java | 22 +- .../weixin/cp}/bean/WxCpMessageTest.java | 6 +- .../weixin/cp}/bean/WxCpXmlMessageTest.java | 4 +- .../cp}/bean/WxCpXmlOutImageMessageTest.java | 2 +- .../cp}/bean/WxCpXmlOutNewsMessageTest.java | 2 +- .../cp}/bean/WxCpXmlOutTextMessageTest.java | 2 +- .../cp}/bean/WxCpXmlOutVideoMessageTest.java | 2 +- .../cp}/bean/WxCpXmlOutVoiceMessageTest.java | 2 +- .../demo/WxCpDemoInMemoryConfigStorage.java | 14 +- .../weixin/cp/demo/WxCpDemoServer.java | 6 +- .../weixin/cp/demo/WxCpDemoServlet.java | 18 +- .../src/test/resources/mm.jpeg | Bin .../src/test/resources/mm.mp3 | Bin .../src/test/resources/mm.mp4 | Bin .../src/test/resources/test-config.sample.xml | 0 weixin-java-cp/src/test/resources/testng.xml | 28 ++ weixin-java-enterprise/README.md | 56 --- .../common/bean/result/WxAccessToken.java | 31 -- .../weixin/enterprise/bean/WxCpMenu.java | 90 ----- .../bean/result/WxMediaUploadResult.java | 54 --- .../util/http/InputStreamResponseHandler.java | 27 -- .../util/json/WxCpAccessTokenAdapter.java | 37 -- .../json/WxCpMediaUploadResultAdapter.java | 43 --- .../util/json/WxCpMenuGsonAdapter.java | 95 ------ .../weixin/enterprise/bean/WxCpMenuTest.java | 111 ------ .../src/test/resources/testng.xml | 32 -- weixin-java-mp/README.md | 9 +- weixin-java-mp/pom.xml | 178 +--------- ...figStorage.java => WxMpConfigStorage.java} | 4 +- .../mp/api/{WxConsts.java => WxMpConsts.java} | 2 +- ...ge.java => WxMpInMemoryConfigStorage.java} | 4 +- ...geHandler.java => WxMpMessageHandler.java} | 10 +- ...eptor.java => WxMpMessageInterceptor.java} | 8 +- ...sageRouter.java => WxMpMessageRouter.java} | 52 +-- .../api/{WxService.java => WxMpService.java} | 75 ++-- ...xServiceImpl.java => WxMpServiceImpl.java} | 133 ++++---- ...tomMessage.java => WxMpCustomMessage.java} | 28 +- .../mp/bean/{WxGroup.java => WxMpGroup.java} | 12 +- ...Message.java => WxMpMassGroupMessage.java} | 19 +- .../{WxMassNews.java => WxMpMassNews.java} | 8 +- ...ssage.java => WxMpMassOpenIdsMessage.java} | 20 +- .../{WxMassVideo.java => WxMpMassVideo.java} | 6 +- ...age.java => WxMpMpXmlOutImageMessage.java} | 12 +- ...{WxXmlMessage.java => WxMpXmlMessage.java} | 68 ++-- ...OutMessage.java => WxMpXmlOutMessage.java} | 23 +- ...essage.java => WxMpXmlOutMewsMessage.java} | 21 +- ...ssage.java => WxMpXmlOutMusicMessage.java} | 12 +- ...essage.java => WxMpXmlOutTextMessage.java} | 12 +- ...ssage.java => WxMpXmlOutVideoMessage.java} | 12 +- ...ssage.java => WxMpXmlOutVoiceMessage.java} | 12 +- .../mp/bean/custombuilder/BaseBuilder.java | 6 +- .../mp/bean/custombuilder/ImageBuilder.java | 12 +- .../mp/bean/custombuilder/MusicBuilder.java | 12 +- .../mp/bean/custombuilder/NewsBuilder.java | 18 +- .../mp/bean/custombuilder/TextBuilder.java | 12 +- .../mp/bean/custombuilder/VideoBuilder.java | 12 +- .../mp/bean/custombuilder/VoiceBuilder.java | 12 +- .../mp/bean/outxmlbuilder/BaseBuilder.java | 5 +- .../mp/bean/outxmlbuilder/ImageBuilder.java | 8 +- .../mp/bean/outxmlbuilder/MusicBuilder.java | 8 +- .../mp/bean/outxmlbuilder/NewsBuilder.java | 16 +- .../mp/bean/outxmlbuilder/TextBuilder.java | 8 +- .../mp/bean/outxmlbuilder/VideoBuilder.java | 8 +- .../mp/bean/outxmlbuilder/VoiceBuilder.java | 8 +- .../weixin/mp/bean/result/WxError.java | 136 -------- ...endResult.java => WxMpMassSendResult.java} | 8 +- ...dResult.java => WxMpMassUploadResult.java} | 8 +- ...rCodeTicket.java => WxMpQrCodeTicket.java} | 8 +- .../result/{WxUser.java => WxMpUser.java} | 8 +- .../{WxUserList.java => WxMpUserList.java} | 10 +- .../weixin/mp/exception/WxErrorException.java | 21 -- .../weixin/mp/util/crypto/ByteGroup.java | 26 -- .../weixin/mp/util/crypto/PKCS7Encoder.java | 68 ---- .../chanjar/weixin/mp/util/crypto/SHA1.java | 42 --- .../weixin/mp/util/crypto/WxCryptUtil.java | 322 ------------------ .../weixin/mp/util/crypto/WxMpCryptUtil.java | 41 +++ .../chanjar/weixin/mp/util/fs/FileUtils.java | 47 --- .../http/MediaDownloadRequestExecutor.java | 67 ---- .../util/http/MediaUploadRequestExecutor.java | 43 --- .../mp/util/http/QrCodeRequestExecutor.java | 28 +- .../weixin/mp/util/http/RequestExecutor.java | 24 -- .../util/http/SimpleGetRequestExecutor.java | 36 -- .../util/http/SimplePostRequestExecutor.java | 36 -- .../mp/util/http/Utf8ResponseHandler.java | 32 -- .../weixin/mp/util/json/GsonHelper.java | 115 ------- .../weixin/mp/util/json/WxErrorAdapter.java | 36 -- .../weixin/mp/util/json/WxGsonBuilder.java | 37 -- ...java => WxMpCustomMessageGsonAdapter.java} | 31 +- ...Adapter.java => WxMpGroupGsonAdapter.java} | 22 +- .../weixin/mp/util/json/WxMpGsonBuilder.java | 31 ++ ...r.java => WxMpMassMessageGsonAdapter.java} | 33 +- ...pter.java => WxMpMassNewsGsonAdapter.java} | 17 +- ...=> WxMpMassOpenIdsMessageGsonAdapter.java} | 38 +-- ...er.java => WxMpMassSendResultAdapter.java} | 9 +- ....java => WxMpMassUploadResultAdapter.java} | 9 +- ...Adapter.java => WxMpMassVideoAdapter.java} | 11 +- .../mp/util/json/WxQrCodeTicketAdapter.java | 9 +- .../mp/util/json/WxUserGsonAdapter.java | 46 ++- .../mp/util/json/WxUserListGsonAdapter.java | 29 +- .../weixin/mp/util/xml/AdapterCDATA.java | 24 -- .../weixin/mp/util/xml/MediaIdMarshaller.java | 21 -- .../weixin/mp/util/xml/XmlTransformer.java | 32 +- .../chanjar/weixin/mp/api/ApiTestModule.java | 16 +- .../chanjar/weixin/mp/api/WxBaseAPITest.java | 6 +- .../weixin/mp/api/WxMessageRouterTest.java | 162 --------- ...est.java => WxMpCustomMessageAPITest.java} | 14 +- ...roupAPITest.java => WxMpGroupAPITest.java} | 16 +- ...ITest.java => WxMpMassMessageAPITest.java} | 70 ++-- ...ediaAPITest.java => WxMpMediaAPITest.java} | 16 +- .../weixin/mp/api/WxMpMenuAPITest.java | 30 +- .../weixin/mp/api/WxMpMessageRouterTest.java | 158 +++++++++ ...odeAPITest.java => WxMpQrCodeAPITest.java} | 14 +- ...lAPITest.java => WxMpShortUrlAPITest.java} | 6 +- .../weixin/mp/api/WxMpUserAPITest.java | 55 +++ .../chanjar/weixin/mp/api/WxUserAPITest.java | 56 --- .../weixin/mp/bean/WxAccessTokenTest.java | 19 -- .../chanjar/weixin/mp/bean/WxErrorTest.java | 38 --- ...geTest.java => WxMpCustomMessageTest.java} | 43 ++- ...ssageTest.java => WxMpXmlMessageTest.java} | 9 +- ...t.java => WxMpXmlOutImageMessageTest.java} | 8 +- .../mp/bean/WxXmlOutMusicMessageTest.java | 6 +- .../mp/bean/WxXmlOutNewsMessageTest.java | 10 +- .../mp/bean/WxXmlOutTextMessageTest.java | 6 +- .../mp/bean/WxXmlOutVideoMessageTest.java | 6 +- .../mp/bean/WxXmlOutVoiceMessageTest.java | 6 +- ...ava => WxMpDemoInMemoryConfigStorage.java} | 10 +- ...{WxTestServer.java => WxMpDemoServer.java} | 4 +- ...xTestServlet.java => WxMpDemoServlet.java} | 49 ++- .../mp/util/crypto/WxCryptUtilTest.java | 95 ------ weixin-java-mp/src/test/resources/testng.xml | 28 +- 212 files changed, 1701 insertions(+), 3459 deletions(-) rename weixin-java-enterprise/pom.xml => pom.xml (75%) create mode 100644 weixin-java-common/pom.xml rename {weixin-java-mp/src/main/java/me/chanjar/weixin/mp => weixin-java-common/src/main/java/me/chanjar/weixin/common}/bean/WxAccessToken.java (79%) rename {weixin-java-mp/src/main/java/me/chanjar/weixin/mp => weixin-java-common/src/main/java/me/chanjar/weixin/common}/bean/WxMenu.java (92%) rename {weixin-java-enterprise => weixin-java-common}/src/main/java/me/chanjar/weixin/common/bean/result/WxError.java (75%) rename {weixin-java-mp/src/main/java/me/chanjar/weixin/mp => weixin-java-common/src/main/java/me/chanjar/weixin/common}/bean/result/WxMediaUploadResult.java (90%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise => weixin-java-common/src/main/java/me/chanjar/weixin/common}/exception/WxErrorException.java (88%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise => weixin-java-common/src/main/java/me/chanjar/weixin/common}/util/crypto/ByteGroup.java (65%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise => weixin-java-common/src/main/java/me/chanjar/weixin/common}/util/crypto/PKCS7Encoder.java (84%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise => weixin-java-common/src/main/java/me/chanjar/weixin/common}/util/crypto/SHA1.java (95%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise => weixin-java-common/src/main/java/me/chanjar/weixin/common}/util/crypto/WxCryptUtil.java (86%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/common/util => weixin-java-common/src/main/java/me/chanjar/weixin/common/util/fs}/FileUtils.java (96%) rename {weixin-java-mp/src/main/java/me/chanjar/weixin/mp => weixin-java-common/src/main/java/me/chanjar/weixin/common}/util/http/InputStreamResponseHandler.java (95%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise => weixin-java-common/src/main/java/me/chanjar/weixin/common}/util/http/MediaDownloadRequestExecutor.java (86%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise => weixin-java-common/src/main/java/me/chanjar/weixin/common}/util/http/MediaUploadRequestExecutor.java (88%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise => weixin-java-common/src/main/java/me/chanjar/weixin/common}/util/http/RequestExecutor.java (82%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise => weixin-java-common/src/main/java/me/chanjar/weixin/common}/util/http/SimpleGetRequestExecutor.java (90%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise => weixin-java-common/src/main/java/me/chanjar/weixin/common}/util/http/SimplePostRequestExecutor.java (91%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise => weixin-java-common/src/main/java/me/chanjar/weixin/common}/util/http/Utf8ResponseHandler.java (95%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/common/util => weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json}/GsonHelper.java (98%) rename {weixin-java-mp/src/main/java/me/chanjar/weixin/mp => weixin-java-common/src/main/java/me/chanjar/weixin/common}/util/json/WxAccessTokenAdapter.java (93%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise => weixin-java-common/src/main/java/me/chanjar/weixin/common}/util/json/WxErrorAdapter.java (93%) create mode 100644 weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxGsonBuilder.java rename {weixin-java-mp/src/main/java/me/chanjar/weixin/mp => weixin-java-common/src/main/java/me/chanjar/weixin/common}/util/json/WxMediaUploadResultAdapter.java (94%) rename {weixin-java-mp/src/main/java/me/chanjar/weixin/mp => weixin-java-common/src/main/java/me/chanjar/weixin/common}/util/json/WxMenuGsonAdapter.java (96%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/common/util => weixin-java-common/src/main/java/me/chanjar/weixin/common/util/xml}/AdapterCDATA.java (91%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/common/util => weixin-java-common/src/main/java/me/chanjar/weixin/common/util/xml}/MediaIdMarshaller.java (90%) rename {weixin-java-enterprise => weixin-java-common}/src/test/java/me/chanjar/weixin/common/bean/WxAccessTokenTest.java (88%) rename {weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise => weixin-java-common/src/test/java/me/chanjar/weixin/common}/bean/WxErrorTest.java (95%) rename {weixin-java-mp/src/test/java/me/chanjar/weixin/mp => weixin-java-common/src/test/java/me/chanjar/weixin/common}/bean/WxMenuTest.java (95%) rename {weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise => weixin-java-common/src/test/java/me/chanjar/weixin/common}/util/crypto/WxCryptUtilTest.java (95%) create mode 100644 weixin-java-common/src/test/resources/testng.xml rename {weixin-java-enterprise => weixin-java-cp}/LICENSE (100%) create mode 100644 weixin-java-cp/README.md create mode 100644 weixin-java-cp/pom.xml rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/main/java/me/chanjar/weixin/cp}/api/WxCpConfigStorage.java (82%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/main/java/me/chanjar/weixin/cp}/api/WxCpConsts.java (97%) rename weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/api/WxInMemoryCpConfigStorage.java => weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpInMemoryConfigStorage.java (90%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/main/java/me/chanjar/weixin/cp}/api/WxCpMessageHandler.java (74%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/main/java/me/chanjar/weixin/cp}/api/WxCpMessageInterceptor.java (81%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/main/java/me/chanjar/weixin/cp}/api/WxCpMessageRouter.java (92%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/main/java/me/chanjar/weixin/cp}/api/WxCpService.java (93%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/main/java/me/chanjar/weixin/cp}/api/WxCpServiceImpl.java (92%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/main/java/me/chanjar/weixin/cp}/bean/WxCpDepart.java (91%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/main/java/me/chanjar/weixin/cp}/bean/WxCpMessage.java (86%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/main/java/me/chanjar/weixin/cp}/bean/WxCpTag.java (66%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/main/java/me/chanjar/weixin/cp}/bean/WxCpUser.java (94%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/main/java/me/chanjar/weixin/cp}/bean/WxCpXmlMessage.java (91%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/main/java/me/chanjar/weixin/cp}/bean/WxCpXmlOutImageMessage.java (82%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/main/java/me/chanjar/weixin/cp}/bean/WxCpXmlOutMessage.java (78%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/main/java/me/chanjar/weixin/cp}/bean/WxCpXmlOutMewsMessage.java (93%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/main/java/me/chanjar/weixin/cp}/bean/WxCpXmlOutTextMessage.java (83%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/main/java/me/chanjar/weixin/cp}/bean/WxCpXmlOutVideoMessage.java (92%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/main/java/me/chanjar/weixin/cp}/bean/WxCpXmlOutVoiceMessage.java (82%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/main/java/me/chanjar/weixin/cp}/bean/messagebuilder/BaseBuilder.java (87%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/main/java/me/chanjar/weixin/cp}/bean/messagebuilder/FileBuilder.java (77%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/main/java/me/chanjar/weixin/cp}/bean/messagebuilder/ImageBuilder.java (77%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/main/java/me/chanjar/weixin/cp}/bean/messagebuilder/NewsBuilder.java (81%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/main/java/me/chanjar/weixin/cp}/bean/messagebuilder/TextBuilder.java (77%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/main/java/me/chanjar/weixin/cp}/bean/messagebuilder/VideoBuilder.java (88%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/main/java/me/chanjar/weixin/cp}/bean/messagebuilder/VoiceBuilder.java (77%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/main/java/me/chanjar/weixin/cp}/bean/outxmlbuilder/BaseBuilder.java (83%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/main/java/me/chanjar/weixin/cp}/bean/outxmlbuilder/ImageBuilder.java (78%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/main/java/me/chanjar/weixin/cp}/bean/outxmlbuilder/NewsBuilder.java (74%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/main/java/me/chanjar/weixin/cp}/bean/outxmlbuilder/TextBuilder.java (78%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/main/java/me/chanjar/weixin/cp}/bean/outxmlbuilder/VideoBuilder.java (86%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/main/java/me/chanjar/weixin/cp}/bean/outxmlbuilder/VoiceBuilder.java (78%) create mode 100755 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/crypto/WxCpCryptUtil.java rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/main/java/me/chanjar/weixin/cp}/util/json/WxCpDepartGsonAdapter.java (94%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/main/java/me/chanjar/weixin/cp}/util/json/WxCpGsonBuilder.java (61%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/main/java/me/chanjar/weixin/cp}/util/json/WxCpMessageGsonAdapter.java (95%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/main/java/me/chanjar/weixin/cp}/util/json/WxCpTagGsonAdapter.java (78%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/main/java/me/chanjar/weixin/cp}/util/json/WxCpUserGsonAdapter.java (96%) rename {weixin-java-enterprise/src/main/java/me/chanjar/weixin/common/util => weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/xml}/XmlTransformer.java (96%) rename {weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/test/java/me/chanjar/weixin/cp}/api/ApiTestModule.java (90%) rename {weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/test/java/me/chanjar/weixin/cp}/api/WxCpBaseAPITest.java (87%) rename {weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/test/java/me/chanjar/weixin/cp}/api/WxCpDepartAPITest.java (91%) rename {weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/test/java/me/chanjar/weixin/cp}/api/WxCpMediaAPITest.java (92%) rename {weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/test/java/me/chanjar/weixin/cp}/api/WxCpMessageAPITest.java (79%) rename {weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/test/java/me/chanjar/weixin/cp}/api/WxCpMessageRouterTest.java (96%) rename {weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/test/java/me/chanjar/weixin/cp}/api/WxCpTagAPITest.java (84%) rename {weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/test/java/me/chanjar/weixin/cp}/api/WxCpUserAPITest.java (89%) rename {weixin-java-mp/src/test/java/me/chanjar/weixin/mp => weixin-java-cp/src/test/java/me/chanjar/weixin/cp}/api/WxMenuAPITest.java (80%) rename {weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/test/java/me/chanjar/weixin/cp}/bean/WxCpMessageTest.java (96%) rename {weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/test/java/me/chanjar/weixin/cp}/bean/WxCpXmlMessageTest.java (98%) rename {weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/test/java/me/chanjar/weixin/cp}/bean/WxCpXmlOutImageMessageTest.java (97%) rename {weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/test/java/me/chanjar/weixin/cp}/bean/WxCpXmlOutNewsMessageTest.java (98%) rename {weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/test/java/me/chanjar/weixin/cp}/bean/WxCpXmlOutTextMessageTest.java (97%) rename {weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/test/java/me/chanjar/weixin/cp}/bean/WxCpXmlOutVideoMessageTest.java (98%) rename {weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise => weixin-java-cp/src/test/java/me/chanjar/weixin/cp}/bean/WxCpXmlOutVoiceMessageTest.java (97%) rename weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/demo/WxTestCpConfigStorage.java => weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpDemoInMemoryConfigStorage.java (53%) rename weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/demo/WxCpTestServer.java => weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpDemoServer.java (71%) rename weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/demo/WxCpTestServlet.java => weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpDemoServlet.java (84%) rename {weixin-java-enterprise => weixin-java-cp}/src/test/resources/mm.jpeg (100%) rename {weixin-java-enterprise => weixin-java-cp}/src/test/resources/mm.mp3 (100%) rename {weixin-java-enterprise => weixin-java-cp}/src/test/resources/mm.mp4 (100%) rename {weixin-java-enterprise => weixin-java-cp}/src/test/resources/test-config.sample.xml (100%) create mode 100644 weixin-java-cp/src/test/resources/testng.xml delete mode 100644 weixin-java-enterprise/README.md delete mode 100644 weixin-java-enterprise/src/main/java/me/chanjar/weixin/common/bean/result/WxAccessToken.java delete mode 100644 weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpMenu.java delete mode 100644 weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/result/WxMediaUploadResult.java delete mode 100644 weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/http/InputStreamResponseHandler.java delete mode 100644 weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxCpAccessTokenAdapter.java delete mode 100644 weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxCpMediaUploadResultAdapter.java delete mode 100644 weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxCpMenuGsonAdapter.java delete mode 100644 weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/bean/WxCpMenuTest.java delete mode 100644 weixin-java-enterprise/src/test/resources/testng.xml rename weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/{WxConfigStorage.java => WxMpConfigStorage.java} (82%) rename weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/{WxConsts.java => WxMpConsts.java} (99%) rename weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/{WxInMemoryConfigStorage.java => WxMpInMemoryConfigStorage.java} (92%) rename weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/{WxMessageHandler.java => WxMpMessageHandler.java} (62%) rename weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/{WxMessageInterceptor.java => WxMpMessageInterceptor.java} (66%) rename weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/{WxMessageRouter.java => WxMpMessageRouter.java} (80%) rename weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/{WxService.java => WxMpService.java} (76%) rename weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/{WxServiceImpl.java => WxMpServiceImpl.java} (76%) rename weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/{WxCustomMessage.java => WxMpCustomMessage.java} (81%) rename weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/{WxGroup.java => WxMpGroup.java} (63%) rename weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/{WxMassGroupMessage.java => WxMpMassGroupMessage.java} (64%) rename weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/{WxMassNews.java => WxMpMassNews.java} (95%) rename weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/{WxMassOpenIdsMessage.java => WxMpMassOpenIdsMessage.java} (69%) rename weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/{WxMassVideo.java => WxMpMassVideo.java} (81%) rename weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/{WxXmlOutImageMessage.java => WxMpMpXmlOutImageMessage.java} (70%) rename weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/{WxXmlMessage.java => WxMpXmlMessage.java} (85%) rename weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/{WxXmlOutMessage.java => WxMpXmlOutMessage.java} (79%) rename weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/{WxXmlOutMewsMessage.java => WxMpXmlOutMewsMessage.java} (78%) rename weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/{WxXmlOutMusicMessage.java => WxMpXmlOutMusicMessage.java} (91%) rename weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/{WxXmlOutTextMessage.java => WxMpXmlOutTextMessage.java} (71%) rename weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/{WxXmlOutVideoMessage.java => WxMpXmlOutVideoMessage.java} (87%) rename weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/{WxXmlOutVoiceMessage.java => WxMpXmlOutVoiceMessage.java} (70%) delete mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxError.java rename weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/{WxMassSendResult.java => WxMpMassSendResult.java} (81%) rename weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/{WxMassUploadResult.java => WxMpMassUploadResult.java} (77%) rename weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/{WxQrCodeTicket.java => WxMpQrCodeTicket.java} (74%) rename weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/{WxUser.java => WxMpUser.java} (90%) rename weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/{WxUserList.java => WxMpUserList.java} (79%) delete mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/exception/WxErrorException.java delete mode 100755 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/crypto/ByteGroup.java delete mode 100755 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/crypto/PKCS7Encoder.java delete mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/crypto/SHA1.java delete mode 100755 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/crypto/WxCryptUtil.java create mode 100755 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/crypto/WxMpCryptUtil.java delete mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/fs/FileUtils.java delete mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MediaDownloadRequestExecutor.java delete mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MediaUploadRequestExecutor.java delete mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/RequestExecutor.java delete mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/SimpleGetRequestExecutor.java delete mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/SimplePostRequestExecutor.java delete mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/Utf8ResponseHandler.java delete mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/GsonHelper.java delete mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxErrorAdapter.java delete mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxGsonBuilder.java rename weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/{WxCustomMessageGsonAdapter.java => WxMpCustomMessageGsonAdapter.java} (71%) rename weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/{WxGroupGsonAdapter.java => WxMpGroupGsonAdapter.java} (68%) create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpGsonBuilder.java rename weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/{WxMassMessageGsonAdapter.java => WxMpMassMessageGsonAdapter.java} (62%) rename weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/{WxMassNewsGsonAdapter.java => WxMpMassNewsGsonAdapter.java} (75%) rename weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/{WxMassOpenIdsMessageGsonAdapter.java => WxMpMassOpenIdsMessageGsonAdapter.java} (55%) rename weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/{WxMassSendResultAdapter.java => WxMpMassSendResultAdapter.java} (76%) rename weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/{WxMassUploadResultAdapter.java => WxMpMassUploadResultAdapter.java} (76%) rename weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/{WxMassVideoAdapter.java => WxMpMassVideoAdapter.java} (67%) delete mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/xml/AdapterCDATA.java delete mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/xml/MediaIdMarshaller.java delete mode 100644 weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMessageRouterTest.java rename weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/{WxCustomMessageAPITest.java => WxMpCustomMessageAPITest.java} (58%) rename weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/{WxGroupAPITest.java => WxMpGroupAPITest.java} (72%) rename weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/{WxMassMessageAPITest.java => WxMpMassMessageAPITest.java} (66%) rename weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/{WxMediaAPITest.java => WxMpMediaAPITest.java} (77%) rename weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/api/WxCpMenuAPITest.java => weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMenuAPITest.java (72%) create mode 100644 weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMessageRouterTest.java rename weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/{WxQrCodeAPITest.java => WxMpQrCodeAPITest.java} (70%) rename weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/{WxShortUrlAPITest.java => WxMpShortUrlAPITest.java} (78%) create mode 100644 weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpUserAPITest.java delete mode 100644 weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxUserAPITest.java delete mode 100644 weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxAccessTokenTest.java delete mode 100644 weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxErrorTest.java rename weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/{WxCustomMessageTest.java => WxMpCustomMessageTest.java} (76%) rename weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/{WxXmlMessageTest.java => WxMpXmlMessageTest.java} (95%) rename weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/{WxXmlOutImageMessageTest.java => WxMpXmlOutImageMessageTest.java} (83%) rename weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/{WxTestConfigStorage.java => WxMpDemoInMemoryConfigStorage.java} (66%) rename weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/{WxTestServer.java => WxMpDemoServer.java} (80%) rename weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/{WxTestServlet.java => WxMpDemoServlet.java} (63%) delete mode 100755 weixin-java-mp/src/test/java/me/chanjar/weixin/mp/util/crypto/WxCryptUtilTest.java diff --git a/weixin-java-enterprise/pom.xml b/pom.xml similarity index 75% rename from weixin-java-enterprise/pom.xml rename to pom.xml index 204d6916a..cd72620e6 100644 --- a/weixin-java-enterprise/pom.xml +++ b/pom.xml @@ -4,10 +4,11 @@ xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 4.0.0 me.chanjar - weixin-java-enterprise-tools + weixin-java-parent 1.0.3-SNAPSHOT - WeiXin Java Enterprise Tools - 微信企业号Java SDK + pom + WeiXin Java Tools - Parent + 微信公众号、企业号上级POM https://github.com/chanjarster/weixin-java-tools @@ -30,19 +31,20 @@ https://github.com/chanjarster/weixin-java-tools + + weixin-java-common + weixin-java-cp + weixin-java-mp + + UTF-8 true true 4.3.5 + - - junit - junit - 4.11 - test - org.apache.httpcomponents fluent-hc @@ -63,34 +65,11 @@ jaxb-impl 2.2.7 - - org.apache.oltu.oauth2 - org.apache.oltu.oauth2.client - 1.0.0 - com.google.code.gson gson 2.2.2 - - org.testng - testng - 6.8.7 - test - - - org.mockito - mockito-all - 1.9.5 - test - - - com.google.inject - guice - 3.0 - test - org.apache.commons commons-lang3 @@ -106,20 +85,49 @@ commons-io 2.4 - - org.eclipse.jetty - jetty-server - 9.3.0.M0 - test - - - org.eclipse.jetty - jetty-servlet - 9.3.0.M0 - test - + + + + junit + junit + 4.11 + test + + + com.google.inject + guice + 3.0 + test + + + org.testng + testng + 6.8.7 + test + + + org.mockito + mockito-all + 1.9.5 + test + + + org.eclipse.jetty + jetty-server + 9.3.0.M0 + test + + + org.eclipse.jetty + jetty-servlet + 9.3.0.M0 + test + + + + ossrh @@ -186,17 +194,17 @@ + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.17 + + + + - - org.apache.maven.plugins - maven-surefire-plugin - 2.17 - - - src/test/resources/testng.xml - - - org.sonatype.plugins nexus-staging-maven-plugin diff --git a/weixin-java-common/pom.xml b/weixin-java-common/pom.xml new file mode 100644 index 000000000..26cc3dddf --- /dev/null +++ b/weixin-java-common/pom.xml @@ -0,0 +1,68 @@ + + + 4.0.0 + + me.chanjar + weixin-java-parent + 1.0.3-SNAPSHOT + + + weixin-java-common + WeiXin Java Tools - Common + 微信公众号、企业号Java SDK Common + + + + junit + junit + test + + + org.testng + testng + 6.8.7 + test + + + org.mockito + mockito-all + 1.9.5 + test + + + com.google.inject + guice + 3.0 + test + + + org.eclipse.jetty + jetty-server + 9.3.0.M0 + test + + + org.eclipse.jetty + jetty-servlet + 9.3.0.M0 + test + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + src/test/resources/testng.xml + + + + + + + diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxAccessToken.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxAccessToken.java similarity index 79% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxAccessToken.java rename to weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxAccessToken.java index c9166effa..2365daa26 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxAccessToken.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxAccessToken.java @@ -1,12 +1,12 @@ -package me.chanjar.weixin.mp.bean; +package me.chanjar.weixin.common.bean; -import me.chanjar.weixin.mp.util.json.WxGsonBuilder; +import me.chanjar.weixin.common.util.json.WxGsonBuilder; public class WxAccessToken { private String accessToken; - private int expiresIn; + private int expiresIn = -1; public String getAccessToken() { return accessToken; diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMenu.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxMenu.java similarity index 92% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMenu.java rename to weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxMenu.java index b1c9a71d0..701102304 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMenu.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxMenu.java @@ -1,15 +1,15 @@ -package me.chanjar.weixin.mp.bean; +package me.chanjar.weixin.common.bean; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; -import me.chanjar.weixin.mp.util.json.WxGsonBuilder; +import me.chanjar.weixin.common.util.json.WxGsonBuilder; /** - * 公众号菜单 - * @author chanjarster + * 企业号菜单 + * @author Daniel Qian * */ public class WxMenu { diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/common/bean/result/WxError.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/result/WxError.java similarity index 75% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/common/bean/result/WxError.java rename to weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/result/WxError.java index 8b5dde6fb..495ede81e 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/common/bean/result/WxError.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/result/WxError.java @@ -1,6 +1,6 @@ package me.chanjar.weixin.common.bean.result; -import me.chanjar.weixin.enterprise.util.json.WxCpGsonBuilder; +import me.chanjar.weixin.common.util.json.WxGsonBuilder; /** * 微信错误码说明 @@ -32,9 +32,16 @@ public class WxError { this.errorMsg = errorMsg; } + public String getJson() { + return json; + } + + public void setJson(String json) { + this.json = json; + } + public static WxError fromJson(String json) { - WxError error = WxCpGsonBuilder.create().fromJson(json, WxError.class); - error.json = json; + WxError error = WxGsonBuilder.create().fromJson(json, WxError.class); return error; } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMediaUploadResult.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/result/WxMediaUploadResult.java similarity index 90% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMediaUploadResult.java rename to weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/result/WxMediaUploadResult.java index 83a838df7..1695489ae 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMediaUploadResult.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/result/WxMediaUploadResult.java @@ -1,6 +1,6 @@ -package me.chanjar.weixin.mp.bean.result; +package me.chanjar.weixin.common.bean.result; -import me.chanjar.weixin.mp.util.json.WxGsonBuilder; +import me.chanjar.weixin.common.util.json.WxGsonBuilder; public class WxMediaUploadResult { @@ -33,10 +33,6 @@ public class WxMediaUploadResult { this.createdAt = createdAt; } - public static WxMediaUploadResult fromJson(String json) { - return WxGsonBuilder.create().fromJson(json, WxMediaUploadResult.class); - } - public String getThumbMediaId() { return thumbMediaId; } @@ -45,6 +41,10 @@ public class WxMediaUploadResult { this.thumbMediaId = thumbMediaId; } + public static WxMediaUploadResult fromJson(String json) { + return WxGsonBuilder.create().fromJson(json, WxMediaUploadResult.class); + } + @Override public String toString() { return "WxUploadResult [type=" + type + ", media_id=" + mediaId + ", thumb_media_id=" + thumbMediaId diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/exception/WxErrorException.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/exception/WxErrorException.java similarity index 88% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/exception/WxErrorException.java rename to weixin-java-common/src/main/java/me/chanjar/weixin/common/exception/WxErrorException.java index da5e47c70..d1dc569be 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/exception/WxErrorException.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/exception/WxErrorException.java @@ -1,4 +1,4 @@ -package me.chanjar.weixin.enterprise.exception; +package me.chanjar.weixin.common.exception; import me.chanjar.weixin.common.bean.result.WxError; diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/crypto/ByteGroup.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/ByteGroup.java similarity index 65% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/crypto/ByteGroup.java rename to weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/ByteGroup.java index 8f4f10d03..de777dc9f 100755 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/crypto/ByteGroup.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/ByteGroup.java @@ -1,11 +1,11 @@ -package me.chanjar.weixin.enterprise.util.crypto; +package me.chanjar.weixin.common.util.crypto; import java.util.ArrayList; -class ByteGroup { +public class ByteGroup { ArrayList byteContainer = new ArrayList(); - byte[] toBytes() { + public byte[] toBytes() { byte[] bytes = new byte[byteContainer.size()]; for (int i = 0; i < byteContainer.size(); i++) { bytes[i] = byteContainer.get(i); @@ -13,14 +13,14 @@ class ByteGroup { return bytes; } - ByteGroup addBytes(byte[] bytes) { + public ByteGroup addBytes(byte[] bytes) { for (byte b : bytes) { byteContainer.add(b); } return this; } - int size() { + public int size() { return byteContainer.size(); } } diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/crypto/PKCS7Encoder.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/PKCS7Encoder.java similarity index 84% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/crypto/PKCS7Encoder.java rename to weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/PKCS7Encoder.java index dd6893ab7..35771c471 100755 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/crypto/PKCS7Encoder.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/PKCS7Encoder.java @@ -6,7 +6,7 @@ // ------------------------------------------------------------------------ -package me.chanjar.weixin.enterprise.util.crypto; +package me.chanjar.weixin.common.util.crypto; import java.nio.charset.Charset; import java.util.Arrays; @@ -14,7 +14,7 @@ import java.util.Arrays; /** * 提供基于PKCS7算法的加解 */ -class PKCS7Encoder { +public class PKCS7Encoder { private static final Charset CHARSET = Charset.forName("utf-8"); private static final int BLOCK_SIZE = 32; @@ -25,7 +25,7 @@ class PKCS7Encoder { * @param count 需要进行填充补位操作的明文字节个数 * @return 补齐用的字节数组 */ - static byte[] encode(int count) { + public static byte[] encode(int count) { // 计算需要填充的位数 int amountToPad = BLOCK_SIZE - (count % BLOCK_SIZE); if (amountToPad == 0) { @@ -46,7 +46,7 @@ class PKCS7Encoder { * @param decrypted 解密后的明文 * @return 删除补位字符后的明文 */ - static byte[] decode(byte[] decrypted) { + public static byte[] decode(byte[] decrypted) { int pad = (int) decrypted[decrypted.length - 1]; if (pad < 1 || pad > 32) { pad = 0; @@ -60,7 +60,7 @@ class PKCS7Encoder { * @param a 需要转化的数字 * @return 转化得到的字符 */ - static char chr(int a) { + public static char chr(int a) { byte target = (byte) (a & 0xFF); return (char) target; } diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/crypto/SHA1.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/SHA1.java similarity index 95% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/crypto/SHA1.java rename to weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/SHA1.java index 99e9951c8..cc2333086 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/crypto/SHA1.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/SHA1.java @@ -1,4 +1,4 @@ -package me.chanjar.weixin.enterprise.util.crypto; +package me.chanjar.weixin.common.util.crypto; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/crypto/WxCryptUtil.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/WxCryptUtil.java similarity index 86% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/crypto/WxCryptUtil.java rename to weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/WxCryptUtil.java index 0a5fe8dd4..363f0be01 100755 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/crypto/WxCryptUtil.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/WxCryptUtil.java @@ -11,13 +11,12 @@ * 需要导入架包commons-codec-1.9(或commons-codec-1.8等其他版本) * 官方下载地址:http://commons.apache.org/proper/commons-codec/download_codec.cgi */ -package me.chanjar.weixin.enterprise.util.crypto; +package me.chanjar.weixin.common.util.crypto; -import java.io.StringReader; -import java.nio.charset.Charset; -import java.security.NoSuchAlgorithmException; -import java.util.Arrays; -import java.util.Random; +import org.apache.commons.codec.binary.Base64; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.xml.sax.InputSource; import javax.crypto.Cipher; import javax.crypto.spec.IvParameterSpec; @@ -25,12 +24,11 @@ import javax.crypto.spec.SecretKeySpec; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; - -import me.chanjar.weixin.enterprise.api.WxCpConfigStorage; -import org.apache.commons.codec.binary.Base64; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.xml.sax.InputSource; +import java.io.StringReader; +import java.nio.charset.Charset; +import java.security.NoSuchAlgorithmException; +import java.util.Arrays; +import java.util.Random; public class WxCryptUtil { @@ -48,41 +46,24 @@ public class WxCryptUtil { } }; - private byte[] aesKey; - private String token; - private String corpId; - - /** - * 构造函数 - * - * @param wxCpConfigStorage - */ - public WxCryptUtil(WxCpConfigStorage wxCpConfigStorage) { - /* - * @param token 公众平台上,开发者设置的token - * @param encodingAesKey 公众平台上,开发者设置的EncodingAESKey - * @param corpId 公众平台appid - */ - String encodingAesKey = wxCpConfigStorage.getAesKey(); - String token = wxCpConfigStorage.getToken(); - String corpId = wxCpConfigStorage.getCorpId(); - - this.token = token; - this.corpId = corpId; - this.aesKey = Base64.decodeBase64(encodingAesKey + "="); + protected byte[] aesKey; + protected String token; + protected String appidOrCorpid; + public WxCryptUtil() { + super(); } /** * 构造函数 * - * @param token 公众平台上,开发者设置的token - * @param encodingAesKey 公众平台上,开发者设置的EncodingAESKey - * @param corpId 公众平台appid + * @param token 公众平台上,开发者设置的token + * @param encodingAesKey 公众平台上,开发者设置的EncodingAESKey + * @param appidOrCorpid 公众平台appid/corpid */ - public WxCryptUtil(String token, String encodingAesKey, String corpId) { + public WxCryptUtil(String token, String encodingAesKey, String appidOrCorpid) { this.token = token; - this.corpId = corpId; + this.appidOrCorpid = appidOrCorpid; this.aesKey = Base64.decodeBase64(encodingAesKey + "="); } @@ -125,7 +106,7 @@ public class WxCryptUtil { byte[] randomStringBytes = randomStr.getBytes(CHARSET); byte[] plainTextBytes = plainText.getBytes(CHARSET); byte[] bytesOfSizeInNetworkOrder = number2BytesInNetworkOrder(plainTextBytes.length); - byte[] appIdBytes = corpId.getBytes(CHARSET); + byte[] appIdBytes = appidOrCorpid.getBytes(CHARSET); // randomStr + networkBytesOrder + text + appid byteCollector.addBytes(randomStringBytes); @@ -235,7 +216,7 @@ public class WxCryptUtil { } // appid不相同的情况 - if (!from_appid.equals(corpId)) { + if (!from_appid.equals(appidOrCorpid)) { throw new RuntimeException("AppID不正确"); } diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/common/util/FileUtils.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/fs/FileUtils.java similarity index 96% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/common/util/FileUtils.java rename to weixin-java-common/src/main/java/me/chanjar/weixin/common/util/fs/FileUtils.java index b4eb72381..d2ecc42a6 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/common/util/FileUtils.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/fs/FileUtils.java @@ -1,4 +1,4 @@ -package me.chanjar.weixin.common.util; +package me.chanjar.weixin.common.util.fs; import java.io.File; import java.io.FileOutputStream; diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/InputStreamResponseHandler.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/InputStreamResponseHandler.java similarity index 95% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/InputStreamResponseHandler.java rename to weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/InputStreamResponseHandler.java index e8926a44a..cf7f26cfb 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/InputStreamResponseHandler.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/InputStreamResponseHandler.java @@ -1,4 +1,4 @@ -package me.chanjar.weixin.mp.util.http; +package me.chanjar.weixin.common.util.http; import java.io.IOException; import java.io.InputStream; diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/http/MediaDownloadRequestExecutor.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/MediaDownloadRequestExecutor.java similarity index 86% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/http/MediaDownloadRequestExecutor.java rename to weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/MediaDownloadRequestExecutor.java index 79ee8261a..caa8e03b4 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/http/MediaDownloadRequestExecutor.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/MediaDownloadRequestExecutor.java @@ -1,11 +1,11 @@ -package me.chanjar.weixin.enterprise.util.http; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.util.regex.Matcher; -import java.util.regex.Pattern; +package me.chanjar.weixin.common.util.http; +import me.chanjar.weixin.common.bean.result.WxError; +import me.chanjar.weixin.common.util.fs.FileUtils; +import me.chanjar.weixin.common.exception.WxErrorException; +import me.chanjar.weixin.common.util.http.InputStreamResponseHandler; +import me.chanjar.weixin.common.util.http.RequestExecutor; +import me.chanjar.weixin.common.util.http.Utf8ResponseHandler; import org.apache.commons.lang3.StringUtils; import org.apache.http.Header; import org.apache.http.client.ClientProtocolException; @@ -13,9 +13,11 @@ import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.entity.ContentType; -import me.chanjar.weixin.common.bean.result.WxError; -import me.chanjar.weixin.enterprise.exception.WxErrorException; -import me.chanjar.weixin.common.util.FileUtils; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * 下载媒体文件请求执行器,请求的参数是String, 返回的结果是File diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/http/MediaUploadRequestExecutor.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/MediaUploadRequestExecutor.java similarity index 88% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/http/MediaUploadRequestExecutor.java rename to weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/MediaUploadRequestExecutor.java index 477ae1d40..622237220 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/http/MediaUploadRequestExecutor.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/MediaUploadRequestExecutor.java @@ -1,8 +1,9 @@ -package me.chanjar.weixin.enterprise.util.http; +package me.chanjar.weixin.common.util.http; import java.io.File; import java.io.IOException; +import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; import org.apache.http.HttpEntity; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.methods.CloseableHttpResponse; @@ -11,8 +12,7 @@ import org.apache.http.entity.ContentType; import org.apache.http.entity.mime.MultipartEntityBuilder; import me.chanjar.weixin.common.bean.result.WxError; -import me.chanjar.weixin.enterprise.bean.result.WxMediaUploadResult; -import me.chanjar.weixin.enterprise.exception.WxErrorException; +import me.chanjar.weixin.common.exception.WxErrorException; /** * 上传媒体文件请求执行器,请求的参数是File, 返回的结果是String diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/http/RequestExecutor.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/RequestExecutor.java similarity index 82% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/http/RequestExecutor.java rename to weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/RequestExecutor.java index 9f30369c1..e7959dca2 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/http/RequestExecutor.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/RequestExecutor.java @@ -1,4 +1,4 @@ -package me.chanjar.weixin.enterprise.util.http; +package me.chanjar.weixin.common.util.http; import java.io.IOException; @@ -6,7 +6,7 @@ import org.apache.http.client.ClientProtocolException; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; -import me.chanjar.weixin.enterprise.exception.WxErrorException; +import me.chanjar.weixin.common.exception.WxErrorException; /** * http请求执行器 diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/http/SimpleGetRequestExecutor.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/SimpleGetRequestExecutor.java similarity index 90% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/http/SimpleGetRequestExecutor.java rename to weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/SimpleGetRequestExecutor.java index c71d26ec4..4d5ea0245 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/http/SimpleGetRequestExecutor.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/SimpleGetRequestExecutor.java @@ -1,4 +1,4 @@ -package me.chanjar.weixin.enterprise.util.http; +package me.chanjar.weixin.common.util.http; import java.io.IOException; @@ -7,7 +7,7 @@ import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import me.chanjar.weixin.common.bean.result.WxError; -import me.chanjar.weixin.enterprise.exception.WxErrorException; +import me.chanjar.weixin.common.exception.WxErrorException; /** * 简单的GET请求执行器,请求的参数是String, 返回的结果也是String diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/http/SimplePostRequestExecutor.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/SimplePostRequestExecutor.java similarity index 91% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/http/SimplePostRequestExecutor.java rename to weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/SimplePostRequestExecutor.java index 4268b22fa..8025d6dce 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/http/SimplePostRequestExecutor.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/SimplePostRequestExecutor.java @@ -1,9 +1,9 @@ -package me.chanjar.weixin.enterprise.util.http; +package me.chanjar.weixin.common.util.http; import java.io.IOException; import me.chanjar.weixin.common.bean.result.WxError; -import me.chanjar.weixin.enterprise.exception.WxErrorException; +import me.chanjar.weixin.common.exception.WxErrorException; import org.apache.http.Consts; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.methods.CloseableHttpResponse; diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/http/Utf8ResponseHandler.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/Utf8ResponseHandler.java similarity index 95% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/http/Utf8ResponseHandler.java rename to weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/Utf8ResponseHandler.java index 21456c2dc..bad067c08 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/http/Utf8ResponseHandler.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/Utf8ResponseHandler.java @@ -1,4 +1,4 @@ -package me.chanjar.weixin.enterprise.util.http; +package me.chanjar.weixin.common.util.http; import java.io.IOException; diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/common/util/GsonHelper.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/GsonHelper.java similarity index 98% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/common/util/GsonHelper.java rename to weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/GsonHelper.java index ffc810226..614e28e29 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/common/util/GsonHelper.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/GsonHelper.java @@ -6,7 +6,7 @@ * arose from modification of the original source, or other redistribution of this source * is not permitted without written permission of the KINGSTAR MEDIA SOLUTIONS LTD. */ -package me.chanjar.weixin.common.util; +package me.chanjar.weixin.common.util.json; import com.google.gson.JsonElement; diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxAccessTokenAdapter.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxAccessTokenAdapter.java similarity index 93% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxAccessTokenAdapter.java rename to weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxAccessTokenAdapter.java index b91e678ca..cfe4edb20 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxAccessTokenAdapter.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxAccessTokenAdapter.java @@ -6,10 +6,10 @@ * arose from modification of the original source, or other redistribution of this source * is not permitted without written permission of the KINGSTAR MEDIA SOLUTIONS LTD. */ -package me.chanjar.weixin.mp.util.json; +package me.chanjar.weixin.common.util.json; import com.google.gson.*; -import me.chanjar.weixin.mp.bean.WxAccessToken; +import me.chanjar.weixin.common.bean.WxAccessToken; import java.lang.reflect.Type; diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxErrorAdapter.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxErrorAdapter.java similarity index 93% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxErrorAdapter.java rename to weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxErrorAdapter.java index 8143c1821..74b9ded8b 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxErrorAdapter.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxErrorAdapter.java @@ -6,10 +6,9 @@ * arose from modification of the original source, or other redistribution of this source * is not permitted without written permission of the KINGSTAR MEDIA SOLUTIONS LTD. */ -package me.chanjar.weixin.enterprise.util.json; +package me.chanjar.weixin.common.util.json; import com.google.gson.*; -import me.chanjar.weixin.common.util.GsonHelper; import me.chanjar.weixin.common.bean.result.WxError; import java.lang.reflect.Type; @@ -31,6 +30,7 @@ public class WxErrorAdapter implements JsonDeserializer { if (wxErrorJsonObject.get("errmsg") != null && !wxErrorJsonObject.get("errmsg").isJsonNull()) { wxError.setErrorMsg(GsonHelper.getAsString(wxErrorJsonObject.get("errmsg"))); } + wxError.setJson(json.toString()); return wxError; } diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxGsonBuilder.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxGsonBuilder.java new file mode 100644 index 000000000..7aa569656 --- /dev/null +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxGsonBuilder.java @@ -0,0 +1,26 @@ +package me.chanjar.weixin.common.util.json; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import me.chanjar.weixin.common.bean.WxMenu; +import me.chanjar.weixin.common.bean.result.WxError; +import me.chanjar.weixin.common.bean.WxAccessToken; +import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; + +public class WxGsonBuilder { + + public static final GsonBuilder INSTANCE = new GsonBuilder(); + + static { + INSTANCE.disableHtmlEscaping(); + INSTANCE.registerTypeAdapter(WxAccessToken.class, new WxAccessTokenAdapter()); + INSTANCE.registerTypeAdapter(WxError.class, new WxErrorAdapter()); + INSTANCE.registerTypeAdapter(WxMenu.class, new WxMenuGsonAdapter()); + INSTANCE.registerTypeAdapter(WxMediaUploadResult.class, new WxMediaUploadResultAdapter()); + } + + public static Gson create() { + return INSTANCE.create(); + } + +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMediaUploadResultAdapter.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxMediaUploadResultAdapter.java similarity index 94% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMediaUploadResultAdapter.java rename to weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxMediaUploadResultAdapter.java index eec8519c5..35eb18b4f 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMediaUploadResultAdapter.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxMediaUploadResultAdapter.java @@ -6,10 +6,10 @@ * arose from modification of the original source, or other redistribution of this source * is not permitted without written permission of the KINGSTAR MEDIA SOLUTIONS LTD. */ -package me.chanjar.weixin.mp.util.json; +package me.chanjar.weixin.common.util.json; import com.google.gson.*; -import me.chanjar.weixin.mp.bean.result.WxMediaUploadResult; +import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; import java.lang.reflect.Type; diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMenuGsonAdapter.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxMenuGsonAdapter.java similarity index 96% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMenuGsonAdapter.java rename to weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxMenuGsonAdapter.java index f60d39ea5..6fc788d30 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMenuGsonAdapter.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxMenuGsonAdapter.java @@ -6,11 +6,11 @@ * arose from modification of the original source, or other redistribution of this source * is not permitted without written permission of the KINGSTAR MEDIA SOLUTIONS LTD. */ -package me.chanjar.weixin.mp.util.json; +package me.chanjar.weixin.common.util.json; import java.lang.reflect.Type; -import me.chanjar.weixin.mp.bean.WxMenu; +import me.chanjar.weixin.common.bean.WxMenu; import com.google.gson.JsonArray; import com.google.gson.JsonDeserializationContext; @@ -23,7 +23,7 @@ import com.google.gson.JsonSerializer; /** * - * @author qianjia + * @author Daniel Qian * */ public class WxMenuGsonAdapter implements JsonSerializer, JsonDeserializer { diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/common/util/AdapterCDATA.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/xml/AdapterCDATA.java similarity index 91% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/common/util/AdapterCDATA.java rename to weixin-java-common/src/main/java/me/chanjar/weixin/common/util/xml/AdapterCDATA.java index 30a8a927c..c38c27951 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/common/util/AdapterCDATA.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/xml/AdapterCDATA.java @@ -1,4 +1,4 @@ -package me.chanjar.weixin.common.util; +package me.chanjar.weixin.common.util.xml; import javax.xml.bind.annotation.adapters.XmlAdapter; diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/common/util/MediaIdMarshaller.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/xml/MediaIdMarshaller.java similarity index 90% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/common/util/MediaIdMarshaller.java rename to weixin-java-common/src/main/java/me/chanjar/weixin/common/util/xml/MediaIdMarshaller.java index cfe3de1a3..10e6a3aab 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/common/util/MediaIdMarshaller.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/xml/MediaIdMarshaller.java @@ -1,4 +1,4 @@ -package me.chanjar.weixin.common.util; +package me.chanjar.weixin.common.util.xml; import javax.xml.bind.annotation.adapters.XmlAdapter; diff --git a/weixin-java-enterprise/src/test/java/me/chanjar/weixin/common/bean/WxAccessTokenTest.java b/weixin-java-common/src/test/java/me/chanjar/weixin/common/bean/WxAccessTokenTest.java similarity index 88% rename from weixin-java-enterprise/src/test/java/me/chanjar/weixin/common/bean/WxAccessTokenTest.java rename to weixin-java-common/src/test/java/me/chanjar/weixin/common/bean/WxAccessTokenTest.java index 76bdeeaff..d236c6310 100644 --- a/weixin-java-enterprise/src/test/java/me/chanjar/weixin/common/bean/WxAccessTokenTest.java +++ b/weixin-java-common/src/test/java/me/chanjar/weixin/common/bean/WxAccessTokenTest.java @@ -1,6 +1,5 @@ package me.chanjar.weixin.common.bean; -import me.chanjar.weixin.common.bean.result.WxAccessToken; import org.testng.Assert; import org.testng.annotations.Test; diff --git a/weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/bean/WxErrorTest.java b/weixin-java-common/src/test/java/me/chanjar/weixin/common/bean/WxErrorTest.java similarity index 95% rename from weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/bean/WxErrorTest.java rename to weixin-java-common/src/test/java/me/chanjar/weixin/common/bean/WxErrorTest.java index ca5c3d3b4..51e9dab36 100644 --- a/weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/bean/WxErrorTest.java +++ b/weixin-java-common/src/test/java/me/chanjar/weixin/common/bean/WxErrorTest.java @@ -1,9 +1,8 @@ -package me.chanjar.weixin.enterprise.bean; - -import org.testng.Assert; -import org.testng.annotations.Test; +package me.chanjar.weixin.common.bean; import me.chanjar.weixin.common.bean.result.WxError; +import org.testng.Assert; +import org.testng.annotations.Test; @Test public class WxErrorTest { diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxMenuTest.java b/weixin-java-common/src/test/java/me/chanjar/weixin/common/bean/WxMenuTest.java similarity index 95% rename from weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxMenuTest.java rename to weixin-java-common/src/test/java/me/chanjar/weixin/common/bean/WxMenuTest.java index 0ba058c28..015889d7b 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxMenuTest.java +++ b/weixin-java-common/src/test/java/me/chanjar/weixin/common/bean/WxMenuTest.java @@ -1,12 +1,10 @@ -package me.chanjar.weixin.mp.bean; +package me.chanjar.weixin.common.bean; -import me.chanjar.weixin.mp.bean.WxMenu; +import me.chanjar.weixin.common.bean.WxMenu.WxMenuButton; import org.testng.Assert; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; -import me.chanjar.weixin.mp.bean.WxMenu.WxMenuButton; - @Test public class WxMenuTest { diff --git a/weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/util/crypto/WxCryptUtilTest.java b/weixin-java-common/src/test/java/me/chanjar/weixin/common/util/crypto/WxCryptUtilTest.java similarity index 95% rename from weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/util/crypto/WxCryptUtilTest.java rename to weixin-java-common/src/test/java/me/chanjar/weixin/common/util/crypto/WxCryptUtilTest.java index fa728401c..15b08c268 100755 --- a/weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/util/crypto/WxCryptUtilTest.java +++ b/weixin-java-common/src/test/java/me/chanjar/weixin/common/util/crypto/WxCryptUtilTest.java @@ -1,6 +1,5 @@ -package me.chanjar.weixin.enterprise.util.crypto; +package me.chanjar.weixin.common.util.crypto; -import me.chanjar.weixin.enterprise.util.crypto.WxCryptUtil; import org.testng.annotations.Test; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -14,7 +13,8 @@ import javax.xml.parsers.ParserConfigurationException; import java.io.IOException; import java.io.StringReader; -import static org.testng.Assert.*; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.fail; @Test public class WxCryptUtilTest { diff --git a/weixin-java-common/src/test/resources/testng.xml b/weixin-java-common/src/test/resources/testng.xml new file mode 100644 index 000000000..f0058b532 --- /dev/null +++ b/weixin-java-common/src/test/resources/testng.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/weixin-java-enterprise/LICENSE b/weixin-java-cp/LICENSE similarity index 100% rename from weixin-java-enterprise/LICENSE rename to weixin-java-cp/LICENSE diff --git a/weixin-java-cp/README.md b/weixin-java-cp/README.md new file mode 100644 index 000000000..e0cefde4e --- /dev/null +++ b/weixin-java-cp/README.md @@ -0,0 +1,46 @@ +weixin-java-cp +=========== + +微信企业号Java SDK开发工具集,本项目主要分为两大块:微信消息路由器、微信Java API + +详细文档请看 [wiki](https://github.com/chanjarster/weixin-java-tools/wiki) + +# Quickstart + +在你的maven项目中添加: +```xml + + me.chanjar + weixin-java-cp-tools + 1.0.3 + +``` + +如果要使用``*-SNAPSHOT``版,则需要在你的``pom.xml``中添加这段: + +```xml + + + + sonatype snapshots + https://oss.sonatype.org/content/repositories/snapshots/ + + +``` + +## Hello World +```java +WxCpInMemoryConfigStorage config = new WxCpInMemoryConfigStorage(); +config.getCorpId(...); // 设置微信企业号的appid +config.getCorpSecret(...); // 设置微信企业号的app corpSecret +config.setAgentId(...); // 设置微信企业号应用ID +config.setToken(...); // 设置微信企业号应用的token +config.setAesKey(...); // 设置微信企业号应用的EncodingAESKey + +WxCpServiceImpl wxCpService = new WxCpServiceImpl(); +wxCpService.setWxCpConfigStorage(config); + +String userId = ...; +WxCpMessage message = WxCpMessage.TEXT().agentId(...).toUser(userId).content("Hello World").build(); +wxService.messageSend(message); +``` diff --git a/weixin-java-cp/pom.xml b/weixin-java-cp/pom.xml new file mode 100644 index 000000000..9c40e02dd --- /dev/null +++ b/weixin-java-cp/pom.xml @@ -0,0 +1,73 @@ + + + 4.0.0 + + me.chanjar + weixin-java-parent + 1.0.3-SNAPSHOT + + + weixin-java-cp + WeiXin Java Tools - CP + 微信企业号Java SDK + + + + me.chanjar + weixin-java-common + ${project.version} + + + junit + junit + test + + + org.testng + testng + 6.8.7 + test + + + org.mockito + mockito-all + 1.9.5 + test + + + com.google.inject + guice + 3.0 + test + + + org.eclipse.jetty + jetty-server + 9.3.0.M0 + test + + + org.eclipse.jetty + jetty-servlet + 9.3.0.M0 + test + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + src/test/resources/testng.xml + + + + + + + diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/api/WxCpConfigStorage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpConfigStorage.java similarity index 82% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/api/WxCpConfigStorage.java rename to weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpConfigStorage.java index 219727b77..d61b0035a 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/api/WxCpConfigStorage.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpConfigStorage.java @@ -1,6 +1,6 @@ -package me.chanjar.weixin.enterprise.api; +package me.chanjar.weixin.cp.api; -import me.chanjar.weixin.common.bean.result.WxAccessToken; +import me.chanjar.weixin.common.bean.WxAccessToken; /** * 微信客户端配置存储 diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/api/WxCpConsts.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpConsts.java similarity index 97% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/api/WxCpConsts.java rename to weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpConsts.java index 1d26ba8f3..9c042d52c 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/api/WxCpConsts.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpConsts.java @@ -1,7 +1,4 @@ -package me.chanjar.weixin.enterprise.api; - -import java.util.HashMap; -import java.util.Map; +package me.chanjar.weixin.cp.api; public class WxCpConsts { diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/api/WxInMemoryCpConfigStorage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpInMemoryConfigStorage.java similarity index 90% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/api/WxInMemoryCpConfigStorage.java rename to weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpInMemoryConfigStorage.java index 5873b12ad..26d15f4bc 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/api/WxInMemoryCpConfigStorage.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpInMemoryConfigStorage.java @@ -1,13 +1,13 @@ -package me.chanjar.weixin.enterprise.api; +package me.chanjar.weixin.cp.api; -import me.chanjar.weixin.common.bean.result.WxAccessToken; +import me.chanjar.weixin.common.bean.WxAccessToken; /** * 基于内存的微信配置provider,在实际生产环境中应该将这些配置持久化 * @author Daniel Qian * */ -public class WxInMemoryCpConfigStorage implements WxCpConfigStorage { +public class WxCpInMemoryConfigStorage implements WxCpConfigStorage { protected String corpId; protected String corpSecret; @@ -86,7 +86,7 @@ public class WxInMemoryCpConfigStorage implements WxCpConfigStorage { @Override public String toString() { return "WxInMemoryCpConfigStorage{" + - "corpId='" + corpId + '\'' + + "appidOrCorpid='" + corpId + '\'' + ", corpSecret='" + corpSecret + '\'' + ", token='" + token + '\'' + ", accessToken='" + accessToken + '\'' + diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/api/WxCpMessageHandler.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageHandler.java similarity index 74% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/api/WxCpMessageHandler.java rename to weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageHandler.java index 41376f94d..b82dddeb2 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/api/WxCpMessageHandler.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageHandler.java @@ -1,9 +1,9 @@ -package me.chanjar.weixin.enterprise.api; +package me.chanjar.weixin.cp.api; import java.util.Map; -import me.chanjar.weixin.enterprise.bean.WxCpXmlMessage; -import me.chanjar.weixin.enterprise.bean.WxCpXmlOutMessage; +import me.chanjar.weixin.cp.bean.WxCpXmlMessage; +import me.chanjar.weixin.cp.bean.WxCpXmlOutMessage; /** * 处理微信推送消息的处理器接口 diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/api/WxCpMessageInterceptor.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageInterceptor.java similarity index 81% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/api/WxCpMessageInterceptor.java rename to weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageInterceptor.java index bf8ec2336..7a09dacda 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/api/WxCpMessageInterceptor.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageInterceptor.java @@ -1,8 +1,8 @@ -package me.chanjar.weixin.enterprise.api; +package me.chanjar.weixin.cp.api; import java.util.Map; -import me.chanjar.weixin.enterprise.bean.WxCpXmlMessage; +import me.chanjar.weixin.cp.bean.WxCpXmlMessage; /** * 微信消息拦截器,可以用来做验证 diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/api/WxCpMessageRouter.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageRouter.java similarity index 92% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/api/WxCpMessageRouter.java rename to weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageRouter.java index 27b22bcb4..333fca9a1 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/api/WxCpMessageRouter.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageRouter.java @@ -1,4 +1,4 @@ -package me.chanjar.weixin.enterprise.api; +package me.chanjar.weixin.cp.api; import java.util.ArrayList; import java.util.HashMap; @@ -8,20 +8,20 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.regex.Pattern; -import me.chanjar.weixin.enterprise.bean.WxCpXmlMessage; -import me.chanjar.weixin.enterprise.bean.WxCpXmlOutMessage; +import me.chanjar.weixin.cp.bean.WxCpXmlMessage; +import me.chanjar.weixin.cp.bean.WxCpXmlOutMessage; /** *
  * 微信消息路由器,通过代码化的配置,把来自微信的消息交给handler处理
- * 
+ *
  * 说明:
  * 1. 配置路由规则时要按照从细到粗的原则,否则可能消息可能会被提前处理
  * 2. 默认情况下消息只会被处理一次,除非使用 {@link Rule#next()}
  * 3. 规则的结束必须用{@link Rule#end()}或者{@link Rule#next()},否则不会生效
- * 
+ *
  * 使用方法:
- * WxMessageRouter router = new WxMessageRouter();
+ * WxCpMessageRouter router = new WxCpMessageRouter();
  * router
  *   .rule()
  *       .msgType("MSG_TYPE").event("EVENT").eventKey("EVENT_KEY").content("CONTENT")
@@ -31,20 +31,20 @@ import me.chanjar.weixin.enterprise.bean.WxCpXmlOutMessage;
  *       // 另外一个匹配规则
  *   .end()
  * ;
- * 
+ *
  * // 将WxXmlMessage交给消息路由器
  * router.route(message);
- * 
+ *
  * 
* @author Daniel Qian * */ public class WxCpMessageRouter { - + private final List rules = new ArrayList(); private final ExecutorService es = Executors.newCachedThreadPool(); - + /** * 开始一个新的Route规则 * @return @@ -65,11 +65,11 @@ public class WxCpMessageRouter { matchRules.add(rule); } } - + if (matchRules.size() == 0) { return null; } - + if (matchRules.get(0).async) { // 只要第一个是异步的,那就异步执行 // 在另一个线程里执行 @@ -85,7 +85,7 @@ public class WxCpMessageRouter { }); return null; } - + WxCpXmlOutMessage res = null; for (final Rule rule : matchRules) { // 返回最后一个匹配规则的结果 @@ -96,33 +96,35 @@ public class WxCpMessageRouter { } return res; } - + public static class Rule { - + private final WxCpMessageRouter routerBuilder; private boolean async = true; - + private String msgType; private String event; - + private String eventKey; - + private String content; - + private String rContent; - + private boolean reEnter = false; - + + private Integer agentId; + private List handlers = new ArrayList(); - + private List interceptors = new ArrayList(); - + protected Rule(WxCpMessageRouter routerBuilder) { this.routerBuilder = routerBuilder; } - + /** * 设置是否异步执行,默认是true * @param async @@ -132,7 +134,17 @@ public class WxCpMessageRouter { this.async = async; return this; } - + + /** + * 如果agentId匹配 + * @param agentId + * @return + */ + public Rule agentId(Integer agentId) { + this.agentId = agentId; + return this; + } + /** * 如果msgType等于某值 * @param msgType @@ -142,7 +154,7 @@ public class WxCpMessageRouter { this.msgType = msgType; return this; } - + /** * 如果event等于某值 * @param event @@ -152,7 +164,7 @@ public class WxCpMessageRouter { this.event = event; return this; } - + /** * 如果eventKey等于某值 * @param eventKey @@ -162,7 +174,7 @@ public class WxCpMessageRouter { this.eventKey = eventKey; return this; } - + /** * 如果content等于某值 * @param content @@ -172,7 +184,7 @@ public class WxCpMessageRouter { this.content = content; return this; } - + /** * 如果content匹配该正则表达式 * @param regex @@ -182,7 +194,7 @@ public class WxCpMessageRouter { this.rContent = regex; return this; } - + /** * 设置微信消息拦截器 * @param interceptor @@ -191,7 +203,7 @@ public class WxCpMessageRouter { public Rule interceptor(WxCpMessageInterceptor interceptor) { return interceptor(interceptor, (WxCpMessageInterceptor[]) null); } - + /** * 设置微信消息拦截器 * @param interceptor @@ -207,7 +219,7 @@ public class WxCpMessageRouter { } return this; } - + /** * 设置微信消息处理器 * @param handler @@ -216,7 +228,7 @@ public class WxCpMessageRouter { public Rule handler(WxCpMessageHandler handler) { return handler(handler, (WxCpMessageHandler[]) null); } - + /** * 设置微信消息处理器 * @param handler @@ -232,7 +244,7 @@ public class WxCpMessageRouter { } return this; } - + /** * 规则结束,代表如果一个消息匹配该规则,那么它将不再会进入其他规则 * @return @@ -241,7 +253,7 @@ public class WxCpMessageRouter { this.routerBuilder.rules.add(this); return this.routerBuilder; } - + /** * 规则结束,但是消息还会进入其他规则 * @return @@ -250,9 +262,11 @@ public class WxCpMessageRouter { this.reEnter = true; return end(); } - + protected boolean test(WxCpXmlMessage wxMessage) { - return + return + (this.agentId == null || this.agentId.equals(wxMessage.getAgentId())) + && (this.msgType == null || this.msgType.equals(wxMessage.getMsgType())) && (this.event == null || this.event.equals(wxMessage.getEvent())) @@ -264,7 +278,7 @@ public class WxCpMessageRouter { (this.rContent == null || Pattern.matches(this.rContent, wxMessage.getContent() == null ? "" : wxMessage.getContent().trim())) ; } - + /** * 处理微信推送过来的消息 * @param wxMessage @@ -278,7 +292,7 @@ public class WxCpMessageRouter { return null; } } - + // 交给handler处理 WxCpXmlOutMessage res = null; for (WxCpMessageHandler handler : this.handlers) { @@ -287,7 +301,7 @@ public class WxCpMessageRouter { } return res; } - + } - + } diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/api/WxCpService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java similarity index 93% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/api/WxCpService.java rename to weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java index 6d161fe0a..900a47f73 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/api/WxCpService.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java @@ -1,15 +1,16 @@ -package me.chanjar.weixin.enterprise.api; +package me.chanjar.weixin.cp.api; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.util.List; -import me.chanjar.weixin.enterprise.bean.*; -import me.chanjar.weixin.enterprise.bean.WxCpDepart; -import me.chanjar.weixin.enterprise.bean.result.WxMediaUploadResult; -import me.chanjar.weixin.enterprise.bean.WxCpUser; -import me.chanjar.weixin.enterprise.exception.WxErrorException; +import me.chanjar.weixin.common.bean.WxMenu; +import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; +import me.chanjar.weixin.cp.bean.*; +import me.chanjar.weixin.cp.bean.WxCpDepart; +import me.chanjar.weixin.cp.bean.WxCpUser; +import me.chanjar.weixin.common.exception.WxErrorException; /** * 微信API的Service @@ -49,7 +50,7 @@ public interface WxCpService { * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=获取access_token * * - * @throws me.chanjar.weixin.enterprise.exception.WxErrorException + * @throws me.chanjar.weixin.common.exception.WxErrorException */ public void accessTokenRefresh() throws WxErrorException; @@ -113,7 +114,7 @@ public interface WxCpService { * @param menu * @throws WxErrorException */ - public void menuCreate(WxCpMenu menu) throws WxErrorException; + public void menuCreate(WxMenu menu) throws WxErrorException; /** *
@@ -134,7 +135,7 @@ public interface WxCpService {
    * @return
    * @throws WxErrorException
    */
-  public WxCpMenu menuGet() throws WxErrorException;
+  public WxMenu menuGet() throws WxErrorException;
 
   /**
    * 
diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/api/WxCpServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java
similarity index 92%
rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/api/WxCpServiceImpl.java
rename to weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java
index 17fe39e7b..4d9b2af30 100644
--- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/api/WxCpServiceImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java
@@ -1,4 +1,4 @@
-package me.chanjar.weixin.enterprise.api;
+package me.chanjar.weixin.cp.api;
 
 import java.io.File;
 import java.io.IOException;
@@ -11,12 +11,14 @@ import java.util.concurrent.atomic.AtomicBoolean;
 import com.google.gson.JsonArray;
 import com.google.gson.JsonObject;
 import com.google.gson.JsonPrimitive;
-import me.chanjar.weixin.common.bean.result.WxAccessToken;
-import me.chanjar.weixin.common.util.GsonHelper;
-import me.chanjar.weixin.enterprise.bean.*;
-import me.chanjar.weixin.enterprise.util.http.SimpleGetRequestExecutor;
-import me.chanjar.weixin.enterprise.util.crypto.SHA1;
-import me.chanjar.weixin.enterprise.util.json.WxCpGsonBuilder;
+import me.chanjar.weixin.common.bean.WxAccessToken;
+import me.chanjar.weixin.common.bean.WxMenu;
+import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
+import me.chanjar.weixin.common.util.json.GsonHelper;
+import me.chanjar.weixin.cp.bean.*;
+import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor;
+import me.chanjar.weixin.common.util.crypto.SHA1;
+import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.http.client.ClientProtocolException;
 import org.apache.http.client.methods.CloseableHttpResponse;
@@ -25,16 +27,15 @@ import org.apache.http.impl.client.BasicResponseHandler;
 import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.impl.client.HttpClients;
 
-import me.chanjar.weixin.enterprise.bean.WxCpDepart;
+import me.chanjar.weixin.cp.bean.WxCpDepart;
 import me.chanjar.weixin.common.bean.result.WxError;
-import me.chanjar.weixin.enterprise.bean.result.WxMediaUploadResult;
-import me.chanjar.weixin.enterprise.bean.WxCpUser;
-import me.chanjar.weixin.enterprise.exception.WxErrorException;
-import me.chanjar.weixin.common.util.FileUtils;
-import me.chanjar.weixin.enterprise.util.http.MediaDownloadRequestExecutor;
-import me.chanjar.weixin.enterprise.util.http.MediaUploadRequestExecutor;
-import me.chanjar.weixin.enterprise.util.http.RequestExecutor;
-import me.chanjar.weixin.enterprise.util.http.SimplePostRequestExecutor;
+import me.chanjar.weixin.cp.bean.WxCpUser;
+import me.chanjar.weixin.common.exception.WxErrorException;
+import me.chanjar.weixin.common.util.fs.FileUtils;
+import me.chanjar.weixin.common.util.http.MediaDownloadRequestExecutor;
+import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor;
+import me.chanjar.weixin.common.util.http.RequestExecutor;
+import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor;
 
 import com.google.gson.JsonElement;
 import com.google.gson.internal.Streams;
@@ -110,7 +111,7 @@ public class WxCpServiceImpl implements WxCpService {
     execute(new SimplePostRequestExecutor(), url, message.toJson());
   }
 
-  public void menuCreate(WxCpMenu menu) throws WxErrorException {
+  public void menuCreate(WxMenu menu) throws WxErrorException {
     String url = "https://qyapi.weixin.qq.com/cgi-bin/menu/create?agentid=" + wxCpConfigStorage.getAgentId();
     execute(new SimplePostRequestExecutor(), url, menu.toJson());
   }
@@ -120,11 +121,11 @@ public class WxCpServiceImpl implements WxCpService {
     execute(new SimpleGetRequestExecutor(), url, null);
   }
 
-  public WxCpMenu menuGet() throws WxErrorException {
+  public WxMenu menuGet() throws WxErrorException {
     String url = "https://qyapi.weixin.qq.com/cgi-bin/menu/get?agentid=" + wxCpConfigStorage.getAgentId();
     try {
       String resultContent = execute(new SimpleGetRequestExecutor(), url, null);
-      return WxCpMenu.fromJson(resultContent);
+      return WxMenu.fromJson(resultContent);
     } catch (WxErrorException e) {
       // 46003 不存在的菜单数据
       if (e.getError().getErrorCode() == 46003) {
diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpDepart.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpDepart.java
similarity index 91%
rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpDepart.java
rename to weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpDepart.java
index 51243d7ee..975cd5957 100644
--- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpDepart.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpDepart.java
@@ -1,6 +1,6 @@
-package me.chanjar.weixin.enterprise.bean;
+package me.chanjar.weixin.cp.bean;
 
-import me.chanjar.weixin.enterprise.util.json.WxCpGsonBuilder;
+import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
 
 /**
  * 微信部门
diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpMessage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpMessage.java
similarity index 86%
rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpMessage.java
rename to weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpMessage.java
index 219e6b512..d700aa746 100644
--- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpMessage.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpMessage.java
@@ -1,10 +1,10 @@
-package me.chanjar.weixin.enterprise.bean;
+package me.chanjar.weixin.cp.bean;
 
 import java.util.ArrayList;
 import java.util.List;
 
-import me.chanjar.weixin.enterprise.bean.messagebuilder.*;
-import me.chanjar.weixin.enterprise.util.json.WxCpGsonBuilder;
+import me.chanjar.weixin.cp.bean.messagebuilder.*;
+import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
 
 /**
  * 消息
@@ -65,12 +65,12 @@ public class WxCpMessage {
   /**
    * 
    * 请使用
-   * {@link me.chanjar.weixin.enterprise.api.WxCpConsts#CUSTOM_MSG_TEXT}
-   * {@link me.chanjar.weixin.enterprise.api.WxCpConsts#CUSTOM_MSG_IMAGE}
-   * {@link me.chanjar.weixin.enterprise.api.WxCpConsts#CUSTOM_MSG_VOICE}
-   * {@link me.chanjar.weixin.enterprise.api.WxCpConsts#CUSTOM_MSG_MUSIC}
-   * {@link me.chanjar.weixin.enterprise.api.WxCpConsts#CUSTOM_MSG_VIDEO}
-   * {@link me.chanjar.weixin.enterprise.api.WxCpConsts#CUSTOM_MSG_NEWS}
+   * {@link me.chanjar.weixin.cp.api.WxCpConsts#CUSTOM_MSG_TEXT}
+   * {@link me.chanjar.weixin.cp.api.WxCpConsts#CUSTOM_MSG_IMAGE}
+   * {@link me.chanjar.weixin.cp.api.WxCpConsts#CUSTOM_MSG_VOICE}
+   * {@link me.chanjar.weixin.cp.api.WxCpConsts#CUSTOM_MSG_MUSIC}
+   * {@link me.chanjar.weixin.cp.api.WxCpConsts#CUSTOM_MSG_VIDEO}
+   * {@link me.chanjar.weixin.cp.api.WxCpConsts#CUSTOM_MSG_NEWS}
    * 
* @param msgType */ diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpTag.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpTag.java similarity index 66% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpTag.java rename to weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpTag.java index 50646b54e..a56e9c5c1 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpTag.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpTag.java @@ -1,13 +1,6 @@ -package me.chanjar.weixin.enterprise.bean; +package me.chanjar.weixin.cp.bean; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.internal.Streams; -import com.google.gson.stream.JsonReader; -import me.chanjar.weixin.common.util.GsonHelper; -import me.chanjar.weixin.enterprise.util.json.WxCpGsonBuilder; - -import java.io.StringReader; +import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; /** * Created by Daniel Qian diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpUser.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpUser.java similarity index 94% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpUser.java rename to weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpUser.java index 5dc87d2d5..90125a5da 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpUser.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpUser.java @@ -1,8 +1,7 @@ -package me.chanjar.weixin.enterprise.bean; +package me.chanjar.weixin.cp.bean; -import me.chanjar.weixin.enterprise.util.json.WxCpGsonBuilder; +import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; -import java.sql.PseudoColumnUsage; import java.util.ArrayList; import java.util.List; diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpXmlMessage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlMessage.java similarity index 91% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpXmlMessage.java rename to weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlMessage.java index 2b540c97e..82d2884cb 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpXmlMessage.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlMessage.java @@ -1,9 +1,9 @@ -package me.chanjar.weixin.enterprise.bean; +package me.chanjar.weixin.cp.bean; -import me.chanjar.weixin.enterprise.api.WxCpConfigStorage; -import me.chanjar.weixin.common.util.AdapterCDATA; -import me.chanjar.weixin.common.util.XmlTransformer; -import me.chanjar.weixin.enterprise.util.crypto.WxCryptUtil; +import me.chanjar.weixin.common.util.xml.AdapterCDATA; +import me.chanjar.weixin.cp.api.WxCpConfigStorage; +import me.chanjar.weixin.cp.util.crypto.WxCpCryptUtil; +import me.chanjar.weixin.cp.util.xml.XmlTransformer; import org.apache.commons.io.IOUtils; import javax.xml.bind.JAXBException; @@ -190,13 +190,13 @@ public class WxCpXmlMessage { /** *
    * 当接受用户消息时,可能会获得以下值:
-   * {@link me.chanjar.weixin.enterprise.api.WxCpConsts#XML_MSG_TEXT}
-   * {@link me.chanjar.weixin.enterprise.api.WxCpConsts#XML_MSG_IMAGE}
-   * {@link me.chanjar.weixin.enterprise.api.WxCpConsts#XML_MSG_VOICE}
-   * {@link me.chanjar.weixin.enterprise.api.WxCpConsts#XML_MSG_VIDEO}
-   * {@link me.chanjar.weixin.enterprise.api.WxCpConsts#XML_MSG_LOCATION}
-   * {@link me.chanjar.weixin.enterprise.api.WxCpConsts#XML_MSG_LINK}
-   * {@link me.chanjar.weixin.enterprise.api.WxCpConsts#XML_MSG_EVENT}
+   * {@link me.chanjar.weixin.cp.api.WxCpConsts#XML_MSG_TEXT}
+   * {@link me.chanjar.weixin.cp.api.WxCpConsts#XML_MSG_IMAGE}
+   * {@link me.chanjar.weixin.cp.api.WxCpConsts#XML_MSG_VOICE}
+   * {@link me.chanjar.weixin.cp.api.WxCpConsts#XML_MSG_VIDEO}
+   * {@link me.chanjar.weixin.cp.api.WxCpConsts#XML_MSG_LOCATION}
+   * {@link me.chanjar.weixin.cp.api.WxCpConsts#XML_MSG_LINK}
+   * {@link me.chanjar.weixin.cp.api.WxCpConsts#XML_MSG_EVENT}
    * 
* * @return @@ -208,12 +208,11 @@ public class WxCpXmlMessage { /** *
    * 当发送消息的时候使用:
-   * {@link me.chanjar.weixin.enterprise.api.WxCpConsts#XML_MSG_TEXT}
-   * {@link me.chanjar.weixin.enterprise.api.WxCpConsts#XML_MSG_IMAGE}
-   * {@link me.chanjar.weixin.enterprise.api.WxCpConsts#XML_MSG_VOICE}
-   * {@link me.chanjar.weixin.enterprise.api.WxCpConsts#XML_MSG_VIDEO}
-   * {@link me.chanjar.weixin.enterprise.api.WxCpConsts#XML_MSG_NEWS}
-   * {@link me.chanjar.weixin.enterprise.api.WxCpConsts#XML_MSG_MUSIC}
+   * {@link me.chanjar.weixin.cp.api.WxCpConsts#XML_MSG_TEXT}
+   * {@link me.chanjar.weixin.cp.api.WxCpConsts#XML_MSG_IMAGE}
+   * {@link me.chanjar.weixin.cp.api.WxCpConsts#XML_MSG_VOICE}
+   * {@link me.chanjar.weixin.cp.api.WxCpConsts#XML_MSG_VIDEO}
+   * {@link me.chanjar.weixin.cp.api.WxCpConsts#XML_MSG_NEWS}
    * 
* * @param msgType @@ -420,7 +419,7 @@ public class WxCpXmlMessage { String encryptedXml, WxCpConfigStorage wxCpConfigStorage, String timestamp, String nonce, String msgSignature) { - WxCryptUtil cryptUtil = new WxCryptUtil(wxCpConfigStorage); + WxCpCryptUtil cryptUtil = new WxCpCryptUtil(wxCpConfigStorage); String plainText = cryptUtil.decrypt(msgSignature, timestamp, nonce, encryptedXml); return fromXml(plainText); } diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutImageMessage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutImageMessage.java similarity index 82% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutImageMessage.java rename to weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutImageMessage.java index ff1508269..29efa04f3 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutImageMessage.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutImageMessage.java @@ -1,4 +1,4 @@ -package me.chanjar.weixin.enterprise.bean; +package me.chanjar.weixin.cp.bean; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; @@ -6,8 +6,8 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; -import me.chanjar.weixin.enterprise.api.WxCpConsts; -import me.chanjar.weixin.common.util.MediaIdMarshaller; +import me.chanjar.weixin.cp.api.WxCpConsts; +import me.chanjar.weixin.common.util.xml.MediaIdMarshaller; @XmlRootElement(name = "xml") @XmlAccessorType(XmlAccessType.FIELD) diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutMessage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutMessage.java similarity index 78% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutMessage.java rename to weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutMessage.java index 8df5b4347..1ccacb005 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutMessage.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutMessage.java @@ -1,4 +1,10 @@ -package me.chanjar.weixin.enterprise.bean; +package me.chanjar.weixin.cp.bean; + +import me.chanjar.weixin.common.util.xml.AdapterCDATA; +import me.chanjar.weixin.cp.api.WxCpConfigStorage; +import me.chanjar.weixin.cp.bean.outxmlbuilder.*; +import me.chanjar.weixin.cp.util.crypto.WxCpCryptUtil; +import me.chanjar.weixin.cp.util.xml.XmlTransformer; import javax.xml.bind.JAXBException; import javax.xml.bind.annotation.XmlAccessType; @@ -7,16 +13,6 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; -import me.chanjar.weixin.enterprise.api.WxCpConfigStorage; -import me.chanjar.weixin.enterprise.bean.outxmlbuilder.ImageBuilder; -import me.chanjar.weixin.enterprise.bean.outxmlbuilder.NewsBuilder; -import me.chanjar.weixin.enterprise.bean.outxmlbuilder.TextBuilder; -import me.chanjar.weixin.enterprise.bean.outxmlbuilder.VideoBuilder; -import me.chanjar.weixin.enterprise.bean.outxmlbuilder.VoiceBuilder; -import me.chanjar.weixin.enterprise.util.crypto.WxCryptUtil; -import me.chanjar.weixin.common.util.AdapterCDATA; -import me.chanjar.weixin.common.util.XmlTransformer; - @XmlRootElement(name = "xml") @XmlAccessorType(XmlAccessType.FIELD) public class WxCpXmlOutMessage { @@ -82,7 +78,7 @@ public class WxCpXmlOutMessage { */ public String toEncryptedXml(WxCpConfigStorage wxCpConfigStorage) { String plainXml = toXml(); - WxCryptUtil pc = new WxCryptUtil(wxCpConfigStorage); + WxCpCryptUtil pc = new WxCpCryptUtil(wxCpConfigStorage); return pc.encrypt(plainXml); } diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutMewsMessage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutMewsMessage.java similarity index 93% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutMewsMessage.java rename to weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutMewsMessage.java index 4cc673636..24264f241 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutMewsMessage.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutMewsMessage.java @@ -1,4 +1,4 @@ -package me.chanjar.weixin.enterprise.bean; +package me.chanjar.weixin.cp.bean; import java.util.ArrayList; import java.util.List; @@ -10,8 +10,8 @@ import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; -import me.chanjar.weixin.enterprise.api.WxCpConsts; -import me.chanjar.weixin.common.util.AdapterCDATA; +import me.chanjar.weixin.cp.api.WxCpConsts; +import me.chanjar.weixin.common.util.xml.AdapterCDATA; @XmlRootElement(name = "xml") @XmlAccessorType(XmlAccessType.FIELD) diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutTextMessage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutTextMessage.java similarity index 83% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutTextMessage.java rename to weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutTextMessage.java index d048933b0..25a447fce 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutTextMessage.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutTextMessage.java @@ -1,4 +1,4 @@ -package me.chanjar.weixin.enterprise.bean; +package me.chanjar.weixin.cp.bean; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; @@ -6,8 +6,8 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; -import me.chanjar.weixin.enterprise.api.WxCpConsts; -import me.chanjar.weixin.common.util.AdapterCDATA; +import me.chanjar.weixin.cp.api.WxCpConsts; +import me.chanjar.weixin.common.util.xml.AdapterCDATA; @XmlRootElement(name = "xml") @XmlAccessorType(XmlAccessType.FIELD) diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutVideoMessage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutVideoMessage.java similarity index 92% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutVideoMessage.java rename to weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutVideoMessage.java index 447298a3a..896a71a5c 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutVideoMessage.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutVideoMessage.java @@ -1,4 +1,4 @@ -package me.chanjar.weixin.enterprise.bean; +package me.chanjar.weixin.cp.bean; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; @@ -6,8 +6,8 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; -import me.chanjar.weixin.enterprise.api.WxCpConsts; -import me.chanjar.weixin.common.util.AdapterCDATA; +import me.chanjar.weixin.cp.api.WxCpConsts; +import me.chanjar.weixin.common.util.xml.AdapterCDATA; @XmlRootElement(name = "xml") @XmlAccessorType(XmlAccessType.FIELD) diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutVoiceMessage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutVoiceMessage.java similarity index 82% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutVoiceMessage.java rename to weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutVoiceMessage.java index 541b276b6..b943aee9e 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutVoiceMessage.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlOutVoiceMessage.java @@ -1,4 +1,4 @@ -package me.chanjar.weixin.enterprise.bean; +package me.chanjar.weixin.cp.bean; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; @@ -6,8 +6,8 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; -import me.chanjar.weixin.enterprise.api.WxCpConsts; -import me.chanjar.weixin.common.util.MediaIdMarshaller; +import me.chanjar.weixin.cp.api.WxCpConsts; +import me.chanjar.weixin.common.util.xml.MediaIdMarshaller; @XmlRootElement(name = "xml") @XmlAccessorType(XmlAccessType.FIELD) diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/messagebuilder/BaseBuilder.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/BaseBuilder.java similarity index 87% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/messagebuilder/BaseBuilder.java rename to weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/BaseBuilder.java index 0be6d2720..f52f274cf 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/messagebuilder/BaseBuilder.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/BaseBuilder.java @@ -1,6 +1,6 @@ -package me.chanjar.weixin.enterprise.bean.messagebuilder; +package me.chanjar.weixin.cp.bean.messagebuilder; -import me.chanjar.weixin.enterprise.bean.WxCpMessage; +import me.chanjar.weixin.cp.bean.WxCpMessage; public class BaseBuilder { protected String msgType; diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/messagebuilder/FileBuilder.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/FileBuilder.java similarity index 77% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/messagebuilder/FileBuilder.java rename to weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/FileBuilder.java index 53875fbca..ce889fb4b 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/messagebuilder/FileBuilder.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/FileBuilder.java @@ -1,7 +1,7 @@ -package me.chanjar.weixin.enterprise.bean.messagebuilder; +package me.chanjar.weixin.cp.bean.messagebuilder; -import me.chanjar.weixin.enterprise.api.WxCpConsts; -import me.chanjar.weixin.enterprise.bean.WxCpMessage; +import me.chanjar.weixin.cp.api.WxCpConsts; +import me.chanjar.weixin.cp.bean.WxCpMessage; /** * 获得消息builder diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/messagebuilder/ImageBuilder.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/ImageBuilder.java similarity index 77% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/messagebuilder/ImageBuilder.java rename to weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/ImageBuilder.java index d40ab6f9d..40232466a 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/messagebuilder/ImageBuilder.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/ImageBuilder.java @@ -1,7 +1,7 @@ -package me.chanjar.weixin.enterprise.bean.messagebuilder; +package me.chanjar.weixin.cp.bean.messagebuilder; -import me.chanjar.weixin.enterprise.api.WxCpConsts; -import me.chanjar.weixin.enterprise.bean.WxCpMessage; +import me.chanjar.weixin.cp.api.WxCpConsts; +import me.chanjar.weixin.cp.bean.WxCpMessage; /** * 获得消息builder diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/messagebuilder/NewsBuilder.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/NewsBuilder.java similarity index 81% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/messagebuilder/NewsBuilder.java rename to weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/NewsBuilder.java index 88bd5dec4..b1ab19a69 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/messagebuilder/NewsBuilder.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/NewsBuilder.java @@ -1,10 +1,10 @@ -package me.chanjar.weixin.enterprise.bean.messagebuilder; +package me.chanjar.weixin.cp.bean.messagebuilder; import java.util.ArrayList; import java.util.List; -import me.chanjar.weixin.enterprise.api.WxCpConsts; -import me.chanjar.weixin.enterprise.bean.WxCpMessage; +import me.chanjar.weixin.cp.api.WxCpConsts; +import me.chanjar.weixin.cp.bean.WxCpMessage; /** * 图文消息builder diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/messagebuilder/TextBuilder.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/TextBuilder.java similarity index 77% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/messagebuilder/TextBuilder.java rename to weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/TextBuilder.java index 7c1a0f463..3bf6e7100 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/messagebuilder/TextBuilder.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/TextBuilder.java @@ -1,7 +1,7 @@ -package me.chanjar.weixin.enterprise.bean.messagebuilder; +package me.chanjar.weixin.cp.bean.messagebuilder; -import me.chanjar.weixin.enterprise.api.WxCpConsts; -import me.chanjar.weixin.enterprise.bean.WxCpMessage; +import me.chanjar.weixin.cp.api.WxCpConsts; +import me.chanjar.weixin.cp.bean.WxCpMessage; /** * 文本消息builder diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/messagebuilder/VideoBuilder.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/VideoBuilder.java similarity index 88% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/messagebuilder/VideoBuilder.java rename to weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/VideoBuilder.java index 088637251..a94499a2c 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/messagebuilder/VideoBuilder.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/VideoBuilder.java @@ -1,7 +1,7 @@ -package me.chanjar.weixin.enterprise.bean.messagebuilder; +package me.chanjar.weixin.cp.bean.messagebuilder; -import me.chanjar.weixin.enterprise.api.WxCpConsts; -import me.chanjar.weixin.enterprise.bean.WxCpMessage; +import me.chanjar.weixin.cp.api.WxCpConsts; +import me.chanjar.weixin.cp.bean.WxCpMessage; /** * 视频消息builder diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/messagebuilder/VoiceBuilder.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/VoiceBuilder.java similarity index 77% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/messagebuilder/VoiceBuilder.java rename to weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/VoiceBuilder.java index 5b1d8dd69..7139811b3 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/messagebuilder/VoiceBuilder.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/VoiceBuilder.java @@ -1,7 +1,7 @@ -package me.chanjar.weixin.enterprise.bean.messagebuilder; +package me.chanjar.weixin.cp.bean.messagebuilder; -import me.chanjar.weixin.enterprise.api.WxCpConsts; -import me.chanjar.weixin.enterprise.bean.WxCpMessage; +import me.chanjar.weixin.cp.api.WxCpConsts; +import me.chanjar.weixin.cp.bean.WxCpMessage; /** * 语音消息builder diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/outxmlbuilder/BaseBuilder.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/outxmlbuilder/BaseBuilder.java similarity index 83% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/outxmlbuilder/BaseBuilder.java rename to weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/outxmlbuilder/BaseBuilder.java index 8498fa0e8..78ba10741 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/outxmlbuilder/BaseBuilder.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/outxmlbuilder/BaseBuilder.java @@ -1,6 +1,6 @@ -package me.chanjar.weixin.enterprise.bean.outxmlbuilder; +package me.chanjar.weixin.cp.bean.outxmlbuilder; -import me.chanjar.weixin.enterprise.bean.WxCpXmlOutMessage; +import me.chanjar.weixin.cp.bean.WxCpXmlOutMessage; public abstract class BaseBuilder { diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/outxmlbuilder/ImageBuilder.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/outxmlbuilder/ImageBuilder.java similarity index 78% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/outxmlbuilder/ImageBuilder.java rename to weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/outxmlbuilder/ImageBuilder.java index 4ffb3423a..ac3b7fc92 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/outxmlbuilder/ImageBuilder.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/outxmlbuilder/ImageBuilder.java @@ -1,6 +1,6 @@ -package me.chanjar.weixin.enterprise.bean.outxmlbuilder; +package me.chanjar.weixin.cp.bean.outxmlbuilder; -import me.chanjar.weixin.enterprise.bean.WxCpXmlOutImageMessage; +import me.chanjar.weixin.cp.bean.WxCpXmlOutImageMessage; /** * 图片消息builder diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/outxmlbuilder/NewsBuilder.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/outxmlbuilder/NewsBuilder.java similarity index 74% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/outxmlbuilder/NewsBuilder.java rename to weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/outxmlbuilder/NewsBuilder.java index afa2fbe49..1785f714a 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/outxmlbuilder/NewsBuilder.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/outxmlbuilder/NewsBuilder.java @@ -1,10 +1,10 @@ -package me.chanjar.weixin.enterprise.bean.outxmlbuilder; +package me.chanjar.weixin.cp.bean.outxmlbuilder; import java.util.ArrayList; import java.util.List; -import me.chanjar.weixin.enterprise.bean.WxCpXmlOutMewsMessage; -import me.chanjar.weixin.enterprise.bean.WxCpXmlOutMewsMessage.Item; +import me.chanjar.weixin.cp.bean.WxCpXmlOutMewsMessage; +import me.chanjar.weixin.cp.bean.WxCpXmlOutMewsMessage.Item; /** * 图文消息builder diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/outxmlbuilder/TextBuilder.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/outxmlbuilder/TextBuilder.java similarity index 78% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/outxmlbuilder/TextBuilder.java rename to weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/outxmlbuilder/TextBuilder.java index 5025dca6f..5b1c2ae64 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/outxmlbuilder/TextBuilder.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/outxmlbuilder/TextBuilder.java @@ -1,6 +1,6 @@ -package me.chanjar.weixin.enterprise.bean.outxmlbuilder; +package me.chanjar.weixin.cp.bean.outxmlbuilder; -import me.chanjar.weixin.enterprise.bean.WxCpXmlOutTextMessage; +import me.chanjar.weixin.cp.bean.WxCpXmlOutTextMessage; /** * 文本消息builder diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/outxmlbuilder/VideoBuilder.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/outxmlbuilder/VideoBuilder.java similarity index 86% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/outxmlbuilder/VideoBuilder.java rename to weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/outxmlbuilder/VideoBuilder.java index 4594b4c3c..1bb42ff24 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/outxmlbuilder/VideoBuilder.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/outxmlbuilder/VideoBuilder.java @@ -1,6 +1,6 @@ -package me.chanjar.weixin.enterprise.bean.outxmlbuilder; +package me.chanjar.weixin.cp.bean.outxmlbuilder; -import me.chanjar.weixin.enterprise.bean.WxCpXmlOutVideoMessage; +import me.chanjar.weixin.cp.bean.WxCpXmlOutVideoMessage; /** * 视频消息builder diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/outxmlbuilder/VoiceBuilder.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/outxmlbuilder/VoiceBuilder.java similarity index 78% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/outxmlbuilder/VoiceBuilder.java rename to weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/outxmlbuilder/VoiceBuilder.java index 0f85534ea..fb07525af 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/outxmlbuilder/VoiceBuilder.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/outxmlbuilder/VoiceBuilder.java @@ -1,6 +1,6 @@ -package me.chanjar.weixin.enterprise.bean.outxmlbuilder; +package me.chanjar.weixin.cp.bean.outxmlbuilder; -import me.chanjar.weixin.enterprise.bean.WxCpXmlOutVoiceMessage; +import me.chanjar.weixin.cp.bean.WxCpXmlOutVoiceMessage; /** * 语音消息builder diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/crypto/WxCpCryptUtil.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/crypto/WxCpCryptUtil.java new file mode 100755 index 000000000..d2d01c09b --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/crypto/WxCpCryptUtil.java @@ -0,0 +1,43 @@ +/** + * 对公众平台发送给公众账号的消息加解密示例代码. + * + * @copyright Copyright (c) 1998-2014 Tencent Inc. + */ + +// ------------------------------------------------------------------------ + +/** + * 针对org.apache.commons.codec.binary.Base64, + * 需要导入架包commons-codec-1.9(或commons-codec-1.8等其他版本) + * 官方下载地址:http://commons.apache.org/proper/commons-codec/download_codec.cgi + */ +package me.chanjar.weixin.cp.util.crypto; + +import me.chanjar.weixin.common.util.crypto.WxCryptUtil; +import me.chanjar.weixin.cp.api.WxCpConfigStorage; +import org.apache.commons.codec.binary.Base64; + +public class WxCpCryptUtil extends WxCryptUtil { + + /** + * 构造函数 + * + * @param wxCpConfigStorage + */ + public WxCpCryptUtil(WxCpConfigStorage wxCpConfigStorage) { + /* + * @param token 公众平台上,开发者设置的token + * @param encodingAesKey 公众平台上,开发者设置的EncodingAESKey + * @param appidOrCorpid 公众平台appid + */ + String encodingAesKey = wxCpConfigStorage.getAesKey(); + String token = wxCpConfigStorage.getToken(); + String corpId = wxCpConfigStorage.getCorpId(); + + this.token = token; + this.appidOrCorpid = corpId; + this.aesKey = Base64.decodeBase64(encodingAesKey + "="); + } + + +} diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxCpDepartGsonAdapter.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpDepartGsonAdapter.java similarity index 94% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxCpDepartGsonAdapter.java rename to weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpDepartGsonAdapter.java index 1d4b29969..022333f83 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxCpDepartGsonAdapter.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpDepartGsonAdapter.java @@ -6,12 +6,12 @@ * arose from modification of the original source, or other redistribution of this source * is not permitted without written permission of the KINGSTAR MEDIA SOLUTIONS LTD. */ -package me.chanjar.weixin.enterprise.util.json; +package me.chanjar.weixin.cp.util.json; import java.lang.reflect.Type; -import me.chanjar.weixin.common.util.GsonHelper; -import me.chanjar.weixin.enterprise.bean.WxCpDepart; +import me.chanjar.weixin.common.util.json.GsonHelper; +import me.chanjar.weixin.cp.bean.WxCpDepart; import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxCpGsonBuilder.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpGsonBuilder.java similarity index 61% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxCpGsonBuilder.java rename to weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpGsonBuilder.java index 3110f119a..3a8b739b4 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxCpGsonBuilder.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpGsonBuilder.java @@ -1,11 +1,12 @@ -package me.chanjar.weixin.enterprise.util.json; +package me.chanjar.weixin.cp.util.json; import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import me.chanjar.weixin.common.bean.result.WxAccessToken; +import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; import me.chanjar.weixin.common.bean.result.WxError; -import me.chanjar.weixin.enterprise.bean.*; -import me.chanjar.weixin.enterprise.bean.result.*; +import me.chanjar.weixin.common.util.json.WxMediaUploadResultAdapter; +import me.chanjar.weixin.common.util.json.WxErrorAdapter; +import me.chanjar.weixin.cp.bean.*; public class WxCpGsonBuilder { @@ -14,12 +15,9 @@ public class WxCpGsonBuilder { static { INSTANCE.disableHtmlEscaping(); INSTANCE.registerTypeAdapter(WxCpMessage.class, new WxCpMessageGsonAdapter()); - INSTANCE.registerTypeAdapter(WxCpMenu.class, new WxCpMenuGsonAdapter()); INSTANCE.registerTypeAdapter(WxCpDepart.class, new WxCpDepartGsonAdapter()); INSTANCE.registerTypeAdapter(WxCpUser.class, new WxCpUserGsonAdapter()); - INSTANCE.registerTypeAdapter(WxAccessToken.class, new WxCpAccessTokenAdapter()); INSTANCE.registerTypeAdapter(WxError.class, new WxErrorAdapter()); - INSTANCE.registerTypeAdapter(WxMediaUploadResult.class, new WxCpMediaUploadResultAdapter()); INSTANCE.registerTypeAdapter(WxCpTag.class, new WxCpTagGsonAdapter()); } diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxCpMessageGsonAdapter.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpMessageGsonAdapter.java similarity index 95% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxCpMessageGsonAdapter.java rename to weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpMessageGsonAdapter.java index 7de4af57b..2864e51f4 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxCpMessageGsonAdapter.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpMessageGsonAdapter.java @@ -6,12 +6,12 @@ * arose from modification of the original source, or other redistribution of this source * is not permitted without written permission of the KINGSTAR MEDIA SOLUTIONS LTD. */ -package me.chanjar.weixin.enterprise.util.json; +package me.chanjar.weixin.cp.util.json; import java.lang.reflect.Type; -import me.chanjar.weixin.enterprise.api.WxCpConsts; -import me.chanjar.weixin.enterprise.bean.WxCpMessage; +import me.chanjar.weixin.cp.api.WxCpConsts; +import me.chanjar.weixin.cp.bean.WxCpMessage; import com.google.gson.JsonArray; import com.google.gson.JsonElement; @@ -30,11 +30,11 @@ public class WxCpMessageGsonAdapter implements JsonSerializer { public JsonElement serialize(WxCpMessage message, Type typeOfSrc, JsonSerializationContext context) { JsonObject messageJson = new JsonObject(); messageJson.addProperty("agentid", message.getAgentId()); - messageJson.addProperty("msgtype", message.getMsgType()); - if (StringUtils.isNotBlank(message.getToUser())) { messageJson.addProperty("touser", message.getToUser()); } + messageJson.addProperty("msgtype", message.getMsgType()); + if (StringUtils.isNotBlank(message.getToParty())) { messageJson.addProperty("toparty", message.getToUser()); } diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxCpTagGsonAdapter.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpTagGsonAdapter.java similarity index 78% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxCpTagGsonAdapter.java rename to weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpTagGsonAdapter.java index 1d015dc70..776e8a448 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxCpTagGsonAdapter.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpTagGsonAdapter.java @@ -6,16 +6,12 @@ * arose from modification of the original source, or other redistribution of this source * is not permitted without written permission of the KINGSTAR MEDIA SOLUTIONS LTD. */ -package me.chanjar.weixin.enterprise.util.json; +package me.chanjar.weixin.cp.util.json; import com.google.gson.*; -import com.google.gson.internal.Streams; -import com.google.gson.stream.JsonReader; -import me.chanjar.weixin.common.util.GsonHelper; -import me.chanjar.weixin.enterprise.bean.WxCpDepart; -import me.chanjar.weixin.enterprise.bean.WxCpTag; +import me.chanjar.weixin.common.util.json.GsonHelper; +import me.chanjar.weixin.cp.bean.WxCpTag; -import java.io.StringReader; import java.lang.reflect.Type; /** diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxCpUserGsonAdapter.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapter.java similarity index 96% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxCpUserGsonAdapter.java rename to weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapter.java index e49fa2608..bf04d50c9 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxCpUserGsonAdapter.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapter.java @@ -6,13 +6,13 @@ * arose from modification of the original source, or other redistribution of this source * is not permitted without written permission of the KINGSTAR MEDIA SOLUTIONS LTD. */ -package me.chanjar.weixin.enterprise.util.json; +package me.chanjar.weixin.cp.util.json; import java.lang.reflect.Type; import com.google.gson.*; -import me.chanjar.weixin.common.util.GsonHelper; -import me.chanjar.weixin.enterprise.bean.WxCpUser; +import me.chanjar.weixin.common.util.json.GsonHelper; +import me.chanjar.weixin.cp.bean.WxCpUser; /** * @author Daniel Qian diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/common/util/XmlTransformer.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/xml/XmlTransformer.java similarity index 96% rename from weixin-java-enterprise/src/main/java/me/chanjar/weixin/common/util/XmlTransformer.java rename to weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/xml/XmlTransformer.java index 3652506b7..39914f44f 100644 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/common/util/XmlTransformer.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/xml/XmlTransformer.java @@ -1,4 +1,4 @@ -package me.chanjar.weixin.common.util; +package me.chanjar.weixin.cp.util.xml; import java.io.IOException; import java.io.InputStream; @@ -8,7 +8,7 @@ import java.io.Writer; import javax.xml.bind.*; -import me.chanjar.weixin.enterprise.bean.*; +import me.chanjar.weixin.cp.bean.*; import org.xml.sax.InputSource; import com.sun.xml.bind.marshaller.CharacterEscapeHandler; diff --git a/weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/api/ApiTestModule.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/ApiTestModule.java similarity index 90% rename from weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/api/ApiTestModule.java rename to weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/ApiTestModule.java index 8c6544475..00b890d94 100644 --- a/weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/api/ApiTestModule.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/ApiTestModule.java @@ -1,4 +1,4 @@ -package me.chanjar.weixin.enterprise.api; +package me.chanjar.weixin.cp.api; import java.io.InputStream; @@ -19,7 +19,7 @@ public class ApiTestModule implements Module { public void configure(Binder binder) { try { InputStream is1 = ClassLoader.getSystemResourceAsStream("test-config.xml"); - WxXmlCpConfigStorage config = fromXml(WxXmlCpConfigStorage.class, is1); + WxXmlCpInMemoryConfigStorage config = fromXml(WxXmlCpInMemoryConfigStorage.class, is1); WxCpServiceImpl wxService = new WxCpServiceImpl(); wxService.setWxCpConfigStorage(config); @@ -40,7 +40,7 @@ public class ApiTestModule implements Module { @XmlRootElement(name = "xml") @XmlAccessorType(XmlAccessType.FIELD) - public static class WxXmlCpConfigStorage extends WxInMemoryCpConfigStorage { + public static class WxXmlCpInMemoryConfigStorage extends WxCpInMemoryConfigStorage { protected String userId; diff --git a/weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/api/WxCpBaseAPITest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpBaseAPITest.java similarity index 87% rename from weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/api/WxCpBaseAPITest.java rename to weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpBaseAPITest.java index 637d93ba3..07d7d0a64 100644 --- a/weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/api/WxCpBaseAPITest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpBaseAPITest.java @@ -1,11 +1,11 @@ -package me.chanjar.weixin.enterprise.api; +package me.chanjar.weixin.cp.api; import org.apache.commons.lang3.StringUtils; import org.testng.Assert; import org.testng.annotations.Guice; import org.testng.annotations.Test; -import me.chanjar.weixin.enterprise.exception.WxErrorException; +import me.chanjar.weixin.common.exception.WxErrorException; import com.google.inject.Inject; diff --git a/weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/api/WxCpDepartAPITest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpDepartAPITest.java similarity index 91% rename from weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/api/WxCpDepartAPITest.java rename to weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpDepartAPITest.java index 6301b1851..1183424f6 100644 --- a/weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/api/WxCpDepartAPITest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpDepartAPITest.java @@ -1,13 +1,13 @@ -package me.chanjar.weixin.enterprise.api; +package me.chanjar.weixin.cp.api; import java.util.List; -import me.chanjar.weixin.enterprise.bean.WxCpDepart; +import me.chanjar.weixin.cp.bean.WxCpDepart; import org.testng.Assert; import org.testng.annotations.Guice; import org.testng.annotations.Test; -import me.chanjar.weixin.enterprise.exception.WxErrorException; +import me.chanjar.weixin.common.exception.WxErrorException; import com.google.inject.Inject; diff --git a/weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/api/WxCpMediaAPITest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMediaAPITest.java similarity index 92% rename from weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/api/WxCpMediaAPITest.java rename to weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMediaAPITest.java index 26e162108..336e11b7d 100644 --- a/weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/api/WxCpMediaAPITest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMediaAPITest.java @@ -1,17 +1,17 @@ -package me.chanjar.weixin.enterprise.api; +package me.chanjar.weixin.cp.api; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.List; +import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; import org.testng.Assert; import org.testng.annotations.DataProvider; import org.testng.annotations.Guice; import org.testng.annotations.Test; -import me.chanjar.weixin.enterprise.bean.result.WxMediaUploadResult; -import me.chanjar.weixin.enterprise.exception.WxErrorException; +import me.chanjar.weixin.common.exception.WxErrorException; import com.google.inject.Inject; diff --git a/weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/api/WxCpMessageAPITest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMessageAPITest.java similarity index 79% rename from weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/api/WxCpMessageAPITest.java rename to weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMessageAPITest.java index 7ee283380..01acca718 100644 --- a/weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/api/WxCpMessageAPITest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMessageAPITest.java @@ -1,10 +1,10 @@ -package me.chanjar.weixin.enterprise.api; +package me.chanjar.weixin.cp.api; -import me.chanjar.weixin.enterprise.bean.WxCpMessage; +import me.chanjar.weixin.cp.bean.WxCpMessage; import org.testng.annotations.Guice; import org.testng.annotations.Test; -import me.chanjar.weixin.enterprise.exception.WxErrorException; +import me.chanjar.weixin.common.exception.WxErrorException; import com.google.inject.Inject; @@ -21,7 +21,7 @@ public class WxCpMessageAPITest { protected WxCpServiceImpl wxService; public void testSendCustomMessage() throws WxErrorException { - ApiTestModule.WxXmlCpConfigStorage configStorage = (ApiTestModule.WxXmlCpConfigStorage) wxService.wxCpConfigStorage; + ApiTestModule.WxXmlCpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlCpInMemoryConfigStorage) wxService.wxCpConfigStorage; WxCpMessage message1 = new WxCpMessage(); message1.setAgentId(configStorage.getAgentId()); message1.setMsgType(WxCpConsts.CUSTOM_MSG_TEXT); diff --git a/weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/api/WxCpMessageRouterTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMessageRouterTest.java similarity index 96% rename from weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/api/WxCpMessageRouterTest.java rename to weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMessageRouterTest.java index 37bcf3beb..6ad6f62c4 100644 --- a/weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/api/WxCpMessageRouterTest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMessageRouterTest.java @@ -1,9 +1,9 @@ -package me.chanjar.weixin.enterprise.api; +package me.chanjar.weixin.cp.api; import java.util.Map; -import me.chanjar.weixin.enterprise.bean.WxCpXmlMessage; -import me.chanjar.weixin.enterprise.bean.WxCpXmlOutMessage; +import me.chanjar.weixin.cp.bean.WxCpXmlMessage; +import me.chanjar.weixin.cp.bean.WxCpXmlOutMessage; import org.testng.Assert; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; diff --git a/weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/api/WxCpTagAPITest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpTagAPITest.java similarity index 84% rename from weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/api/WxCpTagAPITest.java rename to weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpTagAPITest.java index 44b8e3914..0bb7dba92 100644 --- a/weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/api/WxCpTagAPITest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpTagAPITest.java @@ -1,8 +1,8 @@ -package me.chanjar.weixin.enterprise.api; +package me.chanjar.weixin.cp.api; import com.google.inject.Inject; -import me.chanjar.weixin.enterprise.bean.WxCpTag; -import me.chanjar.weixin.enterprise.bean.WxCpUser; +import me.chanjar.weixin.cp.bean.WxCpTag; +import me.chanjar.weixin.cp.bean.WxCpUser; import org.testng.Assert; import org.testng.annotations.Guice; import org.testng.annotations.Test; @@ -41,7 +41,7 @@ public class WxCpTagAPITest { @Test(dependsOnMethods = "testTagGet") public void testTagAddUsers() throws Exception { List userIds = new ArrayList(); - userIds.add(((ApiTestModule.WxXmlCpConfigStorage)configStorage).getUserId()); + userIds.add(((ApiTestModule.WxXmlCpInMemoryConfigStorage)configStorage).getUserId()); wxService.tagAddUsers(tagId, userIds); } @@ -54,7 +54,7 @@ public class WxCpTagAPITest { @Test(dependsOnMethods = "testTagGetUsers") public void testTagRemoveUsers() throws Exception { List userIds = new ArrayList(); - userIds.add(((ApiTestModule.WxXmlCpConfigStorage)configStorage).getUserId()); + userIds.add(((ApiTestModule.WxXmlCpInMemoryConfigStorage)configStorage).getUserId()); wxService.tagRemoveUsers(tagId, userIds); } diff --git a/weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/api/WxCpUserAPITest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpUserAPITest.java similarity index 89% rename from weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/api/WxCpUserAPITest.java rename to weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpUserAPITest.java index a9f3bb101..391d205c3 100644 --- a/weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/api/WxCpUserAPITest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpUserAPITest.java @@ -1,9 +1,9 @@ -package me.chanjar.weixin.enterprise.api; +package me.chanjar.weixin.cp.api; import com.google.inject.Inject; -import me.chanjar.weixin.enterprise.bean.WxCpDepart; -import me.chanjar.weixin.enterprise.bean.WxCpUser; -import me.chanjar.weixin.enterprise.exception.WxErrorException; +import me.chanjar.weixin.cp.bean.WxCpDepart; +import me.chanjar.weixin.cp.bean.WxCpUser; +import me.chanjar.weixin.common.exception.WxErrorException; import org.testng.Assert; import org.testng.annotations.Guice; import org.testng.annotations.Test; diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMenuAPITest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxMenuAPITest.java similarity index 80% rename from weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMenuAPITest.java rename to weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxMenuAPITest.java index 1050bc944..ebb292e23 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMenuAPITest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxMenuAPITest.java @@ -1,7 +1,8 @@ -package me.chanjar.weixin.mp.api; +package me.chanjar.weixin.cp.api; import javax.xml.bind.JAXBException; +import me.chanjar.weixin.common.bean.WxMenu; import org.testng.Assert; import org.testng.annotations.DataProvider; import org.testng.annotations.Guice; @@ -9,13 +10,12 @@ import org.testng.annotations.Test; import com.google.inject.Inject; -import me.chanjar.weixin.mp.bean.WxMenu; -import me.chanjar.weixin.mp.bean.WxMenu.WxMenuButton; -import me.chanjar.weixin.mp.exception.WxErrorException; +import me.chanjar.weixin.common.bean.WxMenu.WxMenuButton; +import me.chanjar.weixin.common.exception.WxErrorException; /** * 测试菜单 - * @author chanjarster + * @author Daniel Qian * */ @Test(groups="menuAPI", dependsOnGroups="baseAPI") @@ -23,7 +23,7 @@ import me.chanjar.weixin.mp.exception.WxErrorException; public class WxMenuAPITest { @Inject - protected WxServiceImpl wxService; + protected WxCpServiceImpl wxService; @Test(dataProvider = "menu") public void testCreateMenu(WxMenu wxMenu) throws WxErrorException { @@ -44,12 +44,12 @@ public class WxMenuAPITest { public Object[][] getMenu() throws JAXBException { WxMenu menu = new WxMenu(); WxMenuButton button1 = new WxMenuButton(); - button1.setType(WxConsts.BUTTON_CLICK); + button1.setType(WxCpConsts.BUTTON_CLICK); button1.setName("今日歌曲"); button1.setKey("V1001_TODAY_MUSIC"); WxMenuButton button2 = new WxMenuButton(); - button2.setType(WxConsts.BUTTON_CLICK); + button2.setType(WxCpConsts.BUTTON_CLICK); button2.setName("歌手简介"); button2.setKey("V1001_TODAY_SINGER"); @@ -61,17 +61,17 @@ public class WxMenuAPITest { menu.getButtons().add(button3); WxMenuButton button31 = new WxMenuButton(); - button31.setType(WxConsts.BUTTON_VIEW); + button31.setType(WxCpConsts.BUTTON_VIEW); button31.setName("搜索"); button31.setUrl("http://www.soso.com/"); WxMenuButton button32 = new WxMenuButton(); - button32.setType(WxConsts.BUTTON_VIEW); + button32.setType(WxCpConsts.BUTTON_VIEW); button32.setName("视频"); button32.setUrl("http://v.qq.com/"); WxMenuButton button33 = new WxMenuButton(); - button33.setType(WxConsts.BUTTON_CLICK); + button33.setType(WxCpConsts.BUTTON_CLICK); button33.setName("赞一下我们"); button33.setKey("V1001_GOOD"); diff --git a/weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/bean/WxCpMessageTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpMessageTest.java similarity index 96% rename from weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/bean/WxCpMessageTest.java rename to weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpMessageTest.java index 806fd6504..56fca7553 100644 --- a/weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/bean/WxCpMessageTest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpMessageTest.java @@ -1,10 +1,10 @@ -package me.chanjar.weixin.enterprise.bean; +package me.chanjar.weixin.cp.bean; -import me.chanjar.weixin.enterprise.api.WxCpConsts; +import me.chanjar.weixin.cp.api.WxCpConsts; import org.testng.Assert; import org.testng.annotations.Test; -import me.chanjar.weixin.enterprise.bean.WxCpMessage.WxArticle; +import me.chanjar.weixin.cp.bean.WxCpMessage.WxArticle; @Test public class WxCpMessageTest { diff --git a/weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/bean/WxCpXmlMessageTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpXmlMessageTest.java similarity index 98% rename from weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/bean/WxCpXmlMessageTest.java rename to weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpXmlMessageTest.java index a2b2e7817..d356126f0 100644 --- a/weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/bean/WxCpXmlMessageTest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpXmlMessageTest.java @@ -1,6 +1,6 @@ -package me.chanjar.weixin.enterprise.bean; +package me.chanjar.weixin.cp.bean; -import me.chanjar.weixin.enterprise.api.WxCpConsts; +import me.chanjar.weixin.cp.api.WxCpConsts; import org.testng.Assert; import org.testng.annotations.Test; diff --git a/weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutImageMessageTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpXmlOutImageMessageTest.java similarity index 97% rename from weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutImageMessageTest.java rename to weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpXmlOutImageMessageTest.java index 63c473a4e..9f97e4b87 100644 --- a/weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutImageMessageTest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpXmlOutImageMessageTest.java @@ -1,4 +1,4 @@ -package me.chanjar.weixin.enterprise.bean; +package me.chanjar.weixin.cp.bean; import org.testng.Assert; import org.testng.annotations.Test; diff --git a/weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutNewsMessageTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpXmlOutNewsMessageTest.java similarity index 98% rename from weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutNewsMessageTest.java rename to weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpXmlOutNewsMessageTest.java index 98e6d0a19..f72c76b33 100644 --- a/weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutNewsMessageTest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpXmlOutNewsMessageTest.java @@ -1,4 +1,4 @@ -package me.chanjar.weixin.enterprise.bean; +package me.chanjar.weixin.cp.bean; import org.testng.Assert; import org.testng.annotations.Test; diff --git a/weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutTextMessageTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpXmlOutTextMessageTest.java similarity index 97% rename from weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutTextMessageTest.java rename to weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpXmlOutTextMessageTest.java index de1710423..4dce4f166 100644 --- a/weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutTextMessageTest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpXmlOutTextMessageTest.java @@ -1,4 +1,4 @@ -package me.chanjar.weixin.enterprise.bean; +package me.chanjar.weixin.cp.bean; import org.testng.Assert; import org.testng.annotations.Test; diff --git a/weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutVideoMessageTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpXmlOutVideoMessageTest.java similarity index 98% rename from weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutVideoMessageTest.java rename to weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpXmlOutVideoMessageTest.java index c351df5e6..b5ba24566 100644 --- a/weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutVideoMessageTest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpXmlOutVideoMessageTest.java @@ -1,4 +1,4 @@ -package me.chanjar.weixin.enterprise.bean; +package me.chanjar.weixin.cp.bean; import org.testng.Assert; import org.testng.annotations.Test; diff --git a/weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutVoiceMessageTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpXmlOutVoiceMessageTest.java similarity index 97% rename from weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutVoiceMessageTest.java rename to weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpXmlOutVoiceMessageTest.java index 401b844ba..fa73a329f 100644 --- a/weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/bean/WxCpXmlOutVoiceMessageTest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/WxCpXmlOutVoiceMessageTest.java @@ -1,4 +1,4 @@ -package me.chanjar.weixin.enterprise.bean; +package me.chanjar.weixin.cp.bean; import org.testng.Assert; import org.testng.annotations.Test; diff --git a/weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/demo/WxTestCpConfigStorage.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpDemoInMemoryConfigStorage.java similarity index 53% rename from weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/demo/WxTestCpConfigStorage.java rename to weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpDemoInMemoryConfigStorage.java index 7de397996..0c0d3961f 100644 --- a/weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/demo/WxTestCpConfigStorage.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpDemoInMemoryConfigStorage.java @@ -1,6 +1,6 @@ -package me.chanjar.weixin.enterprise.demo; +package me.chanjar.weixin.cp.demo; -import me.chanjar.weixin.enterprise.api.WxInMemoryCpConfigStorage; +import me.chanjar.weixin.cp.api.WxCpInMemoryConfigStorage; import org.xml.sax.InputSource; import javax.xml.bind.JAXBContext; @@ -16,20 +16,20 @@ import java.io.InputStream; */ @XmlRootElement(name = "xml") @XmlAccessorType(XmlAccessType.FIELD) -class WxTestCpConfigStorage extends WxInMemoryCpConfigStorage { +class WxCpDemoInMemoryConfigStorage extends WxCpInMemoryConfigStorage { @Override public String toString() { - return "SimpleWxConfigProvider [corpId=" + corpId + ", corpSecret=" + corpSecret + ", accessToken=" + accessToken + return "SimpleWxConfigProvider [appidOrCorpid=" + corpId + ", corpSecret=" + corpSecret + ", accessToken=" + accessToken + ", expiresIn=" + expiresIn + ", token=" + token + ", aesKey=" + aesKey + "]"; } - public static WxTestCpConfigStorage fromXml(InputStream is) throws JAXBException { - Unmarshaller um = JAXBContext.newInstance(WxTestCpConfigStorage.class).createUnmarshaller(); + public static WxCpDemoInMemoryConfigStorage fromXml(InputStream is) throws JAXBException { + Unmarshaller um = JAXBContext.newInstance(WxCpDemoInMemoryConfigStorage.class).createUnmarshaller(); InputSource inputSource = new InputSource(is); inputSource.setEncoding("utf-8"); - return (WxTestCpConfigStorage) um.unmarshal(inputSource); + return (WxCpDemoInMemoryConfigStorage) um.unmarshal(inputSource); } } diff --git a/weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/demo/WxCpTestServer.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpDemoServer.java similarity index 71% rename from weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/demo/WxCpTestServer.java rename to weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpDemoServer.java index d4c1415a2..b56d17803 100644 --- a/weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/demo/WxCpTestServer.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpDemoServer.java @@ -1,4 +1,4 @@ -package me.chanjar.weixin.enterprise.demo; +package me.chanjar.weixin.cp.demo; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletHandler; @@ -6,14 +6,14 @@ import org.eclipse.jetty.servlet.ServletHandler; /** * @author Daniel Qian */ -public class WxCpTestServer { +public class WxCpDemoServer { public static void main(String[] args) throws Exception { Server server = new Server(8080); ServletHandler handler = new ServletHandler(); server.setHandler(handler); - handler.addServletWithMapping(WxCpTestServlet.class, "/*"); + handler.addServletWithMapping(WxCpDemoServlet.class, "/*"); server.start(); server.join(); } diff --git a/weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/demo/WxCpTestServlet.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpDemoServlet.java similarity index 84% rename from weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/demo/WxCpTestServlet.java rename to weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpDemoServlet.java index 31303d13a..b84d786fb 100644 --- a/weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/demo/WxCpTestServlet.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/demo/WxCpDemoServlet.java @@ -1,10 +1,10 @@ -package me.chanjar.weixin.enterprise.demo; +package me.chanjar.weixin.cp.demo; -import me.chanjar.weixin.enterprise.api.*; -import me.chanjar.weixin.enterprise.bean.WxCpXmlMessage; -import me.chanjar.weixin.enterprise.bean.WxCpXmlOutMessage; -import me.chanjar.weixin.enterprise.bean.WxCpXmlOutTextMessage; -import me.chanjar.weixin.enterprise.util.crypto.WxCryptUtil; +import me.chanjar.weixin.cp.api.*; +import me.chanjar.weixin.cp.bean.WxCpXmlMessage; +import me.chanjar.weixin.cp.bean.WxCpXmlOutMessage; +import me.chanjar.weixin.cp.bean.WxCpXmlOutTextMessage; +import me.chanjar.weixin.cp.util.crypto.WxCpCryptUtil; import org.apache.commons.lang3.StringUtils; import javax.servlet.ServletException; @@ -19,7 +19,7 @@ import java.util.Map; /** * @author Daniel Qian */ -public class WxCpTestServlet extends HttpServlet { +public class WxCpDemoServlet extends HttpServlet { protected WxCpService wxCpService; protected WxCpConfigStorage wxCpConfigStorage; @@ -30,7 +30,7 @@ public class WxCpTestServlet extends HttpServlet { super.init(); try { InputStream is1 = ClassLoader.getSystemResourceAsStream("test-config.xml"); - WxTestCpConfigStorage config = WxTestCpConfigStorage.fromXml(is1); + WxCpDemoInMemoryConfigStorage config = WxCpDemoInMemoryConfigStorage.fromXml(is1); wxCpConfigStorage = config; wxCpService = new WxCpServiceImpl(); @@ -77,7 +77,7 @@ public class WxCpTestServlet extends HttpServlet { response.getWriter().println("非法请求"); return; } - WxCryptUtil cryptUtil = new WxCryptUtil(wxCpConfigStorage); + WxCpCryptUtil cryptUtil = new WxCpCryptUtil(wxCpConfigStorage); String plainText = cryptUtil.decrypt(echostr); // 说明是一个仅仅用来验证的请求,回显echostr response.getWriter().println(plainText); diff --git a/weixin-java-enterprise/src/test/resources/mm.jpeg b/weixin-java-cp/src/test/resources/mm.jpeg similarity index 100% rename from weixin-java-enterprise/src/test/resources/mm.jpeg rename to weixin-java-cp/src/test/resources/mm.jpeg diff --git a/weixin-java-enterprise/src/test/resources/mm.mp3 b/weixin-java-cp/src/test/resources/mm.mp3 similarity index 100% rename from weixin-java-enterprise/src/test/resources/mm.mp3 rename to weixin-java-cp/src/test/resources/mm.mp3 diff --git a/weixin-java-enterprise/src/test/resources/mm.mp4 b/weixin-java-cp/src/test/resources/mm.mp4 similarity index 100% rename from weixin-java-enterprise/src/test/resources/mm.mp4 rename to weixin-java-cp/src/test/resources/mm.mp4 diff --git a/weixin-java-enterprise/src/test/resources/test-config.sample.xml b/weixin-java-cp/src/test/resources/test-config.sample.xml similarity index 100% rename from weixin-java-enterprise/src/test/resources/test-config.sample.xml rename to weixin-java-cp/src/test/resources/test-config.sample.xml diff --git a/weixin-java-cp/src/test/resources/testng.xml b/weixin-java-cp/src/test/resources/testng.xml new file mode 100644 index 000000000..4cddddcf0 --- /dev/null +++ b/weixin-java-cp/src/test/resources/testng.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/weixin-java-enterprise/README.md b/weixin-java-enterprise/README.md deleted file mode 100644 index e160e26d5..000000000 --- a/weixin-java-enterprise/README.md +++ /dev/null @@ -1,56 +0,0 @@ -weixin-java-tools -=========== - -微信java开发工具集,本项目主要分为两大块:微信消息路由器、微信Java API - -特性列表: - -1. 不基于Servlet、和其他MVC框架,仅作为工具使用,提供更多的灵活性 -2. 详尽的单元测试代码,可以拿来当example用 -3. 详尽的javadoc -4. access token过期自动刷新的功能 -5. 微信服务端繁忙自动重试的功能 -6. 提供微信错误信息的异常处理机制 - - -详细文档请看 [wiki](https://github.com/chanjarster/weixin-java-tools/wiki) - -# Quickstart - -在你的maven项目中添加: -```xml - - me.chanjar - weixin-java-tools - 1.0.2 - -``` - -如果要使用``*-SNAPSHOT``版,则需要在你的``pom.xml``中添加这段: - -```xml - - - - sonatype snapshots - https://oss.sonatype.org/content/repositories/snapshots/ - - -``` - -## Hello World -```java -WxConfigStorage config = new WxInMemoryConfigStorage(); -config.setAppId(...); // 设置微信企业号的appid -config.setSecret(...); // 设置微信企业号的app corpSecret -config.setToken(...); // 设置微信企业号的token - -WxServiceImpl wxService = new WxServiceImpl(); -wxService.setWxConfigStorage(config); - -// 用户的openid在下面地址获得 -// https://mp.weixin.qq.com/debug/cgi-bin/apiinfo?t=index&type=用户管理&form=获取关注者列表接口%20/user/get -String userId = ...; -WxCustomMessage message = WxCustomMessage.TEXT().toUser(userId).content("Hello World").build(); -wxService.customMessageSend(message); -``` diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/common/bean/result/WxAccessToken.java b/weixin-java-enterprise/src/main/java/me/chanjar/weixin/common/bean/result/WxAccessToken.java deleted file mode 100644 index fe7117b60..000000000 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/common/bean/result/WxAccessToken.java +++ /dev/null @@ -1,31 +0,0 @@ -package me.chanjar.weixin.common.bean.result; - -import me.chanjar.weixin.enterprise.util.json.WxCpGsonBuilder; - -public class WxAccessToken { - - private String accessToken; - - private int expiresIn = -1; - - public String getAccessToken() { - return accessToken; - } - - public void setAccessToken(String accessToken) { - this.accessToken = accessToken; - } - - public int getExpiresIn() { - return expiresIn; - } - - public void setExpiresIn(int expiresIn) { - this.expiresIn = expiresIn; - } - - public static WxAccessToken fromJson(String json) { - return WxCpGsonBuilder.create().fromJson(json, WxAccessToken.class); - } - -} diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpMenu.java b/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpMenu.java deleted file mode 100644 index 62ae6356b..000000000 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/WxCpMenu.java +++ /dev/null @@ -1,90 +0,0 @@ -package me.chanjar.weixin.enterprise.bean; - -import java.io.InputStream; -import java.io.InputStreamReader; -import java.util.ArrayList; -import java.util.List; - -import me.chanjar.weixin.enterprise.util.json.WxCpGsonBuilder; - -/** - * 企业号菜单 - * @author Daniel Qian - * - */ -public class WxCpMenu { - - private List buttons = new ArrayList(); - - public List getButtons() { - return buttons; - } - - public void setButtons(List buttons) { - this.buttons = buttons; - } - - public String toJson() { - return WxCpGsonBuilder.create().toJson(this); - } - - public static WxCpMenu fromJson(String json) { - return WxCpGsonBuilder.create().fromJson(json, WxCpMenu.class); - } - - public static WxCpMenu fromJson(InputStream is) { - return WxCpGsonBuilder.create().fromJson(new InputStreamReader(is), WxCpMenu.class); - } - - public static class WxMenuButton { - - private String type; - private String name; - private String key; - private String url; - - private List subButtons = new ArrayList(); - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getKey() { - return key; - } - - public void setKey(String key) { - this.key = key; - } - - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } - - public List getSubButtons() { - return subButtons; - } - - public void setSubButtons(List subButtons) { - this.subButtons = subButtons; - } - - } - -} diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/result/WxMediaUploadResult.java b/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/result/WxMediaUploadResult.java deleted file mode 100644 index 1816aabe6..000000000 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/bean/result/WxMediaUploadResult.java +++ /dev/null @@ -1,54 +0,0 @@ -package me.chanjar.weixin.enterprise.bean.result; - -import me.chanjar.weixin.enterprise.util.json.WxCpGsonBuilder; - -public class WxMediaUploadResult { - - private String type; - private String mediaId; - private String thumbMediaId; - private long createdAt; - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getMediaId() { - return mediaId; - } - - public void setMediaId(String mediaId) { - this.mediaId = mediaId; - } - - public long getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(long createdAt) { - this.createdAt = createdAt; - } - - public static WxMediaUploadResult fromJson(String json) { - return WxCpGsonBuilder.create().fromJson(json, WxMediaUploadResult.class); - } - - public String getThumbMediaId() { - return thumbMediaId; - } - - public void setThumbMediaId(String thumbMediaId) { - this.thumbMediaId = thumbMediaId; - } - - @Override - public String toString() { - return "WxUploadResult [type=" + type + ", media_id=" + mediaId + ", thumb_media_id=" + thumbMediaId - + ", created_at=" + createdAt + "]"; - } - -} diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/http/InputStreamResponseHandler.java b/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/http/InputStreamResponseHandler.java deleted file mode 100644 index 3b7fa2dde..000000000 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/http/InputStreamResponseHandler.java +++ /dev/null @@ -1,27 +0,0 @@ -package me.chanjar.weixin.enterprise.util.http; - -import java.io.IOException; -import java.io.InputStream; - -import org.apache.http.HttpEntity; -import org.apache.http.HttpResponse; -import org.apache.http.StatusLine; -import org.apache.http.client.HttpResponseException; -import org.apache.http.client.ResponseHandler; -import org.apache.http.util.EntityUtils; - -public class InputStreamResponseHandler implements ResponseHandler { - - public static final ResponseHandler INSTANCE = new InputStreamResponseHandler(); - - public InputStream handleResponse(final HttpResponse response) throws HttpResponseException, IOException { - final StatusLine statusLine = response.getStatusLine(); - final HttpEntity entity = response.getEntity(); - if (statusLine.getStatusCode() >= 300) { - EntityUtils.consume(entity); - throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase()); - } - return entity == null ? null : entity.getContent(); - } - -} diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxCpAccessTokenAdapter.java b/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxCpAccessTokenAdapter.java deleted file mode 100644 index 4578bff05..000000000 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxCpAccessTokenAdapter.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * KINGSTAR MEDIA SOLUTIONS Co.,LTD. Copyright c 2005-2013. All rights reserved. - * - * This source code is the property of KINGSTAR MEDIA SOLUTIONS LTD. It is intended - * only for the use of KINGSTAR MEDIA application development. Reengineering, reproduction - * arose from modification of the original source, or other redistribution of this source - * is not permitted without written permission of the KINGSTAR MEDIA SOLUTIONS LTD. - */ -package me.chanjar.weixin.enterprise.util.json; - -import com.google.gson.*; -import me.chanjar.weixin.common.util.GsonHelper; -import me.chanjar.weixin.common.bean.result.WxAccessToken; - -import java.lang.reflect.Type; - -/** - * - * @author Daniel Qian - * - */ -public class WxCpAccessTokenAdapter implements JsonDeserializer { - - public WxAccessToken deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { - WxAccessToken accessToken = new WxAccessToken(); - JsonObject accessTokenJsonObject = json.getAsJsonObject(); - - if (accessTokenJsonObject.get("access_token") != null && !accessTokenJsonObject.get("access_token").isJsonNull()) { - accessToken.setAccessToken(GsonHelper.getAsString(accessTokenJsonObject.get("access_token"))); - } - if (accessTokenJsonObject.get("expires_in") != null && !accessTokenJsonObject.get("expires_in").isJsonNull()) { - accessToken.setExpiresIn(GsonHelper.getAsPrimitiveInt(accessTokenJsonObject.get("expires_in"))); - } - return accessToken; - } - -} diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxCpMediaUploadResultAdapter.java b/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxCpMediaUploadResultAdapter.java deleted file mode 100644 index 028e6c3f6..000000000 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxCpMediaUploadResultAdapter.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * KINGSTAR MEDIA SOLUTIONS Co.,LTD. Copyright c 2005-2013. All rights reserved. - * - * This source code is the property of KINGSTAR MEDIA SOLUTIONS LTD. It is intended - * only for the use of KINGSTAR MEDIA application development. Reengineering, reproduction - * arose from modification of the original source, or other redistribution of this source - * is not permitted without written permission of the KINGSTAR MEDIA SOLUTIONS LTD. - */ -package me.chanjar.weixin.enterprise.util.json; - -import com.google.gson.*; -import me.chanjar.weixin.common.util.GsonHelper; -import me.chanjar.weixin.enterprise.bean.result.WxMediaUploadResult; - -import java.lang.reflect.Type; - -/** - * - * @author Daniel Qian - * - */ -public class WxCpMediaUploadResultAdapter implements JsonDeserializer { - - public WxMediaUploadResult deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { - WxMediaUploadResult uploadResult = new WxMediaUploadResult(); - JsonObject uploadResultJsonObject = json.getAsJsonObject(); - - if (uploadResultJsonObject.get("type") != null && !uploadResultJsonObject.get("type").isJsonNull()) { - uploadResult.setType(GsonHelper.getAsString(uploadResultJsonObject.get("type"))); - } - if (uploadResultJsonObject.get("media_id") != null && !uploadResultJsonObject.get("media_id").isJsonNull()) { - uploadResult.setMediaId(GsonHelper.getAsString(uploadResultJsonObject.get("media_id"))); - } - if (uploadResultJsonObject.get("thumb_media_id") != null && !uploadResultJsonObject.get("thumb_media_id").isJsonNull()) { - uploadResult.setThumbMediaId(GsonHelper.getAsString(uploadResultJsonObject.get("thumb_media_id"))); - } - if (uploadResultJsonObject.get("created_at") != null && !uploadResultJsonObject.get("created_at").isJsonNull()) { - uploadResult.setCreatedAt(GsonHelper.getAsPrimitiveLong(uploadResultJsonObject.get("created_at"))); - } - return uploadResult; - } - -} diff --git a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxCpMenuGsonAdapter.java b/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxCpMenuGsonAdapter.java deleted file mode 100644 index e2a62f786..000000000 --- a/weixin-java-enterprise/src/main/java/me/chanjar/weixin/enterprise/util/json/WxCpMenuGsonAdapter.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * KINGSTAR MEDIA SOLUTIONS Co.,LTD. Copyright c 2005-2013. All rights reserved. - * - * This source code is the property of KINGSTAR MEDIA SOLUTIONS LTD. It is intended - * only for the use of KINGSTAR MEDIA application development. Reengineering, reproduction - * arose from modification of the original source, or other redistribution of this source - * is not permitted without written permission of the KINGSTAR MEDIA SOLUTIONS LTD. - */ -package me.chanjar.weixin.enterprise.util.json; - -import java.lang.reflect.Type; - -import me.chanjar.weixin.common.util.GsonHelper; -import me.chanjar.weixin.enterprise.bean.WxCpMenu; - -import com.google.gson.JsonArray; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; - -/** - * - * @author Daniel Qian - * - */ -public class WxCpMenuGsonAdapter implements JsonSerializer, JsonDeserializer { - - public JsonElement serialize(WxCpMenu menu, Type typeOfSrc, JsonSerializationContext context) { - JsonObject json = new JsonObject(); - - JsonArray buttonArray = new JsonArray(); - for (WxCpMenu.WxMenuButton button : menu.getButtons()) { - JsonObject buttonJson = convertToJson(button); - buttonArray.add(buttonJson); - } - json.add("button", buttonArray); - - return json; - } - - protected JsonObject convertToJson(WxCpMenu.WxMenuButton button) { - JsonObject buttonJson = new JsonObject(); - buttonJson.addProperty("type", button.getType()); - buttonJson.addProperty("name", button.getName()); - buttonJson.addProperty("key", button.getKey()); - buttonJson.addProperty("url", button.getUrl()); - if (button.getSubButtons() != null && button.getSubButtons().size() > 0) { - JsonArray buttonArray = new JsonArray(); - for (WxCpMenu.WxMenuButton sub_button : button.getSubButtons()) { - buttonArray.add(convertToJson(sub_button)); - } - buttonJson.add("sub_button", buttonArray); - } - return buttonJson; - } - - public WxCpMenu deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { - /* - * 操蛋的微信 - * 创建菜单时是 { button : ... } - * 查询菜单时是 { menu : { button : ... } } - */ - WxCpMenu menu = new WxCpMenu(); - JsonObject menuJson = json.getAsJsonObject().get("menu").getAsJsonObject(); - JsonArray buttonsJson = menuJson.get("button").getAsJsonArray(); - for (int i = 0; i < buttonsJson.size(); i++) { - JsonObject buttonJson = buttonsJson.get(i).getAsJsonObject(); - WxCpMenu.WxMenuButton button = convertFromJson(buttonJson); - menu.getButtons().add(button); - if (buttonJson.get("sub_button") == null || buttonJson.get("sub_button").isJsonNull()) { - continue; - } - JsonArray sub_buttonsJson = buttonJson.get("sub_button").getAsJsonArray(); - for (int j = 0; j < sub_buttonsJson.size(); j++) { - JsonObject sub_buttonJson = sub_buttonsJson.get(j).getAsJsonObject(); - button.getSubButtons().add(convertFromJson(sub_buttonJson)); - } - } - return menu; - } - - protected WxCpMenu.WxMenuButton convertFromJson(JsonObject json) { - WxCpMenu.WxMenuButton button = new WxCpMenu.WxMenuButton(); - button.setName(GsonHelper.getString(json, "name")); - button.setKey(GsonHelper.getString(json, "key")); - button.setUrl(GsonHelper.getString(json, "url")); - button.setType(GsonHelper.getString(json, "type")); - return button; - } - -} diff --git a/weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/bean/WxCpMenuTest.java b/weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/bean/WxCpMenuTest.java deleted file mode 100644 index 56802a657..000000000 --- a/weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/bean/WxCpMenuTest.java +++ /dev/null @@ -1,111 +0,0 @@ -package me.chanjar.weixin.enterprise.bean; - -import org.testng.Assert; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - -import me.chanjar.weixin.enterprise.bean.WxCpMenu.WxMenuButton; - -@Test -public class WxCpMenuTest { - - @Test(dataProvider="wxReturnMenu") - public void testFromJson(String json) { - WxCpMenu menu = WxCpMenu.fromJson(json); - Assert.assertEquals(menu.getButtons().size(), 3); - } - - @Test(dataProvider="wxPushMenu") - public void testToJson(String json) { - WxCpMenu menu = new WxCpMenu(); - WxMenuButton button1 = new WxMenuButton(); - button1.setType("click"); - button1.setName("今日歌曲"); - button1.setKey("V1001_TODAY_MUSIC"); - - WxMenuButton button2 = new WxMenuButton(); - button2.setType("click"); - button2.setName("歌手简介"); - button2.setKey("V1001_TODAY_SINGER"); - - WxMenuButton button3 = new WxMenuButton(); - button3.setName("菜单"); - - menu.getButtons().add(button1); - menu.getButtons().add(button2); - menu.getButtons().add(button3); - - WxMenuButton button31 = new WxMenuButton(); - button31.setType("view"); - button31.setName("搜索"); - button31.setUrl("http://www.soso.com/"); - - WxMenuButton button32 = new WxMenuButton(); - button32.setType("view"); - button32.setName("视频"); - button32.setUrl("http://v.qq.com/"); - - WxMenuButton button33 = new WxMenuButton(); - button33.setType("click"); - button33.setName("赞一下我们"); - button33.setKey("V1001_GOOD"); - - button3.getSubButtons().add(button31); - button3.getSubButtons().add(button32); - button3.getSubButtons().add(button33); - - Assert.assertEquals(menu.toJson(), json); - } - - @DataProvider - public Object[][] wxReturnMenu() { - Object[][] res = menuJson(); - String json = "{ \"menu\" : " + res[0][0] + " }"; - return new Object[][] { - new Object[] { json } - }; - } - - @DataProvider(name="wxPushMenu") - public Object[][] menuJson() { - String json = - "{" - +"\"button\":[" - +"{" - +"\"type\":\"click\"," - +"\"name\":\"今日歌曲\"," - +"\"key\":\"V1001_TODAY_MUSIC\"" - +"}," - +"{" - +"\"type\":\"click\"," - +"\"name\":\"歌手简介\"," - +"\"key\":\"V1001_TODAY_SINGER\"" - +"}," - +"{" - +"\"name\":\"菜单\"," - +"\"sub_button\":[" - +"{" - +"\"type\":\"view\"," - +"\"name\":\"搜索\"," - +"\"url\":\"http://www.soso.com/\"" - +"}," - +"{" - +"\"type\":\"view\"," - +"\"name\":\"视频\"," - +"\"url\":\"http://v.qq.com/\"" - +"}," - +"{" - +"\"type\":\"click\"," - +"\"name\":\"赞一下我们\"," - +"\"key\":\"V1001_GOOD\"" - +"}" - +"]" - +"}" - +"]" - +"}"; - return new Object[][] { - new Object[] { json } - }; - } - -} diff --git a/weixin-java-enterprise/src/test/resources/testng.xml b/weixin-java-enterprise/src/test/resources/testng.xml deleted file mode 100644 index 3c65a32c7..000000000 --- a/weixin-java-enterprise/src/test/resources/testng.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/weixin-java-mp/README.md b/weixin-java-mp/README.md index 0dbe54664..52e1aeb98 100644 --- a/weixin-java-mp/README.md +++ b/weixin-java-mp/README.md @@ -40,10 +40,11 @@ weixin-java-tools ## Hello World ```java -WxConfigStorage config = new WxInMemoryConfigStorage(); -config.setAppId(...); // 设置微信公众号的appid -config.setSecret(...); // 设置微信公众号的app secret -config.setToken(...); // 设置微信公众号的token +WxInMemoryConfigStorage config = new WxInMemoryConfigStorage(); +config.setAppId(...); // 设置微信公众号的appid +config.setSecret(...); // 设置微信公众号的app secret +config.setToken(...); // 设置微信公众号的token +config.setAesKey(...); // 设置微信公众号的EncodingAESKey WxServiceImpl wxService = new WxServiceImpl(); wxService.setWxConfigStorage(config); diff --git a/weixin-java-mp/pom.xml b/weixin-java-mp/pom.xml index fbcf60a7d..c2477c3f5 100644 --- a/weixin-java-mp/pom.xml +++ b/weixin-java-mp/pom.xml @@ -3,76 +3,26 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 4.0.0 - me.chanjar - weixin-java-mp-tools - 1.0.3-SNAPSHOT - WeiXin Java MP Tools + + me.chanjar + weixin-java-parent + 1.0.3-SNAPSHOT + + weixin-java-mp + WeiXin Java Tools - MP 微信公众号Java SDK - https://github.com/chanjarster/weixin-java-tools - - - The Apache License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt - - - - - - Daniel Qian - chanjarster@gmail.com - - - - - scm:git:https://github.com/chanjarster/weixin-java-tools.git - scm:git:git@github.com:chanjarster/weixin-java-tools.git - https://github.com/chanjarster/weixin-java-tools - - - - UTF-8 - true - true - 4.3.5 - + + me.chanjar + weixin-java-common + ${project.version} + junit junit - 4.11 test - - org.apache.httpcomponents - fluent-hc - ${httpclient.version} - - - org.apache.httpcomponents - httpmime - ${httpclient.version} - - - javax.xml.bind - jaxb-api - 2.2.7 - - - com.sun.xml.bind - jaxb-impl - 2.2.7 - - - org.apache.oltu.oauth2 - org.apache.oltu.oauth2.client - 1.0.0 - - - com.google.code.gson - gson - 2.2.2 - org.testng testng @@ -91,21 +41,6 @@ 3.0 test - - org.apache.commons - commons-lang3 - 3.1 - - - commons-codec - commons-codec - 1.9 - - - commons-io - commons-io - 2.4 - org.eclipse.jetty jetty-server @@ -120,107 +55,18 @@ - - - ossrh - https://oss.sonatype.org/content/repositories/snapshots - - - ossrh - https://oss.sonatype.org/service/local/staging/deploy/maven2/ - - - - - - release - - - - org.apache.maven.plugins - maven-source-plugin - 2.2.1 - - - attach-sources - - jar-no-fork - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.9.1 - - - attach-javadocs - - jar - - - - - UTF-8 - zh_CN - - - - org.apache.maven.plugins - maven-gpg-plugin - 1.5 - - - sign-artifacts - verify - - sign - - - - - - - - - org.apache.maven.plugins maven-surefire-plugin - 2.17 src/test/resources/testng.xml - - org.sonatype.plugins - nexus-staging-maven-plugin - 1.6.3 - true - - ossrh - https://oss.sonatype.org/ - false - - - - org.apache.maven.plugins - maven-release-plugin - 2.5 - - true - false - release - deploy - - - diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxConfigStorage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpConfigStorage.java similarity index 82% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxConfigStorage.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpConfigStorage.java index 7c6cc4e50..e90013ffa 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxConfigStorage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpConfigStorage.java @@ -1,13 +1,13 @@ package me.chanjar.weixin.mp.api; -import me.chanjar.weixin.mp.bean.WxAccessToken; +import me.chanjar.weixin.common.bean.WxAccessToken; /** * 微信客户端配置存储 * @author chanjarster * */ -public interface WxConfigStorage { +public interface WxMpConfigStorage { public void updateAccessToken(WxAccessToken accessToken); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxConsts.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpConsts.java similarity index 99% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxConsts.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpConsts.java index 49617cdaf..2f579cfeb 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxConsts.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpConsts.java @@ -3,7 +3,7 @@ package me.chanjar.weixin.mp.api; import java.util.HashMap; import java.util.Map; -public class WxConsts { +public class WxMpConsts { /////////////////////// // 微信推送过来的消息的类型,和发送给微信xml格式消息的消息类型 diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxInMemoryConfigStorage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpInMemoryConfigStorage.java similarity index 92% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxInMemoryConfigStorage.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpInMemoryConfigStorage.java index 1656fa831..0218067b3 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxInMemoryConfigStorage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpInMemoryConfigStorage.java @@ -1,13 +1,13 @@ package me.chanjar.weixin.mp.api; -import me.chanjar.weixin.mp.bean.WxAccessToken; +import me.chanjar.weixin.common.bean.WxAccessToken; /** * 基于内存的微信配置provider,在实际生产环境中应该将这些配置持久化 * @author chanjarster * */ -public class WxInMemoryConfigStorage implements WxConfigStorage { +public class WxMpInMemoryConfigStorage implements WxMpConfigStorage { protected String appId; protected String secret; diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMessageHandler.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageHandler.java similarity index 62% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMessageHandler.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageHandler.java index 0c8c3b330..e80ff5a1f 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMessageHandler.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageHandler.java @@ -1,16 +1,16 @@ package me.chanjar.weixin.mp.api; -import java.util.Map; +import me.chanjar.weixin.mp.bean.WxMpXmlMessage; +import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage; -import me.chanjar.weixin.mp.bean.WxXmlMessage; -import me.chanjar.weixin.mp.bean.WxXmlOutMessage; +import java.util.Map; /** * 处理微信推送消息的处理器接口 * @author chanjarster * */ -public interface WxMessageHandler { +public interface WxMpMessageHandler { /** * @@ -18,6 +18,6 @@ public interface WxMessageHandler { * @param context 上下文,如果handler或interceptor之间有信息要传递,可以用这个 * @return xml格式的消息,如果在异步规则里处理的话,可以返回null */ - public WxXmlOutMessage handle(WxXmlMessage wxMessage, Map context); + public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map context); } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMessageInterceptor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageInterceptor.java similarity index 66% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMessageInterceptor.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageInterceptor.java index 22b3e8f8c..901defeae 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMessageInterceptor.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageInterceptor.java @@ -1,15 +1,15 @@ package me.chanjar.weixin.mp.api; -import java.util.Map; +import me.chanjar.weixin.mp.bean.WxMpXmlMessage; -import me.chanjar.weixin.mp.bean.WxXmlMessage; +import java.util.Map; /** * 微信消息拦截器,可以用来做验证 * @author qianjia * */ -public interface WxMessageInterceptor { +public interface WxMpMessageInterceptor { /** * 拦截微信消息 @@ -17,6 +17,6 @@ public interface WxMessageInterceptor { * @param context 上下文,如果handler或interceptor之间有信息要传递,可以用这个 * @return true代表OK,false代表不OK */ - public boolean intercept(WxXmlMessage wxMessage, Map context); + public boolean intercept(WxMpXmlMessage wxMessage, Map context); } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMessageRouter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageRouter.java similarity index 80% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMessageRouter.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageRouter.java index 00ea678b7..f49cafe63 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMessageRouter.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMessageRouter.java @@ -1,5 +1,8 @@ package me.chanjar.weixin.mp.api; +import me.chanjar.weixin.mp.bean.WxMpXmlMessage; +import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage; + import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -8,9 +11,6 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.regex.Pattern; -import me.chanjar.weixin.mp.bean.WxXmlMessage; -import me.chanjar.weixin.mp.bean.WxXmlOutMessage; - /** *
  * 微信消息路由器,通过代码化的配置,把来自微信的消息交给handler处理
@@ -21,7 +21,7 @@ import me.chanjar.weixin.mp.bean.WxXmlOutMessage;
  * 3. 规则的结束必须用{@link Rule#end()}或者{@link Rule#next()},否则不会生效
  * 
  * 使用方法:
- * WxMessageRouter router = new WxMessageRouter();
+ * WxMpMessageRouter router = new WxMpMessageRouter();
  * router
  *   .rule()
  *       .msgType("MSG_TYPE").event("EVENT").eventKey("EVENT_KEY").content("CONTENT")
@@ -39,7 +39,7 @@ import me.chanjar.weixin.mp.bean.WxXmlOutMessage;
  * @author qianjia
  *
  */
-public class WxMessageRouter {
+public class WxMpMessageRouter {
   
   private final List rules = new ArrayList();
 
@@ -57,7 +57,7 @@ public class WxMessageRouter {
    * 处理微信消息
    * @param wxMessage
    */
-  public WxXmlOutMessage route(final WxXmlMessage wxMessage) {
+  public WxMpXmlOutMessage route(final WxMpXmlMessage wxMessage) {
     final List matchRules = new ArrayList();
     // 收集匹配的规则
     for (final Rule rule : rules) {
@@ -86,7 +86,7 @@ public class WxMessageRouter {
       return null;
     }
     
-    WxXmlOutMessage res = null;
+    WxMpXmlOutMessage res = null;
     for (final Rule rule : matchRules) {
       // 返回最后一个匹配规则的结果
       res = rule.service(wxMessage);
@@ -99,7 +99,7 @@ public class WxMessageRouter {
   
   public static class Rule {
     
-    private final WxMessageRouter routerBuilder;
+    private final WxMpMessageRouter routerBuilder;
 
     private boolean async = true;
     
@@ -115,11 +115,11 @@ public class WxMessageRouter {
     
     private boolean reEnter = false;
     
-    private List handlers = new ArrayList();
+    private List handlers = new ArrayList();
     
-    private List interceptors = new ArrayList();
+    private List interceptors = new ArrayList();
     
-    protected Rule(WxMessageRouter routerBuilder) {
+    protected Rule(WxMpMessageRouter routerBuilder) {
       this.routerBuilder = routerBuilder;
     }
     
@@ -188,8 +188,8 @@ public class WxMessageRouter {
      * @param interceptor
      * @return
      */
-    public Rule interceptor(WxMessageInterceptor interceptor) {
-      return interceptor(interceptor, (WxMessageInterceptor[]) null);
+    public Rule interceptor(WxMpMessageInterceptor interceptor) {
+      return interceptor(interceptor, (WxMpMessageInterceptor[]) null);
     }
     
     /**
@@ -198,10 +198,10 @@ public class WxMessageRouter {
      * @param otherInterceptors
      * @return
      */
-    public Rule interceptor(WxMessageInterceptor interceptor, WxMessageInterceptor... otherInterceptors) {
+    public Rule interceptor(WxMpMessageInterceptor interceptor, WxMpMessageInterceptor... otherInterceptors) {
       this.interceptors.add(interceptor);
       if (otherInterceptors != null && otherInterceptors.length > 0) {
-        for (WxMessageInterceptor i : otherInterceptors) {
+        for (WxMpMessageInterceptor i : otherInterceptors) {
           this.interceptors.add(i);
         }
       }
@@ -213,8 +213,8 @@ public class WxMessageRouter {
      * @param handler
      * @return
      */
-    public Rule handler(WxMessageHandler handler) {
-      return handler(handler, (WxMessageHandler[]) null);
+    public Rule handler(WxMpMessageHandler handler) {
+      return handler(handler, (WxMpMessageHandler[]) null);
     }
     
     /**
@@ -223,10 +223,10 @@ public class WxMessageRouter {
      * @param otherHandlers
      * @return
      */
-    public Rule handler(WxMessageHandler handler, WxMessageHandler... otherHandlers) {
+    public Rule handler(WxMpMessageHandler handler, WxMpMessageHandler... otherHandlers) {
       this.handlers.add(handler);
       if (otherHandlers != null && otherHandlers.length > 0) {
-        for (WxMessageHandler i : otherHandlers) {
+        for (WxMpMessageHandler i : otherHandlers) {
           this.handlers.add(i);
         }
       }
@@ -237,7 +237,7 @@ public class WxMessageRouter {
      * 规则结束,代表如果一个消息匹配该规则,那么它将不再会进入其他规则
      * @return
      */
-    public WxMessageRouter end() {
+    public WxMpMessageRouter end() {
       this.routerBuilder.rules.add(this);
       return this.routerBuilder;
     }
@@ -246,12 +246,12 @@ public class WxMessageRouter {
      * 规则结束,但是消息还会进入其他规则
      * @return
      */
-    public WxMessageRouter next() {
+    public WxMpMessageRouter next() {
       this.reEnter = true;
       return end();
     }
     
-    protected boolean test(WxXmlMessage wxMessage) {
+    protected boolean test(WxMpXmlMessage wxMessage) {
       return 
           (this.msgType == null || this.msgType.equals(wxMessage.getMsgType()))
           &&
@@ -270,18 +270,18 @@ public class WxMessageRouter {
      * @param wxMessage
      * @return true 代表继续执行别的router,false 代表停止执行别的router
      */
-    protected WxXmlOutMessage service(WxXmlMessage wxMessage) {
+    protected WxMpXmlOutMessage service(WxMpXmlMessage wxMessage) {
       Map context = new HashMap();
       // 如果拦截器不通过
-      for (WxMessageInterceptor interceptor : this.interceptors) {
+      for (WxMpMessageInterceptor interceptor : this.interceptors) {
         if (!interceptor.intercept(wxMessage, context)) {
           return null;
         }
       }
       
       // 交给handler处理
-      WxXmlOutMessage res = null;
-      for (WxMessageHandler handler : this.handlers) {
+      WxMpXmlOutMessage res = null;
+      for (WxMpMessageHandler handler : this.handlers) {
         // 返回最后handler的结果
         res = handler.handle(wxMessage, context);
       }
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java
similarity index 76%
rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxService.java
rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java
index 9e37227ac..83065d2c0 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxService.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java
@@ -1,29 +1,20 @@
 package me.chanjar.weixin.mp.api;
 
+import me.chanjar.weixin.common.bean.WxMenu;
+import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
+import me.chanjar.weixin.mp.bean.*;
+import me.chanjar.weixin.mp.bean.result.*;
+import me.chanjar.weixin.common.exception.WxErrorException;
+
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.List;
 
-import me.chanjar.weixin.mp.bean.WxCustomMessage;
-import me.chanjar.weixin.mp.bean.WxGroup;
-import me.chanjar.weixin.mp.bean.WxMassGroupMessage;
-import me.chanjar.weixin.mp.bean.WxMassNews;
-import me.chanjar.weixin.mp.bean.WxMassOpenIdsMessage;
-import me.chanjar.weixin.mp.bean.WxMassVideo;
-import me.chanjar.weixin.mp.bean.WxMenu;
-import me.chanjar.weixin.mp.bean.result.WxMassSendResult;
-import me.chanjar.weixin.mp.bean.result.WxMassUploadResult;
-import me.chanjar.weixin.mp.bean.result.WxMediaUploadResult;
-import me.chanjar.weixin.mp.bean.result.WxQrCodeTicket;
-import me.chanjar.weixin.mp.bean.result.WxUser;
-import me.chanjar.weixin.mp.bean.result.WxUserList;
-import me.chanjar.weixin.mp.exception.WxErrorException;
-
 /**
  * 微信API的Service
  */
-public interface WxService {
+public interface WxMpService {
   
   /**
    * 
@@ -48,7 +39,7 @@ public interface WxService {
 
    * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=获取access_token
    * 
- * @throws me.chanjar.weixin.mp.exception.WxErrorException + * @throws me.chanjar.weixin.common.exception.WxErrorException */ public void accessTokenRefresh() throws WxErrorException; @@ -64,8 +55,8 @@ public interface WxService { * * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=上传下载多媒体文件 *
- * @param mediaType 媒体类型, 请看{@link WxConsts} - * @param fileType 文件类型,请看{@link WxConsts} + * @param mediaType 媒体类型, 请看{@link WxMpConsts} + * @param fileType 文件类型,请看{@link WxMpConsts} * @param inputStream 输入流 * @throws WxErrorException */ @@ -99,7 +90,7 @@ public interface WxService { * @param message * @throws WxErrorException */ - public void customMessageSend(WxCustomMessage message) throws WxErrorException; + public void customMessageSend(WxMpCustomMessage message) throws WxErrorException; /** *
@@ -109,10 +100,10 @@ public interface WxService {
    * 
* @param news * @throws WxErrorException - * @see #massGroupMessageSend(me.chanjar.weixin.mp.bean.WxMassGroupMessage) - * @see #massOpenIdsMessageSend(me.chanjar.weixin.mp.bean.WxMassOpenIdsMessage) + * @see #massGroupMessageSend(me.chanjar.weixin.mp.bean.WxMpMassGroupMessage) + * @see #massOpenIdsMessageSend(me.chanjar.weixin.mp.bean.WxMpMassOpenIdsMessage) */ - public WxMassUploadResult massNewsUpload(WxMassNews news) throws WxErrorException; + public WxMpMassUploadResult massNewsUpload(WxMpMassNews news) throws WxErrorException; /** *
@@ -121,36 +112,36 @@ public interface WxService {
    * 
* @return * @throws WxErrorException - * @see #massGroupMessageSend(me.chanjar.weixin.mp.bean.WxMassGroupMessage) - * @see #massOpenIdsMessageSend(me.chanjar.weixin.mp.bean.WxMassOpenIdsMessage) + * @see #massGroupMessageSend(me.chanjar.weixin.mp.bean.WxMpMassGroupMessage) + * @see #massOpenIdsMessageSend(me.chanjar.weixin.mp.bean.WxMpMassOpenIdsMessage) */ - public WxMassUploadResult massVideoUpload(WxMassVideo video) throws WxErrorException; + public WxMpMassUploadResult massVideoUpload(WxMpMassVideo video) throws WxErrorException; /** *
    * 分组群发消息
-   * 如果发送图文消息,必须先使用 {@link #massNewsUpload(WxMassNews)} 获得media_id,然后再发送
-   * 如果发送视频消息,必须先使用 {@link #massVideoUpload(WxMassVideo)} 获得media_id,然后再发送
+   * 如果发送图文消息,必须先使用 {@link #massNewsUpload(me.chanjar.weixin.mp.bean.WxMpMassNews)} 获得media_id,然后再发送
+   * 如果发送视频消息,必须先使用 {@link #massVideoUpload(me.chanjar.weixin.mp.bean.WxMpMassVideo)} 获得media_id,然后再发送
    * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=高级群发接口
    * 
* @param message * @throws WxErrorException * @return */ - public WxMassSendResult massGroupMessageSend(WxMassGroupMessage message) throws WxErrorException; + public WxMpMassSendResult massGroupMessageSend(WxMpMassGroupMessage message) throws WxErrorException; /** *
    * 按openId列表群发消息
-   * 如果发送图文消息,必须先使用 {@link #massNewsUpload(WxMassNews)} 获得media_id,然后再发送
-   * 如果发送视频消息,必须先使用 {@link #massVideoUpload(WxMassVideo)} 获得media_id,然后再发送
+   * 如果发送图文消息,必须先使用 {@link #massNewsUpload(me.chanjar.weixin.mp.bean.WxMpMassNews)} 获得media_id,然后再发送
+   * 如果发送视频消息,必须先使用 {@link #massVideoUpload(me.chanjar.weixin.mp.bean.WxMpMassVideo)} 获得media_id,然后再发送
    * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=高级群发接口
    * 
* @param message * @return * @throws WxErrorException */ - public WxMassSendResult massOpenIdsMessageSend(WxMassOpenIdsMessage message) throws WxErrorException; + public WxMpMassSendResult massOpenIdsMessageSend(WxMpMassOpenIdsMessage message) throws WxErrorException; /** *
@@ -190,7 +181,7 @@ public interface WxService {
    * @param name 分组名字(30个字符以内) 
    * @throws WxErrorException
    */
-  public WxGroup groupCreate(String name) throws WxErrorException;
+  public WxMpGroup groupCreate(String name) throws WxErrorException;
   
   /**
    * 
@@ -200,7 +191,7 @@ public interface WxService {
    * @return
    * @throws WxErrorException
    */
-  public List groupGet() throws WxErrorException;
+  public List groupGet() throws WxErrorException;
   
   /**
    * 
@@ -222,7 +213,7 @@ public interface WxService {
    * @param group 要更新的group,group的id,name必须设置 
    * @throws WxErrorException
    */
-  public void groupUpdate(WxGroup group) throws WxErrorException;
+  public void groupUpdate(WxMpGroup group) throws WxErrorException;
   
   /**
    * 
@@ -258,7 +249,7 @@ public interface WxService {
    * @return
    * @throws WxErrorException
    */
-  public WxUser userInfo(String openid, String lang) throws WxErrorException;
+  public WxMpUser userInfo(String openid, String lang) throws WxErrorException;
 
   /**
    * 
@@ -269,7 +260,7 @@ public interface WxService {
    * @return
    * @throws WxErrorException
    */
-  public WxUserList userList(String next_openid) throws WxErrorException;
+  public WxMpUserList userList(String next_openid) throws WxErrorException;
 
   /**
    * 
@@ -281,7 +272,7 @@ public interface WxService {
    * @return
    * @throws WxErrorException
    */
-  public WxQrCodeTicket qrCodeCreateTmpTicket(int scene_id, Integer expire_seconds) throws WxErrorException;
+  public WxMpQrCodeTicket qrCodeCreateTmpTicket(int scene_id, Integer expire_seconds) throws WxErrorException;
 
   /**
    * 
@@ -292,7 +283,7 @@ public interface WxService {
    * @return
    * @throws WxErrorException
    */
-  public WxQrCodeTicket qrCodeCreateLastTicket(int scene_id) throws WxErrorException;
+  public WxMpQrCodeTicket qrCodeCreateLastTicket(int scene_id) throws WxErrorException;
 
   /**
    * 
@@ -303,7 +294,7 @@ public interface WxService {
    * @return
    * @throws WxErrorException
    */
-  public File qrCodePicture(WxQrCodeTicket ticket) throws WxErrorException;
+  public File qrCodePicture(WxMpQrCodeTicket ticket) throws WxErrorException;
 
   /**
    * 
@@ -317,8 +308,8 @@ public interface WxService {
   public String shortUrl(String long_url) throws WxErrorException;
   
   /**
-   * 注入 {@link WxConfigStorage} 的实现
+   * 注入 {@link WxMpConfigStorage} 的实现
    * @param wxConfigProvider
    */
-  public void setWxConfigStorage(WxConfigStorage wxConfigProvider);
+  public void setWxMpConfigStorage(WxMpConfigStorage wxConfigProvider);
 }
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java
similarity index 76%
rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxServiceImpl.java
rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java
index a81bc0680..c40af33d7 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxServiceImpl.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java
@@ -1,5 +1,31 @@
 package me.chanjar.weixin.mp.api;
 
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.internal.Streams;
+import com.google.gson.reflect.TypeToken;
+import com.google.gson.stream.JsonReader;
+import me.chanjar.weixin.common.bean.WxAccessToken;
+import me.chanjar.weixin.common.bean.WxMenu;
+import me.chanjar.weixin.common.bean.result.WxError;
+import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
+import me.chanjar.weixin.common.exception.WxErrorException;
+import me.chanjar.weixin.common.util.crypto.SHA1;
+import me.chanjar.weixin.common.util.fs.FileUtils;
+import me.chanjar.weixin.common.util.http.*;
+import me.chanjar.weixin.common.util.json.GsonHelper;
+import me.chanjar.weixin.mp.bean.*;
+import me.chanjar.weixin.mp.bean.result.*;
+import me.chanjar.weixin.mp.util.http.QrCodeRequestExecutor;
+import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.BasicResponseHandler;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
@@ -8,48 +34,7 @@ import java.util.List;
 import java.util.UUID;
 import java.util.concurrent.atomic.AtomicBoolean;
 
-import me.chanjar.weixin.mp.bean.WxCustomMessage;
-import me.chanjar.weixin.mp.bean.result.WxError;
-import me.chanjar.weixin.mp.bean.result.WxMassSendResult;
-import me.chanjar.weixin.mp.bean.result.WxMediaUploadResult;
-import me.chanjar.weixin.mp.bean.result.WxUserList;
-import me.chanjar.weixin.mp.exception.WxErrorException;
-import me.chanjar.weixin.mp.util.crypto.SHA1;
-import me.chanjar.weixin.mp.util.json.GsonHelper;
-import me.chanjar.weixin.mp.util.json.WxGsonBuilder;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.http.client.ClientProtocolException;
-import org.apache.http.client.methods.CloseableHttpResponse;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.impl.client.BasicResponseHandler;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClients;
-
-import me.chanjar.weixin.mp.bean.WxAccessToken;
-import me.chanjar.weixin.mp.bean.WxGroup;
-import me.chanjar.weixin.mp.bean.WxMassGroupMessage;
-import me.chanjar.weixin.mp.bean.WxMassNews;
-import me.chanjar.weixin.mp.bean.WxMassOpenIdsMessage;
-import me.chanjar.weixin.mp.bean.WxMassVideo;
-import me.chanjar.weixin.mp.bean.WxMenu;
-import me.chanjar.weixin.mp.bean.result.WxMassUploadResult;
-import me.chanjar.weixin.mp.bean.result.WxQrCodeTicket;
-import me.chanjar.weixin.mp.bean.result.WxUser;
-import me.chanjar.weixin.mp.util.fs.FileUtils;
-import me.chanjar.weixin.mp.util.http.MediaDownloadRequestExecutor;
-import me.chanjar.weixin.mp.util.http.MediaUploadRequestExecutor;
-import me.chanjar.weixin.mp.util.http.QrCodeRequestExecutor;
-import me.chanjar.weixin.mp.util.http.RequestExecutor;
-import me.chanjar.weixin.mp.util.http.SimpleGetRequestExecutor;
-import me.chanjar.weixin.mp.util.http.SimplePostRequestExecutor;
-
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import com.google.gson.internal.Streams;
-import com.google.gson.reflect.TypeToken;
-import com.google.gson.stream.JsonReader;
-
-public class WxServiceImpl implements WxService {
+public class WxMpServiceImpl implements WxMpService {
 
   /**
    * 全局的是否正在刷新Access Token的flag
@@ -60,13 +45,13 @@ public class WxServiceImpl implements WxService {
   
   protected static final CloseableHttpClient httpclient = HttpClients.createDefault();
   
-  protected WxConfigStorage wxConfigStorage;
+  protected WxMpConfigStorage wxMpConfigStorage;
   
   protected final ThreadLocal retryTimes = new ThreadLocal();
 
   public boolean checkSignature(String timestamp, String nonce, String signature) {
     try {
-      return SHA1.gen(wxConfigStorage.getToken(), timestamp, nonce).equals(signature);
+      return SHA1.gen(wxMpConfigStorage.getToken(), timestamp, nonce).equals(signature);
     } catch (Exception e) {
       return false;
     }
@@ -76,8 +61,8 @@ public class WxServiceImpl implements WxService {
     if (!GLOBAL_ACCESS_TOKEN_REFRESH_FLAG.getAndSet(true)) {
       try {
         String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential"
-            + "&appid=" + wxConfigStorage.getAppId() 
-            + "&secret=" + wxConfigStorage.getSecret()
+            + "&appid=" + wxMpConfigStorage.getAppId()
+            + "&secret=" + wxMpConfigStorage.getSecret()
             ;
         try {
           HttpGet httpGet = new HttpGet(url);
@@ -88,7 +73,7 @@ public class WxServiceImpl implements WxService {
             throw new WxErrorException(error);
           }
           WxAccessToken accessToken = WxAccessToken.fromJson(resultContent);
-          wxConfigStorage.updateAccessToken(accessToken.getAccessToken(), accessToken.getExpiresIn());
+          wxMpConfigStorage.updateAccessToken(accessToken.getAccessToken(), accessToken.getExpiresIn());
         } catch (ClientProtocolException e) {
           throw new RuntimeException(e);
         } catch (IOException e) {
@@ -109,7 +94,7 @@ public class WxServiceImpl implements WxService {
     }
   }
   
-  public void customMessageSend(WxCustomMessage message) throws WxErrorException {
+  public void customMessageSend(WxMpCustomMessage message) throws WxErrorException {
     String url = "https://api.weixin.qq.com/cgi-bin/message/custom/send";
     execute(new SimplePostRequestExecutor(), url, message.toJson());
   }
@@ -152,31 +137,31 @@ public class WxServiceImpl implements WxService {
     return execute(new MediaDownloadRequestExecutor(), url, "media_id=" + media_id);
   }
 
-  public WxMassUploadResult massNewsUpload(WxMassNews news) throws WxErrorException {
+  public WxMpMassUploadResult massNewsUpload(WxMpMassNews news) throws WxErrorException {
     String url = "https://api.weixin.qq.com/cgi-bin/media/uploadnews";
     String responseContent = execute(new SimplePostRequestExecutor(), url, news.toJson());
-    return WxMassUploadResult.fromJson(responseContent);
+    return WxMpMassUploadResult.fromJson(responseContent);
   }
   
-  public WxMassUploadResult massVideoUpload(WxMassVideo video) throws WxErrorException {
+  public WxMpMassUploadResult massVideoUpload(WxMpMassVideo video) throws WxErrorException {
     String url = "http://file.api.weixin.qq.com/cgi-bin/media/uploadvideo";
     String responseContent = execute(new SimplePostRequestExecutor(), url, video.toJson());
-    return WxMassUploadResult.fromJson(responseContent);
+    return WxMpMassUploadResult.fromJson(responseContent);
   }
   
-  public WxMassSendResult massGroupMessageSend(WxMassGroupMessage message) throws WxErrorException {
+  public WxMpMassSendResult massGroupMessageSend(WxMpMassGroupMessage message) throws WxErrorException {
     String url = "https://api.weixin.qq.com/cgi-bin/message/mass/sendall";
     String responseContent = execute(new SimplePostRequestExecutor(), url, message.toJson());
-    return WxMassSendResult.fromJson(responseContent);
+    return WxMpMassSendResult.fromJson(responseContent);
   }
 
-  public WxMassSendResult massOpenIdsMessageSend(WxMassOpenIdsMessage message) throws WxErrorException {
+  public WxMpMassSendResult massOpenIdsMessageSend(WxMpMassOpenIdsMessage message) throws WxErrorException {
     String url = "https://api.weixin.qq.com/cgi-bin/message/mass/send";
     String responseContent = execute(new SimplePostRequestExecutor(), url, message.toJson());
-    return WxMassSendResult.fromJson(responseContent);
+    return WxMpMassSendResult.fromJson(responseContent);
   }
   
-  public WxGroup groupCreate(String name) throws WxErrorException {
+  public WxMpGroup groupCreate(String name) throws WxErrorException {
     String url = "https://api.weixin.qq.com/cgi-bin/groups/create";
     JsonObject json = new JsonObject();
     JsonObject groupJson = new JsonObject();
@@ -187,10 +172,10 @@ public class WxServiceImpl implements WxService {
         new SimplePostRequestExecutor(), 
         url, 
         json.toString());
-    return WxGroup.fromJson(responseContent);
+    return WxMpGroup.fromJson(responseContent);
   }
 
-  public List groupGet() throws WxErrorException {
+  public List groupGet() throws WxErrorException {
     String url = "https://api.weixin.qq.com/cgi-bin/groups/get";
     String responseContent = execute(new SimpleGetRequestExecutor(), url, null);
     /*
@@ -198,7 +183,7 @@ public class WxServiceImpl implements WxService {
      * 查询时返回的是 { groups : [ { id : ..., name : ..., count : ... }, ... ] }
      */
     JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
-    return WxGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement.getAsJsonObject().get("groups"), new TypeToken>(){}.getType());
+    return WxMpGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement.getAsJsonObject().get("groups"), new TypeToken>(){}.getType());
   }
   
   public long userGetGroup(String openid) throws WxErrorException {
@@ -210,7 +195,7 @@ public class WxServiceImpl implements WxService {
     return GsonHelper.getAsLong(tmpJsonElement.getAsJsonObject().get("groupid"));
   }
   
-  public void groupUpdate(WxGroup group) throws WxErrorException {
+  public void groupUpdate(WxMpGroup group) throws WxErrorException {
     String url = "https://api.weixin.qq.com/cgi-bin/groups/update";
     execute(new SimplePostRequestExecutor(), url, group.toJson());
   }
@@ -231,20 +216,20 @@ public class WxServiceImpl implements WxService {
     execute(new SimplePostRequestExecutor(), url, json.toString());
   }
   
-  public WxUser userInfo(String openid, String lang) throws WxErrorException {
+  public WxMpUser userInfo(String openid, String lang) throws WxErrorException {
     String url = "https://api.weixin.qq.com/cgi-bin/user/info";
     lang = lang == null ? "zh_CN" : lang;
     String responseContent = execute(new SimpleGetRequestExecutor(), url, "openid=" + openid + "&lang=" + lang);
-    return WxUser.fromJson(responseContent);
+    return WxMpUser.fromJson(responseContent);
   }
   
-  public WxUserList userList(String next_openid) throws WxErrorException {
+  public WxMpUserList userList(String next_openid) throws WxErrorException {
     String url = "https://api.weixin.qq.com/cgi-bin/user/get";
     String responseContent = execute(new SimpleGetRequestExecutor(), url, next_openid == null ? null : "next_openid=" + next_openid);
-    return WxUserList.fromJson(responseContent);
+    return WxMpUserList.fromJson(responseContent);
   }
   
-  public WxQrCodeTicket qrCodeCreateTmpTicket(int scene_id, Integer expire_seconds) throws WxErrorException {
+  public WxMpQrCodeTicket qrCodeCreateTmpTicket(int scene_id, Integer expire_seconds) throws WxErrorException {
     String url = "https://api.weixin.qq.com/cgi-bin/qrcode/create";
     JsonObject json = new JsonObject();
     json.addProperty("action_name", "QR_SCENE");
@@ -257,10 +242,10 @@ public class WxServiceImpl implements WxService {
     actionInfo.add("scene", scene);
     json.add("action_info", actionInfo);
     String responseContent = execute(new SimplePostRequestExecutor(), url, json.toString());
-    return WxQrCodeTicket.fromJson(responseContent);
+    return WxMpQrCodeTicket.fromJson(responseContent);
   }
   
-  public WxQrCodeTicket qrCodeCreateLastTicket(int scene_id) throws WxErrorException {
+  public WxMpQrCodeTicket qrCodeCreateLastTicket(int scene_id) throws WxErrorException {
     String url = "https://api.weixin.qq.com/cgi-bin/qrcode/create";
     JsonObject json = new JsonObject();
     json.addProperty("action_name", "QR_LIMIT_SCENE");
@@ -270,10 +255,10 @@ public class WxServiceImpl implements WxService {
     actionInfo.add("scene", scene);
     json.add("action_info", actionInfo);
     String responseContent = execute(new SimplePostRequestExecutor(), url, json.toString());
-    return WxQrCodeTicket.fromJson(responseContent);
+    return WxMpQrCodeTicket.fromJson(responseContent);
   }
   
-  public File qrCodePicture(WxQrCodeTicket ticket) throws WxErrorException {
+  public File qrCodePicture(WxMpQrCodeTicket ticket) throws WxErrorException {
     String url = "https://mp.weixin.qq.com/cgi-bin/showqrcode";
     return execute(new QrCodeRequestExecutor(), url, ticket);
   }
@@ -297,10 +282,10 @@ public class WxServiceImpl implements WxService {
    * @throws WxErrorException
    */
   public  T execute(RequestExecutor executor, String uri, E data) throws WxErrorException {
-    if (StringUtils.isBlank(wxConfigStorage.getAccessToken())) {
+    if (StringUtils.isBlank(wxMpConfigStorage.getAccessToken())) {
       accessTokenRefresh();
     }
-    String accessToken = wxConfigStorage.getAccessToken();
+    String accessToken = wxMpConfigStorage.getAccessToken();
     
     String uriWithAccessToken = uri;
     uriWithAccessToken += uri.indexOf('?') == -1 ? "?access_token=" + accessToken : "&access_token=" + accessToken;
@@ -350,8 +335,8 @@ public class WxServiceImpl implements WxService {
     }
   }
   
-  public void setWxConfigStorage(WxConfigStorage wxConfigProvider) {
-    this.wxConfigStorage = wxConfigProvider;
+  public void setWxMpConfigStorage(WxMpConfigStorage wxConfigProvider) {
+    this.wxMpConfigStorage = wxConfigProvider;
   }
 
 }
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxCustomMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpCustomMessage.java
similarity index 81%
rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxCustomMessage.java
rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpCustomMessage.java
index e832eb80d..dff95b3d5 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxCustomMessage.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpCustomMessage.java
@@ -1,23 +1,17 @@
 package me.chanjar.weixin.mp.bean;
 
+import me.chanjar.weixin.mp.bean.custombuilder.*;
+import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
+
 import java.util.ArrayList;
 import java.util.List;
 
-import me.chanjar.weixin.mp.api.WxConsts;
-import me.chanjar.weixin.mp.bean.custombuilder.ImageBuilder;
-import me.chanjar.weixin.mp.bean.custombuilder.MusicBuilder;
-import me.chanjar.weixin.mp.bean.custombuilder.NewsBuilder;
-import me.chanjar.weixin.mp.bean.custombuilder.TextBuilder;
-import me.chanjar.weixin.mp.bean.custombuilder.VideoBuilder;
-import me.chanjar.weixin.mp.bean.custombuilder.VoiceBuilder;
-import me.chanjar.weixin.mp.util.json.WxGsonBuilder;
-
 /**
  * 客服消息
  * @author chanjarster
  *
  */
-public class WxCustomMessage {
+public class WxMpCustomMessage {
 
   private String toUser;
   private String msgType;
@@ -43,12 +37,12 @@ public class WxCustomMessage {
   /**
    * 
    * 请使用
-   * {@link WxConsts#CUSTOM_MSG_TEXT}
-   * {@link WxConsts#CUSTOM_MSG_IMAGE}
-   * {@link WxConsts#CUSTOM_MSG_VOICE}
-   * {@link WxConsts#CUSTOM_MSG_MUSIC}
-   * {@link WxConsts#CUSTOM_MSG_VIDEO}
-   * {@link WxConsts#CUSTOM_MSG_NEWS}
+   * {@link me.chanjar.weixin.mp.api.WxMpConsts#CUSTOM_MSG_TEXT}
+   * {@link me.chanjar.weixin.mp.api.WxMpConsts#CUSTOM_MSG_IMAGE}
+   * {@link me.chanjar.weixin.mp.api.WxMpConsts#CUSTOM_MSG_VOICE}
+   * {@link me.chanjar.weixin.mp.api.WxMpConsts#CUSTOM_MSG_MUSIC}
+   * {@link me.chanjar.weixin.mp.api.WxMpConsts#CUSTOM_MSG_VIDEO}
+   * {@link me.chanjar.weixin.mp.api.WxMpConsts#CUSTOM_MSG_NEWS}
    * 
* @param msgType */ @@ -105,7 +99,7 @@ public class WxCustomMessage { } public String toJson() { - return WxGsonBuilder.INSTANCE.create().toJson(this); + return WxMpGsonBuilder.INSTANCE.create().toJson(this); } public static class WxArticle { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxGroup.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpGroup.java similarity index 63% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxGroup.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpGroup.java index be2388bf6..cfa5fcb6a 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxGroup.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpGroup.java @@ -1,13 +1,13 @@ package me.chanjar.weixin.mp.bean; -import me.chanjar.weixin.mp.util.json.WxGsonBuilder; +import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; /** * 微信用户分组 * @author chanjarster * */ -public class WxGroup { +public class WxMpGroup { private long id = -1; private String name; @@ -31,16 +31,16 @@ public class WxGroup { this.count = count; } - public static WxGroup fromJson(String json) { - return WxGsonBuilder.create().fromJson(json, WxGroup.class); + public static WxMpGroup fromJson(String json) { + return WxMpGsonBuilder.create().fromJson(json, WxMpGroup.class); } public String toJson() { - return WxGsonBuilder.create().toJson(this); + return WxMpGsonBuilder.create().toJson(this); } @Override public String toString() { - return "WxGroup [id=" + id + ", name=" + name + ", count=" + count + "]"; + return "WxMpGroup [id=" + id + ", name=" + name + ", count=" + count + "]"; } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMassGroupMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassGroupMessage.java similarity index 64% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMassGroupMessage.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassGroupMessage.java index 07c4dbae3..7aaebb3c0 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMassGroupMessage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassGroupMessage.java @@ -1,21 +1,20 @@ package me.chanjar.weixin.mp.bean; -import me.chanjar.weixin.mp.api.WxConsts; -import me.chanjar.weixin.mp.util.json.WxGsonBuilder; +import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; /** * 分组群发的消息 * * @author chanjarster */ -public class WxMassGroupMessage { +public class WxMpMassGroupMessage { private long groupId; private String msgtype; private String content; private String mediaId; - public WxMassGroupMessage() { + public WxMpMassGroupMessage() { super(); } @@ -26,11 +25,11 @@ public class WxMassGroupMessage { /** *
    * 请使用
-   * {@link WxConsts#MASS_MSG_IMAGE}
-   * {@link WxConsts#MASS_MSG_NEWS}
-   * {@link WxConsts#MASS_MSG_TEXT}
-   * {@link WxConsts#MASS_MSG_VIDEO}
-   * {@link WxConsts#MASS_MSG_VOICE}
+   * {@link me.chanjar.weixin.mp.api.WxMpConsts#MASS_MSG_IMAGE}
+   * {@link me.chanjar.weixin.mp.api.WxMpConsts#MASS_MSG_NEWS}
+   * {@link me.chanjar.weixin.mp.api.WxMpConsts#MASS_MSG_TEXT}
+   * {@link me.chanjar.weixin.mp.api.WxMpConsts#MASS_MSG_VIDEO}
+   * {@link me.chanjar.weixin.mp.api.WxMpConsts#MASS_MSG_VOICE}
    * 如果msgtype和media_id不匹配的话,会返回系统繁忙的错误
    * 
* @param msgtype @@ -56,7 +55,7 @@ public class WxMassGroupMessage { } public String toJson() { - return WxGsonBuilder.INSTANCE.create().toJson(this); + return WxMpGsonBuilder.INSTANCE.create().toJson(this); } public long getGroupId() { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMassNews.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassNews.java similarity index 95% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMassNews.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassNews.java index 01872005c..bbae8b263 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMassNews.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassNews.java @@ -1,16 +1,16 @@ package me.chanjar.weixin.mp.bean; +import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; + import java.util.ArrayList; import java.util.List; -import me.chanjar.weixin.mp.util.json.WxGsonBuilder; - /** * 群发时用到的图文消息素材 * @author chanjarster * */ -public class WxMassNews { +public class WxMpMassNews { private List articles = new ArrayList(); @@ -23,7 +23,7 @@ public class WxMassNews { } public String toJson() { - return WxGsonBuilder.INSTANCE.create().toJson(this); + return WxMpGsonBuilder.INSTANCE.create().toJson(this); } /** diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMassOpenIdsMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassOpenIdsMessage.java similarity index 69% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMassOpenIdsMessage.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassOpenIdsMessage.java index 8dc190d04..6fd18b286 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMassOpenIdsMessage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassOpenIdsMessage.java @@ -1,23 +1,23 @@ package me.chanjar.weixin.mp.bean; +import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; + import java.util.ArrayList; import java.util.List; -import me.chanjar.weixin.mp.util.json.WxGsonBuilder; - /** * OpenId列表群发的消息 * * @author chanjarster */ -public class WxMassOpenIdsMessage { +public class WxMpMassOpenIdsMessage { private List toUsers = new ArrayList(); private String msgType; private String content; private String mediaId; - public WxMassOpenIdsMessage() { + public WxMpMassOpenIdsMessage() { super(); } @@ -28,11 +28,11 @@ public class WxMassOpenIdsMessage { /** *
    * 请使用
-   * {@link me.chanjar.weixin.mp.api.WxConsts#MASS_MSG_IMAGE}
-   * {@link me.chanjar.weixin.mp.api.WxConsts#MASS_MSG_NEWS}
-   * {@link me.chanjar.weixin.mp.api.WxConsts#MASS_MSG_TEXT}
-   * {@link me.chanjar.weixin.mp.api.WxConsts#MASS_MSG_VIDEO}
-   * {@link me.chanjar.weixin.mp.api.WxConsts#MASS_MSG_VOICE}
+   * {@link me.chanjar.weixin.mp.api.WxMpConsts#MASS_MSG_IMAGE}
+   * {@link me.chanjar.weixin.mp.api.WxMpConsts#MASS_MSG_NEWS}
+   * {@link me.chanjar.weixin.mp.api.WxMpConsts#MASS_MSG_TEXT}
+   * {@link me.chanjar.weixin.mp.api.WxMpConsts#MASS_MSG_VIDEO}
+   * {@link me.chanjar.weixin.mp.api.WxMpConsts#MASS_MSG_VOICE}
    * 如果msgtype和media_id不匹配的话,会返回系统繁忙的错误
    * 
* @param msgType @@ -58,7 +58,7 @@ public class WxMassOpenIdsMessage { } public String toJson() { - return WxGsonBuilder.INSTANCE.create().toJson(this); + return WxMpGsonBuilder.INSTANCE.create().toJson(this); } /** diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMassVideo.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassVideo.java similarity index 81% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMassVideo.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassVideo.java index 4c89c80f5..3dc6c5d78 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMassVideo.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMassVideo.java @@ -1,13 +1,13 @@ package me.chanjar.weixin.mp.bean; -import me.chanjar.weixin.mp.util.json.WxGsonBuilder; +import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; /** * 群发时用到的视频素材 * * @author chanjarster */ -public class WxMassVideo { +public class WxMpMassVideo { private String mediaId; private String title; @@ -38,6 +38,6 @@ public class WxMassVideo { } public String toJson() { - return WxGsonBuilder.INSTANCE.create().toJson(this); + return WxMpGsonBuilder.INSTANCE.create().toJson(this); } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxXmlOutImageMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMpXmlOutImageMessage.java similarity index 70% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxXmlOutImageMessage.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMpXmlOutImageMessage.java index 4f1cb5f83..2d84f9f2a 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxXmlOutImageMessage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpMpXmlOutImageMessage.java @@ -1,24 +1,24 @@ package me.chanjar.weixin.mp.bean; +import me.chanjar.weixin.common.util.xml.MediaIdMarshaller; +import me.chanjar.weixin.mp.api.WxMpConsts; + import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; -import me.chanjar.weixin.mp.api.WxConsts; -import me.chanjar.weixin.mp.util.xml.MediaIdMarshaller; - @XmlRootElement(name = "xml") @XmlAccessorType(XmlAccessType.FIELD) -public class WxXmlOutImageMessage extends WxXmlOutMessage { +public class WxMpMpXmlOutImageMessage extends WxMpXmlOutMessage { @XmlElement(name="Image") @XmlJavaTypeAdapter(MediaIdMarshaller.class) private String mediaId; - public WxXmlOutImageMessage() { - this.msgType = WxConsts.XML_MSG_IMAGE; + public WxMpMpXmlOutImageMessage() { + this.msgType = WxMpConsts.XML_MSG_IMAGE; } public String getMediaId() { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxXmlMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlMessage.java similarity index 85% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxXmlMessage.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlMessage.java index 5d7f07aa4..75475c4ea 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxXmlMessage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlMessage.java @@ -1,8 +1,8 @@ package me.chanjar.weixin.mp.bean; -import me.chanjar.weixin.mp.api.WxConfigStorage; -import me.chanjar.weixin.mp.util.crypto.WxCryptUtil; -import me.chanjar.weixin.mp.util.xml.AdapterCDATA; +import me.chanjar.weixin.common.util.xml.AdapterCDATA; +import me.chanjar.weixin.mp.api.WxMpConfigStorage; +import me.chanjar.weixin.mp.util.crypto.WxMpCryptUtil; import me.chanjar.weixin.mp.util.xml.XmlTransformer; import org.apache.commons.io.IOUtils; @@ -27,7 +27,7 @@ import java.util.List; */ @XmlRootElement(name = "xml") @XmlAccessorType(XmlAccessType.FIELD) -public class WxXmlMessage { +public class WxMpXmlMessage { /////////////////////// // 以下都是微信推送过来的消息的xml的element所对应的属性 @@ -179,13 +179,13 @@ public class WxXmlMessage { /** *
    * 当接受用户消息时,可能会获得以下值:
-   * {@link me.chanjar.weixin.mp.api.WxConsts#XML_MSG_TEXT}
-   * {@link me.chanjar.weixin.mp.api.WxConsts#XML_MSG_IMAGE}
-   * {@link me.chanjar.weixin.mp.api.WxConsts#XML_MSG_VOICE}
-   * {@link me.chanjar.weixin.mp.api.WxConsts#XML_MSG_VIDEO}
-   * {@link me.chanjar.weixin.mp.api.WxConsts#XML_MSG_LOCATION}
-   * {@link me.chanjar.weixin.mp.api.WxConsts#XML_MSG_LINK}
-   * {@link me.chanjar.weixin.mp.api.WxConsts#XML_MSG_EVENT}
+   * {@link me.chanjar.weixin.mp.api.WxMpConsts#XML_MSG_TEXT}
+   * {@link me.chanjar.weixin.mp.api.WxMpConsts#XML_MSG_IMAGE}
+   * {@link me.chanjar.weixin.mp.api.WxMpConsts#XML_MSG_VOICE}
+   * {@link me.chanjar.weixin.mp.api.WxMpConsts#XML_MSG_VIDEO}
+   * {@link me.chanjar.weixin.mp.api.WxMpConsts#XML_MSG_LOCATION}
+   * {@link me.chanjar.weixin.mp.api.WxMpConsts#XML_MSG_LINK}
+   * {@link me.chanjar.weixin.mp.api.WxMpConsts#XML_MSG_EVENT}
    * 
* * @return @@ -197,12 +197,12 @@ public class WxXmlMessage { /** *
    * 当发送消息的时候使用:
-   * {@link me.chanjar.weixin.mp.api.WxConsts#XML_MSG_TEXT}
-   * {@link me.chanjar.weixin.mp.api.WxConsts#XML_MSG_IMAGE}
-   * {@link me.chanjar.weixin.mp.api.WxConsts#XML_MSG_VOICE}
-   * {@link me.chanjar.weixin.mp.api.WxConsts#XML_MSG_VIDEO}
-   * {@link me.chanjar.weixin.mp.api.WxConsts#XML_MSG_NEWS}
-   * {@link me.chanjar.weixin.mp.api.WxConsts#XML_MSG_MUSIC}
+   * {@link me.chanjar.weixin.mp.api.WxMpConsts#XML_MSG_TEXT}
+   * {@link me.chanjar.weixin.mp.api.WxMpConsts#XML_MSG_IMAGE}
+   * {@link me.chanjar.weixin.mp.api.WxMpConsts#XML_MSG_VOICE}
+   * {@link me.chanjar.weixin.mp.api.WxMpConsts#XML_MSG_VIDEO}
+   * {@link me.chanjar.weixin.mp.api.WxMpConsts#XML_MSG_NEWS}
+   * {@link me.chanjar.weixin.mp.api.WxMpConsts#XML_MSG_MUSIC}
    * 
* * @param msgType @@ -379,17 +379,17 @@ public class WxXmlMessage { this.fromUserName = fromUserName; } - public static WxXmlMessage fromXml(String xml) { + public static WxMpXmlMessage fromXml(String xml) { try { - return XmlTransformer.fromXml(WxXmlMessage.class, xml); + return XmlTransformer.fromXml(WxMpXmlMessage.class, xml); } catch (JAXBException e) { throw new RuntimeException(e); } } - public static WxXmlMessage fromXml(InputStream is) { + public static WxMpXmlMessage fromXml(InputStream is) { try { - return XmlTransformer.fromXml(WxXmlMessage.class, is); + return XmlTransformer.fromXml(WxMpXmlMessage.class, is); } catch (JAXBException e) { throw new RuntimeException(e); } @@ -399,27 +399,27 @@ public class WxXmlMessage { * 从加密字符串转换 * * @param encryptedXml - * @param wxConfigStorage + * @param wxMpConfigStorage * @param timestamp * @param nonce * @param msgSignature * @return */ - public static WxXmlMessage fromEncryptedXml( + public static WxMpXmlMessage fromEncryptedXml( String encryptedXml, - WxConfigStorage wxConfigStorage, + WxMpConfigStorage wxMpConfigStorage, String timestamp, String nonce, String msgSignature) { - WxCryptUtil cryptUtil = new WxCryptUtil(wxConfigStorage); + WxMpCryptUtil cryptUtil = new WxMpCryptUtil(wxMpConfigStorage); String plainText = cryptUtil.decrypt(msgSignature, timestamp, nonce, encryptedXml); return fromXml(plainText); } - public static WxXmlMessage fromEncryptedXml( + public static WxMpXmlMessage fromEncryptedXml( InputStream is, - WxConfigStorage wxConfigStorage, + WxMpConfigStorage wxMpConfigStorage, String timestamp, String nonce, String msgSignature) { try { - return fromEncryptedXml(IOUtils.toString(is, "UTF-8"), wxConfigStorage, timestamp, nonce, msgSignature); + return fromEncryptedXml(IOUtils.toString(is, "UTF-8"), wxMpConfigStorage, timestamp, nonce, msgSignature); } catch (IOException e) { throw new RuntimeException(e); } @@ -465,27 +465,27 @@ public class WxXmlMessage { this.errorCount = errorCount; } - public WxXmlMessage.ScanCodeInfo getScanCodeInfo() { + public WxMpXmlMessage.ScanCodeInfo getScanCodeInfo() { return scanCodeInfo; } - public void setScanCodeInfo(WxXmlMessage.ScanCodeInfo scanCodeInfo) { + public void setScanCodeInfo(WxMpXmlMessage.ScanCodeInfo scanCodeInfo) { this.scanCodeInfo = scanCodeInfo; } - public WxXmlMessage.SendPicsInfo getSendPicsInfo() { + public WxMpXmlMessage.SendPicsInfo getSendPicsInfo() { return sendPicsInfo; } - public void setSendPicsInfo(WxXmlMessage.SendPicsInfo sendPicsInfo) { + public void setSendPicsInfo(WxMpXmlMessage.SendPicsInfo sendPicsInfo) { this.sendPicsInfo = sendPicsInfo; } - public WxXmlMessage.SendLocationInfo getSendLocationInfo() { + public WxMpXmlMessage.SendLocationInfo getSendLocationInfo() { return sendLocationInfo; } - public void setSendLocationInfo(WxXmlMessage.SendLocationInfo sendLocationInfo) { + public void setSendLocationInfo(WxMpXmlMessage.SendLocationInfo sendLocationInfo) { this.sendLocationInfo = sendLocationInfo; } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxXmlOutMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutMessage.java similarity index 79% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxXmlOutMessage.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutMessage.java index b64ae73dc..b9e4507d4 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxXmlOutMessage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutMessage.java @@ -1,5 +1,11 @@ package me.chanjar.weixin.mp.bean; +import me.chanjar.weixin.common.util.xml.AdapterCDATA; +import me.chanjar.weixin.mp.api.WxMpConfigStorage; +import me.chanjar.weixin.mp.bean.outxmlbuilder.*; +import me.chanjar.weixin.mp.util.crypto.WxMpCryptUtil; +import me.chanjar.weixin.mp.util.xml.XmlTransformer; + import javax.xml.bind.JAXBException; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; @@ -7,20 +13,9 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; -import me.chanjar.weixin.mp.api.WxConfigStorage; -import me.chanjar.weixin.mp.bean.outxmlbuilder.ImageBuilder; -import me.chanjar.weixin.mp.bean.outxmlbuilder.MusicBuilder; -import me.chanjar.weixin.mp.bean.outxmlbuilder.NewsBuilder; -import me.chanjar.weixin.mp.bean.outxmlbuilder.TextBuilder; -import me.chanjar.weixin.mp.bean.outxmlbuilder.VideoBuilder; -import me.chanjar.weixin.mp.bean.outxmlbuilder.VoiceBuilder; -import me.chanjar.weixin.mp.util.crypto.WxCryptUtil; -import me.chanjar.weixin.mp.util.xml.AdapterCDATA; -import me.chanjar.weixin.mp.util.xml.XmlTransformer; - @XmlRootElement(name = "xml") @XmlAccessorType(XmlAccessType.FIELD) -public class WxXmlOutMessage { +public class WxMpXmlOutMessage { @XmlElement(name="ToUserName") @XmlJavaTypeAdapter(AdapterCDATA.class) @@ -81,9 +76,9 @@ public class WxXmlOutMessage { * 转换成加密的xml格式 * @return */ - public String toEncryptedXml(WxConfigStorage wxConfigStorage) { + public String toEncryptedXml(WxMpConfigStorage wxMpConfigStorage) { String plainXml = toXml(); - WxCryptUtil pc = new WxCryptUtil(wxConfigStorage); + WxMpCryptUtil pc = new WxMpCryptUtil(wxMpConfigStorage); return pc.encrypt(plainXml); } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxXmlOutMewsMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutMewsMessage.java similarity index 78% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxXmlOutMewsMessage.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutMewsMessage.java index f783b1347..b881452f4 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxXmlOutMewsMessage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutMewsMessage.java @@ -1,21 +1,16 @@ package me.chanjar.weixin.mp.bean; +import me.chanjar.weixin.common.util.xml.AdapterCDATA; +import me.chanjar.weixin.mp.api.WxMpConsts; + +import javax.xml.bind.annotation.*; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import java.util.ArrayList; import java.util.List; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlElementWrapper; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; - -import me.chanjar.weixin.mp.api.WxConsts; -import me.chanjar.weixin.mp.util.xml.AdapterCDATA; - @XmlRootElement(name = "xml") @XmlAccessorType(XmlAccessType.FIELD) -public class WxXmlOutMewsMessage extends WxXmlOutMessage { +public class WxMpXmlOutMewsMessage extends WxMpXmlOutMessage { @XmlElement(name = "ArticleCount") protected int articleCount; @@ -24,8 +19,8 @@ public class WxXmlOutMewsMessage extends WxXmlOutMessage { @XmlElement(name = "item") protected final List articles = new ArrayList(); - public WxXmlOutMewsMessage() { - this.msgType = WxConsts.XML_MSG_NEWS; + public WxMpXmlOutMewsMessage() { + this.msgType = WxMpConsts.XML_MSG_NEWS; } public int getArticleCount() { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxXmlOutMusicMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutMusicMessage.java similarity index 91% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxXmlOutMusicMessage.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutMusicMessage.java index 69f7359d2..e0270a5f9 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxXmlOutMusicMessage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutMusicMessage.java @@ -1,23 +1,23 @@ package me.chanjar.weixin.mp.bean; +import me.chanjar.weixin.common.util.xml.AdapterCDATA; +import me.chanjar.weixin.mp.api.WxMpConsts; + import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; -import me.chanjar.weixin.mp.api.WxConsts; -import me.chanjar.weixin.mp.util.xml.AdapterCDATA; - @XmlRootElement(name = "xml") @XmlAccessorType(XmlAccessType.FIELD) -public class WxXmlOutMusicMessage extends WxXmlOutMessage { +public class WxMpXmlOutMusicMessage extends WxMpXmlOutMessage { @XmlElement(name = "Music") protected final Music music = new Music(); - public WxXmlOutMusicMessage() { - this.msgType = WxConsts.XML_MSG_MUSIC; + public WxMpXmlOutMusicMessage() { + this.msgType = WxMpConsts.XML_MSG_MUSIC; } public String getTitle() { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxXmlOutTextMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutTextMessage.java similarity index 71% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxXmlOutTextMessage.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutTextMessage.java index 3bafc7440..6452a1ea6 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxXmlOutTextMessage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutTextMessage.java @@ -1,24 +1,24 @@ package me.chanjar.weixin.mp.bean; +import me.chanjar.weixin.common.util.xml.AdapterCDATA; +import me.chanjar.weixin.mp.api.WxMpConsts; + import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; -import me.chanjar.weixin.mp.api.WxConsts; -import me.chanjar.weixin.mp.util.xml.AdapterCDATA; - @XmlRootElement(name = "xml") @XmlAccessorType(XmlAccessType.FIELD) -public class WxXmlOutTextMessage extends WxXmlOutMessage { +public class WxMpXmlOutTextMessage extends WxMpXmlOutMessage { @XmlElement(name="Content") @XmlJavaTypeAdapter(AdapterCDATA.class) private String content; - public WxXmlOutTextMessage() { - this.msgType = WxConsts.XML_MSG_TEXT; + public WxMpXmlOutTextMessage() { + this.msgType = WxMpConsts.XML_MSG_TEXT; } public String getContent() { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxXmlOutVideoMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutVideoMessage.java similarity index 87% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxXmlOutVideoMessage.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutVideoMessage.java index 3a7ec0ba4..2b0dff682 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxXmlOutVideoMessage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutVideoMessage.java @@ -1,23 +1,23 @@ package me.chanjar.weixin.mp.bean; +import me.chanjar.weixin.common.util.xml.AdapterCDATA; +import me.chanjar.weixin.mp.api.WxMpConsts; + import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; -import me.chanjar.weixin.mp.api.WxConsts; -import me.chanjar.weixin.mp.util.xml.AdapterCDATA; - @XmlRootElement(name = "xml") @XmlAccessorType(XmlAccessType.FIELD) -public class WxXmlOutVideoMessage extends WxXmlOutMessage { +public class WxMpXmlOutVideoMessage extends WxMpXmlOutMessage { @XmlElement(name = "Video") protected final Video video = new Video(); - public WxXmlOutVideoMessage() { - this.msgType = WxConsts.XML_MSG_VIDEO; + public WxMpXmlOutVideoMessage() { + this.msgType = WxMpConsts.XML_MSG_VIDEO; } public String getMediaId() { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxXmlOutVoiceMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutVoiceMessage.java similarity index 70% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxXmlOutVoiceMessage.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutVoiceMessage.java index a875bf9ac..88d1deb1c 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxXmlOutVoiceMessage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpXmlOutVoiceMessage.java @@ -1,24 +1,24 @@ package me.chanjar.weixin.mp.bean; +import me.chanjar.weixin.common.util.xml.MediaIdMarshaller; +import me.chanjar.weixin.mp.api.WxMpConsts; + import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; -import me.chanjar.weixin.mp.api.WxConsts; -import me.chanjar.weixin.mp.util.xml.MediaIdMarshaller; - @XmlRootElement(name = "xml") @XmlAccessorType(XmlAccessType.FIELD) -public class WxXmlOutVoiceMessage extends WxXmlOutMessage { +public class WxMpXmlOutVoiceMessage extends WxMpXmlOutMessage { @XmlElement(name="Voice") @XmlJavaTypeAdapter(MediaIdMarshaller.class) private String mediaId; - public WxXmlOutVoiceMessage() { - this.msgType = WxConsts.XML_MSG_VOICE; + public WxMpXmlOutVoiceMessage() { + this.msgType = WxMpConsts.XML_MSG_VOICE; } public String getMediaId() { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/BaseBuilder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/BaseBuilder.java index 85f150c48..18bf81f9a 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/BaseBuilder.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/BaseBuilder.java @@ -1,6 +1,6 @@ package me.chanjar.weixin.mp.bean.custombuilder; -import me.chanjar.weixin.mp.bean.WxCustomMessage; +import me.chanjar.weixin.mp.bean.WxMpCustomMessage; public class BaseBuilder { protected String msgType; @@ -11,8 +11,8 @@ public class BaseBuilder { return (T) this; } - public WxCustomMessage build() { - WxCustomMessage m = new WxCustomMessage(); + public WxMpCustomMessage build() { + WxMpCustomMessage m = new WxMpCustomMessage(); m.setMsgType(this.msgType); m.setToUser(this.toUser); return m; diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/ImageBuilder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/ImageBuilder.java index 37d30a724..f7de15e24 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/ImageBuilder.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/ImageBuilder.java @@ -1,12 +1,12 @@ package me.chanjar.weixin.mp.bean.custombuilder; -import me.chanjar.weixin.mp.api.WxConsts; -import me.chanjar.weixin.mp.bean.WxCustomMessage; +import me.chanjar.weixin.mp.api.WxMpConsts; +import me.chanjar.weixin.mp.bean.WxMpCustomMessage; /** * 获得消息builder *
- * 用法: WxCustomMessage m = WxCustomMessage.IMAGE().mediaId(...).toUser(...).build();
+ * 用法: WxMpCustomMessage m = WxMpCustomMessage.IMAGE().mediaId(...).toUser(...).build();
  * 
* @author chanjarster * @@ -15,7 +15,7 @@ public final class ImageBuilder extends BaseBuilder { private String mediaId; public ImageBuilder() { - this.msgType = WxConsts.CUSTOM_MSG_IMAGE; + this.msgType = WxMpConsts.CUSTOM_MSG_IMAGE; } public ImageBuilder mediaId(String media_id) { @@ -23,8 +23,8 @@ public final class ImageBuilder extends BaseBuilder { return this; } - public WxCustomMessage build() { - WxCustomMessage m = super.build(); + public WxMpCustomMessage build() { + WxMpCustomMessage m = super.build(); m.setMediaId(this.mediaId); return m; } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/MusicBuilder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/MusicBuilder.java index 06f48eb6d..9c882d5d1 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/MusicBuilder.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/MusicBuilder.java @@ -1,12 +1,12 @@ package me.chanjar.weixin.mp.bean.custombuilder; -import me.chanjar.weixin.mp.api.WxConsts; -import me.chanjar.weixin.mp.bean.WxCustomMessage; +import me.chanjar.weixin.mp.api.WxMpConsts; +import me.chanjar.weixin.mp.bean.WxMpCustomMessage; /** * 音乐消息builder *
- * 用法: WxCustomMessage m = WxCustomMessage.MUSIC()
+ * 用法: WxMpCustomMessage m = WxMpCustomMessage.MUSIC()
  *                      .musicUrl(...)
  *                      .hqMusicUrl(...)
  *                      .title(...)
@@ -24,7 +24,7 @@ public final class MusicBuilder extends BaseBuilder {
   private String hqMusicUrl;
 
   public MusicBuilder() {
-    this.msgType = WxConsts.CUSTOM_MSG_MUSIC;
+    this.msgType = WxMpConsts.CUSTOM_MSG_MUSIC;
   }
 
   public MusicBuilder musicUrl(String musicurl) {
@@ -52,8 +52,8 @@ public final class MusicBuilder extends BaseBuilder {
     return this;
   }
 
-  public WxCustomMessage build() {
-    WxCustomMessage m = super.build();
+  public WxMpCustomMessage build() {
+    WxMpCustomMessage m = super.build();
     m.setMusicUrl(this.musicUrl);
     m.setHqMusicUrl(this.hqMusicUrl);
     m.setTitle(title);
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/NewsBuilder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/NewsBuilder.java
index 8ab490889..91da45cc9 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/NewsBuilder.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/NewsBuilder.java
@@ -1,35 +1,35 @@
 package me.chanjar.weixin.mp.bean.custombuilder;
 
+import me.chanjar.weixin.mp.api.WxMpConsts;
+import me.chanjar.weixin.mp.bean.WxMpCustomMessage;
+
 import java.util.ArrayList;
 import java.util.List;
 
-import me.chanjar.weixin.mp.api.WxConsts;
-import me.chanjar.weixin.mp.bean.WxCustomMessage;
-
 /**
  * 图文消息builder
  * 
  * 用法:
- * WxCustomMessage m = WxCustomMessage.NEWS().addArticle(article).toUser(...).build();
+ * WxMpCustomMessage m = WxMpCustomMessage.NEWS().addArticle(article).toUser(...).build();
  * 
* @author chanjarster * */ public final class NewsBuilder extends BaseBuilder { - private List articles = new ArrayList(); + private List articles = new ArrayList(); public NewsBuilder() { - this.msgType = WxConsts.CUSTOM_MSG_NEWS; + this.msgType = WxMpConsts.CUSTOM_MSG_NEWS; } - public NewsBuilder addArticle(WxCustomMessage.WxArticle article) { + public NewsBuilder addArticle(WxMpCustomMessage.WxArticle article) { this.articles.add(article); return this; } - public WxCustomMessage build() { - WxCustomMessage m = super.build(); + public WxMpCustomMessage build() { + WxMpCustomMessage m = super.build(); m.setArticles(this.articles); return m; } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/TextBuilder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/TextBuilder.java index 9db18631e..b2fb5cd4a 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/TextBuilder.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/TextBuilder.java @@ -1,12 +1,12 @@ package me.chanjar.weixin.mp.bean.custombuilder; -import me.chanjar.weixin.mp.api.WxConsts; -import me.chanjar.weixin.mp.bean.WxCustomMessage; +import me.chanjar.weixin.mp.api.WxMpConsts; +import me.chanjar.weixin.mp.bean.WxMpCustomMessage; /** * 文本消息builder *
- * 用法: WxCustomMessage m = WxCustomMessage.TEXT().content(...).toUser(...).build();
+ * 用法: WxMpCustomMessage m = WxMpCustomMessage.TEXT().content(...).toUser(...).build();
  * 
* @author chanjarster * @@ -15,7 +15,7 @@ public final class TextBuilder extends BaseBuilder { private String content; public TextBuilder() { - this.msgType = WxConsts.CUSTOM_MSG_TEXT; + this.msgType = WxMpConsts.CUSTOM_MSG_TEXT; } public TextBuilder content(String content) { @@ -23,8 +23,8 @@ public final class TextBuilder extends BaseBuilder { return this; } - public WxCustomMessage build() { - WxCustomMessage m = super.build(); + public WxMpCustomMessage build() { + WxMpCustomMessage m = super.build(); m.setContent(this.content); return m; } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/VideoBuilder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/VideoBuilder.java index 5d7ec8c0c..998b8dfa4 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/VideoBuilder.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/VideoBuilder.java @@ -1,12 +1,12 @@ package me.chanjar.weixin.mp.bean.custombuilder; -import me.chanjar.weixin.mp.api.WxConsts; -import me.chanjar.weixin.mp.bean.WxCustomMessage; +import me.chanjar.weixin.mp.api.WxMpConsts; +import me.chanjar.weixin.mp.bean.WxMpCustomMessage; /** * 视频消息builder *
- * 用法: WxCustomMessage m = WxCustomMessage.VOICE()
+ * 用法: WxMpCustomMessage m = WxMpCustomMessage.VOICE()
  *                              .mediaId(...)
  *                              .title(...)
  *                              .thumbMediaId(..)
@@ -24,7 +24,7 @@ public final class VideoBuilder extends BaseBuilder {
   private String thumbMediaId;
 
   public VideoBuilder() {
-    this.msgType = WxConsts.CUSTOM_MSG_VIDEO;
+    this.msgType = WxMpConsts.CUSTOM_MSG_VIDEO;
   }
 
   public VideoBuilder mediaId(String mediaId) {
@@ -47,8 +47,8 @@ public final class VideoBuilder extends BaseBuilder {
     return this;
   }
 
-  public WxCustomMessage build() {
-    WxCustomMessage m = super.build();
+  public WxMpCustomMessage build() {
+    WxMpCustomMessage m = super.build();
     m.setMediaId(this.mediaId);
     m.setTitle(title);
     m.setDescription(description);
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/VoiceBuilder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/VoiceBuilder.java
index 593c6e70f..e17aa3a10 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/VoiceBuilder.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/custombuilder/VoiceBuilder.java
@@ -1,12 +1,12 @@
 package me.chanjar.weixin.mp.bean.custombuilder;
 
-import me.chanjar.weixin.mp.api.WxConsts;
-import me.chanjar.weixin.mp.bean.WxCustomMessage;
+import me.chanjar.weixin.mp.api.WxMpConsts;
+import me.chanjar.weixin.mp.bean.WxMpCustomMessage;
 
 /**
  * 语音消息builder
  * 
- * 用法: WxCustomMessage m = WxCustomMessage.VOICE().mediaId(...).toUser(...).build();
+ * 用法: WxMpCustomMessage m = WxMpCustomMessage.VOICE().mediaId(...).toUser(...).build();
  * 
* @author chanjarster * @@ -15,7 +15,7 @@ public final class VoiceBuilder extends BaseBuilder { private String mediaId; public VoiceBuilder() { - this.msgType = WxConsts.CUSTOM_MSG_VOICE; + this.msgType = WxMpConsts.CUSTOM_MSG_VOICE; } public VoiceBuilder mediaId(String media_id) { @@ -23,8 +23,8 @@ public final class VoiceBuilder extends BaseBuilder { return this; } - public WxCustomMessage build() { - WxCustomMessage m = super.build(); + public WxMpCustomMessage build() { + WxMpCustomMessage m = super.build(); m.setMediaId(this.mediaId); return m; } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/outxmlbuilder/BaseBuilder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/outxmlbuilder/BaseBuilder.java index 641ecc013..77db2617c 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/outxmlbuilder/BaseBuilder.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/outxmlbuilder/BaseBuilder.java @@ -1,7 +1,6 @@ package me.chanjar.weixin.mp.bean.outxmlbuilder; -import me.chanjar.weixin.mp.bean.WxXmlOutMessage; - +import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage; public abstract class BaseBuilder { @@ -21,7 +20,7 @@ public abstract class BaseBuilder { public abstract ValueType build(); - public void setCommon(WxXmlOutMessage m) { + public void setCommon(WxMpXmlOutMessage m) { m.setToUserName(this.toUserName); m.setFromUserName(this.fromUserName); m.setCreateTime(System.currentTimeMillis() / 1000l); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/outxmlbuilder/ImageBuilder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/outxmlbuilder/ImageBuilder.java index 3dbce7450..f127406ad 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/outxmlbuilder/ImageBuilder.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/outxmlbuilder/ImageBuilder.java @@ -1,12 +1,12 @@ package me.chanjar.weixin.mp.bean.outxmlbuilder; -import me.chanjar.weixin.mp.bean.WxXmlOutImageMessage; +import me.chanjar.weixin.mp.bean.WxMpMpXmlOutImageMessage; /** * 图片消息builder * @author chanjarster */ -public final class ImageBuilder extends BaseBuilder { +public final class ImageBuilder extends BaseBuilder { private String mediaId; @@ -15,8 +15,8 @@ public final class ImageBuilder extends BaseBuilder { +public final class MusicBuilder extends BaseBuilder { private String title; private String description; @@ -40,8 +40,8 @@ public final class MusicBuilder extends BaseBuilder { +public final class NewsBuilder extends BaseBuilder { - protected final List articles = new ArrayList(); + protected final List articles = new ArrayList(); - public NewsBuilder addArticle(WxXmlOutMewsMessage.Item item) { + public NewsBuilder addArticle(WxMpXmlOutMewsMessage.Item item) { this.articles.add(item); return this; } - public WxXmlOutMewsMessage build() { - WxXmlOutMewsMessage m = new WxXmlOutMewsMessage(); - for(WxXmlOutMewsMessage.Item item : articles) { + public WxMpXmlOutMewsMessage build() { + WxMpXmlOutMewsMessage m = new WxMpXmlOutMewsMessage(); + for(WxMpXmlOutMewsMessage.Item item : articles) { m.addArticle(item); } setCommon(m); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/outxmlbuilder/TextBuilder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/outxmlbuilder/TextBuilder.java index 43c54feba..8352ddead 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/outxmlbuilder/TextBuilder.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/outxmlbuilder/TextBuilder.java @@ -1,13 +1,13 @@ package me.chanjar.weixin.mp.bean.outxmlbuilder; -import me.chanjar.weixin.mp.bean.WxXmlOutTextMessage; +import me.chanjar.weixin.mp.bean.WxMpXmlOutTextMessage; /** * 文本消息builder * @author chanjarster * */ -public final class TextBuilder extends BaseBuilder { +public final class TextBuilder extends BaseBuilder { private String content; public TextBuilder content(String content) { @@ -15,8 +15,8 @@ public final class TextBuilder extends BaseBuilder { +public final class VideoBuilder extends BaseBuilder { private String mediaId; private String title; @@ -26,8 +26,8 @@ public final class VideoBuilder extends BaseBuilder { +public final class VoiceBuilder extends BaseBuilder { private String mediaId; @@ -15,8 +15,8 @@ public final class VoiceBuilder extends BaseBuilder errMap = new HashMap(); - - static { - errMap.put(-1, "系统繁忙"); - errMap.put(0, "请求成功"); - errMap.put(40001, "获取access_token时AppSecret错误,或者access_token无效"); - errMap.put(40002, "不合法的凭证类型"); - errMap.put(40003, "不合法的OpenID"); - errMap.put(40004, "不合法的媒体文件类型"); - errMap.put(40005, "不合法的文件类型"); - errMap.put(40006, "不合法的文件大小"); - errMap.put(40007, "不合法的媒体文件id"); - errMap.put(40008, "不合法的消息类型"); - errMap.put(40009, "不合法的图片文件大小"); - errMap.put(40010, "不合法的语音文件大小"); - errMap.put(40011, "不合法的视频文件大小"); - errMap.put(40012, "不合法的缩略图文件大小"); - errMap.put(40013, "不合法的APPID"); - errMap.put(40014, "不合法的access_token"); - errMap.put(40015, "不合法的菜单类型"); - errMap.put(40016, "不合法的按钮个数"); - errMap.put(40017, "不合法的按钮个数"); - errMap.put(40018, "不合法的按钮名字长度"); - errMap.put(40019, "不合法的按钮KEY长度"); - errMap.put(40020, "不合法的按钮URL长度"); - errMap.put(40021, "不合法的菜单版本号"); - errMap.put(40022, "不合法的子菜单级数"); - errMap.put(40023, "不合法的子菜单按钮个数"); - errMap.put(40024, "不合法的子菜单按钮类型"); - errMap.put(40025, "不合法的子菜单按钮名字长度"); - errMap.put(40026, "不合法的子菜单按钮KEY长度"); - errMap.put(40027, "不合法的子菜单按钮URL长度"); - errMap.put(40028, "不合法的自定义菜单使用用户"); - errMap.put(40029, "不合法的oauth_code"); - errMap.put(40030, "不合法的refresh_token"); - errMap.put(40031, "不合法的openid列表"); - errMap.put(40032, "不合法的openid列表长度"); - errMap.put(40033, "不合法的请求字符,不能包含\\uxxxx格式的字符"); - errMap.put(40035, "不合法的参数"); - errMap.put(40038, "不合法的请求格式"); - errMap.put(40039, "不合法的URL长度"); - errMap.put(40050, "不合法的分组id"); - errMap.put(40051, "分组名字不合法"); - errMap.put(41001, "缺少access_token参数"); - errMap.put(41002, "缺少appid参数"); - errMap.put(41003, "缺少refresh_token参数"); - errMap.put(41004, "缺少secret参数"); - errMap.put(41005, "缺少多媒体文件数据"); - errMap.put(41006, "缺少media_id参数"); - errMap.put(41007, "缺少子菜单数据"); - errMap.put(41008, "缺少oauth code"); - errMap.put(41009, "缺少openid"); - errMap.put(42001, "access_token超时"); - errMap.put(42002, "refresh_token超时"); - errMap.put(42003, "oauth_code超时"); - errMap.put(43001, "需要GET请求"); - errMap.put(43002, "需要POST请求"); - errMap.put(43003, "需要HTTPS请求"); - errMap.put(43004, "需要接收者关注"); - errMap.put(43005, "需要好友关系"); - errMap.put(44001, "多媒体文件为空"); - errMap.put(44002, "POST的数据包为空"); - errMap.put(44003, "图文消息内容为空"); - errMap.put(44004, "文本消息内容为空"); - errMap.put(45001, "多媒体文件大小超过限制"); - errMap.put(45002, "消息内容超过限制"); - errMap.put(45003, "标题字段超过限制"); - errMap.put(45004, "描述字段超过限制"); - errMap.put(45005, "链接字段超过限制"); - errMap.put(45006, "图片链接字段超过限制"); - errMap.put(45007, "语音播放时间超过限制"); - errMap.put(45008, "图文消息超过限制"); - errMap.put(45009, "接口调用超过限制"); - errMap.put(45010, "创建菜单个数超过限制"); - errMap.put(45015, "回复时间超过限制"); - errMap.put(45016, "系统分组,不允许修改"); - errMap.put(45017, "分组名字过长"); - errMap.put(45018, "分组数量超过上限"); - errMap.put(46001, "不存在媒体数据"); - errMap.put(46002, "不存在的菜单版本"); - errMap.put(46003, "不存在的菜单数据"); - errMap.put(46004, "不存在的用户"); - errMap.put(47001, "解析JSON/XML内容错误"); - errMap.put(48001, "api功能未授权"); - errMap.put(50001, "用户未授权该api"); - } - - protected int errorCode; - - protected String errorMsg; - - public int getErrorCode() { - return errorCode; - } - - public void setErrorCode(int errorCode) { - this.errorCode = errorCode; - } - - public String getErrorMsg() { - return errorMsg; - } - - public void setErrorMsg(String errorMsg) { - this.errorMsg = errorMsg; - } - - public String getDescription() { - return errMap.get(errorCode); - } - - public static WxError fromJson(String json) { - return WxGsonBuilder.create().fromJson(json, WxError.class); - } - - @Override - public String toString() { - return "微信错误 errcode=" + errorCode + ", errmsg=" + errorMsg + ", description=" + getDescription(); - } - -} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMassSendResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpMassSendResult.java similarity index 81% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMassSendResult.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpMassSendResult.java index d71b579d2..9b5df2b81 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMassSendResult.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpMassSendResult.java @@ -1,6 +1,6 @@ package me.chanjar.weixin.mp.bean.result; -import me.chanjar.weixin.mp.util.json.WxGsonBuilder; +import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; /** *
@@ -13,7 +13,7 @@ import me.chanjar.weixin.mp.util.json.WxGsonBuilder;
  * @author chanjarster
  *
  */
-public class WxMassSendResult {
+public class WxMpMassSendResult {
 
   private String errorCode;
   private String errorMsg;
@@ -43,8 +43,8 @@ public class WxMassSendResult {
     this.msgId = msgId;
   }
   
-  public static WxMassSendResult fromJson(String json) {
-    return WxGsonBuilder.create().fromJson(json, WxMassSendResult.class);
+  public static WxMpMassSendResult fromJson(String json) {
+    return WxMpGsonBuilder.create().fromJson(json, WxMpMassSendResult.class);
   }
 
   @Override
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMassUploadResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpMassUploadResult.java
similarity index 77%
rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMassUploadResult.java
rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpMassUploadResult.java
index f3efe6859..e0ed145bf 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMassUploadResult.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpMassUploadResult.java
@@ -1,6 +1,6 @@
 package me.chanjar.weixin.mp.bean.result;
 
-import me.chanjar.weixin.mp.util.json.WxGsonBuilder;
+import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
 
 /**
  * 
@@ -10,7 +10,7 @@ import me.chanjar.weixin.mp.util.json.WxGsonBuilder;
  * @author chanjarster
  *
  */
-public class WxMassUploadResult {
+public class WxMpMassUploadResult {
 
   private String type;
   private String mediaId;
@@ -40,8 +40,8 @@ public class WxMassUploadResult {
     this.createdAt = createdAt;
   }
 
-  public static WxMassUploadResult fromJson(String json) {
-    return WxGsonBuilder.create().fromJson(json, WxMassUploadResult.class);
+  public static WxMpMassUploadResult fromJson(String json) {
+    return WxMpGsonBuilder.create().fromJson(json, WxMpMassUploadResult.class);
   }
 
   @Override
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxQrCodeTicket.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpQrCodeTicket.java
similarity index 74%
rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxQrCodeTicket.java
rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpQrCodeTicket.java
index fd13ade83..bf240c57f 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxQrCodeTicket.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpQrCodeTicket.java
@@ -1,13 +1,13 @@
 package me.chanjar.weixin.mp.bean.result;
 
-import me.chanjar.weixin.mp.util.json.WxGsonBuilder;
+import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
 
 /**
  * 换取二维码的Ticket
  * 
  * @author chanjarster
  */
-public class WxQrCodeTicket {
+public class WxMpQrCodeTicket {
   
   protected String ticket;
   protected int expire_seconds = -1;
@@ -40,7 +40,7 @@ public class WxQrCodeTicket {
     this.url = url;
   }
 
-  public static WxQrCodeTicket fromJson(String json) {
-    return WxGsonBuilder.INSTANCE.create().fromJson(json, WxQrCodeTicket.class);
+  public static WxMpQrCodeTicket fromJson(String json) {
+    return WxMpGsonBuilder.INSTANCE.create().fromJson(json, WxMpQrCodeTicket.class);
   }
 }
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxUser.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpUser.java
similarity index 90%
rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxUser.java
rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpUser.java
index c6fd81e5f..fa4aee6df 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxUser.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpUser.java
@@ -1,13 +1,13 @@
 package me.chanjar.weixin.mp.bean.result;
 
-import me.chanjar.weixin.mp.util.json.WxGsonBuilder;
+import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
 
 /**
  * 微信用户信息
  * @author chanjarster
  *
  */
-public class WxUser {
+public class WxMpUser {
 
   protected boolean subscribe;
   protected String openId;
@@ -88,8 +88,8 @@ public class WxUser {
     this.unionId = unionId;
   }
   
-  public static WxUser fromJson(String json) {
-    return WxGsonBuilder.INSTANCE.create().fromJson(json, WxUser.class);
+  public static WxMpUser fromJson(String json) {
+    return WxMpGsonBuilder.INSTANCE.create().fromJson(json, WxMpUser.class);
   }
   
 }
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxUserList.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpUserList.java
similarity index 79%
rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxUserList.java
rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpUserList.java
index 29ab1a60f..489d5bedb 100644
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxUserList.java
+++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpUserList.java
@@ -1,16 +1,16 @@
 package me.chanjar.weixin.mp.bean.result;
 
+import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
+
 import java.util.ArrayList;
 import java.util.List;
 
-import me.chanjar.weixin.mp.util.json.WxGsonBuilder;
-
 /**
  * 关注者列表
  * @author chanjarster
  *
  */
-public class WxUserList {
+public class WxMpUserList {
 
   protected int total = -1;
   protected int count = -1;
@@ -41,7 +41,7 @@ public class WxUserList {
     this.nextOpenId = nextOpenId;
   }
   
-  public static WxUserList fromJson(String json) {
-    return WxGsonBuilder.INSTANCE.create().fromJson(json, WxUserList.class);
+  public static WxMpUserList fromJson(String json) {
+    return WxMpGsonBuilder.INSTANCE.create().fromJson(json, WxMpUserList.class);
   }
 }
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/exception/WxErrorException.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/exception/WxErrorException.java
deleted file mode 100644
index 5685289d1..000000000
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/exception/WxErrorException.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package me.chanjar.weixin.mp.exception;
-
-import me.chanjar.weixin.mp.bean.result.WxError;
-
-public class WxErrorException extends Exception {
-
-  private static final long serialVersionUID = -6357149550353160810L;
-  
-  private WxError error;
-
-  public WxErrorException(WxError error) {
-    super(error.toString());
-    this.error = error;
-  }
-
-  public WxError getError() {
-    return error;
-  }
-
- 
-}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/crypto/ByteGroup.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/crypto/ByteGroup.java
deleted file mode 100755
index 329bf4172..000000000
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/crypto/ByteGroup.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package me.chanjar.weixin.mp.util.crypto;
-
-import java.util.ArrayList;
-
-class ByteGroup {
-	ArrayList byteContainer = new ArrayList();
-
-  byte[] toBytes() {
-		byte[] bytes = new byte[byteContainer.size()];
-		for (int i = 0; i < byteContainer.size(); i++) {
-			bytes[i] = byteContainer.get(i);
-		}
-		return bytes;
-	}
-
-	ByteGroup addBytes(byte[] bytes) {
-		for (byte b : bytes) {
-			byteContainer.add(b);
-		}
-		return this;
-	}
-
-	int size() {
-		return byteContainer.size();
-	}
-}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/crypto/PKCS7Encoder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/crypto/PKCS7Encoder.java
deleted file mode 100755
index 5bd23383f..000000000
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/crypto/PKCS7Encoder.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/**
- * 对公众平台发送给公众账号的消息加解密示例代码.
- * 
- * @copyright Copyright (c) 1998-2014 Tencent Inc.
- */
-
-// ------------------------------------------------------------------------
-
-package me.chanjar.weixin.mp.util.crypto;
-
-import java.nio.charset.Charset;
-import java.util.Arrays;
-
-/**
- * 提供基于PKCS7算法的加解
- */
-class PKCS7Encoder {
-
-	private static final Charset CHARSET = Charset.forName("utf-8");
-	private static final int BLOCK_SIZE = 32;
-
-	/**
-	 * 获得对明文进行补位填充的字节.
-	 * 
-	 * @param count 需要进行填充补位操作的明文字节个数
-	 * @return 补齐用的字节数组
-	 */
-	static byte[] encode(int count) {
-		// 计算需要填充的位数
-		int amountToPad = BLOCK_SIZE - (count % BLOCK_SIZE);
-		if (amountToPad == 0) {
-			amountToPad = BLOCK_SIZE;
-		}
-		// 获得补位所用的字符
-		char padChr = chr(amountToPad);
-		String tmp = new String();
-		for (int index = 0; index < amountToPad; index++) {
-			tmp += padChr;
-		}
-		return tmp.getBytes(CHARSET);
-	}
-
-	/**
-	 * 删除解密后明文的补位字符
-	 * 
-	 * @param decrypted 解密后的明文
-	 * @return 删除补位字符后的明文
-	 */
-	static byte[] decode(byte[] decrypted) {
-		int pad = (int) decrypted[decrypted.length - 1];
-		if (pad < 1 || pad > 32) {
-			pad = 0;
-		}
-		return Arrays.copyOfRange(decrypted, 0, decrypted.length - pad);
-	}
-
-	/**
-	 * 将数字转化成ASCII码对应的字符,用于对明文进行补码
-	 * 
-	 * @param a 需要转化的数字
-	 * @return 转化得到的字符
-	 */
-	static char chr(int a) {
-		byte target = (byte) (a & 0xFF);
-		return (char) target;
-	}
-
-}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/crypto/SHA1.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/crypto/SHA1.java
deleted file mode 100644
index 1a842822a..000000000
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/crypto/SHA1.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package me.chanjar.weixin.mp.util.crypto;
-
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-import java.util.Arrays;
-
-/**
- * Created by qianjia on 14/10/19.
- */
-public class SHA1 {
-
-  /**
-   * 生成SHA1签名
-   * @param arr
-   * @return
-   */
-  public static String gen(String... arr) throws NoSuchAlgorithmException {
-    Arrays.sort(arr);
-    StringBuilder sb = new StringBuilder();
-    for(String a : arr) {
-      sb.append(a);
-    }
-
-    MessageDigest sha1 = MessageDigest.getInstance("SHA1");
-    sha1.update(sb.toString().getBytes());
-    byte[] output = sha1.digest();
-    return bytesToHex(output);
-  }
-
-
-  protected static String bytesToHex(byte[] b) {
-    char hexDigit[] = {'0', '1', '2', '3', '4', '5', '6', '7',
-        '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
-    StringBuffer buf = new StringBuffer();
-    for (int j = 0; j < b.length; j++) {
-      buf.append(hexDigit[(b[j] >> 4) & 0x0f]);
-      buf.append(hexDigit[b[j] & 0x0f]);
-    }
-    return buf.toString();
-  }
-
-}
diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/crypto/WxCryptUtil.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/crypto/WxCryptUtil.java
deleted file mode 100755
index d4931472a..000000000
--- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/crypto/WxCryptUtil.java
+++ /dev/null
@@ -1,322 +0,0 @@
-/**
- * 对公众平台发送给公众账号的消息加解密示例代码.
- *
- * @copyright Copyright (c) 1998-2014 Tencent Inc.
- */
-
-// ------------------------------------------------------------------------
-
-/**
- * 针对org.apache.commons.codec.binary.Base64,
- * 需要导入架包commons-codec-1.9(或commons-codec-1.8等其他版本)
- * 官方下载地址:http://commons.apache.org/proper/commons-codec/download_codec.cgi
- */
-package me.chanjar.weixin.mp.util.crypto;
-
-import java.io.StringReader;
-import java.nio.charset.Charset;
-import java.security.NoSuchAlgorithmException;
-import java.util.Arrays;
-import java.util.Random;
-
-import javax.crypto.Cipher;
-import javax.crypto.spec.IvParameterSpec;
-import javax.crypto.spec.SecretKeySpec;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
-import me.chanjar.weixin.mp.api.WxConfigStorage;
-import org.apache.commons.codec.binary.Base64;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.xml.sax.InputSource;
-
-public class WxCryptUtil {
-
-  private static final Base64 base64 = new Base64();
-  private static final Charset CHARSET = Charset.forName("utf-8");
-
-  private static final ThreadLocal builderLocal =
-      new ThreadLocal() {
-        @Override protected DocumentBuilder initialValue() {
-          try {
-            return DocumentBuilderFactory.newInstance().newDocumentBuilder();
-          } catch (ParserConfigurationException exc) {
-            throw new IllegalArgumentException(exc);
-          }
-        }
-      };
-
-  private byte[] aesKey;
-  private String token;
-  private String appId;
-
-  /**
-   * 构造函数
-   *
-   * @param wxConfigStorage
-   */
-  public WxCryptUtil(WxConfigStorage wxConfigStorage) {
-    /*
-     * @param token          公众平台上,开发者设置的token
-     * @param encodingAesKey 公众平台上,开发者设置的EncodingAESKey
-     * @param appId          公众平台appid
-     */
-    String encodingAesKey = wxConfigStorage.getAesKey();
-    String token = wxConfigStorage.getToken();
-    String appId = wxConfigStorage.getAppId();
-
-    this.token = token;
-    this.appId = appId;
-    this.aesKey = Base64.decodeBase64(encodingAesKey + "=");
-
-  }
-
-  /**
-   * 构造函数
-   *
-   * @param token          公众平台上,开发者设置的token
-   * @param encodingAesKey 公众平台上,开发者设置的EncodingAESKey
-   * @param appId          公众平台appid
-   */
-  public WxCryptUtil(String token, String encodingAesKey, String appId) {
-    this.token = token;
-    this.appId = appId;
-    this.aesKey = Base64.decodeBase64(encodingAesKey + "=");
-  }
-
-  /**
-   * 将公众平台回复用户的消息加密打包.
-   * 
    - *
  1. 对要发送的消息进行AES-CBC加密
  2. - *
  3. 生成安全签名
  4. - *
  5. 将消息密文和安全签名打包成xml格式
  6. - *
- * - * @param plainText 公众平台待回复用户的消息,xml格式的字符串 - * @return 加密后的可以直接回复用户的密文,包括msg_signature, timestamp, nonce, encrypt的xml格式的字符串 - */ - public String encrypt(String plainText) { - // 加密 - String encryptedXml = encrypt(genRandomStr(), plainText); - - // 生成安全签名 - String timeStamp = timeStamp = Long.toString(System.currentTimeMillis() / 1000l); - String nonce = genRandomStr(); - - try { - String signature = SHA1.gen(token, timeStamp, nonce, encryptedXml); - String result = generateXml(encryptedXml, signature, timeStamp, nonce); - return result; - } catch (NoSuchAlgorithmException e) { - throw new RuntimeException(e); - } - } - - /** - * 对明文进行加密. - * - * @param plainText 需要加密的明文 - * @return 加密后base64编码的字符串 - */ - protected String encrypt(String randomStr, String plainText) { - ByteGroup byteCollector = new ByteGroup(); - byte[] randomStringBytes = randomStr.getBytes(CHARSET); - byte[] plainTextBytes = plainText.getBytes(CHARSET); - byte[] bytesOfSizeInNetworkOrder = number2BytesInNetworkOrder(plainTextBytes.length); - byte[] appIdBytes = appId.getBytes(CHARSET); - - // randomStr + networkBytesOrder + text + appid - byteCollector.addBytes(randomStringBytes); - byteCollector.addBytes(bytesOfSizeInNetworkOrder); - byteCollector.addBytes(plainTextBytes); - byteCollector.addBytes(appIdBytes); - - // ... + pad: 使用自定义的填充方式对明文进行补位填充 - byte[] padBytes = PKCS7Encoder.encode(byteCollector.size()); - byteCollector.addBytes(padBytes); - - // 获得最终的字节流, 未加密 - byte[] unencrypted = byteCollector.toBytes(); - - try { - // 设置加密模式为AES的CBC模式 - Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); - SecretKeySpec keySpec = new SecretKeySpec(aesKey, "AES"); - IvParameterSpec iv = new IvParameterSpec(aesKey, 0, 16); - cipher.init(Cipher.ENCRYPT_MODE, keySpec, iv); - - // 加密 - byte[] encrypted = cipher.doFinal(unencrypted); - - // 使用BASE64对加密后的字符串进行编码 - String base64Encrypted = base64.encodeToString(encrypted); - - return base64Encrypted; - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - /** - * 检验消息的真实性,并且获取解密后的明文. - *
    - *
  1. 利用收到的密文生成安全签名,进行签名验证
  2. - *
  3. 若验证通过,则提取xml中的加密消息
  4. - *
  5. 对消息进行解密
  6. - *
- * - * @param msgSignature 签名串,对应URL参数的msg_signature - * @param timeStamp 时间戳,对应URL参数的timestamp - * @param nonce 随机串,对应URL参数的nonce - * @param encryptedXml 密文,对应POST请求的数据 - * @return 解密后的原文 - */ - public String decrypt(String msgSignature, String timeStamp, String nonce, String encryptedXml) { - // 密钥,公众账号的app secret - // 提取密文 - String cipherText = extractEncryptPart(encryptedXml); - - try { - // 验证安全签名 - String signature = SHA1.gen(token, timeStamp, nonce, cipherText); - if (!signature.equals(msgSignature)) { - throw new RuntimeException("加密消息签名校验失败"); - } - } catch (NoSuchAlgorithmException e) { - throw new RuntimeException(e); - } - - // 解密 - String result = decrypt(cipherText); - return result; - } - - /** - * 对密文进行解密. - * - * @param cipherText 需要解密的密文 - * @return 解密得到的明文 - */ - protected String decrypt(String cipherText) { - byte[] original; - try { - // 设置解密模式为AES的CBC模式 - Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); - SecretKeySpec key_spec = new SecretKeySpec(aesKey, "AES"); - IvParameterSpec iv = new IvParameterSpec(Arrays.copyOfRange(aesKey, 0, 16)); - cipher.init(Cipher.DECRYPT_MODE, key_spec, iv); - - // 使用BASE64对密文进行解码 - byte[] encrypted = Base64.decodeBase64(cipherText); - - // 解密 - original = cipher.doFinal(encrypted); - } catch (Exception e) { - throw new RuntimeException(e); - } - - String xmlContent, from_appid; - try { - // 去除补位字符 - byte[] bytes = PKCS7Encoder.decode(original); - - // 分离16位随机字符串,网络字节序和AppId - byte[] networkOrder = Arrays.copyOfRange(bytes, 16, 20); - - int xmlLength = bytesNetworkOrder2Number(networkOrder); - - xmlContent = new String(Arrays.copyOfRange(bytes, 20, 20 + xmlLength), CHARSET); - from_appid = new String(Arrays.copyOfRange(bytes, 20 + xmlLength, bytes.length), - CHARSET); - } catch (Exception e) { - throw new RuntimeException(e); - } - - // appid不相同的情况 - if (!from_appid.equals(appId)) { - throw new RuntimeException("AppID不正确"); - } - - return xmlContent; - - } - - /** - * 将一个数字转换成生成4个字节的网络字节序bytes数组 - * - * @param number - */ - private byte[] number2BytesInNetworkOrder(int number) { - byte[] orderBytes = new byte[4]; - orderBytes[3] = (byte) (number & 0xFF); - orderBytes[2] = (byte) (number >> 8 & 0xFF); - orderBytes[1] = (byte) (number >> 16 & 0xFF); - orderBytes[0] = (byte) (number >> 24 & 0xFF); - return orderBytes; - } - - /** - * 4个字节的网络字节序bytes数组还原成一个数字 - * - * @param bytesInNetworkOrder - */ - private int bytesNetworkOrder2Number(byte[] bytesInNetworkOrder) { - int sourceNumber = 0; - for (int i = 0; i < 4; i++) { - sourceNumber <<= 8; - sourceNumber |= bytesInNetworkOrder[i] & 0xff; - } - return sourceNumber; - } - - /** - * 随机生成16位字符串 - * - * @return - */ - private String genRandomStr() { - String base = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; - Random random = new Random(); - StringBuffer sb = new StringBuffer(); - for (int i = 0; i < 16; i++) { - int number = random.nextInt(base.length()); - sb.append(base.charAt(number)); - } - return sb.toString(); - } - - /** - * 生成xml消息 - * - * @param encrypt 加密后的消息密文 - * @param signature 安全签名 - * @param timestamp 时间戳 - * @param nonce 随机字符串 - * @return 生成的xml字符串 - */ - private String generateXml(String encrypt, String signature, String timestamp, String nonce) { - String format = - "\n" - + "\n" - + "\n" - + "%3$s\n" - + "\n" - + ""; - return String.format(format, encrypt, signature, timestamp, nonce); - } - - static String extractEncryptPart(String xml) { - try { - DocumentBuilder db = builderLocal.get(); - Document document = db.parse(new InputSource(new StringReader(xml))); - - Element root = document.getDocumentElement(); - return root.getElementsByTagName("Encrypt").item(0).getTextContent(); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - -} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/crypto/WxMpCryptUtil.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/crypto/WxMpCryptUtil.java new file mode 100755 index 000000000..39165b5c1 --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/crypto/WxMpCryptUtil.java @@ -0,0 +1,41 @@ +/** + * 对公众平台发送给公众账号的消息加解密示例代码. + * + * @copyright Copyright (c) 1998-2014 Tencent Inc. + */ + +// ------------------------------------------------------------------------ + +/** + * 针对org.apache.commons.codec.binary.Base64, + * 需要导入架包commons-codec-1.9(或commons-codec-1.8等其他版本) + * 官方下载地址:http://commons.apache.org/proper/commons-codec/download_codec.cgi + */ +package me.chanjar.weixin.mp.util.crypto; + +import me.chanjar.weixin.mp.api.WxMpConfigStorage; +import org.apache.commons.codec.binary.Base64; + +public class WxMpCryptUtil extends me.chanjar.weixin.common.util.crypto.WxCryptUtil { + + /** + * 构造函数 + * + * @param wxMpConfigStorage + */ + public WxMpCryptUtil(WxMpConfigStorage wxMpConfigStorage) { + /* + * @param token 公众平台上,开发者设置的token + * @param encodingAesKey 公众平台上,开发者设置的EncodingAESKey + * @param appId 公众平台appid + */ + String encodingAesKey = wxMpConfigStorage.getAesKey(); + String token = wxMpConfigStorage.getToken(); + String appId = wxMpConfigStorage.getAppId(); + + this.token = token; + this.appidOrCorpid = appId; + this.aesKey = Base64.decodeBase64(encodingAesKey + "="); + } + +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/fs/FileUtils.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/fs/FileUtils.java deleted file mode 100644 index c73efa587..000000000 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/fs/FileUtils.java +++ /dev/null @@ -1,47 +0,0 @@ -package me.chanjar.weixin.mp.util.fs; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; - -public class FileUtils { - - /** - * 创建临时文件 - * @param inputStream - * @param name 文件名 - * @param ext 扩展名 - * @return - * @throws IOException - */ - public static File createTmpFile(InputStream inputStream, String name, String ext) throws IOException { - FileOutputStream fos = null; - try { - File tmpFile = File.createTempFile(name, '.' + ext); - tmpFile.deleteOnExit(); - fos = new FileOutputStream(tmpFile); - int read = 0; - byte[] bytes = new byte[1024 * 100]; - while ((read = inputStream.read(bytes)) != -1) { - fos.write(bytes, 0, read); - } - fos.flush(); - return tmpFile; - } finally { - if (inputStream != null) { - try { - inputStream.close(); - } catch (IOException e) { - } - } - if (fos != null) { - try { - fos.close(); - } catch (IOException e) { - } - } - } - } - -} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MediaDownloadRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MediaDownloadRequestExecutor.java deleted file mode 100644 index 83df39dab..000000000 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MediaDownloadRequestExecutor.java +++ /dev/null @@ -1,67 +0,0 @@ -package me.chanjar.weixin.mp.util.http; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import me.chanjar.weixin.mp.bean.result.WxError; -import me.chanjar.weixin.mp.exception.WxErrorException; -import me.chanjar.weixin.mp.util.fs.FileUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.http.Header; -import org.apache.http.client.ClientProtocolException; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.entity.ContentType; - -/** - * 下载媒体文件请求执行器,请求的参数是String, 返回的结果是File - * @author chanjarster - * - */ -public class MediaDownloadRequestExecutor implements RequestExecutor { - - @Override - public File execute(String uri, String queryParam) throws WxErrorException, ClientProtocolException, IOException { - if (queryParam != null) { - if (uri.indexOf('?') == -1) { - uri += '?'; - } - uri += uri.endsWith("?") ? queryParam : '&' + queryParam; - } - - HttpGet httpGet = new HttpGet(uri); - CloseableHttpResponse response = httpclient.execute(httpGet); - - Header[] contentTypeHeader = response.getHeaders("Content-Type"); - if (contentTypeHeader != null && contentTypeHeader.length > 0) { - // 下载媒体文件出错 - if (ContentType.TEXT_PLAIN.getMimeType().equals(contentTypeHeader[0].getValue())) { - String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response); - throw new WxErrorException(WxError.fromJson(responseContent)); - } - } - InputStream inputStream = InputStreamResponseHandler.INSTANCE.handleResponse(response); - - // 视频文件不支持下载 - String fileName = getFileName(response); - if (StringUtils.isBlank(fileName)) { - return null; - } - String[] name_ext = fileName.split("\\."); - File localFile = FileUtils.createTmpFile(inputStream, name_ext[0], name_ext[1]); - return localFile; - } - - protected String getFileName(CloseableHttpResponse response) { - Header[] contentDispositionHeader = response.getHeaders("Content-disposition"); - Pattern p = Pattern.compile(".*filename=\"(.*)\""); - Matcher m = p.matcher(contentDispositionHeader[0].getValue()); - m.matches(); - String fileName = m.group(1); - return fileName; - } - -} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MediaUploadRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MediaUploadRequestExecutor.java deleted file mode 100644 index d7c85fdf8..000000000 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MediaUploadRequestExecutor.java +++ /dev/null @@ -1,43 +0,0 @@ -package me.chanjar.weixin.mp.util.http; - -import java.io.File; -import java.io.IOException; - -import me.chanjar.weixin.mp.bean.result.WxError; -import me.chanjar.weixin.mp.bean.result.WxMediaUploadResult; -import me.chanjar.weixin.mp.exception.WxErrorException; -import org.apache.http.HttpEntity; -import org.apache.http.client.ClientProtocolException; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.entity.ContentType; -import org.apache.http.entity.mime.MultipartEntityBuilder; - -/** - * 上传媒体文件请求执行器,请求的参数是File, 返回的结果是String - * @author chanjarster - * - */ -public class MediaUploadRequestExecutor implements RequestExecutor { - - @Override - public WxMediaUploadResult execute(String uri, File file) throws WxErrorException, ClientProtocolException, IOException { - HttpPost httpPost = new HttpPost(uri); - if (file != null) { - HttpEntity entity = MultipartEntityBuilder - .create() - .addBinaryBody("media", file) - .build(); - httpPost.setEntity(entity); - httpPost.setHeader("Content-Type", ContentType.MULTIPART_FORM_DATA.toString()); - } - CloseableHttpResponse response = httpclient.execute(httpPost); - String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response); - WxError error = WxError.fromJson(responseContent); - if (error.getErrorCode() != 0) { - throw new WxErrorException(error); - } - return WxMediaUploadResult.fromJson(responseContent); - } - -} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/QrCodeRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/QrCodeRequestExecutor.java index e018d7248..554c9b8f2 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/QrCodeRequestExecutor.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/QrCodeRequestExecutor.java @@ -1,31 +1,33 @@ package me.chanjar.weixin.mp.util.http; +import me.chanjar.weixin.common.bean.result.WxError; +import me.chanjar.weixin.common.util.fs.FileUtils; +import me.chanjar.weixin.common.util.http.InputStreamResponseHandler; +import me.chanjar.weixin.common.util.http.RequestExecutor; +import me.chanjar.weixin.common.util.http.Utf8ResponseHandler; +import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket; +import me.chanjar.weixin.common.exception.WxErrorException; +import org.apache.http.Header; +import org.apache.http.client.ClientProtocolException; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.entity.ContentType; + import java.io.File; import java.io.IOException; import java.io.InputStream; import java.net.URLEncoder; import java.util.UUID; -import org.apache.http.Header; -import org.apache.http.client.ClientProtocolException; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.entity.ContentType; - -import me.chanjar.weixin.mp.bean.result.WxError; -import me.chanjar.weixin.mp.bean.result.WxQrCodeTicket; -import me.chanjar.weixin.mp.exception.WxErrorException; -import me.chanjar.weixin.mp.util.fs.FileUtils; - /** * 获得QrCode图片 请求执行器 * @author chanjarster * */ -public class QrCodeRequestExecutor implements RequestExecutor { +public class QrCodeRequestExecutor implements RequestExecutor { @Override - public File execute(String uri, WxQrCodeTicket ticket) throws WxErrorException, ClientProtocolException, IOException { + public File execute(String uri, WxMpQrCodeTicket ticket) throws WxErrorException, ClientProtocolException, IOException { if (ticket != null) { if (uri.indexOf('?') == -1) { uri += '?'; diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/RequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/RequestExecutor.java deleted file mode 100644 index f729d08a7..000000000 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/RequestExecutor.java +++ /dev/null @@ -1,24 +0,0 @@ -package me.chanjar.weixin.mp.util.http; - -import java.io.IOException; - -import org.apache.http.client.ClientProtocolException; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; - -import me.chanjar.weixin.mp.exception.WxErrorException; - -/** - * http请求执行器 - * @author chanjarster - * - * @param 返回值类型 - * @param 请求参数类型 - */ -public interface RequestExecutor { - - public static final CloseableHttpClient httpclient = HttpClients.createDefault(); - - public T execute(String uri, E data) throws WxErrorException, ClientProtocolException, IOException; - -} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/SimpleGetRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/SimpleGetRequestExecutor.java deleted file mode 100644 index d03145164..000000000 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/SimpleGetRequestExecutor.java +++ /dev/null @@ -1,36 +0,0 @@ -package me.chanjar.weixin.mp.util.http; - -import java.io.IOException; - -import me.chanjar.weixin.mp.bean.result.WxError; -import me.chanjar.weixin.mp.exception.WxErrorException; -import org.apache.http.client.ClientProtocolException; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpGet; - -/** - * 简单的GET请求执行器,请求的参数是String, 返回的结果也是String - * @author chanjarster - * - */ -public class SimpleGetRequestExecutor implements RequestExecutor { - - @Override - public String execute(String uri, String queryParam) throws WxErrorException, ClientProtocolException, IOException { - if (queryParam != null) { - if (uri.indexOf('?') == -1) { - uri += '?'; - } - uri += uri.endsWith("?") ? queryParam : '&' + queryParam; - } - HttpGet httpGet = new HttpGet(uri); - CloseableHttpResponse response = httpclient.execute(httpGet); - String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response); - WxError error = WxError.fromJson(responseContent); - if (error.getErrorCode() != 0) { - throw new WxErrorException(error); - } - return responseContent; - } - -} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/SimplePostRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/SimplePostRequestExecutor.java deleted file mode 100644 index 2af893268..000000000 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/SimplePostRequestExecutor.java +++ /dev/null @@ -1,36 +0,0 @@ -package me.chanjar.weixin.mp.util.http; - -import java.io.IOException; - -import me.chanjar.weixin.mp.bean.result.WxError; -import me.chanjar.weixin.mp.exception.WxErrorException; -import org.apache.http.Consts; -import org.apache.http.client.ClientProtocolException; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.entity.StringEntity; - -/** - * 简单的POST请求执行器,请求的参数是String, 返回的结果也是String - * @author chanjarster - * - */ -public class SimplePostRequestExecutor implements RequestExecutor { - - @Override - public String execute(String uri, String postEntity) throws WxErrorException, ClientProtocolException, IOException { - HttpPost httpPost = new HttpPost(uri); - if (postEntity != null) { - StringEntity entity = new StringEntity(postEntity, Consts.UTF_8); - httpPost.setEntity(entity); - } - CloseableHttpResponse response = httpclient.execute(httpPost); - String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response); - WxError error = WxError.fromJson(responseContent); - if (error.getErrorCode() != 0) { - throw new WxErrorException(error); - } - return responseContent; - } - -} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/Utf8ResponseHandler.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/Utf8ResponseHandler.java deleted file mode 100644 index e4b008def..000000000 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/Utf8ResponseHandler.java +++ /dev/null @@ -1,32 +0,0 @@ -package me.chanjar.weixin.mp.util.http; - -import java.io.IOException; - -import org.apache.http.Consts; -import org.apache.http.HttpEntity; -import org.apache.http.HttpResponse; -import org.apache.http.StatusLine; -import org.apache.http.client.HttpResponseException; -import org.apache.http.client.ResponseHandler; -import org.apache.http.util.EntityUtils; - -/** - * copy from {@link org.apache.http.impl.client.BasicResponseHandler} - * @author chanjarster - * - */ -public class Utf8ResponseHandler implements ResponseHandler { - - public static final ResponseHandler INSTANCE = new Utf8ResponseHandler(); - - public String handleResponse(final HttpResponse response) throws HttpResponseException, IOException { - final StatusLine statusLine = response.getStatusLine(); - final HttpEntity entity = response.getEntity(); - if (statusLine.getStatusCode() >= 300) { - EntityUtils.consume(entity); - throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase()); - } - return entity == null ? null : EntityUtils.toString(entity, Consts.UTF_8); - } - -} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/GsonHelper.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/GsonHelper.java deleted file mode 100644 index 7957dae05..000000000 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/GsonHelper.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * KINGSTAR MEDIA SOLUTIONS Co.,LTD. Copyright c 2005-2013. All rights reserved. - * - * This source code is the property of KINGSTAR MEDIA SOLUTIONS LTD. It is intended - * only for the use of KINGSTAR MEDIA application development. Reengineering, reproduction - * arose from modification of the original source, or other redistribution of this source - * is not permitted without written permission of the KINGSTAR MEDIA SOLUTIONS LTD. - */ -package me.chanjar.weixin.mp.util.json; - - -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; - - -public class GsonHelper { - - public static boolean isNull(JsonElement element) { - return element == null || element.isJsonNull(); - } - - public static boolean isNotNull(JsonElement element) { - return !isNull(element); - } - - public static Long getLong(JsonObject json, String property) { - return getAsLong(json.get(property)); - } - - public static long getPrimitiveLong(JsonObject json, String property) { - return getAsPrimitiveLong(json.get(property)); - } - - public static Integer getInteger(JsonObject json, String property) { - return getAsInteger(json.get(property)); - } - - public static int getPrimitiveInteger(JsonObject json, String property) { - return getAsPrimitiveInt(json.get(property)); - } - - public static Double getDouble(JsonObject json, String property) { - return getAsDouble(json.get(property)); - } - - public static double getPrimitiveDouble(JsonObject json, String property) { - return getAsPrimitiveDouble(json.get(property)); - } - - public static Float getFloat(JsonObject json, String property) { - return getAsFloat(json.get(property)); - } - - public static float getPrimitiveFloat(JsonObject json, String property) { - return getAsPrimitiveFloat(json.get(property)); - } - - public static Boolean getBoolean(JsonObject json, String property) { - return getAsBoolean(json.get(property)); - } - - public static String getString(JsonObject json, String property) { - return getAsString(json.get(property)); - } - - public static String getAsString(JsonElement element) { - return isNull(element) ? null : element.getAsString(); - } - - public static Long getAsLong(JsonElement element) { - return isNull(element) ? null : element.getAsLong(); - } - - public static long getAsPrimitiveLong(JsonElement element) { - Long r = getAsLong(element); - return r == null ? 0l : r; - } - - public static Integer getAsInteger(JsonElement element) { - return isNull(element) ? null : element.getAsInt(); - } - - public static int getAsPrimitiveInt(JsonElement element) { - Integer r = getAsInteger(element); - return r == null ? 0 : r; - } - - public static Boolean getAsBoolean(JsonElement element) { - return isNull(element) ? null : element.getAsBoolean(); - } - - public static boolean getAsPrimitiveBool(JsonElement element) { - Boolean r = getAsBoolean(element); - return r == null ? false : r.booleanValue(); - } - - public static Double getAsDouble(JsonElement element) { - return isNull(element) ? null : element.getAsDouble(); - } - - public static double getAsPrimitiveDouble(JsonElement element) { - Double r = getAsDouble(element); - return r == null ? 0d : r; - } - - public static Float getAsFloat(JsonElement element) { - return isNull(element) ? null : element.getAsFloat(); - } - - public static float getAsPrimitiveFloat(JsonElement element) { - Float r = getAsFloat(element); - return r == null ? 0f : r; - } - -} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxErrorAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxErrorAdapter.java deleted file mode 100644 index e85314b01..000000000 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxErrorAdapter.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * KINGSTAR MEDIA SOLUTIONS Co.,LTD. Copyright c 2005-2013. All rights reserved. - * - * This source code is the property of KINGSTAR MEDIA SOLUTIONS LTD. It is intended - * only for the use of KINGSTAR MEDIA application development. Reengineering, reproduction - * arose from modification of the original source, or other redistribution of this source - * is not permitted without written permission of the KINGSTAR MEDIA SOLUTIONS LTD. - */ -package me.chanjar.weixin.mp.util.json; - -import com.google.gson.*; -import me.chanjar.weixin.mp.bean.result.WxError; - -import java.lang.reflect.Type; - -/** - * - * @author Daniel Qian - * - */ -public class WxErrorAdapter implements JsonDeserializer { - - public WxError deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { - WxError wxError = new WxError(); - JsonObject wxErrorJsonObject = json.getAsJsonObject(); - - if (wxErrorJsonObject.get("errcode") != null && !wxErrorJsonObject.get("errcode").isJsonNull()) { - wxError.setErrorCode(GsonHelper.getAsPrimitiveInt(wxErrorJsonObject.get("errcode"))); - } - if (wxErrorJsonObject.get("errmsg") != null && !wxErrorJsonObject.get("errmsg").isJsonNull()) { - wxError.setErrorMsg(GsonHelper.getAsString(wxErrorJsonObject.get("errmsg"))); - } - return wxError; - } - -} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxGsonBuilder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxGsonBuilder.java deleted file mode 100644 index 320335039..000000000 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxGsonBuilder.java +++ /dev/null @@ -1,37 +0,0 @@ -package me.chanjar.weixin.mp.util.json; - -import me.chanjar.weixin.bean.*; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import me.chanjar.weixin.mp.bean.*; -import me.chanjar.weixin.mp.bean.result.*; - -public class WxGsonBuilder { - - public static final GsonBuilder INSTANCE = new GsonBuilder(); - - static { - INSTANCE.disableHtmlEscaping(); - INSTANCE.registerTypeAdapter(WxCustomMessage.class, new WxCustomMessageGsonAdapter()); - INSTANCE.registerTypeAdapter(WxMenu.class, new WxMenuGsonAdapter()); - INSTANCE.registerTypeAdapter(WxMassNews.class, new WxMassNewsGsonAdapter()); - INSTANCE.registerTypeAdapter(WxMassGroupMessage.class, new WxMassMessageGsonAdapter()); - INSTANCE.registerTypeAdapter(WxMassOpenIdsMessage.class, new WxMassOpenIdsMessageGsonAdapter()); - INSTANCE.registerTypeAdapter(WxGroup.class, new WxGroupGsonAdapter()); - INSTANCE.registerTypeAdapter(WxUser.class, new WxUserGsonAdapter()); - INSTANCE.registerTypeAdapter(WxUserList.class, new WxUserListGsonAdapter()); - INSTANCE.registerTypeAdapter(WxAccessToken.class, new WxAccessTokenAdapter()); - INSTANCE.registerTypeAdapter(WxError.class, new WxErrorAdapter()); - INSTANCE.registerTypeAdapter(WxMassVideo.class, new WxMassVideoAdapter()); - INSTANCE.registerTypeAdapter(WxMediaUploadResult.class, new WxMediaUploadResultAdapter()); - INSTANCE.registerTypeAdapter(WxMassSendResult.class, new WxMassSendResultAdapter()); - INSTANCE.registerTypeAdapter(WxMassUploadResult.class, new WxMassUploadResultAdapter()); - INSTANCE.registerTypeAdapter(WxQrCodeTicket.class, new WxQrCodeTicketAdapter()); - } - - public static Gson create() { - return INSTANCE.create(); - } - -} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxCustomMessageGsonAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpCustomMessageGsonAdapter.java similarity index 71% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxCustomMessageGsonAdapter.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpCustomMessageGsonAdapter.java index 699b7d3fd..ad662a85a 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxCustomMessageGsonAdapter.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpCustomMessageGsonAdapter.java @@ -8,48 +8,43 @@ */ package me.chanjar.weixin.mp.util.json; +import com.google.gson.*; +import me.chanjar.weixin.mp.api.WxMpConsts; +import me.chanjar.weixin.mp.bean.WxMpCustomMessage; + import java.lang.reflect.Type; -import me.chanjar.weixin.mp.api.WxConsts; -import me.chanjar.weixin.mp.bean.WxCustomMessage; - -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; - /** * * @author qianjia * */ -public class WxCustomMessageGsonAdapter implements JsonSerializer { +public class WxMpCustomMessageGsonAdapter implements JsonSerializer { - public JsonElement serialize(WxCustomMessage message, Type typeOfSrc, JsonSerializationContext context) { + public JsonElement serialize(WxMpCustomMessage message, Type typeOfSrc, JsonSerializationContext context) { JsonObject messageJson = new JsonObject(); messageJson.addProperty("touser", message.getToUser()); messageJson.addProperty("msgtype", message.getMsgType()); - if (WxConsts.CUSTOM_MSG_TEXT.equals(message.getMsgType())) { + if (WxMpConsts.CUSTOM_MSG_TEXT.equals(message.getMsgType())) { JsonObject text = new JsonObject(); text.addProperty("content", message.getContent()); messageJson.add("text", text); } - if (WxConsts.CUSTOM_MSG_IMAGE.equals(message.getMsgType())) { + if (WxMpConsts.CUSTOM_MSG_IMAGE.equals(message.getMsgType())) { JsonObject image = new JsonObject(); image.addProperty("media_id", message.getMediaId()); messageJson.add("image", image); } - if (WxConsts.CUSTOM_MSG_VOICE.equals(message.getMsgType())) { + if (WxMpConsts.CUSTOM_MSG_VOICE.equals(message.getMsgType())) { JsonObject voice = new JsonObject(); voice.addProperty("media_id", message.getMediaId()); messageJson.add("voice", voice); } - if (WxConsts.CUSTOM_MSG_VIDEO.equals(message.getMsgType())) { + if (WxMpConsts.CUSTOM_MSG_VIDEO.equals(message.getMsgType())) { JsonObject video = new JsonObject(); video.addProperty("media_id", message.getMediaId()); video.addProperty("thumb_media_id", message.getThumbMediaId()); @@ -58,7 +53,7 @@ public class WxCustomMessageGsonAdapter implements JsonSerializer, JsonDeserializer { +public class WxMpGroupGsonAdapter implements JsonSerializer, JsonDeserializer { - public JsonElement serialize(WxGroup group, Type typeOfSrc, JsonSerializationContext context) { + public JsonElement serialize(WxMpGroup group, Type typeOfSrc, JsonSerializationContext context) { JsonObject json = new JsonObject(); JsonObject groupJson = new JsonObject(); groupJson.addProperty("name", group.getName()); @@ -37,8 +31,8 @@ public class WxGroupGsonAdapter implements JsonSerializer, JsonDeserial return json; } - public WxGroup deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { - WxGroup group = new WxGroup(); + public WxMpGroup deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + WxMpGroup group = new WxMpGroup(); JsonObject groupJson = json.getAsJsonObject(); if (json.getAsJsonObject().get("group") != null) { groupJson = json.getAsJsonObject().get("group").getAsJsonObject(); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpGsonBuilder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpGsonBuilder.java new file mode 100644 index 000000000..021b660d9 --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpGsonBuilder.java @@ -0,0 +1,31 @@ +package me.chanjar.weixin.mp.util.json; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import me.chanjar.weixin.mp.bean.*; +import me.chanjar.weixin.mp.bean.result.*; + +public class WxMpGsonBuilder { + + public static final GsonBuilder INSTANCE = new GsonBuilder(); + + static { + INSTANCE.disableHtmlEscaping(); + INSTANCE.registerTypeAdapter(WxMpCustomMessage.class, new WxMpCustomMessageGsonAdapter()); + INSTANCE.registerTypeAdapter(WxMpMassNews.class, new WxMpMassNewsGsonAdapter()); + INSTANCE.registerTypeAdapter(WxMpMassGroupMessage.class, new WxMpMassMessageGsonAdapter()); + INSTANCE.registerTypeAdapter(WxMpMassOpenIdsMessage.class, new WxMpMassOpenIdsMessageGsonAdapter()); + INSTANCE.registerTypeAdapter(WxMpGroup.class, new WxMpGroupGsonAdapter()); + INSTANCE.registerTypeAdapter(WxMpUser.class, new WxUserGsonAdapter()); + INSTANCE.registerTypeAdapter(WxMpUserList.class, new WxUserListGsonAdapter()); + INSTANCE.registerTypeAdapter(WxMpMassVideo.class, new WxMpMassVideoAdapter()); + INSTANCE.registerTypeAdapter(WxMpMassSendResult.class, new WxMpMassSendResultAdapter()); + INSTANCE.registerTypeAdapter(WxMpMassUploadResult.class, new WxMpMassUploadResultAdapter()); + INSTANCE.registerTypeAdapter(WxMpQrCodeTicket.class, new WxQrCodeTicketAdapter()); + } + + public static Gson create() { + return INSTANCE.create(); + } + +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMassMessageGsonAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassMessageGsonAdapter.java similarity index 62% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMassMessageGsonAdapter.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassMessageGsonAdapter.java index 5a24b5bb9..3c7ef51a6 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMassMessageGsonAdapter.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassMessageGsonAdapter.java @@ -8,54 +8,53 @@ */ package me.chanjar.weixin.mp.util.json; -import java.lang.reflect.Type; - -import me.chanjar.weixin.mp.api.WxConsts; -import me.chanjar.weixin.mp.bean.WxMassGroupMessage; - import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; +import me.chanjar.weixin.mp.api.WxMpConsts; +import me.chanjar.weixin.mp.bean.WxMpMassGroupMessage; + +import java.lang.reflect.Type; /** * * @author qianjia * */ -public class WxMassMessageGsonAdapter implements JsonSerializer { +public class WxMpMassMessageGsonAdapter implements JsonSerializer { - public JsonElement serialize(WxMassGroupMessage message, Type typeOfSrc, JsonSerializationContext context) { + public JsonElement serialize(WxMpMassGroupMessage message, Type typeOfSrc, JsonSerializationContext context) { JsonObject messageJson = new JsonObject(); JsonObject filter = new JsonObject(); filter.addProperty("group_id", message.getGroupId()); messageJson.add("filter", filter); - if (WxConsts.MASS_MSG_NEWS.equals(message.getMsgtype())) { + if (WxMpConsts.MASS_MSG_NEWS.equals(message.getMsgtype())) { JsonObject sub = new JsonObject(); sub.addProperty("media_id", message.getMediaId()); - messageJson.add(WxConsts.MASS_MSG_NEWS, sub); + messageJson.add(WxMpConsts.MASS_MSG_NEWS, sub); } - if (WxConsts.MASS_MSG_TEXT.equals(message.getMsgtype())) { + if (WxMpConsts.MASS_MSG_TEXT.equals(message.getMsgtype())) { JsonObject sub = new JsonObject(); sub.addProperty("content", message.getContent()); - messageJson.add(WxConsts.MASS_MSG_TEXT, sub); + messageJson.add(WxMpConsts.MASS_MSG_TEXT, sub); } - if (WxConsts.MASS_MSG_VOICE.equals(message.getMsgtype())) { + if (WxMpConsts.MASS_MSG_VOICE.equals(message.getMsgtype())) { JsonObject sub = new JsonObject(); sub.addProperty("media_id", message.getMediaId()); - messageJson.add(WxConsts.MASS_MSG_VOICE, sub); + messageJson.add(WxMpConsts.MASS_MSG_VOICE, sub); } - if (WxConsts.MASS_MSG_IMAGE.equals(message.getMsgtype())) { + if (WxMpConsts.MASS_MSG_IMAGE.equals(message.getMsgtype())) { JsonObject sub = new JsonObject(); sub.addProperty("media_id", message.getMediaId()); - messageJson.add(WxConsts.MASS_MSG_IMAGE, sub); + messageJson.add(WxMpConsts.MASS_MSG_IMAGE, sub); } - if (WxConsts.MASS_MSG_VIDEO.equals(message.getMsgtype())) { + if (WxMpConsts.MASS_MSG_VIDEO.equals(message.getMsgtype())) { JsonObject sub = new JsonObject(); sub.addProperty("media_id", message.getMediaId()); - messageJson.add(WxConsts.MASS_MSG_VIDEO, sub); + messageJson.add(WxMpConsts.MASS_MSG_VIDEO, sub); } messageJson.addProperty("msgtype", message.getMsgtype()); return messageJson; diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMassNewsGsonAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassNewsGsonAdapter.java similarity index 75% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMassNewsGsonAdapter.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassNewsGsonAdapter.java index 42b35da19..e5f0a485b 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMassNewsGsonAdapter.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassNewsGsonAdapter.java @@ -8,28 +8,23 @@ */ package me.chanjar.weixin.mp.util.json; +import com.google.gson.*; +import me.chanjar.weixin.mp.bean.WxMpMassNews; + import java.lang.reflect.Type; -import me.chanjar.weixin.mp.bean.WxMassNews; - -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; - /** * * @author qianjia * */ -public class WxMassNewsGsonAdapter implements JsonSerializer { +public class WxMpMassNewsGsonAdapter implements JsonSerializer { - public JsonElement serialize(WxMassNews message, Type typeOfSrc, JsonSerializationContext context) { + public JsonElement serialize(WxMpMassNews message, Type typeOfSrc, JsonSerializationContext context) { JsonObject newsJson = new JsonObject(); JsonArray articleJsonArray = new JsonArray(); - for (WxMassNews.WxMassNewsArticle article : message.getArticles()) { + for (WxMpMassNews.WxMassNewsArticle article : message.getArticles()) { JsonObject articleJson = new JsonObject(); articleJson.addProperty("thumb_media_id", article.getThumbMediaId()); articleJson.addProperty("title", article.getTitle()); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMassOpenIdsMessageGsonAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassOpenIdsMessageGsonAdapter.java similarity index 55% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMassOpenIdsMessageGsonAdapter.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassOpenIdsMessageGsonAdapter.java index 2b8a7403d..e3d680a60 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMassOpenIdsMessageGsonAdapter.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassOpenIdsMessageGsonAdapter.java @@ -8,26 +8,20 @@ */ package me.chanjar.weixin.mp.util.json; +import com.google.gson.*; +import me.chanjar.weixin.mp.api.WxMpConsts; +import me.chanjar.weixin.mp.bean.WxMpMassOpenIdsMessage; + import java.lang.reflect.Type; -import me.chanjar.weixin.mp.api.WxConsts; -import me.chanjar.weixin.mp.bean.WxMassOpenIdsMessage; - -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; - /** * * @author qianjia * */ -public class WxMassOpenIdsMessageGsonAdapter implements JsonSerializer { +public class WxMpMassOpenIdsMessageGsonAdapter implements JsonSerializer { - public JsonElement serialize(WxMassOpenIdsMessage message, Type typeOfSrc, JsonSerializationContext context) { + public JsonElement serialize(WxMpMassOpenIdsMessage message, Type typeOfSrc, JsonSerializationContext context) { JsonObject messageJson = new JsonObject(); JsonArray toUsers = new JsonArray(); @@ -36,30 +30,30 @@ public class WxMassOpenIdsMessageGsonAdapter implements JsonSerializer { +public class WxMpMassSendResultAdapter implements JsonDeserializer { - public WxMassSendResult deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { - WxMassSendResult sendResult = new WxMassSendResult(); + public WxMpMassSendResult deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + WxMpMassSendResult sendResult = new WxMpMassSendResult(); JsonObject sendResultJsonObject = json.getAsJsonObject(); if (sendResultJsonObject.get("errcode") != null && !sendResultJsonObject.get("errcode").isJsonNull()) { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMassUploadResultAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassUploadResultAdapter.java similarity index 76% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMassUploadResultAdapter.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassUploadResultAdapter.java index 30fa554c1..73f033827 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMassUploadResultAdapter.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassUploadResultAdapter.java @@ -9,7 +9,8 @@ package me.chanjar.weixin.mp.util.json; import com.google.gson.*; -import me.chanjar.weixin.mp.bean.result.WxMassUploadResult; +import me.chanjar.weixin.common.util.json.GsonHelper; +import me.chanjar.weixin.mp.bean.result.WxMpMassUploadResult; import java.lang.reflect.Type; @@ -18,10 +19,10 @@ import java.lang.reflect.Type; * @author Daniel Qian * */ -public class WxMassUploadResultAdapter implements JsonDeserializer { +public class WxMpMassUploadResultAdapter implements JsonDeserializer { - public WxMassUploadResult deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { - WxMassUploadResult uploadResult = new WxMassUploadResult(); + public WxMpMassUploadResult deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + WxMpMassUploadResult uploadResult = new WxMpMassUploadResult(); JsonObject uploadResultJsonObject = json.getAsJsonObject(); if (uploadResultJsonObject.get("type") != null && !uploadResultJsonObject.get("type").isJsonNull()) { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMassVideoAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassVideoAdapter.java similarity index 67% rename from weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMassVideoAdapter.java rename to weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassVideoAdapter.java index d7071f9b8..d4b37b816 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMassVideoAdapter.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpMassVideoAdapter.java @@ -8,8 +8,11 @@ */ package me.chanjar.weixin.mp.util.json; -import com.google.gson.*; -import me.chanjar.weixin.mp.bean.WxMassVideo; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import me.chanjar.weixin.mp.bean.WxMpMassVideo; import java.lang.reflect.Type; @@ -18,9 +21,9 @@ import java.lang.reflect.Type; * @author Daniel Qian * */ -public class WxMassVideoAdapter implements JsonSerializer { +public class WxMpMassVideoAdapter implements JsonSerializer { - public JsonElement serialize(WxMassVideo message, Type typeOfSrc, JsonSerializationContext context) { + public JsonElement serialize(WxMpMassVideo message, Type typeOfSrc, JsonSerializationContext context) { JsonObject messageJson = new JsonObject(); messageJson.addProperty("media_id", message.getMediaId()); messageJson.addProperty("description", message.getDescription()); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxQrCodeTicketAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxQrCodeTicketAdapter.java index 441644792..522d70d06 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxQrCodeTicketAdapter.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxQrCodeTicketAdapter.java @@ -9,7 +9,8 @@ package me.chanjar.weixin.mp.util.json; import com.google.gson.*; -import me.chanjar.weixin.mp.bean.result.WxQrCodeTicket; +import me.chanjar.weixin.common.util.json.GsonHelper; +import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket; import java.lang.reflect.Type; @@ -18,10 +19,10 @@ import java.lang.reflect.Type; * @author Daniel Qian * */ -public class WxQrCodeTicketAdapter implements JsonDeserializer { +public class WxQrCodeTicketAdapter implements JsonDeserializer { - public WxQrCodeTicket deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { - WxQrCodeTicket ticket = new WxQrCodeTicket(); + public WxMpQrCodeTicket deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + WxMpQrCodeTicket ticket = new WxMpQrCodeTicket(); JsonObject ticketJsonObject = json.getAsJsonObject(); if (ticketJsonObject.get("ticket") != null && !ticketJsonObject.get("ticket").isJsonNull()) { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxUserGsonAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxUserGsonAdapter.java index d6bd0f9c8..cbbc3080b 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxUserGsonAdapter.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxUserGsonAdapter.java @@ -8,45 +8,41 @@ */ package me.chanjar.weixin.mp.util.json; +import com.google.gson.*; +import me.chanjar.weixin.common.util.json.GsonHelper; +import me.chanjar.weixin.mp.bean.result.WxMpUser; + import java.lang.reflect.Type; -import me.chanjar.weixin.mp.bean.result.WxUser; - -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; - /** * * @author qianjia * */ -public class WxUserGsonAdapter implements JsonDeserializer { +public class WxUserGsonAdapter implements JsonDeserializer { - public WxUser deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + public WxMpUser deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject o = json.getAsJsonObject(); - WxUser wxUser = new WxUser(); - wxUser.setSubscribe(new Integer(0).equals(GsonHelper.getInteger(o, "subscribe")) ? false : true); - wxUser.setCity(GsonHelper.getString(o, "city")); - wxUser.setCountry(GsonHelper.getString(o, "country")); - wxUser.setHeadImgUrl(GsonHelper.getString(o, "headimgurl")); - wxUser.setLanguage(GsonHelper.getString(o, "language")); - wxUser.setNickname(GsonHelper.getString(o, "nickname")); - wxUser.setOpenId(GsonHelper.getString(o, "openid")); - wxUser.setProvince(GsonHelper.getString(o, "province")); - wxUser.setSubscribeTime(GsonHelper.getLong(o, "subscribe_time")); - wxUser.setUnionId(GsonHelper.getString(o, "unionid")); + WxMpUser wxMpUser = new WxMpUser(); + wxMpUser.setSubscribe(new Integer(0).equals(GsonHelper.getInteger(o, "subscribe")) ? false : true); + wxMpUser.setCity(GsonHelper.getString(o, "city")); + wxMpUser.setCountry(GsonHelper.getString(o, "country")); + wxMpUser.setHeadImgUrl(GsonHelper.getString(o, "headimgurl")); + wxMpUser.setLanguage(GsonHelper.getString(o, "language")); + wxMpUser.setNickname(GsonHelper.getString(o, "nickname")); + wxMpUser.setOpenId(GsonHelper.getString(o, "openid")); + wxMpUser.setProvince(GsonHelper.getString(o, "province")); + wxMpUser.setSubscribeTime(GsonHelper.getLong(o, "subscribe_time")); + wxMpUser.setUnionId(GsonHelper.getString(o, "unionid")); Integer sex = GsonHelper.getInteger(o, "sex"); if(new Integer(1).equals(sex)) { - wxUser.setSex("男"); + wxMpUser.setSex("男"); } else if (new Integer(2).equals(sex)) { - wxUser.setSex("女"); + wxMpUser.setSex("女"); } else { - wxUser.setSex("未知"); + wxMpUser.setSex("未知"); } - return wxUser; + return wxMpUser; } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxUserListGsonAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxUserListGsonAdapter.java index 56fa11387..ec65735e2 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxUserListGsonAdapter.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxUserListGsonAdapter.java @@ -8,35 +8,30 @@ */ package me.chanjar.weixin.mp.util.json; +import com.google.gson.*; +import me.chanjar.weixin.common.util.json.GsonHelper; +import me.chanjar.weixin.mp.bean.result.WxMpUserList; + import java.lang.reflect.Type; -import me.chanjar.weixin.mp.bean.result.WxUserList; - -import com.google.gson.JsonArray; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; - /** * * @author qianjia * */ -public class WxUserListGsonAdapter implements JsonDeserializer { +public class WxUserListGsonAdapter implements JsonDeserializer { - public WxUserList deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + public WxMpUserList deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject o = json.getAsJsonObject(); - WxUserList wxUserList = new WxUserList(); - wxUserList.setTotal(GsonHelper.getInteger(o, "total")); - wxUserList.setCount(GsonHelper.getInteger(o, "count")); - wxUserList.setNextOpenId(GsonHelper.getString(o, "next_openid")); + WxMpUserList wxMpUserList = new WxMpUserList(); + wxMpUserList.setTotal(GsonHelper.getInteger(o, "total")); + wxMpUserList.setCount(GsonHelper.getInteger(o, "count")); + wxMpUserList.setNextOpenId(GsonHelper.getString(o, "next_openid")); JsonArray data = o.get("data").getAsJsonObject().get("openid").getAsJsonArray(); for (int i = 0; i < data.size(); i++) { - wxUserList.getOpenIds().add(GsonHelper.getAsString(data.get(i))); + wxMpUserList.getOpenIds().add(GsonHelper.getAsString(data.get(i))); } - return wxUserList; + return wxMpUserList; } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/xml/AdapterCDATA.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/xml/AdapterCDATA.java deleted file mode 100644 index b7e137153..000000000 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/xml/AdapterCDATA.java +++ /dev/null @@ -1,24 +0,0 @@ -package me.chanjar.weixin.mp.util.xml; - -import javax.xml.bind.annotation.adapters.XmlAdapter; - -/** - * - * http://stackoverflow.com/questions/14193944/jaxb-marshalling-unmarshalling-with-cdata - * - * @author chanjarster - * - */ -public class AdapterCDATA extends XmlAdapter { - - @Override - public String marshal(String arg0) throws Exception { - return ""; - } - - @Override - public String unmarshal(String arg0) throws Exception { - return arg0; - } - -} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/xml/MediaIdMarshaller.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/xml/MediaIdMarshaller.java deleted file mode 100644 index 1be8a080e..000000000 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/xml/MediaIdMarshaller.java +++ /dev/null @@ -1,21 +0,0 @@ -package me.chanjar.weixin.mp.util.xml; - -import javax.xml.bind.annotation.adapters.XmlAdapter; - -/** - * @author chanjarster - */ -public class MediaIdMarshaller extends XmlAdapter { - - @Override - public String marshal(String arg0) throws Exception { - return ""; - } - - @Override - public String unmarshal(String arg0) throws Exception { - // do nothing - return arg0; - } - -} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/xml/XmlTransformer.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/xml/XmlTransformer.java index 707b8743c..5e6197469 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/xml/XmlTransformer.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/xml/XmlTransformer.java @@ -1,18 +1,14 @@ package me.chanjar.weixin.mp.util.xml; -import java.io.IOException; -import java.io.InputStream; -import java.io.StringReader; -import java.io.StringWriter; -import java.io.Writer; - -import javax.xml.bind.*; - -import me.chanjar.weixin.bean.*; +import com.sun.xml.bind.marshaller.CharacterEscapeHandler; import me.chanjar.weixin.mp.bean.*; import org.xml.sax.InputSource; -import com.sun.xml.bind.marshaller.CharacterEscapeHandler; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; +import java.io.*; public class XmlTransformer { @@ -78,14 +74,14 @@ public class XmlTransformer { */ try { return JAXBContext.newInstance( - WxXmlOutMessage.class, - WxXmlOutImageMessage.class, - WxXmlOutMewsMessage.class, - WxXmlOutMusicMessage.class, - WxXmlOutTextMessage.class, - WxXmlOutVideoMessage.class, - WxXmlOutVoiceMessage.class, - WxXmlMessage.class); + WxMpXmlOutMessage.class, + WxMpMpXmlOutImageMessage.class, + WxMpXmlOutMewsMessage.class, + WxMpXmlOutMusicMessage.class, + WxMpXmlOutTextMessage.class, + WxMpXmlOutVideoMessage.class, + WxMpXmlOutVoiceMessage.class, + WxMpXmlMessage.class); } catch (JAXBException e) { throw new RuntimeException(e); } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/ApiTestModule.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/ApiTestModule.java index 07a20e4a3..ca4cbc133 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/ApiTestModule.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/ApiTestModule.java @@ -9,10 +9,6 @@ import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; -import me.chanjar.weixin.mp.api.WxConfigStorage; -import me.chanjar.weixin.mp.api.WxInMemoryConfigStorage; -import me.chanjar.weixin.mp.api.WxServiceImpl; - import com.google.inject.Binder; import com.google.inject.Module; import org.xml.sax.InputSource; @@ -23,12 +19,12 @@ public class ApiTestModule implements Module { public void configure(Binder binder) { try { InputStream is1 = ClassLoader.getSystemResourceAsStream("test-config.xml"); - WxXmlConfigStorage config = fromXml(WxXmlConfigStorage.class, is1); - WxServiceImpl wxService = new WxServiceImpl(); - wxService.setWxConfigStorage(config); + WxXmlMpInMemoryConfigStorage config = fromXml(WxXmlMpInMemoryConfigStorage.class, is1); + WxMpServiceImpl wxService = new WxMpServiceImpl(); + wxService.setWxMpConfigStorage(config); - binder.bind(WxServiceImpl.class).toInstance(wxService); - binder.bind(WxConfigStorage.class).toInstance(config); + binder.bind(WxMpServiceImpl.class).toInstance(wxService); + binder.bind(WxMpConfigStorage.class).toInstance(config); } catch (JAXBException e) { throw new RuntimeException(e); } @@ -44,7 +40,7 @@ public class ApiTestModule implements Module { @XmlRootElement(name = "xml") @XmlAccessorType(XmlAccessType.FIELD) - public static class WxXmlConfigStorage extends WxInMemoryConfigStorage { + public static class WxXmlMpInMemoryConfigStorage extends WxMpInMemoryConfigStorage { protected String openId; diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxBaseAPITest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxBaseAPITest.java index b6f565e65..65d889281 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxBaseAPITest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxBaseAPITest.java @@ -5,7 +5,7 @@ import org.testng.Assert; import org.testng.annotations.Guice; import org.testng.annotations.Test; -import me.chanjar.weixin.mp.exception.WxErrorException; +import me.chanjar.weixin.common.exception.WxErrorException; import com.google.inject.Inject; @@ -19,10 +19,10 @@ import com.google.inject.Inject; public class WxBaseAPITest { @Inject - protected WxServiceImpl wxService; + protected WxMpServiceImpl wxService; public void testRefreshAccessToken() throws WxErrorException { - WxConfigStorage configStorage = wxService.wxConfigStorage; + WxMpConfigStorage configStorage = wxService.wxMpConfigStorage; String before = configStorage.getAccessToken(); wxService.accessTokenRefresh(); diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMessageRouterTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMessageRouterTest.java deleted file mode 100644 index 9b944bcbc..000000000 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMessageRouterTest.java +++ /dev/null @@ -1,162 +0,0 @@ -package me.chanjar.weixin.mp.api; - -import java.util.Map; - -import me.chanjar.weixin.mp.api.WxConsts; -import me.chanjar.weixin.mp.api.WxMessageHandler; -import me.chanjar.weixin.mp.api.WxMessageRouter; -import org.testng.Assert; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - -import me.chanjar.weixin.mp.bean.WxXmlMessage; -import me.chanjar.weixin.mp.bean.WxXmlOutMessage; - -/** - * 测试消息路由器 - * @author chanjarster - * - */ -@Test -public class WxMessageRouterTest { - - @Test(enabled = false) - public void prepare(boolean async, StringBuffer sb, WxMessageRouter router) { - router - .rule() - .async(async) - .msgType(WxConsts.XML_MSG_TEXT).event(WxConsts.EVT_CLICK).eventKey("KEY_1").content("CONTENT_1") - .handler(new WxEchoMessageHandler(sb, "COMBINE_4")) - .end() - .rule() - .async(async) - .msgType(WxConsts.XML_MSG_TEXT).event(WxConsts.EVT_CLICK).eventKey("KEY_1") - .handler(new WxEchoMessageHandler(sb, "COMBINE_3")) - .end() - .rule() - .async(async) - .msgType(WxConsts.XML_MSG_TEXT).event(WxConsts.EVT_CLICK) - .handler(new WxEchoMessageHandler(sb, "COMBINE_2")) - .end() - .rule().async(async).msgType(WxConsts.XML_MSG_TEXT).handler(new WxEchoMessageHandler(sb, WxConsts.XML_MSG_TEXT)).end() - .rule().async(async).event(WxConsts.EVT_CLICK).handler(new WxEchoMessageHandler(sb, WxConsts.EVT_CLICK)).end() - .rule().async(async).eventKey("KEY_1").handler(new WxEchoMessageHandler(sb, "KEY_1")).end() - .rule().async(async).content("CONTENT_1").handler(new WxEchoMessageHandler(sb, "CONTENT_1")).end() - .rule().async(async).rContent(".*bc.*").handler(new WxEchoMessageHandler(sb, "abcd")).end() - .rule().async(async).handler(new WxEchoMessageHandler(sb, "ALL")).end(); - ; - } - - @Test(dataProvider="messages-1") - public void testSync(WxXmlMessage message, String expected) { - StringBuffer sb = new StringBuffer(); - WxMessageRouter router = new WxMessageRouter(); - prepare(false, sb, router); - router.route(message); - Assert.assertEquals(sb.toString(), expected); - } - - @Test(dataProvider="messages-1") - public void testAsync(WxXmlMessage message, String expected) throws InterruptedException { - StringBuffer sb = new StringBuffer(); - WxMessageRouter router = new WxMessageRouter(); - prepare(true, sb, router); - router.route(message); - Thread.sleep(500l); - Assert.assertEquals(sb.toString(), expected); - } - - public void testConcurrency() throws InterruptedException { - final WxMessageRouter router = new WxMessageRouter(); - router.rule().handler(new WxMessageHandler() { - @Override - public WxXmlOutMessage handle(WxXmlMessage wxMessage, Map context) { - return null; - } - }).end(); - - final WxXmlMessage m = new WxXmlMessage(); - Runnable r = new Runnable() { - @Override - public void run() { - router.route(m); - try { - Thread.sleep(1000l); - } catch (InterruptedException e) { - } - } - }; - for (int i = 0; i < 10; i++) { - new Thread(r).start(); - } - - Thread.sleep(1000l * 2); - } - @DataProvider(name="messages-1") - public Object[][] messages2() { - WxXmlMessage message1 = new WxXmlMessage(); - message1.setMsgType(WxConsts.XML_MSG_TEXT); - - WxXmlMessage message2 = new WxXmlMessage(); - message2.setEvent(WxConsts.EVT_CLICK); - - WxXmlMessage message3 = new WxXmlMessage(); - message3.setEventKey("KEY_1"); - - WxXmlMessage message4 = new WxXmlMessage(); - message4.setContent("CONTENT_1"); - - WxXmlMessage message5 = new WxXmlMessage(); - message5.setContent("BLA"); - - WxXmlMessage message6 = new WxXmlMessage(); - message6.setContent("abcd"); - - WxXmlMessage c2 = new WxXmlMessage(); - c2.setMsgType(WxConsts.XML_MSG_TEXT); - c2.setEvent(WxConsts.EVT_CLICK); - - WxXmlMessage c3 = new WxXmlMessage(); - c3.setMsgType(WxConsts.XML_MSG_TEXT); - c3.setEvent(WxConsts.EVT_CLICK); - c3.setEventKey("KEY_1"); - - WxXmlMessage c4 = new WxXmlMessage(); - c4.setMsgType(WxConsts.XML_MSG_TEXT); - c4.setEvent(WxConsts.EVT_CLICK); - c4.setEventKey("KEY_1"); - c4.setContent("CONTENT_1"); - - return new Object[][] { - new Object[] { message1, WxConsts.XML_MSG_TEXT + "," }, - new Object[] { message2, WxConsts.EVT_CLICK + "," }, - new Object[] { message3, "KEY_1," }, - new Object[] { message4, "CONTENT_1," }, - new Object[] { message5, "ALL," }, - new Object[] { message6, "abcd," }, - new Object[] { c2, "COMBINE_2," }, - new Object[] { c3, "COMBINE_3," }, - new Object[] { c4, "COMBINE_4," } - }; - - } - - public static class WxEchoMessageHandler implements WxMessageHandler { - - private StringBuffer sb; - private String echoStr; - - public WxEchoMessageHandler(StringBuffer sb, String echoStr) { - this.sb = sb; - this.echoStr = echoStr; - } - - @Override - public WxXmlOutMessage handle(WxXmlMessage wxMessage, Map context) { - sb.append(this.echoStr).append(','); - return null; - } - - } - -} diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxCustomMessageAPITest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpCustomMessageAPITest.java similarity index 58% rename from weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxCustomMessageAPITest.java rename to weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpCustomMessageAPITest.java index 5a601a518..993385a7e 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxCustomMessageAPITest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpCustomMessageAPITest.java @@ -1,10 +1,10 @@ package me.chanjar.weixin.mp.api; +import me.chanjar.weixin.mp.bean.WxMpCustomMessage; import org.testng.annotations.Guice; import org.testng.annotations.Test; -import me.chanjar.weixin.mp.bean.WxCustomMessage; -import me.chanjar.weixin.mp.exception.WxErrorException; +import me.chanjar.weixin.common.exception.WxErrorException; import com.google.inject.Inject; @@ -15,15 +15,15 @@ import com.google.inject.Inject; */ @Test(groups="customMessageAPI", dependsOnGroups = "baseAPI") @Guice(modules = ApiTestModule.class) -public class WxCustomMessageAPITest { +public class WxMpCustomMessageAPITest { @Inject - protected WxServiceImpl wxService; + protected WxMpServiceImpl wxService; public void testSendCustomMessage() throws WxErrorException { - ApiTestModule.WxXmlConfigStorage configStorage = (ApiTestModule.WxXmlConfigStorage) wxService.wxConfigStorage; - WxCustomMessage message = new WxCustomMessage(); - message.setMsgType(WxConsts.CUSTOM_MSG_TEXT); + ApiTestModule.WxXmlMpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlMpInMemoryConfigStorage) wxService.wxMpConfigStorage; + WxMpCustomMessage message = new WxMpCustomMessage(); + message.setMsgType(WxMpConsts.CUSTOM_MSG_TEXT); message.setToUser(configStorage.getOpenId()); message.setContent("欢迎欢迎,热烈欢迎\n换行测试\n超链接:Hello World"); diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxGroupAPITest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpGroupAPITest.java similarity index 72% rename from weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxGroupAPITest.java rename to weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpGroupAPITest.java index 7fdb520f8..ca6f20ed6 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxGroupAPITest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpGroupAPITest.java @@ -2,12 +2,12 @@ package me.chanjar.weixin.mp.api; import java.util.List; +import me.chanjar.weixin.mp.bean.WxMpGroup; import org.testng.Assert; import org.testng.annotations.Guice; import org.testng.annotations.Test; -import me.chanjar.weixin.mp.bean.WxGroup; -import me.chanjar.weixin.mp.exception.WxErrorException; +import me.chanjar.weixin.common.exception.WxErrorException; import com.google.inject.Inject; @@ -18,24 +18,24 @@ import com.google.inject.Inject; */ @Test(groups = "groupAPI", dependsOnGroups = "baseAPI") @Guice(modules = ApiTestModule.class) -public class WxGroupAPITest { +public class WxMpGroupAPITest { @Inject - protected WxServiceImpl wxService; + protected WxMpServiceImpl wxService; - protected WxGroup group; + protected WxMpGroup group; public void testGroupCreate() throws WxErrorException { - WxGroup res = wxService.groupCreate("测试分组1"); + WxMpGroup res = wxService.groupCreate("测试分组1"); Assert.assertEquals(res.getName(), "测试分组1"); } @Test(dependsOnMethods="testGroupCreate") public void testGroupGet() throws WxErrorException { - List groupList = wxService.groupGet(); + List groupList = wxService.groupGet(); Assert.assertNotNull(groupList); Assert.assertTrue(groupList.size() > 0); - for (WxGroup g : groupList) { + for (WxMpGroup g : groupList) { group = g; Assert.assertNotNull(g.getName()); } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMassMessageAPITest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMassMessageAPITest.java similarity index 66% rename from weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMassMessageAPITest.java rename to weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMassMessageAPITest.java index 53cf74f94..a02e35c98 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMassMessageAPITest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMassMessageAPITest.java @@ -3,20 +3,20 @@ package me.chanjar.weixin.mp.api; import java.io.IOException; import java.io.InputStream; +import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; +import me.chanjar.weixin.mp.bean.WxMpMassGroupMessage; +import me.chanjar.weixin.mp.bean.WxMpMassNews; +import me.chanjar.weixin.mp.bean.WxMpMassOpenIdsMessage; +import me.chanjar.weixin.mp.bean.WxMpMassVideo; +import me.chanjar.weixin.mp.bean.result.WxMpMassSendResult; +import me.chanjar.weixin.mp.bean.result.WxMpMassUploadResult; import org.testng.Assert; import org.testng.annotations.DataProvider; import org.testng.annotations.Guice; import org.testng.annotations.Test; -import me.chanjar.weixin.mp.bean.WxMassGroupMessage; -import me.chanjar.weixin.mp.bean.WxMassNews; -import me.chanjar.weixin.mp.bean.WxMassNews.WxMassNewsArticle; -import me.chanjar.weixin.mp.bean.WxMassOpenIdsMessage; -import me.chanjar.weixin.mp.bean.WxMassVideo; -import me.chanjar.weixin.mp.bean.result.WxMassSendResult; -import me.chanjar.weixin.mp.bean.result.WxMassUploadResult; -import me.chanjar.weixin.mp.bean.result.WxMediaUploadResult; -import me.chanjar.weixin.mp.exception.WxErrorException; +import me.chanjar.weixin.mp.bean.WxMpMassNews.WxMassNewsArticle; +import me.chanjar.weixin.common.exception.WxErrorException; import com.google.inject.Inject; @@ -27,21 +27,21 @@ import com.google.inject.Inject; */ @Test(groups = "massAPI", dependsOnGroups = { "baseAPI", "mediaAPI", "groupAPI"}) @Guice(modules = ApiTestModule.class) -public class WxMassMessageAPITest { +public class WxMpMassMessageAPITest { @Inject - protected WxServiceImpl wxService; + protected WxMpServiceImpl wxService; @Test public void testTextMassOpenIdsMessageSend() throws WxErrorException { // 发送群发消息 - ApiTestModule.WxXmlConfigStorage configProvider = (ApiTestModule.WxXmlConfigStorage) wxService.wxConfigStorage; - WxMassOpenIdsMessage massMessage = new WxMassOpenIdsMessage(); - massMessage.setMsgType(WxConsts.MASS_MSG_TEXT); + ApiTestModule.WxXmlMpInMemoryConfigStorage configProvider = (ApiTestModule.WxXmlMpInMemoryConfigStorage) wxService.wxMpConfigStorage; + WxMpMassOpenIdsMessage massMessage = new WxMpMassOpenIdsMessage(); + massMessage.setMsgType(WxMpConsts.MASS_MSG_TEXT); massMessage.setContent("测试群发消息\n欢迎欢迎,热烈欢迎\n换行测试\n超链接:Hello World"); massMessage.getToUsers().add(configProvider.getOpenId()); - WxMassSendResult massResult = wxService.massOpenIdsMessageSend(massMessage); + WxMpMassSendResult massResult = wxService.massOpenIdsMessageSend(massMessage); Assert.assertNotNull(massResult); Assert.assertNotNull(massResult.getMsgId()); } @@ -49,37 +49,37 @@ public class WxMassMessageAPITest { @Test(dataProvider="massMessages") public void testMediaMassOpenIdsMessageSend(String massMsgType, String mediaId) throws WxErrorException, IOException { // 发送群发消息 - ApiTestModule.WxXmlConfigStorage configProvider = (ApiTestModule.WxXmlConfigStorage) wxService.wxConfigStorage; - WxMassOpenIdsMessage massMessage = new WxMassOpenIdsMessage(); + ApiTestModule.WxXmlMpInMemoryConfigStorage configProvider = (ApiTestModule.WxXmlMpInMemoryConfigStorage) wxService.wxMpConfigStorage; + WxMpMassOpenIdsMessage massMessage = new WxMpMassOpenIdsMessage(); massMessage.setMsgType(massMsgType); massMessage.setMediaId(mediaId); massMessage.getToUsers().add(configProvider.getOpenId()); - WxMassSendResult massResult = wxService.massOpenIdsMessageSend(massMessage); + WxMpMassSendResult massResult = wxService.massOpenIdsMessageSend(massMessage); Assert.assertNotNull(massResult); Assert.assertNotNull(massResult.getMsgId()); } @Test public void testTextMassGroupMessageSend() throws WxErrorException { - WxMassGroupMessage massMessage = new WxMassGroupMessage(); - massMessage.setMsgtype(WxConsts.MASS_MSG_TEXT); + WxMpMassGroupMessage massMessage = new WxMpMassGroupMessage(); + massMessage.setMsgtype(WxMpConsts.MASS_MSG_TEXT); massMessage.setContent("测试群发消息\n欢迎欢迎,热烈欢迎\n换行测试\n超链接:Hello World"); massMessage.setGroupId(wxService.groupGet().get(0).getId()); - WxMassSendResult massResult = wxService.massGroupMessageSend(massMessage); + WxMpMassSendResult massResult = wxService.massGroupMessageSend(massMessage); Assert.assertNotNull(massResult); Assert.assertNotNull(massResult.getMsgId()); } @Test(dataProvider="massMessages") public void testMediaMassGroupMessageSend(String massMsgType, String mediaId) throws WxErrorException, IOException { - WxMassGroupMessage massMessage = new WxMassGroupMessage(); + WxMpMassGroupMessage massMessage = new WxMpMassGroupMessage(); massMessage.setMsgtype(massMsgType); massMessage.setMediaId(mediaId); massMessage.setGroupId(wxService.groupGet().get(0).getId()); - WxMassSendResult massResult = wxService.massGroupMessageSend(massMessage); + WxMpMassSendResult massResult = wxService.massGroupMessageSend(massMessage); Assert.assertNotNull(massResult); Assert.assertNotNull(massResult.getMsgId()); } @@ -93,39 +93,39 @@ public class WxMassMessageAPITest { { // 上传视频到媒体库 InputStream inputStream = ClassLoader.getSystemResourceAsStream("mm.mp4"); - WxMediaUploadResult uploadMediaRes = wxService.mediaUpload(WxConsts.MEDIA_VIDEO, WxConsts.FILE_MP4, inputStream); + WxMediaUploadResult uploadMediaRes = wxService.mediaUpload(WxMpConsts.MEDIA_VIDEO, WxMpConsts.FILE_MP4, inputStream); Assert.assertNotNull(uploadMediaRes); Assert.assertNotNull(uploadMediaRes.getMediaId()); // 把视频变成可被群发的媒体 - WxMassVideo video = new WxMassVideo(); + WxMpMassVideo video = new WxMpMassVideo(); video.setTitle("测试标题"); video.setDescription("测试描述"); video.setMediaId(uploadMediaRes.getMediaId()); - WxMassUploadResult uploadResult = wxService.massVideoUpload(video); + WxMpMassUploadResult uploadResult = wxService.massVideoUpload(video); Assert.assertNotNull(uploadResult); Assert.assertNotNull(uploadResult.getMediaId()); - messages[0] = new Object[] { WxConsts.MASS_MSG_VIDEO, uploadResult.getMediaId() }; + messages[0] = new Object[] { WxMpConsts.MASS_MSG_VIDEO, uploadResult.getMediaId() }; } /** * 图片素材 */ { InputStream inputStream = ClassLoader.getSystemResourceAsStream("mm.jpeg"); - WxMediaUploadResult uploadMediaRes = wxService.mediaUpload(WxConsts.MEDIA_IMAGE, WxConsts.FILE_JPG, inputStream); + WxMediaUploadResult uploadMediaRes = wxService.mediaUpload(WxMpConsts.MEDIA_IMAGE, WxMpConsts.FILE_JPG, inputStream); Assert.assertNotNull(uploadMediaRes); Assert.assertNotNull(uploadMediaRes.getMediaId()); - messages[1] = new Object[] { WxConsts.MASS_MSG_IMAGE, uploadMediaRes.getMediaId() }; + messages[1] = new Object[] { WxMpConsts.MASS_MSG_IMAGE, uploadMediaRes.getMediaId() }; } /** * 语音素材 */ { InputStream inputStream = ClassLoader.getSystemResourceAsStream("mm.mp3"); - WxMediaUploadResult uploadMediaRes = wxService.mediaUpload(WxConsts.MEDIA_VOICE, WxConsts.FILE_MP3, inputStream); + WxMediaUploadResult uploadMediaRes = wxService.mediaUpload(WxMpConsts.MEDIA_VOICE, WxMpConsts.FILE_MP3, inputStream); Assert.assertNotNull(uploadMediaRes); Assert.assertNotNull(uploadMediaRes.getMediaId()); - messages[2] = new Object[] { WxConsts.MASS_MSG_VOICE, uploadMediaRes.getMediaId() }; + messages[2] = new Object[] { WxMpConsts.MASS_MSG_VOICE, uploadMediaRes.getMediaId() }; } /** * 图文素材 @@ -133,12 +133,12 @@ public class WxMassMessageAPITest { { // 上传照片到媒体库 InputStream inputStream = ClassLoader.getSystemResourceAsStream("mm.jpeg"); - WxMediaUploadResult uploadMediaRes = wxService.mediaUpload(WxConsts.MEDIA_IMAGE, WxConsts.FILE_JPG, inputStream); + WxMediaUploadResult uploadMediaRes = wxService.mediaUpload(WxMpConsts.MEDIA_IMAGE, WxMpConsts.FILE_JPG, inputStream); Assert.assertNotNull(uploadMediaRes); Assert.assertNotNull(uploadMediaRes.getMediaId()); // 上传图文消息 - WxMassNews news = new WxMassNews(); + WxMpMassNews news = new WxMpMassNews(); WxMassNewsArticle article1 = new WxMassNewsArticle(); article1.setTitle("标题1"); article1.setContent("内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1"); @@ -155,10 +155,10 @@ public class WxMassMessageAPITest { article2.setDigest("摘要2"); news.addArticle(article2); - WxMassUploadResult massUploadResult = wxService.massNewsUpload(news); + WxMpMassUploadResult massUploadResult = wxService.massNewsUpload(news); Assert.assertNotNull(massUploadResult); Assert.assertNotNull(uploadMediaRes.getMediaId()); - messages[3] = new Object[] { WxConsts.MASS_MSG_NEWS, massUploadResult.getMediaId() }; + messages[3] = new Object[] { WxMpConsts.MASS_MSG_NEWS, massUploadResult.getMediaId() }; } return messages; } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMediaAPITest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMediaAPITest.java similarity index 77% rename from weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMediaAPITest.java rename to weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMediaAPITest.java index 58c7c25fc..434a2f456 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMediaAPITest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMediaAPITest.java @@ -5,13 +5,13 @@ import java.io.InputStream; import java.util.ArrayList; import java.util.List; +import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; import org.testng.Assert; import org.testng.annotations.DataProvider; import org.testng.annotations.Guice; import org.testng.annotations.Test; -import me.chanjar.weixin.mp.bean.result.WxMediaUploadResult; -import me.chanjar.weixin.mp.exception.WxErrorException; +import me.chanjar.weixin.common.exception.WxErrorException; import com.google.inject.Inject; @@ -22,10 +22,10 @@ import com.google.inject.Inject; */ @Test(groups="mediaAPI", dependsOnGroups="baseAPI") @Guice(modules = ApiTestModule.class) -public class WxMediaAPITest { +public class WxMpMediaAPITest { @Inject - protected WxServiceImpl wxService; + protected WxMpServiceImpl wxService; private List media_ids = new ArrayList(); @@ -48,10 +48,10 @@ public class WxMediaAPITest { @DataProvider public Object[][] uploadMedia() { return new Object[][] { - new Object[] { WxConsts.MEDIA_IMAGE, WxConsts.FILE_JPG, "mm.jpeg" }, - new Object[] { WxConsts.MEDIA_VOICE, WxConsts.FILE_MP3, "mm.mp3" }, - new Object[] { WxConsts.MEDIA_VIDEO, WxConsts.FILE_MP4, "mm.mp4" }, - new Object[] { WxConsts.MEDIA_THUMB, WxConsts.FILE_JPG, "mm.jpeg" } + new Object[] { WxMpConsts.MEDIA_IMAGE, WxMpConsts.FILE_JPG, "mm.jpeg" }, + new Object[] { WxMpConsts.MEDIA_VOICE, WxMpConsts.FILE_MP3, "mm.mp3" }, + new Object[] { WxMpConsts.MEDIA_VIDEO, WxMpConsts.FILE_MP4, "mm.mp4" }, + new Object[] { WxMpConsts.MEDIA_THUMB, WxMpConsts.FILE_JPG, "mm.jpeg" } }; } diff --git a/weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/api/WxCpMenuAPITest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMenuAPITest.java similarity index 72% rename from weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/api/WxCpMenuAPITest.java rename to weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMenuAPITest.java index cf1b70bef..797ceabb4 100644 --- a/weixin-java-enterprise/src/test/java/me/chanjar/weixin/enterprise/api/WxCpMenuAPITest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMenuAPITest.java @@ -1,8 +1,7 @@ -package me.chanjar.weixin.enterprise.api; +package me.chanjar.weixin.mp.api; import javax.xml.bind.JAXBException; -import me.chanjar.weixin.enterprise.bean.WxCpMenu; import org.testng.Assert; import org.testng.annotations.DataProvider; import org.testng.annotations.Guice; @@ -10,24 +9,25 @@ import org.testng.annotations.Test; import com.google.inject.Inject; -import me.chanjar.weixin.enterprise.bean.WxCpMenu.WxMenuButton; -import me.chanjar.weixin.enterprise.exception.WxErrorException; +import me.chanjar.weixin.common.bean.WxMenu; +import me.chanjar.weixin.common.bean.WxMenu.WxMenuButton; +import me.chanjar.weixin.common.exception.WxErrorException; /** * 测试菜单 - * @author Daniel Qian + * @author chanjarster * */ @Test(groups="menuAPI", dependsOnGroups="baseAPI") @Guice(modules = ApiTestModule.class) -public class WxCpMenuAPITest { +public class WxMpMenuAPITest { @Inject - protected WxCpServiceImpl wxService; + protected WxMpServiceImpl wxService; @Test(dataProvider = "menu") - public void testCreateMenu(WxCpMenu wxCpMenu) throws WxErrorException { - wxService.menuCreate(wxCpMenu); + public void testCreateMenu(WxMenu wxMenu) throws WxErrorException { + wxService.menuCreate(wxMenu); } @Test(dependsOnMethods = { "testCreateMenu"}) @@ -42,14 +42,14 @@ public class WxCpMenuAPITest { @DataProvider(name="menu") public Object[][] getMenu() throws JAXBException { - WxCpMenu menu = new WxCpMenu(); + WxMenu menu = new WxMenu(); WxMenuButton button1 = new WxMenuButton(); - button1.setType(WxCpConsts.BUTTON_CLICK); + button1.setType(WxMpConsts.BUTTON_CLICK); button1.setName("今日歌曲"); button1.setKey("V1001_TODAY_MUSIC"); WxMenuButton button2 = new WxMenuButton(); - button2.setType(WxCpConsts.BUTTON_CLICK); + button2.setType(WxMpConsts.BUTTON_CLICK); button2.setName("歌手简介"); button2.setKey("V1001_TODAY_SINGER"); @@ -61,17 +61,17 @@ public class WxCpMenuAPITest { menu.getButtons().add(button3); WxMenuButton button31 = new WxMenuButton(); - button31.setType(WxCpConsts.BUTTON_VIEW); + button31.setType(WxMpConsts.BUTTON_VIEW); button31.setName("搜索"); button31.setUrl("http://www.soso.com/"); WxMenuButton button32 = new WxMenuButton(); - button32.setType(WxCpConsts.BUTTON_VIEW); + button32.setType(WxMpConsts.BUTTON_VIEW); button32.setName("视频"); button32.setUrl("http://v.qq.com/"); WxMenuButton button33 = new WxMenuButton(); - button33.setType(WxCpConsts.BUTTON_CLICK); + button33.setType(WxMpConsts.BUTTON_CLICK); button33.setName("赞一下我们"); button33.setKey("V1001_GOOD"); diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMessageRouterTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMessageRouterTest.java new file mode 100644 index 000000000..f6d465334 --- /dev/null +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMessageRouterTest.java @@ -0,0 +1,158 @@ +package me.chanjar.weixin.mp.api; + +import java.util.Map; + +import me.chanjar.weixin.mp.bean.WxMpXmlMessage; +import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage; +import org.testng.Assert; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +/** + * 测试消息路由器 + * @author chanjarster + * + */ +@Test +public class WxMpMessageRouterTest { + + @Test(enabled = false) + public void prepare(boolean async, StringBuffer sb, WxMpMessageRouter router) { + router + .rule() + .async(async) + .msgType(WxMpConsts.XML_MSG_TEXT).event(WxMpConsts.EVT_CLICK).eventKey("KEY_1").content("CONTENT_1") + .handler(new WxEchoMpMessageHandler(sb, "COMBINE_4")) + .end() + .rule() + .async(async) + .msgType(WxMpConsts.XML_MSG_TEXT).event(WxMpConsts.EVT_CLICK).eventKey("KEY_1") + .handler(new WxEchoMpMessageHandler(sb, "COMBINE_3")) + .end() + .rule() + .async(async) + .msgType(WxMpConsts.XML_MSG_TEXT).event(WxMpConsts.EVT_CLICK) + .handler(new WxEchoMpMessageHandler(sb, "COMBINE_2")) + .end() + .rule().async(async).msgType(WxMpConsts.XML_MSG_TEXT).handler(new WxEchoMpMessageHandler(sb, WxMpConsts.XML_MSG_TEXT)).end() + .rule().async(async).event(WxMpConsts.EVT_CLICK).handler(new WxEchoMpMessageHandler(sb, WxMpConsts.EVT_CLICK)).end() + .rule().async(async).eventKey("KEY_1").handler(new WxEchoMpMessageHandler(sb, "KEY_1")).end() + .rule().async(async).content("CONTENT_1").handler(new WxEchoMpMessageHandler(sb, "CONTENT_1")).end() + .rule().async(async).rContent(".*bc.*").handler(new WxEchoMpMessageHandler(sb, "abcd")).end() + .rule().async(async).handler(new WxEchoMpMessageHandler(sb, "ALL")).end(); + ; + } + + @Test(dataProvider="messages-1") + public void testSync(WxMpXmlMessage message, String expected) { + StringBuffer sb = new StringBuffer(); + WxMpMessageRouter router = new WxMpMessageRouter(); + prepare(false, sb, router); + router.route(message); + Assert.assertEquals(sb.toString(), expected); + } + + @Test(dataProvider="messages-1") + public void testAsync(WxMpXmlMessage message, String expected) throws InterruptedException { + StringBuffer sb = new StringBuffer(); + WxMpMessageRouter router = new WxMpMessageRouter(); + prepare(true, sb, router); + router.route(message); + Thread.sleep(500l); + Assert.assertEquals(sb.toString(), expected); + } + + public void testConcurrency() throws InterruptedException { + final WxMpMessageRouter router = new WxMpMessageRouter(); + router.rule().handler(new WxMpMessageHandler() { + @Override + public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map context) { + return null; + } + }).end(); + + final WxMpXmlMessage m = new WxMpXmlMessage(); + Runnable r = new Runnable() { + @Override + public void run() { + router.route(m); + try { + Thread.sleep(1000l); + } catch (InterruptedException e) { + } + } + }; + for (int i = 0; i < 10; i++) { + new Thread(r).start(); + } + + Thread.sleep(1000l * 2); + } + @DataProvider(name="messages-1") + public Object[][] messages2() { + WxMpXmlMessage message1 = new WxMpXmlMessage(); + message1.setMsgType(WxMpConsts.XML_MSG_TEXT); + + WxMpXmlMessage message2 = new WxMpXmlMessage(); + message2.setEvent(WxMpConsts.EVT_CLICK); + + WxMpXmlMessage message3 = new WxMpXmlMessage(); + message3.setEventKey("KEY_1"); + + WxMpXmlMessage message4 = new WxMpXmlMessage(); + message4.setContent("CONTENT_1"); + + WxMpXmlMessage message5 = new WxMpXmlMessage(); + message5.setContent("BLA"); + + WxMpXmlMessage message6 = new WxMpXmlMessage(); + message6.setContent("abcd"); + + WxMpXmlMessage c2 = new WxMpXmlMessage(); + c2.setMsgType(WxMpConsts.XML_MSG_TEXT); + c2.setEvent(WxMpConsts.EVT_CLICK); + + WxMpXmlMessage c3 = new WxMpXmlMessage(); + c3.setMsgType(WxMpConsts.XML_MSG_TEXT); + c3.setEvent(WxMpConsts.EVT_CLICK); + c3.setEventKey("KEY_1"); + + WxMpXmlMessage c4 = new WxMpXmlMessage(); + c4.setMsgType(WxMpConsts.XML_MSG_TEXT); + c4.setEvent(WxMpConsts.EVT_CLICK); + c4.setEventKey("KEY_1"); + c4.setContent("CONTENT_1"); + + return new Object[][] { + new Object[] { message1, WxMpConsts.XML_MSG_TEXT + "," }, + new Object[] { message2, WxMpConsts.EVT_CLICK + "," }, + new Object[] { message3, "KEY_1," }, + new Object[] { message4, "CONTENT_1," }, + new Object[] { message5, "ALL," }, + new Object[] { message6, "abcd," }, + new Object[] { c2, "COMBINE_2," }, + new Object[] { c3, "COMBINE_3," }, + new Object[] { c4, "COMBINE_4," } + }; + + } + + public static class WxEchoMpMessageHandler implements WxMpMessageHandler { + + private StringBuffer sb; + private String echoStr; + + public WxEchoMpMessageHandler(StringBuffer sb, String echoStr) { + this.sb = sb; + this.echoStr = echoStr; + } + + @Override + public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map context) { + sb.append(this.echoStr).append(','); + return null; + } + + } + +} diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxQrCodeAPITest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpQrCodeAPITest.java similarity index 70% rename from weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxQrCodeAPITest.java rename to weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpQrCodeAPITest.java index 0e4fef1e1..2a206d2ef 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxQrCodeAPITest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpQrCodeAPITest.java @@ -2,12 +2,12 @@ package me.chanjar.weixin.mp.api; import java.io.File; +import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket; import org.testng.Assert; import org.testng.annotations.Guice; import org.testng.annotations.Test; -import me.chanjar.weixin.mp.bean.result.WxQrCodeTicket; -import me.chanjar.weixin.mp.exception.WxErrorException; +import me.chanjar.weixin.common.exception.WxErrorException; import com.google.inject.Inject; @@ -18,27 +18,27 @@ import com.google.inject.Inject; */ @Test(groups = "qrCodeAPI", dependsOnGroups = { "baseAPI" }) @Guice(modules = ApiTestModule.class) -public class WxQrCodeAPITest { +public class WxMpQrCodeAPITest { @Inject - protected WxServiceImpl wxService; + protected WxMpServiceImpl wxService; public void testQrCodeCreateTmpTicket() throws WxErrorException { - WxQrCodeTicket ticket = wxService.qrCodeCreateTmpTicket(1, null); + WxMpQrCodeTicket ticket = wxService.qrCodeCreateTmpTicket(1, null); Assert.assertNotNull(ticket.getUrl()); Assert.assertNotNull(ticket.getTicket()); Assert.assertTrue(ticket.getExpire_seconds() != -1); } public void testQrCodeCreateLastTicket() throws WxErrorException { - WxQrCodeTicket ticket = wxService.qrCodeCreateLastTicket(1); + WxMpQrCodeTicket ticket = wxService.qrCodeCreateLastTicket(1); Assert.assertNotNull(ticket.getUrl()); Assert.assertNotNull(ticket.getTicket()); Assert.assertTrue(ticket.getExpire_seconds() == -1); } public void testQrCodePicture() throws WxErrorException { - WxQrCodeTicket ticket = wxService.qrCodeCreateLastTicket(1); + WxMpQrCodeTicket ticket = wxService.qrCodeCreateLastTicket(1); File file = wxService.qrCodePicture(ticket); Assert.assertNotNull(file); } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxShortUrlAPITest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpShortUrlAPITest.java similarity index 78% rename from weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxShortUrlAPITest.java rename to weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpShortUrlAPITest.java index ac815b030..e854ed08c 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxShortUrlAPITest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpShortUrlAPITest.java @@ -4,7 +4,7 @@ import org.testng.Assert; import org.testng.annotations.Guice; import org.testng.annotations.Test; -import me.chanjar.weixin.mp.exception.WxErrorException; +import me.chanjar.weixin.common.exception.WxErrorException; import com.google.inject.Inject; @@ -15,10 +15,10 @@ import com.google.inject.Inject; */ @Test(groups = "shortURLAPI", dependsOnGroups = { "baseAPI" }) @Guice(modules = ApiTestModule.class) -public class WxShortUrlAPITest { +public class WxMpShortUrlAPITest { @Inject - protected WxServiceImpl wxService; + protected WxMpServiceImpl wxService; public void testShortUrl() throws WxErrorException { String shortUrl = wxService.shortUrl("www.baidu.com"); diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpUserAPITest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpUserAPITest.java new file mode 100644 index 000000000..c29bda83b --- /dev/null +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpUserAPITest.java @@ -0,0 +1,55 @@ +package me.chanjar.weixin.mp.api; + +import me.chanjar.weixin.mp.bean.result.WxMpUserList; +import org.testng.Assert; +import org.testng.annotations.Guice; +import org.testng.annotations.Test; + +import me.chanjar.weixin.mp.bean.result.WxMpUser; +import me.chanjar.weixin.common.exception.WxErrorException; + +import com.google.inject.Inject; + +/** + * 测试用户相关的接口 + * @author chanjarster + * + */ +@Test(groups = "userAPI", dependsOnGroups = { "baseAPI", "groupAPI" }) +@Guice(modules = ApiTestModule.class) +public class WxMpUserAPITest { + + @Inject + protected WxMpServiceImpl wxService; + + public void testUserUpdateRemark() throws WxErrorException { + ApiTestModule.WxXmlMpInMemoryConfigStorage configProvider = (ApiTestModule.WxXmlMpInMemoryConfigStorage) wxService.wxMpConfigStorage; + wxService.userUpdateRemark(configProvider.getOpenId(), "测试备注名"); + } + + public void testUserInfo() throws WxErrorException { + ApiTestModule.WxXmlMpInMemoryConfigStorage configProvider = (ApiTestModule.WxXmlMpInMemoryConfigStorage) wxService.wxMpConfigStorage; + WxMpUser user = wxService.userInfo(configProvider.getOpenId(), null); + Assert.assertNotNull(user); + } + + public void testUserList() throws WxErrorException { + WxMpUserList wxMpUserList = wxService.userList(null); + Assert.assertNotNull(wxMpUserList); + Assert.assertFalse(wxMpUserList.getCount() == -1); + Assert.assertFalse(wxMpUserList.getTotal() == -1); + Assert.assertFalse(wxMpUserList.getOpenIds().size() == -1); + } + + public void testGroupQueryUserGroup() throws WxErrorException { + ApiTestModule.WxXmlMpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlMpInMemoryConfigStorage) wxService.wxMpConfigStorage; + long groupid = wxService.userGetGroup(configStorage.getOpenId()); + Assert.assertTrue(groupid != -1l); + } + + public void getGroupMoveUser() throws WxErrorException { + ApiTestModule.WxXmlMpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlMpInMemoryConfigStorage) wxService.wxMpConfigStorage; + wxService.userUpdateGroup(configStorage.getOpenId(), wxService.groupGet().get(3).getId()); + } + +} diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxUserAPITest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxUserAPITest.java deleted file mode 100644 index ce4ba6c4e..000000000 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxUserAPITest.java +++ /dev/null @@ -1,56 +0,0 @@ -package me.chanjar.weixin.mp.api; - -import org.testng.Assert; -import org.testng.annotations.Guice; -import org.testng.annotations.Test; - -import me.chanjar.weixin.mp.api.ApiTestModule.WxXmlConfigStorage; -import me.chanjar.weixin.mp.bean.result.WxUser; -import me.chanjar.weixin.mp.bean.result.WxUserList; -import me.chanjar.weixin.mp.exception.WxErrorException; - -import com.google.inject.Inject; - -/** - * 测试用户相关的接口 - * @author chanjarster - * - */ -@Test(groups = "userAPI", dependsOnGroups = { "baseAPI", "groupAPI" }) -@Guice(modules = ApiTestModule.class) -public class WxUserAPITest { - - @Inject - protected WxServiceImpl wxService; - - public void testUserUpdateRemark() throws WxErrorException { - WxXmlConfigStorage configProvider = (WxXmlConfigStorage) wxService.wxConfigStorage; - wxService.userUpdateRemark(configProvider.getOpenId(), "测试备注名"); - } - - public void testUserInfo() throws WxErrorException { - WxXmlConfigStorage configProvider = (WxXmlConfigStorage) wxService.wxConfigStorage; - WxUser user = wxService.userInfo(configProvider.getOpenId(), null); - Assert.assertNotNull(user); - } - - public void testUserList() throws WxErrorException { - WxUserList wxUserList = wxService.userList(null); - Assert.assertNotNull(wxUserList); - Assert.assertFalse(wxUserList.getCount() == -1); - Assert.assertFalse(wxUserList.getTotal() == -1); - Assert.assertFalse(wxUserList.getOpenIds().size() == -1); - } - - public void testGroupQueryUserGroup() throws WxErrorException { - WxXmlConfigStorage configStorage = (WxXmlConfigStorage) wxService.wxConfigStorage; - long groupid = wxService.userGetGroup(configStorage.getOpenId()); - Assert.assertTrue(groupid != -1l); - } - - public void getGroupMoveUser() throws WxErrorException { - WxXmlConfigStorage configStorage = (WxXmlConfigStorage) wxService.wxConfigStorage; - wxService.userUpdateGroup(configStorage.getOpenId(), wxService.groupGet().get(3).getId()); - } - -} diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxAccessTokenTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxAccessTokenTest.java deleted file mode 100644 index 2ada1fbd3..000000000 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxAccessTokenTest.java +++ /dev/null @@ -1,19 +0,0 @@ -package me.chanjar.weixin.mp.bean; - -import me.chanjar.weixin.mp.bean.WxAccessToken; -import org.testng.Assert; -import org.testng.annotations.Test; - -@Test -public class WxAccessTokenTest { - - public void testFromJson() { - - String json = "{\"access_token\":\"ACCESS_TOKEN\",\"expires_in\":7200}"; - WxAccessToken wxError = WxAccessToken.fromJson(json); - Assert.assertEquals(wxError.getAccessToken(), "ACCESS_TOKEN"); - Assert.assertTrue(wxError.getExpiresIn() == 7200); - - } - -} diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxErrorTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxErrorTest.java deleted file mode 100644 index f20f20807..000000000 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxErrorTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package me.chanjar.weixin.mp.bean; - -import org.testng.Assert; -import org.testng.annotations.Test; - -import me.chanjar.weixin.mp.bean.result.WxError; - -@Test -public class WxErrorTest { - - public void testFromJson() { - - String json = "{ \"errcode\": 40003, \"errmsg\": \"invalid openid\" }"; - WxError wxError = WxError.fromJson(json); - Assert.assertTrue(wxError.getErrorCode() == 40003); - Assert.assertEquals(wxError.getErrorMsg(), "invalid openid"); - - } - - public void testFromBadJson1() { - - String json = "{ \"errcode\": 40003, \"errmsg\": \"invalid openid\", \"media_id\": \"12323423dsfafsf232f\" }"; - WxError wxError = WxError.fromJson(json); - Assert.assertTrue(wxError.getErrorCode() == 40003); - Assert.assertEquals(wxError.getErrorMsg(), "invalid openid"); - - } - - public void testFromBadJson2() { - - String json = "{\"access_token\":\"ACCESS_TOKEN\",\"expires_in\":7200}"; - WxError wxError = WxError.fromJson(json); - Assert.assertTrue(wxError.getErrorCode() == 0); - Assert.assertEquals(wxError.getErrorMsg(), null); - - } - -} diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxCustomMessageTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxMpCustomMessageTest.java similarity index 76% rename from weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxCustomMessageTest.java rename to weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxMpCustomMessageTest.java index 730900537..2599b2f8f 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxCustomMessageTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxMpCustomMessageTest.java @@ -1,58 +1,57 @@ package me.chanjar.weixin.mp.bean; -import me.chanjar.weixin.mp.bean.WxCustomMessage; +import me.chanjar.weixin.mp.api.WxMpConsts; import org.testng.Assert; import org.testng.annotations.Test; -import me.chanjar.weixin.mp.api.WxConsts; -import me.chanjar.weixin.mp.bean.WxCustomMessage.WxArticle; +import me.chanjar.weixin.mp.bean.WxMpCustomMessage.WxArticle; @Test -public class WxCustomMessageTest { +public class WxMpCustomMessageTest { public void testTextReply() { - WxCustomMessage reply = new WxCustomMessage(); + WxMpCustomMessage reply = new WxMpCustomMessage(); reply.setToUser("OPENID"); - reply.setMsgType(WxConsts.CUSTOM_MSG_TEXT); + reply.setMsgType(WxMpConsts.CUSTOM_MSG_TEXT); reply.setContent("sfsfdsdf"); Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"text\",\"text\":{\"content\":\"sfsfdsdf\"}}"); } public void testTextBuild() { - WxCustomMessage reply = WxCustomMessage.TEXT().toUser("OPENID").content("sfsfdsdf").build(); + WxMpCustomMessage reply = WxMpCustomMessage.TEXT().toUser("OPENID").content("sfsfdsdf").build(); Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"text\",\"text\":{\"content\":\"sfsfdsdf\"}}"); } public void testImageReply() { - WxCustomMessage reply = new WxCustomMessage(); + WxMpCustomMessage reply = new WxMpCustomMessage(); reply.setToUser("OPENID"); - reply.setMsgType(WxConsts.CUSTOM_MSG_IMAGE); + reply.setMsgType(WxMpConsts.CUSTOM_MSG_IMAGE); reply.setMediaId("MEDIA_ID"); Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"image\",\"image\":{\"media_id\":\"MEDIA_ID\"}}"); } public void testImageBuild() { - WxCustomMessage reply = WxCustomMessage.IMAGE().toUser("OPENID").mediaId("MEDIA_ID").build(); + WxMpCustomMessage reply = WxMpCustomMessage.IMAGE().toUser("OPENID").mediaId("MEDIA_ID").build(); Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"image\",\"image\":{\"media_id\":\"MEDIA_ID\"}}"); } public void testVoiceReply() { - WxCustomMessage reply = new WxCustomMessage(); + WxMpCustomMessage reply = new WxMpCustomMessage(); reply.setToUser("OPENID"); - reply.setMsgType(WxConsts.CUSTOM_MSG_VOICE); + reply.setMsgType(WxMpConsts.CUSTOM_MSG_VOICE); reply.setMediaId("MEDIA_ID"); Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"voice\",\"voice\":{\"media_id\":\"MEDIA_ID\"}}"); } public void testVoiceBuild() { - WxCustomMessage reply = WxCustomMessage.VOICE().toUser("OPENID").mediaId("MEDIA_ID").build(); + WxMpCustomMessage reply = WxMpCustomMessage.VOICE().toUser("OPENID").mediaId("MEDIA_ID").build(); Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"voice\",\"voice\":{\"media_id\":\"MEDIA_ID\"}}"); } public void testVideoReply() { - WxCustomMessage reply = new WxCustomMessage(); + WxMpCustomMessage reply = new WxMpCustomMessage(); reply.setToUser("OPENID"); - reply.setMsgType(WxConsts.CUSTOM_MSG_VIDEO); + reply.setMsgType(WxMpConsts.CUSTOM_MSG_VIDEO); reply.setMediaId("MEDIA_ID"); reply.setThumbMediaId("MEDIA_ID"); reply.setTitle("TITLE"); @@ -61,14 +60,14 @@ public class WxCustomMessageTest { } public void testVideoBuild() { - WxCustomMessage reply = WxCustomMessage.VIDEO().toUser("OPENID").title("TITLE").mediaId("MEDIA_ID").thumbMediaId("MEDIA_ID").description("DESCRIPTION").build(); + WxMpCustomMessage reply = WxMpCustomMessage.VIDEO().toUser("OPENID").title("TITLE").mediaId("MEDIA_ID").thumbMediaId("MEDIA_ID").description("DESCRIPTION").build(); Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"video\",\"video\":{\"media_id\":\"MEDIA_ID\",\"thumb_media_id\":\"MEDIA_ID\",\"title\":\"TITLE\",\"description\":\"DESCRIPTION\"}}"); } public void testMusicReply() { - WxCustomMessage reply = new WxCustomMessage(); + WxMpCustomMessage reply = new WxMpCustomMessage(); reply.setToUser("OPENID"); - reply.setMsgType(WxConsts.CUSTOM_MSG_MUSIC); + reply.setMsgType(WxMpConsts.CUSTOM_MSG_MUSIC); reply.setThumbMediaId("MEDIA_ID"); reply.setDescription("DESCRIPTION"); reply.setTitle("TITLE"); @@ -78,7 +77,7 @@ public class WxCustomMessageTest { } public void testMusicBuild() { - WxCustomMessage reply = WxCustomMessage.MUSIC() + WxMpCustomMessage reply = WxMpCustomMessage.MUSIC() .toUser("OPENID") .title("TITLE") .thumbMediaId("MEDIA_ID") @@ -90,9 +89,9 @@ public class WxCustomMessageTest { } public void testNewsReply() { - WxCustomMessage reply = new WxCustomMessage(); + WxMpCustomMessage reply = new WxMpCustomMessage(); reply.setToUser("OPENID"); - reply.setMsgType(WxConsts.CUSTOM_MSG_NEWS); + reply.setMsgType(WxMpConsts.CUSTOM_MSG_NEWS); WxArticle article1 = new WxArticle(); article1.setUrl("URL"); @@ -125,7 +124,7 @@ public class WxCustomMessageTest { article2.setDescription("Is Really A Happy Day"); article2.setTitle("Happy Day"); - WxCustomMessage reply = WxCustomMessage.NEWS().toUser("OPENID").addArticle(article1).addArticle(article2).build(); + WxMpCustomMessage reply = WxMpCustomMessage.NEWS().toUser("OPENID").addArticle(article1).addArticle(article2).build(); Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"news\",\"articles\":[{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"},{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"}]}"); } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxXmlMessageTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxMpXmlMessageTest.java similarity index 95% rename from weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxXmlMessageTest.java rename to weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxMpXmlMessageTest.java index 3db6e8290..684ffed24 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxXmlMessageTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxMpXmlMessageTest.java @@ -1,12 +1,11 @@ package me.chanjar.weixin.mp.bean; -import me.chanjar.weixin.mp.api.WxConsts; -import me.chanjar.weixin.mp.bean.WxXmlMessage; +import me.chanjar.weixin.mp.api.WxMpConsts; import org.testng.Assert; import org.testng.annotations.Test; @Test -public class WxXmlMessageTest { +public class WxMpXmlMessageTest { public void testFromXml() { @@ -54,11 +53,11 @@ public class WxXmlMessageTest { + " \n" + "" + ""; - WxXmlMessage wxMessage = WxXmlMessage.fromXml(xml); + WxMpXmlMessage wxMessage = WxMpXmlMessage.fromXml(xml); Assert.assertEquals(wxMessage.getToUserName(), "toUser"); Assert.assertEquals(wxMessage.getFromUserName(), "fromUser"); Assert.assertEquals(wxMessage.getCreateTime(), new Long(1348831860l)); - Assert.assertEquals(wxMessage.getMsgType(), WxConsts.XML_MSG_TEXT); + Assert.assertEquals(wxMessage.getMsgType(), WxMpConsts.XML_MSG_TEXT); Assert.assertEquals(wxMessage.getContent(), "this is a test"); Assert.assertEquals(wxMessage.getMsgId(), new Long(1234567890123456l)); Assert.assertEquals(wxMessage.getPicUrl(), "this is a url"); diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxXmlOutImageMessageTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxMpXmlOutImageMessageTest.java similarity index 83% rename from weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxXmlOutImageMessageTest.java rename to weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxMpXmlOutImageMessageTest.java index 0d8b06494..e0377cb6c 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxXmlOutImageMessageTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxMpXmlOutImageMessageTest.java @@ -1,15 +1,13 @@ package me.chanjar.weixin.mp.bean; -import me.chanjar.weixin.mp.bean.WxXmlOutImageMessage; -import me.chanjar.weixin.mp.bean.WxXmlOutMessage; import org.testng.Assert; import org.testng.annotations.Test; @Test -public class WxXmlOutImageMessageTest { +public class WxMpXmlOutImageMessageTest { public void test() { - WxXmlOutImageMessage m = new WxXmlOutImageMessage(); + WxMpMpXmlOutImageMessage m = new WxMpMpXmlOutImageMessage(); m.setMediaId("ddfefesfsdfef"); m.setCreateTime(1122l); m.setFromUserName("from"); @@ -28,7 +26,7 @@ public class WxXmlOutImageMessageTest { } public void testBuild() { - WxXmlOutImageMessage m = WxXmlOutMessage.IMAGE().mediaId("ddfefesfsdfef").fromUser("from").toUser("to").build(); + WxMpMpXmlOutImageMessage m = WxMpXmlOutMessage.IMAGE().mediaId("ddfefesfsdfef").fromUser("from").toUser("to").build(); String expected = "" + "" + "" diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxXmlOutMusicMessageTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxXmlOutMusicMessageTest.java index b3c4c6626..0471e2c3d 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxXmlOutMusicMessageTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxXmlOutMusicMessageTest.java @@ -1,7 +1,5 @@ package me.chanjar.weixin.mp.bean; -import me.chanjar.weixin.mp.bean.WxXmlOutMessage; -import me.chanjar.weixin.mp.bean.WxXmlOutMusicMessage; import org.testng.Assert; import org.testng.annotations.Test; @@ -9,7 +7,7 @@ import org.testng.annotations.Test; public class WxXmlOutMusicMessageTest { public void test() { - WxXmlOutMusicMessage m = new WxXmlOutMusicMessage(); + WxMpXmlOutMusicMessage m = new WxMpXmlOutMusicMessage(); m.setTitle("title"); m.setDescription("ddfff"); m.setHqMusicUrl("hQMusicUrl"); @@ -38,7 +36,7 @@ public class WxXmlOutMusicMessageTest { } public void testBuild() { - WxXmlOutMusicMessage m = WxXmlOutMessage.MUSIC() + WxMpXmlOutMusicMessage m = WxMpXmlOutMessage.MUSIC() .fromUser("fromUser") .toUser("toUser") .title("title") diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxXmlOutNewsMessageTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxXmlOutNewsMessageTest.java index 1fcdbbc54..782a6abef 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxXmlOutNewsMessageTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxXmlOutNewsMessageTest.java @@ -1,7 +1,5 @@ package me.chanjar.weixin.mp.bean; -import me.chanjar.weixin.mp.bean.WxXmlOutMessage; -import me.chanjar.weixin.mp.bean.WxXmlOutMewsMessage; import org.testng.Assert; import org.testng.annotations.Test; @@ -9,12 +7,12 @@ import org.testng.annotations.Test; public class WxXmlOutNewsMessageTest { public void test() { - WxXmlOutMewsMessage m = new WxXmlOutMewsMessage(); + WxMpXmlOutMewsMessage m = new WxMpXmlOutMewsMessage(); m.setCreateTime(1122l); m.setFromUserName("fromUser"); m.setToUserName("toUser"); - WxXmlOutMewsMessage.Item item = new WxXmlOutMewsMessage.Item(); + WxMpXmlOutMewsMessage.Item item = new WxMpXmlOutMewsMessage.Item(); item.setDescription("description"); item.setPicUrl("picUrl"); item.setTitle("title"); @@ -48,13 +46,13 @@ public class WxXmlOutNewsMessageTest { } public void testBuild() { - WxXmlOutMewsMessage.Item item = new WxXmlOutMewsMessage.Item(); + WxMpXmlOutMewsMessage.Item item = new WxMpXmlOutMewsMessage.Item(); item.setDescription("description"); item.setPicUrl("picUrl"); item.setTitle("title"); item.setUrl("url"); - WxXmlOutMewsMessage m = WxXmlOutMessage.NEWS() + WxMpXmlOutMewsMessage m = WxMpXmlOutMessage.NEWS() .fromUser("fromUser") .toUser("toUser") .addArticle(item) diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxXmlOutTextMessageTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxXmlOutTextMessageTest.java index 58d7840c0..a845abcd6 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxXmlOutTextMessageTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxXmlOutTextMessageTest.java @@ -1,7 +1,5 @@ package me.chanjar.weixin.mp.bean; -import me.chanjar.weixin.mp.bean.WxXmlOutMessage; -import me.chanjar.weixin.mp.bean.WxXmlOutTextMessage; import org.testng.Assert; import org.testng.annotations.Test; @@ -9,7 +7,7 @@ import org.testng.annotations.Test; public class WxXmlOutTextMessageTest { public void test() { - WxXmlOutTextMessage m = new WxXmlOutTextMessage(); + WxMpXmlOutTextMessage m = new WxMpXmlOutTextMessage(); m.setContent("content"); m.setCreateTime(1122l); m.setFromUserName("from"); @@ -28,7 +26,7 @@ public class WxXmlOutTextMessageTest { } public void testBuild() { - WxXmlOutTextMessage m = WxXmlOutMessage.TEXT().content("content").fromUser("from").toUser("to").build(); + WxMpXmlOutTextMessage m = WxMpXmlOutMessage.TEXT().content("content").fromUser("from").toUser("to").build(); String expected = "" + "" + "" diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxXmlOutVideoMessageTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxXmlOutVideoMessageTest.java index 16e08fa5c..b033b0401 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxXmlOutVideoMessageTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxXmlOutVideoMessageTest.java @@ -1,7 +1,5 @@ package me.chanjar.weixin.mp.bean; -import me.chanjar.weixin.mp.bean.WxXmlOutMessage; -import me.chanjar.weixin.mp.bean.WxXmlOutVideoMessage; import org.testng.Assert; import org.testng.annotations.Test; @@ -9,7 +7,7 @@ import org.testng.annotations.Test; public class WxXmlOutVideoMessageTest { public void test() { - WxXmlOutVideoMessage m = new WxXmlOutVideoMessage(); + WxMpXmlOutVideoMessage m = new WxMpXmlOutVideoMessage(); m.setMediaId("media_id"); m.setTitle("title"); m.setDescription("ddfff"); @@ -34,7 +32,7 @@ public class WxXmlOutVideoMessageTest { } public void testBuild() { - WxXmlOutVideoMessage m = WxXmlOutMessage.VIDEO() + WxMpXmlOutVideoMessage m = WxMpXmlOutMessage.VIDEO() .mediaId("media_id") .fromUser("fromUser") .toUser("toUser") diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxXmlOutVoiceMessageTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxXmlOutVoiceMessageTest.java index b3aee0e04..65644f3d1 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxXmlOutVoiceMessageTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/bean/WxXmlOutVoiceMessageTest.java @@ -1,7 +1,5 @@ package me.chanjar.weixin.mp.bean; -import me.chanjar.weixin.mp.bean.WxXmlOutMessage; -import me.chanjar.weixin.mp.bean.WxXmlOutVoiceMessage; import org.testng.Assert; import org.testng.annotations.Test; @@ -9,7 +7,7 @@ import org.testng.annotations.Test; public class WxXmlOutVoiceMessageTest { public void test() { - WxXmlOutVoiceMessage m = new WxXmlOutVoiceMessage(); + WxMpXmlOutVoiceMessage m = new WxMpXmlOutVoiceMessage(); m.setMediaId("ddfefesfsdfef"); m.setCreateTime(1122l); m.setFromUserName("from"); @@ -28,7 +26,7 @@ public class WxXmlOutVoiceMessageTest { } public void testBuild() { - WxXmlOutVoiceMessage m = WxXmlOutMessage.VOICE().mediaId("ddfefesfsdfef").fromUser("from").toUser("to").build(); + WxMpXmlOutVoiceMessage m = WxMpXmlOutMessage.VOICE().mediaId("ddfefesfsdfef").fromUser("from").toUser("to").build(); String expected = "" + "" + "" diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxTestConfigStorage.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpDemoInMemoryConfigStorage.java similarity index 66% rename from weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxTestConfigStorage.java rename to weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpDemoInMemoryConfigStorage.java index 3cfe9e478..430d327d6 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxTestConfigStorage.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpDemoInMemoryConfigStorage.java @@ -1,6 +1,6 @@ package me.chanjar.weixin.mp.demo; -import me.chanjar.weixin.mp.api.WxInMemoryConfigStorage; +import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage; import org.xml.sax.InputSource; import javax.xml.bind.JAXBContext; @@ -16,7 +16,7 @@ import java.io.InputStream; */ @XmlRootElement(name = "xml") @XmlAccessorType(XmlAccessType.FIELD) -class WxTestConfigStorage extends WxInMemoryConfigStorage { +class WxMpDemoInMemoryConfigStorage extends WxMpInMemoryConfigStorage { @Override public String toString() { @@ -25,11 +25,11 @@ class WxTestConfigStorage extends WxInMemoryConfigStorage { } - public static WxTestConfigStorage fromXml(InputStream is) throws JAXBException { - Unmarshaller um = JAXBContext.newInstance(WxTestConfigStorage.class).createUnmarshaller(); + public static WxMpDemoInMemoryConfigStorage fromXml(InputStream is) throws JAXBException { + Unmarshaller um = JAXBContext.newInstance(WxMpDemoInMemoryConfigStorage.class).createUnmarshaller(); InputSource inputSource = new InputSource(is); inputSource.setEncoding("utf-8"); - return (WxTestConfigStorage) um.unmarshal(inputSource); + return (WxMpDemoInMemoryConfigStorage) um.unmarshal(inputSource); } } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxTestServer.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpDemoServer.java similarity index 80% rename from weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxTestServer.java rename to weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpDemoServer.java index c51f0f8d5..e0bb64989 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxTestServer.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpDemoServer.java @@ -6,14 +6,14 @@ import org.eclipse.jetty.servlet.ServletHandler; /** * @author Daniel Qian */ -public class WxTestServer { +public class WxMpDemoServer { public static void main(String[] args) throws Exception { Server server = new Server(8080); ServletHandler handler = new ServletHandler(); server.setHandler(handler); - handler.addServletWithMapping(WxTestServlet.class, "/*"); + handler.addServletWithMapping(WxMpDemoServlet.class, "/*"); server.start(); server.join(); } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxTestServlet.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpDemoServlet.java similarity index 63% rename from weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxTestServlet.java rename to weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpDemoServlet.java index 91e2e2660..7ceb2e269 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxTestServlet.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/WxMpDemoServlet.java @@ -1,9 +1,9 @@ package me.chanjar.weixin.mp.demo; import me.chanjar.weixin.mp.api.*; -import me.chanjar.weixin.mp.bean.WxXmlMessage; -import me.chanjar.weixin.mp.bean.WxXmlOutMessage; -import me.chanjar.weixin.mp.bean.WxXmlOutTextMessage; +import me.chanjar.weixin.mp.bean.WxMpXmlMessage; +import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage; +import me.chanjar.weixin.mp.bean.WxMpXmlOutTextMessage; import org.apache.commons.lang3.StringUtils; import javax.servlet.ServletException; @@ -18,34 +18,34 @@ import java.util.Map; /** * @author Daniel Qian */ -public class WxTestServlet extends HttpServlet { +public class WxMpDemoServlet extends HttpServlet { - protected WxService wxService; - protected WxConfigStorage wxConfigStorage; - protected WxMessageRouter wxMessageRouter; + protected WxMpService wxMpService; + protected WxMpConfigStorage wxMpConfigStorage; + protected WxMpMessageRouter wxMpMessageRouter; @Override public void init() throws ServletException { // super.init(); try { InputStream is1 = ClassLoader.getSystemResourceAsStream("test-config.xml"); - WxTestConfigStorage config = WxTestConfigStorage.fromXml(is1); + WxMpDemoInMemoryConfigStorage config = WxMpDemoInMemoryConfigStorage.fromXml(is1); - wxConfigStorage = config; - wxService = new WxServiceImpl(); - wxService.setWxConfigStorage(config); + wxMpConfigStorage = config; + wxMpService = new WxMpServiceImpl(); + wxMpService.setWxMpConfigStorage(config); - WxMessageHandler handler = new WxMessageHandler() { - @Override public WxXmlOutMessage handle(WxXmlMessage wxMessage, Map context) { - WxXmlOutTextMessage m - = WxXmlOutMessage.TEXT().content("测试加密消息").fromUser(wxMessage.getToUserName()) + WxMpMessageHandler handler = new WxMpMessageHandler() { + @Override public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map context) { + WxMpXmlOutTextMessage m + = WxMpXmlOutMessage.TEXT().content("测试加密消息").fromUser(wxMessage.getToUserName()) .toUser(wxMessage.getFromUserName()).build(); return m; } }; - wxMessageRouter = new WxMessageRouter(); - wxMessageRouter + wxMpMessageRouter = new WxMpMessageRouter(); + wxMpMessageRouter .rule() .async(false) .content("哈哈") // 拦截内容为“哈哈”的消息 @@ -67,7 +67,7 @@ public class WxTestServlet extends HttpServlet { response.setContentType("text/html;charset=utf-8"); response.setStatus(HttpServletResponse.SC_OK); - if (!wxService.checkSignature(timestamp, nonce, signature)) { + if (!wxMpService.checkSignature(timestamp, nonce, signature)) { // 消息签名不正确,说明不是公众平台发过来的消息 response.getWriter().println("非法请求"); return; @@ -84,30 +84,27 @@ public class WxTestServlet extends HttpServlet { "raw" : request.getParameter("encrypt_type"); - WxXmlMessage inMessage = null; + WxMpXmlMessage inMessage = null; if ("raw".equals(encryptType)) { // 明文传输的消息 - inMessage = WxXmlMessage.fromXml(request.getInputStream()); + inMessage = WxMpXmlMessage.fromXml(request.getInputStream()); } else if ("aes".equals(encryptType)) { // 是aes加密的消息 String msgSignature = request.getParameter("msg_signature"); - inMessage = WxXmlMessage.fromEncryptedXml( - request.getInputStream(), - wxConfigStorage, - timestamp, nonce, msgSignature); + inMessage = WxMpXmlMessage.fromEncryptedXml(request.getInputStream(), wxMpConfigStorage, timestamp, nonce, msgSignature); } else { response.getWriter().println("不可识别的加密类型"); return; } - WxXmlOutMessage outMessage = wxMessageRouter.route(inMessage); + WxMpXmlOutMessage outMessage = wxMpMessageRouter.route(inMessage); if (outMessage != null) { if ("raw".equals(encryptType)) { response.getWriter().write(outMessage.toXml()); } else if ("aes".equals(encryptType)) { - response.getWriter().write(outMessage.toEncryptedXml(wxConfigStorage)); + response.getWriter().write(outMessage.toEncryptedXml(wxMpConfigStorage)); } return; } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/util/crypto/WxCryptUtilTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/util/crypto/WxCryptUtilTest.java deleted file mode 100755 index bac5ae5a9..000000000 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/util/crypto/WxCryptUtilTest.java +++ /dev/null @@ -1,95 +0,0 @@ -package me.chanjar.weixin.mp.util.crypto; - -import me.chanjar.weixin.mp.util.crypto.WxCryptUtil; -import org.testng.annotations.Test; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import java.io.IOException; -import java.io.StringReader; - -import static org.testng.Assert.*; - -@Test -public class WxCryptUtilTest { - String encodingAesKey = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFG"; - String token = "pamtest"; - String timestamp = "1409304348"; - String nonce = "xxxxxx"; - String appId = "wxb11529c136998cb6"; - String randomStr = "aaaabbbbccccdddd"; - - String xmlFormat = ""; - String replyMsg = "我是中文abcd123"; - - String afterAesEncrypt = "jn1L23DB+6ELqJ+6bruv21Y6MD7KeIfP82D6gU39rmkgczbWwt5+3bnyg5K55bgVtVzd832WzZGMhkP72vVOfg=="; - - String replyMsg2 = "1407743423"; - String afterAesEncrypt2 = "jn1L23DB+6ELqJ+6bruv23M2GmYfkv0xBh2h+XTBOKVKcgDFHle6gqcZ1cZrk3e1qjPQ1F4RsLWzQRG9udbKWesxlkupqcEcW7ZQweImX9+wLMa0GaUzpkycA8+IamDBxn5loLgZpnS7fVAbExOkK5DYHBmv5tptA9tklE/fTIILHR8HLXa5nQvFb3tYPKAlHF3rtTeayNf0QuM+UW/wM9enGIDIJHF7CLHiDNAYxr+r+OrJCmPQyTy8cVWlu9iSvOHPT/77bZqJucQHQ04sq7KZI27OcqpQNSto2OdHCoTccjggX5Z9Mma0nMJBU+jLKJ38YB1fBIz+vBzsYjrTmFQ44YfeEuZ+xRTQwr92vhA9OxchWVINGC50qE/6lmkwWTwGX9wtQpsJKhP+oS7rvTY8+VdzETdfakjkwQ5/Xka042OlUb1/slTwo4RscuQ+RdxSGvDahxAJ6+EAjLt9d8igHngxIbf6YyqqROxuxqIeIch3CssH/LqRs+iAcILvApYZckqmA7FNERspKA5f8GoJ9sv8xmGvZ9Yrf57cExWtnX8aCMMaBropU/1k+hKP5LVdzbWCG0hGwx/dQudYR/eXp3P0XxjlFiy+9DMlaFExWUZQDajPkdPrEeOwofJb"; - - public void testNormal() throws ParserConfigurationException, SAXException, IOException { - WxCryptUtil pc = new WxCryptUtil(token, encodingAesKey, appId); - String encryptedXml = pc.encrypt(replyMsg); - - System.out.println(encryptedXml); - - DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); - DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); - Document document = documentBuilder.parse(new InputSource(new StringReader(encryptedXml))); - - Element root = document.getDocumentElement(); - String cipherText = root.getElementsByTagName("Encrypt").item(0).getTextContent(); - String msgSignature = root.getElementsByTagName("MsgSignature").item(0).getTextContent(); - String timestamp = root.getElementsByTagName("TimeStamp").item(0).getTextContent(); - String nonce = root.getElementsByTagName("Nonce").item(0).getTextContent(); - - String messageText = String.format(xmlFormat, cipherText); - - // 第三方收到公众号平台发送的消息 - String plainMessage = pc.decrypt(cipherText); - - System.out.println(plainMessage); - assertEquals(plainMessage, replyMsg); - } - - public void testAesEncrypt() { - WxCryptUtil pc = new WxCryptUtil(token, encodingAesKey, appId); - assertEquals(pc.encrypt(randomStr, replyMsg), afterAesEncrypt); - } - - public void testAesEncrypt2() { - WxCryptUtil pc = new WxCryptUtil(token, encodingAesKey, appId); - assertEquals(pc.encrypt(randomStr, replyMsg2), afterAesEncrypt2); - } - - public void testValidateSignatureError() throws ParserConfigurationException, SAXException, - IOException { - try { - WxCryptUtil pc = new WxCryptUtil(token, encodingAesKey, appId); - String afterEncrpt = pc.encrypt(replyMsg); - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - DocumentBuilder db = dbf.newDocumentBuilder(); - StringReader sr = new StringReader(afterEncrpt); - InputSource is = new InputSource(sr); - Document document = db.parse(is); - - Element root = document.getDocumentElement(); - NodeList nodelist1 = root.getElementsByTagName("Encrypt"); - - String encrypt = nodelist1.item(0).getTextContent(); - String fromXML = String.format(xmlFormat, encrypt); - pc.decrypt("12345", timestamp, nonce, fromXML); // 这里签名错误 - } catch (RuntimeException e) { - assertEquals(e.getMessage(), "加密消息签名校验失败"); - return; - } - fail("错误流程不抛出异常???"); - } - -} diff --git a/weixin-java-mp/src/test/resources/testng.xml b/weixin-java-mp/src/test/resources/testng.xml index 4318ffdb8..8987f7623 100644 --- a/weixin-java-mp/src/test/resources/testng.xml +++ b/weixin-java-mp/src/test/resources/testng.xml @@ -4,32 +4,28 @@ - - - - - - - - - + + + + + + + + + - - - - - - + + + -