Repository: honeyzhaoAliyun/WeixinMultiPlatform Branch: master Commit: 1ff6c7ace782 Files: 130 Total size: 228.4 KB Directory structure: gitextract_caiphvtt/ ├── .gitignore ├── .mymetadata ├── LICENSE ├── README.md ├── pom.xml └── src/ ├── main/ │ ├── java/ │ │ └── org/ │ │ └── hamster/ │ │ └── weixinmp/ │ │ ├── config/ │ │ │ └── WxConfig.java │ │ ├── constant/ │ │ │ ├── WxMediaType.java │ │ │ ├── WxMediaTypeEnum.java │ │ │ ├── WxMenuBtnType.java │ │ │ ├── WxMenuBtnTypeEnum.java │ │ │ ├── WxMsgEventType.java │ │ │ ├── WxMsgEventTypeEnum.java │ │ │ ├── WxMsgRespType.java │ │ │ ├── WxMsgRespTypeEnum.java │ │ │ ├── WxMsgType.java │ │ │ └── WxMsgTypeEnum.java │ │ ├── controller/ │ │ │ ├── WxController.java │ │ │ └── util/ │ │ │ ├── WxJsonUtil.java │ │ │ └── WxXmlUtil.java │ │ ├── dao/ │ │ │ ├── entity/ │ │ │ │ ├── auth/ │ │ │ │ │ ├── WxAuth.java │ │ │ │ │ └── WxAuthReq.java │ │ │ │ ├── base/ │ │ │ │ │ ├── WxBaseEntity.java │ │ │ │ │ ├── WxBaseItemMediaEntity.java │ │ │ │ │ ├── WxBaseMsgEntity.java │ │ │ │ │ └── WxBaseRespEntity.java │ │ │ │ ├── item/ │ │ │ │ │ ├── WxItemImageEntity.java │ │ │ │ │ ├── WxItemMusicEntity.java │ │ │ │ │ ├── WxItemPicDescEntity.java │ │ │ │ │ ├── WxItemThumbEntity.java │ │ │ │ │ ├── WxItemVideoEntity.java │ │ │ │ │ └── WxItemVoiceEntity.java │ │ │ │ ├── menu/ │ │ │ │ │ └── WxMenuBtnEntity.java │ │ │ │ ├── msg/ │ │ │ │ │ ├── WxMsgEventEntity.java │ │ │ │ │ ├── WxMsgImageEntity.java │ │ │ │ │ ├── WxMsgLinkEntity.java │ │ │ │ │ ├── WxMsgLocEntity.java │ │ │ │ │ ├── WxMsgTextEntity.java │ │ │ │ │ ├── WxMsgVideoEntity.java │ │ │ │ │ └── WxMsgVoiceEntity.java │ │ │ │ ├── qr/ │ │ │ │ │ └── WxQrEntity.java │ │ │ │ ├── resp/ │ │ │ │ │ ├── WxRespImageEntity.java │ │ │ │ │ ├── WxRespMusicEntity.java │ │ │ │ │ ├── WxRespPicDescEntity.java │ │ │ │ │ ├── WxRespTextEntity.java │ │ │ │ │ ├── WxRespVideoEntity.java │ │ │ │ │ └── WxRespVoiceEntity.java │ │ │ │ └── user/ │ │ │ │ ├── WxGroupEntity.java │ │ │ │ └── WxUserEntity.java │ │ │ └── repository/ │ │ │ ├── auth/ │ │ │ │ ├── WxAuthDao.java │ │ │ │ └── WxAuthReqDao.java │ │ │ ├── item/ │ │ │ │ ├── WxItemImageDao.java │ │ │ │ ├── WxItemMusicDao.java │ │ │ │ ├── WxItemPicDescDao.java │ │ │ │ ├── WxItemThumbDao.java │ │ │ │ ├── WxItemVideoDao.java │ │ │ │ └── WxItemVoiceDao.java │ │ │ ├── menu/ │ │ │ │ └── WxMenuBtnDao.java │ │ │ ├── msg/ │ │ │ │ ├── WxBaseMsgDao.java │ │ │ │ ├── WxMsgEventDao.java │ │ │ │ ├── WxMsgImageDao.java │ │ │ │ ├── WxMsgLinkDao.java │ │ │ │ ├── WxMsgLocDao.java │ │ │ │ ├── WxMsgTextDao.java │ │ │ │ ├── WxMsgVideoDao.java │ │ │ │ └── WxMsgVoiceDao.java │ │ │ ├── resp/ │ │ │ │ ├── WxRespImageDao.java │ │ │ │ ├── WxRespMusicDao.java │ │ │ │ ├── WxRespPicDescDao.java │ │ │ │ ├── WxRespTextDao.java │ │ │ │ ├── WxRespVideoDao.java │ │ │ │ └── WxRespVoiceDao.java │ │ │ └── user/ │ │ │ ├── WxGroupDao.java │ │ │ └── WxUserDao.java │ │ ├── exception/ │ │ │ └── WxException.java │ │ ├── gson/ │ │ │ └── WxMenuBtnSerializer.java │ │ ├── model/ │ │ │ ├── WxAccessTokenJson.java │ │ │ ├── WxRespCode.java │ │ │ ├── menu/ │ │ │ │ ├── WxMenuCreateJson.java │ │ │ │ └── WxMenuGetJson.java │ │ │ ├── qr/ │ │ │ │ ├── WxQrActionInfoJson.java │ │ │ │ ├── WxQrCreateJson.java │ │ │ │ └── WxQrSceneJson.java │ │ │ ├── send/ │ │ │ │ ├── SendImageJson.java │ │ │ │ ├── SendItemPicDescJson.java │ │ │ │ ├── SendMusicJson.java │ │ │ │ ├── SendTextJson.java │ │ │ │ ├── SendVideoJson.java │ │ │ │ ├── SendVoiceJson.java │ │ │ │ └── item/ │ │ │ │ ├── SendItemArticleJson.java │ │ │ │ ├── SendItemImageJson.java │ │ │ │ ├── SendItemMusicJson.java │ │ │ │ ├── SendItemTextJson.java │ │ │ │ ├── SendItemVideoJson.java │ │ │ │ ├── SendItemVoiceJson.java │ │ │ │ └── wrapper/ │ │ │ │ └── WxSendItemArticleWrapper.java │ │ │ └── user/ │ │ │ ├── WxOpenIdListJson.java │ │ │ └── WxUserGetJson.java │ │ ├── service/ │ │ │ ├── WxAuthService.java │ │ │ ├── WxMediaService.java │ │ │ ├── WxMenuService.java │ │ │ ├── WxMessageService.java │ │ │ ├── WxQrService.java │ │ │ ├── WxStorageService.java │ │ │ ├── WxUserGroupService.java │ │ │ ├── WxUserService.java │ │ │ └── handler/ │ │ │ └── WxMessageHandlerIfc.java │ │ └── util/ │ │ └── WxUtil.java │ ├── resources/ │ │ ├── applicationContext-weixinmp.xml │ │ └── wx.properties │ └── webapp/ │ ├── META-INF/ │ │ └── MANIFEST.MF │ ├── MyHtml.html │ ├── WEB-INF/ │ │ ├── classes/ │ │ │ └── weixin/ │ │ │ └── popular/ │ │ │ └── example/ │ │ │ └── pay_example.jsp.jsp │ │ └── web.xml │ ├── default/ │ │ └── index.html │ └── index.jsp └── test/ ├── java/ │ └── org/ │ └── hamster/ │ └── weixinmp/ │ └── test/ │ ├── base/ │ │ ├── AbstractServiceTest.java │ │ └── AbstractWxServiceTest.java │ ├── controller/ │ │ └── WxControllerManualTest.java │ ├── service/ │ │ ├── WxGroupServceTest.java │ │ ├── WxMediaServiceTest.java │ │ ├── WxMenuServiceTest.java │ │ ├── WxQrServiceTest.java │ │ ├── WxServiceTest.java │ │ └── WxUserServiceTest.java │ └── xml/ │ └── WxXMLUtilTest.java └── resources/ ├── .gitignore ├── application.development.properties ├── applicationContext-test-weixinmp.xml ├── log4j.properties └── sql/ └── import-data.sql ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ target/ .project .settings/ .classpath /logs ================================================ FILE: .mymetadata ================================================ ================================================ FILE: LICENSE ================================================ Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: You must give any other recipients of the Work or Derivative Works a copy of this License; and You must cause any modified files to carry prominent notices stating that You changed the files; and You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ================================================ FILE: README.md ================================================ # WeixinMultiPlatform weixin-mp-java 基于Java,Spring,Maven实现的微信公众平台一整套代码,从前端Controller到后端的Dao的实现<br /> ============== 1.0.1 2013-1月更新: 支持上传下载多媒体文件 支持接收消息(语音似乎总有问题,同时收到来自微信两个服务器的空的POST的请求,论坛上也有很多人反映此情况) 支持用户管理 支持自定义菜单CRD 支持推广支持接口 强化测试代码 优化代码结构,增加WxMessageHandlerIfc, 只要实现该接口的所有spring bean在收到消息后都会被自动调用. ============== 实现功能:消息接口,通用接口和菜单接口(没有内测号无法测试)<br /> ============== 由于涉及的框架比较杂乱,在此一一解释:<br /> 1. 简便实用的前置条件:<br /> 你的项目是基于Spring,Maven,Hibernate架构;<br /> 你的项目至少有一个已经存在的配置文件;<br /> 需要在配置文件(例子:application.properties)中添加<br /> wx_token=your_token<br /> wx_appid=asdf<br /> wx_appsecret=secret<br /> 没有在线的Maven仓库,强烈建议clone代码到本地作为子工程使用;<br /> 2. 如果你是通过spring-annotation配置bean的话,那么只要在你的Spring xml配置文件里加入以下两句便可:<br /> &lt;context:component-scan base-package="com.hamster.weixinmp" /&gt;<br /> &lt;util:properties id="wxProperties" location="classpath:/application.properties"/&gt;<br /> 如果没有util的话,在beans xml声明中加入:<br /> xmlns:util="http://www.springframework.org/schema/util"<br /> xsi:schemaLocation="…..<br /> http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd"<br /> 在org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean的packageToScan中添加org.hamster.weixinmp.dao 3. 如果不想用数据库,那么只扫描com.hamster.weixinmp.service和com.hamster.weixinmp.controller即可,所有的dao在wxService中配置模式均为可选,如果没有注入,则不会执行存储操作;<br /> 4. 项目使用了lombok生成Getter/Setter, toString, hashCode, equals方法,lombok有eclipse插件,具体怎么安装请看这里:http://projectlombok.org/download.html,如果不想用lombok的话那么就手动删掉那些注解并用eclipse等工具重新生成一下这些方法便可。<br /> 5. 如果你的项目是通过xml的方式配置的话,你需要将所有的dao,service和controller配置到xml中(浩大的工程= =)<br /> 6. 数据库的前缀为wx_,一般来说不会有冲突,真冲突了那就自己手动改改吧,反正也不麻烦<br /> 7. 数据库有些额外的字段,比如自增长的id,created_date等,用不到就无视吧<br /> 8. 如果你不用maven的话……那就把java代码都拷贝到自己的工程里面去吧……<br /> ================================================ FILE: pom.xml ================================================ 4.0.0 weixin-mp Weixin Multi Platform 1.0.2 org.hamster war http://maven.apache.org 1.3.2.RELEASE 2.2.2 3.1.3.RELEASE 1.7.2 1.2.17 2.4 4.3.1 3.1 3.6.10.Final 3.0.1 1.3.170 4.11 2.2.4 15.0 UTF-8 org.springframework.data spring-data-jpa ${spring-data-jpa.version} junit junit-dep cglib cglib ${cglib.version} com.google.code.gson gson ${gson.version} com.google.guava guava ${guava.version} org.springframework spring-webmvc 3.2.4.RELEASE org.slf4j slf4j-api ${slf4j.version} org.slf4j slf4j-simple ${slf4j.version} org.slf4j slf4j-log4j12 ${slf4j.version} org.slf4j jcl-over-slf4j ${slf4j.version} org.slf4j jul-to-slf4j ${slf4j.version} log4j log4j ${log4j.version} org.apache.httpcomponents httpclient ${httpclient.version} org.apache.httpcomponents httpmime ${httpclient.version} org.apache.commons commons-lang3 ${commons-lang3.version} commons-io commons-io ${commons-io.version} org.hibernate hibernate-entitymanager ${hibernate.version} junit junit ${junit.version} test mysql mysql-connector-java 5.1.18 org.springframework spring-test ${spring.version} test org.springframework.data spring-data-jpa junit junit-dep cglib cglib com.google.code.gson gson com.google.guava guava 15.0 pom org.springframework spring-webmvc 3.2.4.RELEASE org.springframework spring-core 3.2.4.RELEASE org.slf4j slf4j-api org.slf4j slf4j-simple org.slf4j slf4j-log4j12 org.slf4j jcl-over-slf4j org.slf4j jul-to-slf4j log4j log4j javax.servlet servlet-api 2.5 provided com.alibaba fastjson 1.2.0 org.apache.httpcomponents httpclient org.apache.httpcomponents httpmime org.apache.commons commons-lang3 commons-io commons-io org.hibernate hibernate-entitymanager junit junit test mysql mysql-connector-java 5.1.18 org.springframework spring-test test ================================================ FILE: src/main/java/org/hamster/weixinmp/config/WxConfig.java ================================================ /** * */ package org.hamster.weixinmp.config; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; /** * @author honey.zhao@aliyun.com * @version Jul 29, 2013 * */ @Configuration public class WxConfig { public static final String TABLE_PREFIX = "wx_"; public static final int COL_LEN_URL = 1024; public static final int COL_LEN_CONTENT = 4000; public static final int COL_LEN_TITLE = 200; public static final int COL_LEN_USER_NAME = 100; public static final int COL_LEN_INDICATOR = 64; private @Value("#{wxProperties.wx_token}") String token; private @Value("#{wxProperties.wx_appid}") String appid; private @Value("#{wxProperties.wx_appsecret}") String appsecret; private @Value("#{wxProperties.wx_menu_create_url}") String menuCreateUrl; private @Value("#{wxProperties.wx_menu_get_url}") String menuGetUrl; private @Value("#{wxProperties.wx_menu_delete_url}") String menuDeleteUrl; private @Value("#{wxProperties.wx_access_token_create_url}") String accessTokenCreateUrl; private @Value("#{wxProperties.wx_custom_send_url}") String customSendUrl; private @Value("#{wxProperties.wx_media_upload_url}") String mediaUploadUrl; private @Value("#{wxProperties.wx_qrcode_create_url}") String qrcodeCreateUrl; private @Value("#{wxProperties.wx_user_info_url}") String userInfoUrl; private @Value("#{wxProperties.wx_user_get_url}") String userGetUrl; private @Value("#{wxProperties.wx_groups_create_url}") String groupsCreateUrl; private @Value("#{wxProperties.wx_groups_get_url}") String groupsGetUrl; private @Value("#{wxProperties.wx_groups_getid_url}") String groupsGetIdUrl; private @Value("#{wxProperties.wx_groups_update_url}") String groupsUpdateUrl; private @Value("#{wxProperties.wx_groups_members_update_url}") String groupsMembersUpdateUrl; public String getToken() { return token; } public void setToken(String token) { this.token = token; } public String getAppid() { return appid; } public void setAppid(String appid) { this.appid = appid; } public String getAppsecret() { return appsecret; } public void setAppsecret(String appsecret) { this.appsecret = appsecret; } public String getMenuCreateUrl() { return menuCreateUrl; } public void setMenuCreateUrl(String menuCreateUrl) { this.menuCreateUrl = menuCreateUrl; } public String getMenuGetUrl() { return menuGetUrl; } public void setMenuGetUrl(String menuGetUrl) { this.menuGetUrl = menuGetUrl; } public String getMenuDeleteUrl() { return menuDeleteUrl; } public void setMenuDeleteUrl(String menuDeleteUrl) { this.menuDeleteUrl = menuDeleteUrl; } public String getAccessTokenCreateUrl() { return accessTokenCreateUrl; } public void setAccessTokenCreateUrl(String accessTokenCreateUrl) { this.accessTokenCreateUrl = accessTokenCreateUrl; } public String getCustomSendUrl() { return customSendUrl; } public void setCustomSendUrl(String customSendUrl) { this.customSendUrl = customSendUrl; } public String getMediaUploadUrl() { return mediaUploadUrl; } public void setMediaUploadUrl(String mediaUploadUrl) { this.mediaUploadUrl = mediaUploadUrl; } public String getQrcodeCreateUrl() { return qrcodeCreateUrl; } public void setQrcodeCreateUrl(String qrcodeCreateUrl) { this.qrcodeCreateUrl = qrcodeCreateUrl; } public String getUserInfoUrl() { return userInfoUrl; } public void setUserInfoUrl(String userInfoUrl) { this.userInfoUrl = userInfoUrl; } public String getUserGetUrl() { return userGetUrl; } public void setUserGetUrl(String userGetUrl) { this.userGetUrl = userGetUrl; } public String getGroupsCreateUrl() { return groupsCreateUrl; } public void setGroupsCreateUrl(String groupsCreateUrl) { this.groupsCreateUrl = groupsCreateUrl; } public String getGroupsGetUrl() { return groupsGetUrl; } public void setGroupsGetUrl(String groupsGetUrl) { this.groupsGetUrl = groupsGetUrl; } public String getGroupsGetIdUrl() { return groupsGetIdUrl; } public void setGroupsGetIdUrl(String groupsGetIdUrl) { this.groupsGetIdUrl = groupsGetIdUrl; } public String getGroupsUpdateUrl() { return groupsUpdateUrl; } public void setGroupsUpdateUrl(String groupsUpdateUrl) { this.groupsUpdateUrl = groupsUpdateUrl; } public String getGroupsMembersUpdateUrl() { return groupsMembersUpdateUrl; } public void setGroupsMembersUpdateUrl(String groupsMembersUpdateUrl) { this.groupsMembersUpdateUrl = groupsMembersUpdateUrl; } public static String getTablePrefix() { return TABLE_PREFIX; } public static int getColLenUrl() { return COL_LEN_URL; } public static int getColLenContent() { return COL_LEN_CONTENT; } public static int getColLenTitle() { return COL_LEN_TITLE; } public static int getColLenUserName() { return COL_LEN_USER_NAME; } public static int getColLenIndicator() { return COL_LEN_INDICATOR; } public WxConfig() { super(); // TODO Auto-generated constructor stub } public WxConfig(String token, String appid, String appsecret, String menuCreateUrl, String menuGetUrl, String menuDeleteUrl, String accessTokenCreateUrl, String customSendUrl, String mediaUploadUrl, String qrcodeCreateUrl, String userInfoUrl, String userGetUrl, String groupsCreateUrl, String groupsGetUrl, String groupsGetIdUrl, String groupsUpdateUrl, String groupsMembersUpdateUrl) { super(); this.token = token; this.appid = appid; this.appsecret = appsecret; this.menuCreateUrl = menuCreateUrl; this.menuGetUrl = menuGetUrl; this.menuDeleteUrl = menuDeleteUrl; this.accessTokenCreateUrl = accessTokenCreateUrl; this.customSendUrl = customSendUrl; this.mediaUploadUrl = mediaUploadUrl; this.qrcodeCreateUrl = qrcodeCreateUrl; this.userInfoUrl = userInfoUrl; this.userGetUrl = userGetUrl; this.groupsCreateUrl = groupsCreateUrl; this.groupsGetUrl = groupsGetUrl; this.groupsGetIdUrl = groupsGetIdUrl; this.groupsUpdateUrl = groupsUpdateUrl; this.groupsMembersUpdateUrl = groupsMembersUpdateUrl; } @Override public String toString() { return "WxConfig [token=" + token + ", appid=" + appid + ", appsecret=" + appsecret + ", menuCreateUrl=" + menuCreateUrl + ", menuGetUrl=" + menuGetUrl + ", menuDeleteUrl=" + menuDeleteUrl + ", accessTokenCreateUrl=" + accessTokenCreateUrl + ", customSendUrl=" + customSendUrl + ", mediaUploadUrl=" + mediaUploadUrl + ", qrcodeCreateUrl=" + qrcodeCreateUrl + ", userInfoUrl=" + userInfoUrl + ", userGetUrl=" + userGetUrl + ", groupsCreateUrl=" + groupsCreateUrl + ", groupsGetUrl=" + groupsGetUrl + ", groupsGetIdUrl=" + groupsGetIdUrl + ", groupsUpdateUrl=" + groupsUpdateUrl + ", groupsMembersUpdateUrl=" + groupsMembersUpdateUrl + "]"; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((accessTokenCreateUrl == null) ? 0 : accessTokenCreateUrl .hashCode()); result = prime * result + ((appid == null) ? 0 : appid.hashCode()); result = prime * result + ((appsecret == null) ? 0 : appsecret.hashCode()); result = prime * result + ((customSendUrl == null) ? 0 : customSendUrl.hashCode()); result = prime * result + ((groupsCreateUrl == null) ? 0 : groupsCreateUrl.hashCode()); result = prime * result + ((groupsGetIdUrl == null) ? 0 : groupsGetIdUrl.hashCode()); result = prime * result + ((groupsGetUrl == null) ? 0 : groupsGetUrl.hashCode()); result = prime * result + ((groupsMembersUpdateUrl == null) ? 0 : groupsMembersUpdateUrl.hashCode()); result = prime * result + ((groupsUpdateUrl == null) ? 0 : groupsUpdateUrl.hashCode()); result = prime * result + ((mediaUploadUrl == null) ? 0 : mediaUploadUrl.hashCode()); result = prime * result + ((menuCreateUrl == null) ? 0 : menuCreateUrl.hashCode()); result = prime * result + ((menuDeleteUrl == null) ? 0 : menuDeleteUrl.hashCode()); result = prime * result + ((menuGetUrl == null) ? 0 : menuGetUrl.hashCode()); result = prime * result + ((qrcodeCreateUrl == null) ? 0 : qrcodeCreateUrl.hashCode()); result = prime * result + ((token == null) ? 0 : token.hashCode()); result = prime * result + ((userGetUrl == null) ? 0 : userGetUrl.hashCode()); result = prime * result + ((userInfoUrl == null) ? 0 : userInfoUrl.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; WxConfig other = (WxConfig) obj; if (accessTokenCreateUrl == null) { if (other.accessTokenCreateUrl != null) return false; } else if (!accessTokenCreateUrl.equals(other.accessTokenCreateUrl)) return false; if (appid == null) { if (other.appid != null) return false; } else if (!appid.equals(other.appid)) return false; if (appsecret == null) { if (other.appsecret != null) return false; } else if (!appsecret.equals(other.appsecret)) return false; if (customSendUrl == null) { if (other.customSendUrl != null) return false; } else if (!customSendUrl.equals(other.customSendUrl)) return false; if (groupsCreateUrl == null) { if (other.groupsCreateUrl != null) return false; } else if (!groupsCreateUrl.equals(other.groupsCreateUrl)) return false; if (groupsGetIdUrl == null) { if (other.groupsGetIdUrl != null) return false; } else if (!groupsGetIdUrl.equals(other.groupsGetIdUrl)) return false; if (groupsGetUrl == null) { if (other.groupsGetUrl != null) return false; } else if (!groupsGetUrl.equals(other.groupsGetUrl)) return false; if (groupsMembersUpdateUrl == null) { if (other.groupsMembersUpdateUrl != null) return false; } else if (!groupsMembersUpdateUrl.equals(other.groupsMembersUpdateUrl)) return false; if (groupsUpdateUrl == null) { if (other.groupsUpdateUrl != null) return false; } else if (!groupsUpdateUrl.equals(other.groupsUpdateUrl)) return false; if (mediaUploadUrl == null) { if (other.mediaUploadUrl != null) return false; } else if (!mediaUploadUrl.equals(other.mediaUploadUrl)) return false; if (menuCreateUrl == null) { if (other.menuCreateUrl != null) return false; } else if (!menuCreateUrl.equals(other.menuCreateUrl)) return false; if (menuDeleteUrl == null) { if (other.menuDeleteUrl != null) return false; } else if (!menuDeleteUrl.equals(other.menuDeleteUrl)) return false; if (menuGetUrl == null) { if (other.menuGetUrl != null) return false; } else if (!menuGetUrl.equals(other.menuGetUrl)) return false; if (qrcodeCreateUrl == null) { if (other.qrcodeCreateUrl != null) return false; } else if (!qrcodeCreateUrl.equals(other.qrcodeCreateUrl)) return false; if (token == null) { if (other.token != null) return false; } else if (!token.equals(other.token)) return false; if (userGetUrl == null) { if (other.userGetUrl != null) return false; } else if (!userGetUrl.equals(other.userGetUrl)) return false; if (userInfoUrl == null) { if (other.userInfoUrl != null) return false; } else if (!userInfoUrl.equals(other.userInfoUrl)) return false; return true; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/constant/WxMediaType.java ================================================ /** * */ package org.hamster.weixinmp.constant; /** * @author honey.zhao@aliyun.com * @version Dec 29, 2013 * */ public class WxMediaType { public static final String VIDEO = "Video"; public static final String VOICE = "Voice"; public static final String MUSIC = "Music"; public static final String THUMB = "Thumb"; public static final String IMAGE = "Image"; public static final String PIC_DESC = "Article"; public static final String DEFAULT = "Default"; private WxMediaType() { } } ================================================ FILE: src/main/java/org/hamster/weixinmp/constant/WxMediaTypeEnum.java ================================================ /** * */ package org.hamster.weixinmp.constant; /** * @author honey.zhao@aliyun.com * @version Jan 4, 2014 * */ public enum WxMediaTypeEnum { IMAGE(WxMediaType.IMAGE), MUSIC(WxMediaType.MUSIC), PIC_DESC(WxMediaType.PIC_DESC), THUMB(WxMediaType.THUMB), VIDEO(WxMediaType.VIDEO), VOICE(WxMediaType.VOICE), DEFAULT(WxMediaType.DEFAULT), ; /** * @param text */ WxMediaTypeEnum(final String text) { this._text = text; } private final String _text; /* * (non-Javadoc) * * @see java.lang.Enum#toString() */ @Override public String toString() { return _text; } public static WxMediaTypeEnum inst(String strVal) { for (WxMediaTypeEnum type : WxMediaTypeEnum.values()) { if (type.toString().equalsIgnoreCase(strVal)) { return type; } } return null; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/constant/WxMenuBtnType.java ================================================ /** * */ package org.hamster.weixinmp.constant; /** * @author honey.zhao@aliyun.com * @version Jan 5, 2014 * */ public class WxMenuBtnType { public static final String VIEW = "view"; public static final String CLICK = "click"; } ================================================ FILE: src/main/java/org/hamster/weixinmp/constant/WxMenuBtnTypeEnum.java ================================================ /** * */ package org.hamster.weixinmp.constant; /** * @author honey.zhao@aliyun.com * @version Jan 4, 2014 * */ public enum WxMenuBtnTypeEnum { VIEW(WxMenuBtnType.VIEW), CLICK(WxMenuBtnType.CLICK); /** * @param text */ WxMenuBtnTypeEnum(final String text) { this._text = text; } private final String _text; /* * (non-Javadoc) * * @see java.lang.Enum#toString() */ @Override public String toString() { return _text; } public static WxMenuBtnTypeEnum inst(String strVal) { for (WxMenuBtnTypeEnum type : WxMenuBtnTypeEnum.values()) { if (type.toString().equalsIgnoreCase(strVal)) { return type; } } return null; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/constant/WxMsgEventType.java ================================================ /** * */ package org.hamster.weixinmp.constant; /** * @author honey.zhao@aliyun.com * @version Dec 30, 2013 * */ public class WxMsgEventType { public static final String SUBSCRIBE = "subscribe"; public static final String UNSUBSCRIBE = "unsubscribe"; public static final String SCAN = "scan"; public static final String LOCATION = "LOCATION"; // wtf?? public static final String CLICK = "CLICK"; // wtf?? } ================================================ FILE: src/main/java/org/hamster/weixinmp/constant/WxMsgEventTypeEnum.java ================================================ /** * */ package org.hamster.weixinmp.constant; /** * @author honey.zhao@aliyun.com * @version Jan 5, 2014 * */ public enum WxMsgEventTypeEnum { SUBSCRIBE(WxMsgEventType.SUBSCRIBE), UNSUBSCRIBE(WxMsgEventType.UNSUBSCRIBE), SCAN(WxMsgEventType.SCAN), LOCATION(WxMsgEventType.LOCATION), CLICK(WxMsgEventType.CLICK); /** * @param text */ WxMsgEventTypeEnum(final String text) { this._text = text; } private final String _text; /* * (non-Javadoc) * * @see java.lang.Enum#toString() */ @Override public String toString() { return _text; } public static WxMsgEventTypeEnum inst(String strVal) { for (WxMsgEventTypeEnum type : WxMsgEventTypeEnum.values()) { if (type.toString().equalsIgnoreCase(strVal)) { return type; } } return null; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/constant/WxMsgRespType.java ================================================ /** * */ package org.hamster.weixinmp.constant; /** * @author honey.zhao@aliyun.com * @version Jan 5, 2014 * */ public class WxMsgRespType { public static final String TEXT = "text"; public static final String IMAGE = "image"; public static final String VOICE = "voice"; public static final String VIDEO = "video"; public static final String MUSIC = "music"; public static final String NEWS = "news"; } ================================================ FILE: src/main/java/org/hamster/weixinmp/constant/WxMsgRespTypeEnum.java ================================================ /** * */ package org.hamster.weixinmp.constant; /** * @author honey.zhao@aliyun.com * @version Jan 5, 2014 * */ public enum WxMsgRespTypeEnum { TEXT(WxMsgRespType.TEXT), IMAGE(WxMsgRespType.IMAGE), MUSIC(WxMsgRespType.MUSIC), NEWS(WxMsgRespType.NEWS), VIDEO(WxMsgRespType.VIDEO), VOICE(WxMsgRespType.VOICE); /** * @param text */ private WxMsgRespTypeEnum(final String text) { this._text = text; } private final String _text; /* * (non-Javadoc) * * @see java.lang.Enum#toString() */ @Override public String toString() { return _text; } public static WxMsgRespTypeEnum inst(String strVal) { for (WxMsgRespTypeEnum type : WxMsgRespTypeEnum.values()) { if (type.toString().equalsIgnoreCase(strVal)) { return type; } } return null; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/constant/WxMsgType.java ================================================ /** * */ package org.hamster.weixinmp.constant; /** * @author honey.zhao@aliyun.com * @version Dec 30, 2013 * */ public class WxMsgType { public static final String TEXT = "text"; public static final String IMAGE = "image"; public static final String LOCATION = "location"; public static final String LINK = "link"; public static final String EVENT = "event"; public static final String VIDEO = "video"; public static final String VOICE = "voice"; } ================================================ FILE: src/main/java/org/hamster/weixinmp/constant/WxMsgTypeEnum.java ================================================ package org.hamster.weixinmp.constant; /** * @author honey.zhao@aliyun.com * @version Jul 28, 2013 * */ public enum WxMsgTypeEnum { TEXT(WxMsgType.TEXT), IMAGE(WxMsgType.IMAGE), LOCATION(WxMsgType.LOCATION), LINK(WxMsgType.LINK), EVENT(WxMsgType.EVENT), VIDEO(WxMsgType.VIDEO), VOICE(WxMsgType.VOICE); /** * @param text */ private WxMsgTypeEnum(final String text) { this._text = text; } private final String _text; /* * (non-Javadoc) * * @see java.lang.Enum#toString() */ @Override public String toString() { return _text; } public static WxMsgTypeEnum inst(String strVal) { for (WxMsgTypeEnum type : WxMsgTypeEnum.values()) { if (type.toString().equalsIgnoreCase(strVal)) { return type; } } return null; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/controller/WxController.java ================================================ /** * */ package org.hamster.weixinmp.controller; import org.apache.log4j.Logger; import org.dom4j.DocumentException; import org.hamster.weixinmp.dao.entity.base.WxBaseMsgEntity; import org.hamster.weixinmp.dao.entity.base.WxBaseRespEntity; import org.hamster.weixinmp.exception.WxException; import org.hamster.weixinmp.service.WxAuthService; import org.hamster.weixinmp.service.WxMessageService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; /** * @author honey.zhao@aliyun.com * @version Jul 28, 2013 * */ @Controller @RequestMapping("/rest/weixinmp") public class WxController { private static final Logger log = Logger.getLogger(WxController.class); @Autowired private WxAuthService authService; @Autowired private WxMessageService messageService; @RequestMapping(method = {RequestMethod.GET,}) public @ResponseBody String authGet(@RequestParam("signature") String signature, @RequestParam("timestamp") String timestamp, @RequestParam("nonce") String nonce, @RequestParam("echostr") String echostr) throws WxException { if (authService.validateAuth(signature, timestamp, nonce, echostr)) { log.info("received authentication message from Weixin Server."); return echostr; } return null; } @RequestMapping(method = RequestMethod.POST) public @ResponseBody String post(@RequestBody String requestBody) throws DocumentException, WxException { WxBaseMsgEntity msg = messageService.parseXML(requestBody); log.info("received " + msg.getMsgType() + " message."); WxBaseRespEntity resp = messageService.handleMessage(msg); return messageService.parseRespXML(resp).asXML(); } } ================================================ FILE: src/main/java/org/hamster/weixinmp/controller/util/WxJsonUtil.java ================================================ /** * */ package org.hamster.weixinmp.controller.util; import java.util.List; import org.hamster.weixinmp.dao.entity.menu.WxMenuBtnEntity; import org.hamster.weixinmp.model.WxAccessTokenJson; import org.hamster.weixinmp.model.WxRespCode; import org.hamster.weixinmp.model.menu.WxMenuCreateJson; import com.google.gson.Gson; /** * @author honey.zhao@aliyun.com * @version Aug 4, 2013 * */ public class WxJsonUtil { private WxJsonUtil() { } public static final String toMenuCreateReqBody(List wxMenuBtnList) { Gson gson = new Gson(); WxMenuCreateJson wxMenuCreateJson = new WxMenuCreateJson(); wxMenuCreateJson.setButton(wxMenuBtnList); return gson.toJson(wxMenuCreateJson); } public static final WxRespCode toWxErrorJson(String errorResult) { if (errorResult != null && (errorResult.startsWith("{\"errcode") || errorResult.startsWith("{\"errmsg"))) { return new Gson().fromJson(errorResult, WxRespCode.class); } return null; } public static final WxAccessTokenJson toAccessTokenJson(String result) { return new Gson().fromJson(result, WxAccessTokenJson.class); } } ================================================ FILE: src/main/java/org/hamster/weixinmp/controller/util/WxXmlUtil.java ================================================ /** * */ package org.hamster.weixinmp.controller.util; import java.util.Date; import org.apache.commons.lang3.StringUtils; import org.dom4j.Document; import org.dom4j.DocumentException; import org.dom4j.DocumentHelper; import org.dom4j.Element; import org.hamster.weixinmp.constant.WxMsgTypeEnum; import org.hamster.weixinmp.dao.entity.auth.WxAuthReq; import org.hamster.weixinmp.dao.entity.base.WxBaseMsgEntity; import org.hamster.weixinmp.dao.entity.base.WxBaseRespEntity; import org.hamster.weixinmp.dao.entity.item.WxItemImageEntity; import org.hamster.weixinmp.dao.entity.item.WxItemPicDescEntity; import org.hamster.weixinmp.dao.entity.item.WxItemThumbEntity; import org.hamster.weixinmp.dao.entity.item.WxItemVideoEntity; import org.hamster.weixinmp.dao.entity.item.WxItemVoiceEntity; import org.hamster.weixinmp.dao.entity.msg.WxMsgEventEntity; import org.hamster.weixinmp.dao.entity.msg.WxMsgImageEntity; import org.hamster.weixinmp.dao.entity.msg.WxMsgLinkEntity; import org.hamster.weixinmp.dao.entity.msg.WxMsgLocEntity; import org.hamster.weixinmp.dao.entity.msg.WxMsgTextEntity; import org.hamster.weixinmp.dao.entity.msg.WxMsgVideoEntity; import org.hamster.weixinmp.dao.entity.msg.WxMsgVoiceEntity; import org.hamster.weixinmp.dao.entity.resp.WxRespImageEntity; import org.hamster.weixinmp.dao.entity.resp.WxRespMusicEntity; import org.hamster.weixinmp.dao.entity.resp.WxRespPicDescEntity; import org.hamster.weixinmp.dao.entity.resp.WxRespTextEntity; import org.hamster.weixinmp.dao.entity.resp.WxRespVideoEntity; import org.hamster.weixinmp.dao.entity.resp.WxRespVoiceEntity; import org.hamster.weixinmp.util.WxUtil; /** * @author honey.zhao@aliyun.com * @version Jul 28, 2013 * */ public class WxXmlUtil { private WxXmlUtil() { } public static WxAuthReq getAuthReq(String signature, String timestamp, String nonce, String echostr) { WxAuthReq result = new WxAuthReq(); result.setSignature(signature); result.setTimestamp(timestamp); result.setNonce(nonce); result.setEchostr(echostr); return result; } /** * * <xml>
*   <ToUserName><![CDATA[toUser]]></ToUserName>
*   <FromUserName><![CDATA[fromUser]]></ * FromUserName>
*   <CreateTime>1348831860</CreateTime>
*   <MsgType><![CDATA[text]]></MsgType>
*   <Content><![CDATA[this is a * test]]></Content>
*   <MsgId>1234567890123456</MsgId>
* </xml>
*
* * @param xmlstr * @return * @throws DocumentException */ public static WxMsgTextEntity getMsgText(Element ele) throws DocumentException { WxMsgTextEntity result = msgEntityFactory(WxMsgTextEntity.class, ele); result.setMsgId(longVal(ele, "MsgId")); result.setContent(strVal(ele, "Content")); return result; } /** * * <xml> *   <ToUserName><![CDATA[toUser]]></ToUserName> *   <FromUserName><![CDATA[fromUser]]></FromUserName> *   <CreateTime>1348831860</CreateTime> *   <MsgType><![CDATA[image]]></MsgType> *   <PicUrl><![CDATA[this is a url]]></PicUrl> *   <MediaId><![CDATA[media_id]]></MediaId> *   <MsgId>1234567890123456</MsgId> * </xml> * * * @param xmlstr * @return * @throws DocumentException */ public static WxMsgImageEntity getMsgImage(Element ele) throws DocumentException { WxMsgImageEntity result = msgEntityFactory(WxMsgImageEntity.class, ele); WxItemImageEntity image = new WxItemImageEntity(); image.setMediaId(strVal(ele, "MediaId")); image.setPicUrl(strVal(ele, "PicUrl")); result.setImage(image); return result; } /** * * <xml>
*   <ToUserName><![CDATA[toUser]]></ToUserName>
*   <FromUserName><![CDATA[fromUser]]></FromUserName>
*   <CreateTime>1357290913</CreateTime>
*   <MsgType><![CDATA[voice]]></MsgType>
*   <MediaId><![CDATA[media_id]]></MediaId>
*   <Format><![CDATA[Format]]></Format>
*   <MsgId>1234567890123456</MsgId>
* </xml> *
* * @param ele * @return * @throws DocumentException */ public static WxMsgVoiceEntity getMsgVoice(Element ele) throws DocumentException { WxMsgVoiceEntity result = msgEntityFactory(WxMsgVideoEntity.class, ele); WxItemVoiceEntity voice = new WxItemVoiceEntity(); voice.setMediaId(strVal(ele, "MediaId")); voice.setFormat(strVal(ele, "Format")); if (!StringUtils.isEmpty(ele.elementText("Recognition"))) { voice.setRecognition(strVal(ele, "Recognition")); } result.setVoice(voice); return result; } /** * * <xml>
*   <ToUserName><![CDATA[toUser]]></ToUserName>
*   <FromUserName><![CDATA[fromUser]]></FromUserName>
*   <CreateTime>1357290913</CreateTime>
*   <MsgType><![CDATA[video]]></MsgType>
*   <MediaId><![CDATA[media_id]]></MediaId>
*   <ThumbMediaId><![CDATA[thumb_media_id]]></ThumbMediaId>
*   <MsgId>1234567890123456</MsgId>
* </xml> *
* @param ele * @return * @throws DocumentException */ public static WxMsgVideoEntity getMsgVideo(Element ele) throws DocumentException { WxMsgVideoEntity result = msgEntityFactory(WxMsgVideoEntity.class, ele); WxItemVideoEntity video = new WxItemVideoEntity(); video.setMediaId(strVal(ele, "MediaId")); WxItemThumbEntity thumb = new WxItemThumbEntity(); thumb.setMediaId(strVal(ele, "ThumbMediaId")); video.setThumb(thumb); result.setVideo(video); return result; } /** * * <xml>
*   <ToUserName><![CDATA[toUser]]></ToUserName>
*   <FromUserName><![CDATA[fromUser]]></FromUserName>
*   <CreateTime>1351776360</CreateTime>
*   <MsgType><![CDATA[location]]></MsgType>
*   <Location_X>23.134521</Location_X>
*   <Location_Y>113.358803</Location_Y>
*   <Scale>20</Scale>
*   <Label><![CDATA[Location Information]]></Label>
*   <MsgId>1234567890123456</MsgId>
* </xml> *
* * * @param xmlstr * @return * @throws DocumentException */ public static WxMsgLocEntity getMsgLoc(Element ele) throws DocumentException { WxMsgLocEntity result = msgEntityFactory(WxMsgLocEntity.class, ele); result.setLabel(strVal(ele, "Label")); result.setLocationX(doubleVal(ele, "Location_X")); result.setLocationY(doubleVal(ele, "Location_Y")); result.setScale(doubleVal(ele, "Scale")); return result; } /** * * <xml>
*   <ToUserName><![CDATA[toUser]]></ToUserName>
*   <FromUserName><![CDATA[fromUser]]></FromUserName>
*   <CreateTime>1351776360</CreateTime>
*   <MsgType><![CDATA[link]]></MsgType>
*   <Title><![CDATA[公众平台官网链接]]></Title>
*   <Description><![CDATA[公众平台官网链接]]></Description>
*   <Url><![CDATA[url]]></Url>
*   <MsgId>1234567890123456</MsgId>
* </xml> *
* * @param xmlstr * @return * @throws DocumentException */ public static WxMsgLinkEntity getMsgLink(Element ele) throws DocumentException { WxMsgLinkEntity result = msgEntityFactory(WxMsgLinkEntity.class, ele); result.setTitle(strVal(ele, "Title")); result.setDescription(strVal(ele, "Description")); result.setUrl(strVal(ele, "Url")); return result; } /** * * <xml>
*   <ToUserName><![CDATA[toUser]]></ToUserName>
*   <FromUserName><![CDATA[FromUser]]></FromUserName>
*   <CreateTime>123456789</CreateTime>
*   <MsgType><![CDATA[event]]></MsgType>
*   <Event><![CDATA[EVENT]]></Event>
*   <EventKey><![CDATA[EVENTKEY]]></EventKey>
* </xml> *
* * @param xmlstr * @return * @throws DocumentException */ public static WxMsgEventEntity getMsgEvent(Element ele) throws DocumentException { WxMsgEventEntity result = msgEntityFactory(WxMsgEventEntity.class, ele); result.setEvent(strVal(ele, "Event")); if (ele.elementText("EventKey") != null) { result.setEventKey(strVal(ele, "EventKey")); } if (ele.elementText("Ticket") != null) { result.setEventKey(strVal(ele, "Ticket")); } return result; } /** * * <xml>
*   <ToUserName><![CDATA[toUser]]></ToUserName>
*   <FromUserName><![CDATA[fromUser]]></FromUserName>
*   <CreateTime>12345678</CreateTime>
*   <MsgType><![CDATA[text]]></MsgType>
*   <Content><![CDATA[content]]></Content>
*   <FuncFlag>0</FuncFlag>
* </xml> *
* * @param respText * @return * @throws DocumentException */ public static Element getRespTextXML(WxRespTextEntity respText) throws DocumentException { Element ele = respEntityFactory(respText); ele.addElement("Content").addCDATA(respText.getContent()); return ele; } /** * * <xml>
*   <ToUserName><![CDATA[toUser]]></ToUserName>
*   <FromUserName><![CDATA[fromUser]]></FromUserName>
*   <CreateTime>12345678</CreateTime>
*   <MsgType><![CDATA[image]]></MsgType>
*   <Image>
*     <MediaId><![CDATA[media_id]]></MediaId>
*   </Image>
* </xml>
*
* * @param respImage * @return * @throws DocumentException */ public static Element getRespImage(WxRespImageEntity respImage) throws DocumentException { Element ele = respEntityFactory(respImage); Element imageEle = ele.addElement("Image"); imageEle.addElement("MediaId").addCDATA(respImage.getImage().getMediaId()); return ele; } /** * * <xml>
*   <ToUserName><![CDATA[toUser]]></ToUserName>
*   <FromUserName><![CDATA[fromUser]]></FromUserName>
*   <CreateTime>12345678</CreateTime>
*   <MsgType><![CDATA[voice]]></MsgType>
*   <Voice>
*     <MediaId><![CDATA[media_id]]></MediaId>
*   </Voice>
* </xml>
*
* * @param respVoice * @return * @throws DocumentException */ public static Element getRespVoice(WxRespVoiceEntity respVoice) throws DocumentException { Element ele = respEntityFactory(respVoice); Element voiceEle = ele.addElement("Voice"); voiceEle.addElement("MediaId").addCDATA(respVoice.getVoice().getMediaId()); return ele; } /** * * <xml>
*   <ToUserName><![CDATA[toUser]]></ToUserName>
*   <FromUserName><![CDATA[fromUser]]></FromUserName>
*   <CreateTime>12345678</CreateTime>
*   <MsgType><![CDATA[video]]></MsgType>
*   <Video>
*     <MediaId><![CDATA[media_id]]></MediaId>
*     <Title><![CDATA[title]]></Title>
*     <Description><![CDATA[description]]></Description>
*   </Video>
* </xml>
*
* * @param respVideo * @return * @throws DocumentException */ public static Element getRespVideo(WxRespVideoEntity respVideo) throws DocumentException { Element ele = respEntityFactory(respVideo); Element videoEle = ele.addElement("Video"); videoEle.addElement("MediaId").addCDATA(respVideo.getVideo().getMediaId()); videoEle.addElement("Title").addCDATA(StringUtils.defaultString(respVideo.getVideo().getTitle())); videoEle.addElement("Description").addCDATA(StringUtils.defaultString(respVideo.getVideo().getDescription())); return ele; } /** * * <xml>
*   <ToUserName><![CDATA[toUser]]></ToUserName>
*   <FromUserName><![CDATA[fromUser]]></FromUserName>
*   <CreateTime>12345678</CreateTime>
*   <MsgType><![CDATA[music]]></MsgType>
*   <Music>
*     <Title><![CDATA[TITLE]]></Title>
*     <Description><![CDATA[DESCRIPTION]]></Description>
*     <MusicUrl><![CDATA[MUSIC_Url]]></MusicUrl>
*     <HQMusicUrl><![CDATA[HQ_MUSIC_Url]]></HQMusicUrl>
*     <ThumbMediaId><![CDATA[media_id]]></ThumbMediaId>
*   </Music>
*   <FuncFlag>0</FuncFlag>
* </xml> *
* * @param respMusic * @return * @throws DocumentException */ public static Element getRespMusic(WxRespMusicEntity respMusic, WxItemThumbEntity thumb) throws DocumentException { Element ele = respEntityFactory(respMusic); Element musicEle = ele.addElement("Music"); musicEle.addElement("Title").addCDATA(StringUtils.defaultString(respMusic.getMusic().getTitle())); musicEle.addElement("Description").addCDATA(StringUtils.defaultString(respMusic.getMusic().getDescription())); musicEle.addElement("MusicUrl").addCDATA(StringUtils.defaultString(respMusic.getMusic().getMusicUrl())); musicEle.addElement("HQMusicUrl").addCDATA(StringUtils.defaultString(respMusic.getMusic().getHqMusicUrl())); musicEle.addElement("ThumbMediaId").addCDATA(thumb.getMediaId()); return ele; } /** * * <xml>
*   <ToUserName><![CDATA[toUser]]></ToUserName>
*   <FromUserName><![CDATA[fromUser]]></FromUserName>
*   <CreateTime>12345678</CreateTime>
*   <MsgType><![CDATA[news]]></MsgType>
*   <ArticleCount>2</ArticleCount>
*   <Articles>
*     <item>
*       <Title><![CDATA[title1]]></Title>
*       <Description><![CDATA[description1]]></Description>
*       <PicUrl><![CDATA[picurl]]></PicUrl>
*       <Url><![CDATA[url]]></Url>
*     </item>
*     <item>
*       <Title><![CDATA[title]]></Title>
*       <Description><![CDATA[description]]></Description>
*       <PicUrl><![CDATA[picurl]]></PicUrl>
*       <Url><![CDATA[url]]></Url>
*     </item>
*   </Articles>
*   <FuncFlag>1</FuncFlag>
* </xml> *
* * @param respPicDesc * @return * @throws DocumentException */ public static Element getRespPicDesc(WxRespPicDescEntity respPicDesc) throws DocumentException { Element ele = respEntityFactory(respPicDesc); ele.addElement("ArticleCount").addText(String.valueOf(respPicDesc.getArticles().size())); Element articlesEle = ele.addElement("Articles"); for (WxItemPicDescEntity item : respPicDesc.getArticles()) { Element itemEle = articlesEle.addElement("item"); itemEle.addElement("Title").addCDATA(item.getTitle()); itemEle.addElement("Description").addCDATA(item.getDescription()); itemEle.addElement("PicUrl").addCDATA(item.getPicUrl()); itemEle.addElement("HQMusicUrl").addCDATA(item.getUrl()); } return ele; } public static Element toXML(String xmlstr) throws DocumentException { Document doc = DocumentHelper.parseText(xmlstr); return doc.getRootElement(); } public static WxMsgTypeEnum getReqType(Element ele) { String type = ele.element("MsgType").getTextTrim(); return WxMsgTypeEnum.inst(type); } ////////////////////////////////////////////////// // Private Methods // ////////////////////////////////////////////////// @SuppressWarnings("unchecked") private static T msgEntityFactory( Class clazz, Element ele) { WxBaseMsgEntity result; try { result = clazz.newInstance(); result.setToUserName(strVal(ele, "ToUserName")); result.setFromUserName(strVal(ele, "FromUserName")); result.setCreateTime(longVal(ele, "CreateTime")); result.setCreatedDate(new Date()); result.setMsgType(strVal(ele, "MsgType")); if (ele.element("MsgId") != null) { result.setMsgId(longVal(ele, "MsgId")); } return (T) result; } catch (Exception e) { // never occurs return null; } } private static Element respEntityFactory(WxBaseRespEntity entity) { Element ele = DocumentHelper.createElement("xml"); ele.addElement("ToUserName").addCDATA(entity.getToUserName()); ele.addElement("FromUserName").addCDATA(entity.getFromUserName()); String createTime = String.valueOf(entity.getCreateTime()); if (StringUtils.isBlank(createTime)) { Long currentTime = WxUtil.currentTimeInSec(); entity.setCreateTime(currentTime); createTime = String.valueOf(currentTime); } ele.addElement("CreateTime").setText(createTime); ele.addElement("MsgType").addCDATA(entity.getMsgType()); ele.addElement("FuncFlag").setText(String.valueOf(entity.getFuncFlag())); return ele; } private static String strVal(Element ele, String name) { return ele.element(name).getStringValue(); } private static Long longVal(Element ele, String name) { return Long.valueOf(ele.element(name).getStringValue()); } private static Double doubleVal(Element ele, String name) { return Double.valueOf(ele.element(name).getStringValue()); } } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/entity/auth/WxAuth.java ================================================ /** * */ package org.hamster.weixinmp.dao.entity.auth; import java.util.Date; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; import org.hamster.weixinmp.dao.entity.base.WxBaseEntity; import com.google.gson.annotations.SerializedName; /** * * * @author honey.zhao@aliyun.com * @version Aug 3, 2013 * */ @Entity @Table(name = "wx_auth") public class WxAuth extends WxBaseEntity { @Column(name = "grant_type", length = 50, nullable = false) private String grantType; @Column(name = "appid", length = 100, nullable = false) private String appid; @Column(name = "secret", length = 100, nullable = false) private String secret; @SerializedName("access_token") @Column(name = "access_token", length = 200, nullable = false) private String accessToken; @SerializedName("expires_in") @Column(name = "expires_in", nullable = false) private Long expiresIn; public String getGrantType() { return grantType; } public void setGrantType(String grantType) { this.grantType = grantType; } public String getAppid() { return appid; } public void setAppid(String appid) { this.appid = appid; } public String getSecret() { return secret; } public void setSecret(String secret) { this.secret = secret; } public String getAccessToken() { return accessToken; } public void setAccessToken(String accessToken) { this.accessToken = accessToken; } public Long getExpiresIn() { return expiresIn; } public void setExpiresIn(Long expiresIn) { this.expiresIn = expiresIn; } public WxAuth() { super(); // TODO Auto-generated constructor stub } public WxAuth(Long id, Date createdDate) { super(id, createdDate); // TODO Auto-generated constructor stub } public WxAuth(String grantType, String appid, String secret, String accessToken, Long expiresIn) { super(); this.grantType = grantType; this.appid = appid; this.secret = secret; this.accessToken = accessToken; this.expiresIn = expiresIn; } @Override public String toString() { return "WxAuth [grantType=" + grantType + ", appid=" + appid + ", secret=" + secret + ", accessToken=" + accessToken + ", expiresIn=" + expiresIn + "]"; } @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((accessToken == null) ? 0 : accessToken.hashCode()); result = prime * result + ((appid == null) ? 0 : appid.hashCode()); result = prime * result + ((expiresIn == null) ? 0 : expiresIn.hashCode()); result = prime * result + ((grantType == null) ? 0 : grantType.hashCode()); result = prime * result + ((secret == null) ? 0 : secret.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; WxAuth other = (WxAuth) obj; if (accessToken == null) { if (other.accessToken != null) return false; } else if (!accessToken.equals(other.accessToken)) return false; if (appid == null) { if (other.appid != null) return false; } else if (!appid.equals(other.appid)) return false; if (expiresIn == null) { if (other.expiresIn != null) return false; } else if (!expiresIn.equals(other.expiresIn)) return false; if (grantType == null) { if (other.grantType != null) return false; } else if (!grantType.equals(other.grantType)) return false; if (secret == null) { if (other.secret != null) return false; } else if (!secret.equals(other.secret)) return false; return true; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/entity/auth/WxAuthReq.java ================================================ /** * */ package org.hamster.weixinmp.dao.entity.auth; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; import org.hamster.weixinmp.dao.entity.base.WxBaseEntity; /** * @author honey.zhao@aliyun.com * @version Jul 27, 2013 */ @Entity @Table(name = "wx_auth_req") public class WxAuthReq extends WxBaseEntity { @Column(name = "signature", length = 100, nullable = false) private String signature; @Column(name = "timestamp", length = 50, nullable = false) private String timestamp; @Column(name = "nonce", length = 50, nullable = false) private String nonce; @Column(name = "echostr", length = 200, nullable = false) private String echostr; public String getSignature() { return signature; } public void setSignature(String signature) { this.signature = signature; } public String getTimestamp() { return timestamp; } public void setTimestamp(String timestamp) { this.timestamp = timestamp; } public String getNonce() { return nonce; } public void setNonce(String nonce) { this.nonce = nonce; } public String getEchostr() { return echostr; } public void setEchostr(String echostr) { this.echostr = echostr; } public WxAuthReq() { super(); // TODO Auto-generated constructor stub } @Override public String toString() { return "WxAuthReq [signature=" + signature + ", timestamp=" + timestamp + ", nonce=" + nonce + ", echostr=" + echostr + "]"; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/entity/base/WxBaseEntity.java ================================================ /** * */ package org.hamster.weixinmp.dao.entity.base; import java.util.Date; import javax.persistence.Column; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.MappedSuperclass; import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; /** * @author honey.zhao@aliyun.com * @version Jul 27, 2013 * */ @MappedSuperclass public abstract class WxBaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Expose(serialize = false, deserialize = false) @SerializedName("_id") protected Long id; @Column(name = "created_date") @Expose(serialize = false, deserialize = false) @SerializedName("_createddate") protected Date createdDate; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public Date getCreatedDate() { return createdDate; } public void setCreatedDate(Date createdDate) { this.createdDate = createdDate; } public WxBaseEntity() { super(); // TODO Auto-generated constructor stub } public WxBaseEntity(Long id, Date createdDate) { super(); this.id = id; this.createdDate = createdDate; } @Override public String toString() { return "WxBaseEntity [id=" + id + ", createdDate=" + createdDate + "]"; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((createdDate == null) ? 0 : createdDate.hashCode()); result = prime * result + ((id == null) ? 0 : id.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; WxBaseEntity other = (WxBaseEntity) obj; if (createdDate == null) { if (other.createdDate != null) return false; } else if (!createdDate.equals(other.createdDate)) return false; if (id == null) { if (other.id != null) return false; } else if (!id.equals(other.id)) return false; return true; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/entity/base/WxBaseItemMediaEntity.java ================================================ /** * */ package org.hamster.weixinmp.dao.entity.base; import javax.persistence.MappedSuperclass; /** * @author honey.zhao@aliyun.com * @version Dec 29, 2013 * */ @MappedSuperclass public class WxBaseItemMediaEntity extends WxBaseEntity { } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/entity/base/WxBaseMsgEntity.java ================================================ /** * */ package org.hamster.weixinmp.dao.entity.base; import javax.persistence.Column; import javax.persistence.DiscriminatorColumn; import javax.persistence.Entity; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; import javax.persistence.Table; import org.hamster.weixinmp.config.WxConfig; /** * @author honey.zhao@aliyun.com * @version Jul 28, 2013 * */ @Entity @Table(name = WxConfig.TABLE_PREFIX + "msg_base") @DiscriminatorColumn(name = "msg_type", length = 20) @Inheritance(strategy = InheritanceType.JOINED) public abstract class WxBaseMsgEntity extends WxBaseEntity { @Column(name = "to_user_name", length = WxConfig.COL_LEN_USER_NAME, nullable = false) protected String toUserName; @Column(name = "from_user_name", length = WxConfig.COL_LEN_USER_NAME, nullable = false) protected String fromUserName; @Column(name = "create_time", nullable = false) protected Long createTime; @Column(name = "msg_type", length = WxConfig.COL_LEN_INDICATOR, nullable = false) protected String msgType; @Column(name = "msg_id", nullable = true) protected Long msgId; public String getToUserName() { return toUserName; } public void setToUserName(String toUserName) { this.toUserName = toUserName; } public String getFromUserName() { return fromUserName; } public void setFromUserName(String fromUserName) { this.fromUserName = fromUserName; } public Long getCreateTime() { return createTime; } public void setCreateTime(Long createTime) { this.createTime = createTime; } public String getMsgType() { return msgType; } public void setMsgType(String msgType) { this.msgType = msgType; } public Long getMsgId() { return msgId; } public void setMsgId(Long msgId) { this.msgId = msgId; } public WxBaseMsgEntity(String toUserName, String fromUserName, Long createTime, String msgType, Long msgId) { super(); this.toUserName = toUserName; this.fromUserName = fromUserName; this.createTime = createTime; this.msgType = msgType; this.msgId = msgId; } public WxBaseMsgEntity() { super(); // TODO Auto-generated constructor stub } @Override public String toString() { return "WxBaseMsgEntity [toUserName=" + toUserName + ", fromUserName=" + fromUserName + ", createTime=" + createTime + ", msgType=" + msgType + ", msgId=" + msgId + "]"; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/entity/base/WxBaseRespEntity.java ================================================ /** * */ package org.hamster.weixinmp.dao.entity.base; import java.util.Date; import javax.persistence.Column; import javax.persistence.MappedSuperclass; import org.hamster.weixinmp.config.WxConfig; /** * @author honey.zhao@aliyun.com * @version Jul 28, 2013 * */ @MappedSuperclass public abstract class WxBaseRespEntity extends WxBaseEntity { @Column(name="func_flag", nullable = false) protected Integer funcFlag; @Column(name = "to_user_name", length = WxConfig.COL_LEN_USER_NAME, nullable = false) protected String toUserName; @Column(name = "from_user_name", length = WxConfig.COL_LEN_USER_NAME, nullable = false) protected String fromUserName; @Column(name = "create_time", nullable = false) protected Long createTime; @Column(name = "msg_type", length = WxConfig.COL_LEN_INDICATOR, nullable = false) protected String msgType; public WxBaseRespEntity() { super(); // TODO Auto-generated constructor stub } public WxBaseRespEntity(Long id, Date createdDate) { super(id, createdDate); // TODO Auto-generated constructor stub } public WxBaseRespEntity(Integer funcFlag, String toUserName, String fromUserName, Long createTime, String msgType) { super(); this.funcFlag = funcFlag; this.toUserName = toUserName; this.fromUserName = fromUserName; this.createTime = createTime; this.msgType = msgType; } @Override public String toString() { return "WxBaseRespEntity [funcFlag=" + funcFlag + ", toUserName=" + toUserName + ", fromUserName=" + fromUserName + ", createTime=" + createTime + ", msgType=" + msgType + "]"; } @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((createTime == null) ? 0 : createTime.hashCode()); result = prime * result + ((fromUserName == null) ? 0 : fromUserName.hashCode()); result = prime * result + ((funcFlag == null) ? 0 : funcFlag.hashCode()); result = prime * result + ((msgType == null) ? 0 : msgType.hashCode()); result = prime * result + ((toUserName == null) ? 0 : toUserName.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; WxBaseRespEntity other = (WxBaseRespEntity) obj; if (createTime == null) { if (other.createTime != null) return false; } else if (!createTime.equals(other.createTime)) return false; if (fromUserName == null) { if (other.fromUserName != null) return false; } else if (!fromUserName.equals(other.fromUserName)) return false; if (funcFlag == null) { if (other.funcFlag != null) return false; } else if (!funcFlag.equals(other.funcFlag)) return false; if (msgType == null) { if (other.msgType != null) return false; } else if (!msgType.equals(other.msgType)) return false; if (toUserName == null) { if (other.toUserName != null) return false; } else if (!toUserName.equals(other.toUserName)) return false; return true; } public Integer getFuncFlag() { return funcFlag; } public void setFuncFlag(Integer funcFlag) { this.funcFlag = funcFlag; } public String getToUserName() { return toUserName; } public void setToUserName(String toUserName) { this.toUserName = toUserName; } public String getFromUserName() { return fromUserName; } public void setFromUserName(String fromUserName) { this.fromUserName = fromUserName; } public Long getCreateTime() { return createTime; } public void setCreateTime(Long createTime) { this.createTime = createTime; } public String getMsgType() { return msgType; } public void setMsgType(String msgType) { this.msgType = msgType; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/entity/item/WxItemImageEntity.java ================================================ /** * */ package org.hamster.weixinmp.dao.entity.item; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; import org.hamster.weixinmp.config.WxConfig; import org.hamster.weixinmp.dao.entity.base.WxBaseItemMediaEntity; /** * @author honey.zhao@aliyun.com * @version Dec 29, 2013 * */ @Entity @Table(name=WxConfig.TABLE_PREFIX + "item_image") public class WxItemImageEntity extends WxBaseItemMediaEntity { @Column(name = "media_id", length = WxConfig.COL_LEN_INDICATOR, nullable = true) private String mediaId; @Column(name="pic_url", length=WxConfig.COL_LEN_URL, nullable=true) private String picUrl; public String getMediaId() { return mediaId; } public void setMediaId(String mediaId) { this.mediaId = mediaId; } public String getPicUrl() { return picUrl; } public void setPicUrl(String picUrl) { this.picUrl = picUrl; } public WxItemImageEntity(String mediaId, String picUrl) { super(); this.mediaId = mediaId; this.picUrl = picUrl; } public WxItemImageEntity() { super(); // TODO Auto-generated constructor stub } @Override public String toString() { return "WxItemImageEntity [mediaId=" + mediaId + ", picUrl=" + picUrl + "]"; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/entity/item/WxItemMusicEntity.java ================================================ /** * */ package org.hamster.weixinmp.dao.entity.item; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; import org.hamster.weixinmp.config.WxConfig; import org.hamster.weixinmp.dao.entity.base.WxBaseItemMediaEntity; /** * @author honey.zhao@aliyun.com * @version Jul 28, 2013 * */ @Entity @Table(name=WxConfig.TABLE_PREFIX + "item_music") public class WxItemMusicEntity extends WxBaseItemMediaEntity { @Column(name = "media_id", length = WxConfig.COL_LEN_INDICATOR, nullable = true) private String mediaId; @Column(name="title", length = WxConfig.COL_LEN_TITLE, nullable = true) private String title; @Column(name="description", length = WxConfig.COL_LEN_CONTENT, nullable = true) private String description; @Column(name="music_url", length = WxConfig.COL_LEN_URL, nullable = true) private String musicUrl; @Column(name="hq_music_url", length = WxConfig.COL_LEN_URL, nullable = true) private String hqMusicUrl; public String getMediaId() { return mediaId; } public void setMediaId(String mediaId) { this.mediaId = mediaId; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public String getMusicUrl() { return musicUrl; } public void setMusicUrl(String musicUrl) { this.musicUrl = musicUrl; } public String getHqMusicUrl() { return hqMusicUrl; } public void setHqMusicUrl(String hqMusicUrl) { this.hqMusicUrl = hqMusicUrl; } public WxItemMusicEntity() { super(); // TODO Auto-generated constructor stub } public WxItemMusicEntity(String mediaId, String title, String description, String musicUrl, String hqMusicUrl) { super(); this.mediaId = mediaId; this.title = title; this.description = description; this.musicUrl = musicUrl; this.hqMusicUrl = hqMusicUrl; } @Override public String toString() { return "WxItemMusicEntity [mediaId=" + mediaId + ", title=" + title + ", description=" + description + ", musicUrl=" + musicUrl + ", hqMusicUrl=" + hqMusicUrl + "]"; } @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((description == null) ? 0 : description.hashCode()); result = prime * result + ((hqMusicUrl == null) ? 0 : hqMusicUrl.hashCode()); result = prime * result + ((mediaId == null) ? 0 : mediaId.hashCode()); result = prime * result + ((musicUrl == null) ? 0 : musicUrl.hashCode()); result = prime * result + ((title == null) ? 0 : title.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; WxItemMusicEntity other = (WxItemMusicEntity) obj; if (description == null) { if (other.description != null) return false; } else if (!description.equals(other.description)) return false; if (hqMusicUrl == null) { if (other.hqMusicUrl != null) return false; } else if (!hqMusicUrl.equals(other.hqMusicUrl)) return false; if (mediaId == null) { if (other.mediaId != null) return false; } else if (!mediaId.equals(other.mediaId)) return false; if (musicUrl == null) { if (other.musicUrl != null) return false; } else if (!musicUrl.equals(other.musicUrl)) return false; if (title == null) { if (other.title != null) return false; } else if (!title.equals(other.title)) return false; return true; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/entity/item/WxItemPicDescEntity.java ================================================ /** * */ package org.hamster.weixinmp.dao.entity.item; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; import org.hamster.weixinmp.config.WxConfig; import org.hamster.weixinmp.dao.entity.base.WxBaseItemMediaEntity; /** * @author honey.zhao@aliyun.com * @version Jul 28, 2013 * */ @Entity @Table(name=WxConfig.TABLE_PREFIX + "wx_item_pic_desc") public class WxItemPicDescEntity extends WxBaseItemMediaEntity { @Column(name="title", length = WxConfig.COL_LEN_TITLE, nullable = false) private String title; @Column(name="description", length = WxConfig.COL_LEN_CONTENT, nullable = false) private String description; @Column(name="pic_url", length = WxConfig.COL_LEN_URL, nullable = false) private String picUrl; @Column(name="url", length = WxConfig.COL_LEN_URL, nullable = false) private String url; public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public String getPicUrl() { return picUrl; } public void setPicUrl(String picUrl) { this.picUrl = picUrl; } public String getUrl() { return url; } public void setUrl(String url) { this.url = url; } public WxItemPicDescEntity() { super(); // TODO Auto-generated constructor stub } public WxItemPicDescEntity(String title, String description, String picUrl, String url) { super(); this.title = title; this.description = description; this.picUrl = picUrl; this.url = url; } @Override public String toString() { return "WxItemPicDescEntity [title=" + title + ", description=" + description + ", picUrl=" + picUrl + ", url=" + url + "]"; } @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((description == null) ? 0 : description.hashCode()); result = prime * result + ((picUrl == null) ? 0 : picUrl.hashCode()); result = prime * result + ((title == null) ? 0 : title.hashCode()); result = prime * result + ((url == null) ? 0 : url.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; WxItemPicDescEntity other = (WxItemPicDescEntity) obj; if (description == null) { if (other.description != null) return false; } else if (!description.equals(other.description)) return false; if (picUrl == null) { if (other.picUrl != null) return false; } else if (!picUrl.equals(other.picUrl)) return false; if (title == null) { if (other.title != null) return false; } else if (!title.equals(other.title)) return false; if (url == null) { if (other.url != null) return false; } else if (!url.equals(other.url)) return false; return true; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/entity/item/WxItemThumbEntity.java ================================================ /** * */ package org.hamster.weixinmp.dao.entity.item; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; import org.hamster.weixinmp.config.WxConfig; import org.hamster.weixinmp.dao.entity.base.WxBaseItemMediaEntity; /** * @author honey.zhao@aliyun.com * @version Dec 29, 2013 * */ @Entity @Table(name=WxConfig.TABLE_PREFIX + "item_thumb") public class WxItemThumbEntity extends WxBaseItemMediaEntity { @Column(name = "media_id", length = WxConfig.COL_LEN_INDICATOR, nullable = true) private String mediaId; public String getMediaId() { return mediaId; } public void setMediaId(String mediaId) { this.mediaId = mediaId; } public WxItemThumbEntity() { super(); // TODO Auto-generated constructor stub } public WxItemThumbEntity(String mediaId) { super(); this.mediaId = mediaId; } @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((mediaId == null) ? 0 : mediaId.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; WxItemThumbEntity other = (WxItemThumbEntity) obj; if (mediaId == null) { if (other.mediaId != null) return false; } else if (!mediaId.equals(other.mediaId)) return false; return true; } @Override public String toString() { return "WxItemThumbEntity [mediaId=" + mediaId + "]"; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/entity/item/WxItemVideoEntity.java ================================================ /** * */ package org.hamster.weixinmp.dao.entity.item; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; import org.hamster.weixinmp.config.WxConfig; import org.hamster.weixinmp.dao.entity.base.WxBaseItemMediaEntity; /** * @author honey.zhao@aliyun.com * @version Dec 29, 2013 * */ @Entity @Table(name = WxConfig.TABLE_PREFIX + "item_video") public class WxItemVideoEntity extends WxBaseItemMediaEntity { @Column(name = "media_id", length = WxConfig.COL_LEN_INDICATOR, nullable = true) private String mediaId; @Column(name = "title", length = WxConfig.COL_LEN_TITLE, nullable = true) private String title; @Column(name = "description", length = WxConfig.COL_LEN_CONTENT, nullable = true) private String description; @ManyToOne @JoinColumn(name = "thumb_id", nullable = true) WxItemThumbEntity thumb; public String getMediaId() { return mediaId; } public void setMediaId(String mediaId) { this.mediaId = mediaId; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public WxItemThumbEntity getThumb() { return thumb; } public void setThumb(WxItemThumbEntity thumb) { this.thumb = thumb; } public WxItemVideoEntity() { super(); // TODO Auto-generated constructor stub } public WxItemVideoEntity(String mediaId, String title, String description, WxItemThumbEntity thumb) { super(); this.mediaId = mediaId; this.title = title; this.description = description; this.thumb = thumb; } @Override public String toString() { return "WxItemVideoEntity [mediaId=" + mediaId + ", title=" + title + ", description=" + description + ", thumb=" + thumb + "]"; } @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((description == null) ? 0 : description.hashCode()); result = prime * result + ((mediaId == null) ? 0 : mediaId.hashCode()); result = prime * result + ((thumb == null) ? 0 : thumb.hashCode()); result = prime * result + ((title == null) ? 0 : title.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; WxItemVideoEntity other = (WxItemVideoEntity) obj; if (description == null) { if (other.description != null) return false; } else if (!description.equals(other.description)) return false; if (mediaId == null) { if (other.mediaId != null) return false; } else if (!mediaId.equals(other.mediaId)) return false; if (thumb == null) { if (other.thumb != null) return false; } else if (!thumb.equals(other.thumb)) return false; if (title == null) { if (other.title != null) return false; } else if (!title.equals(other.title)) return false; return true; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/entity/item/WxItemVoiceEntity.java ================================================ /** * */ package org.hamster.weixinmp.dao.entity.item; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; import org.hamster.weixinmp.config.WxConfig; import org.hamster.weixinmp.dao.entity.base.WxBaseItemMediaEntity; /** * @author honey.zhao@aliyun.com * @version Dec 29, 2013 * */ @Entity @Table(name=WxConfig.TABLE_PREFIX + "item_voice") public class WxItemVoiceEntity extends WxBaseItemMediaEntity { @Column(name = "media_id", length = WxConfig.COL_LEN_INDICATOR, nullable = true) private String mediaId; @Column(name = "format", length = 10, nullable = true) private String format; @Column(name = "recognition", length = WxConfig.COL_LEN_TITLE, nullable = true) private String recognition; public String getMediaId() { return mediaId; } public void setMediaId(String mediaId) { this.mediaId = mediaId; } public String getFormat() { return format; } public void setFormat(String format) { this.format = format; } public String getRecognition() { return recognition; } public void setRecognition(String recognition) { this.recognition = recognition; } public WxItemVoiceEntity() { super(); // TODO Auto-generated constructor stub } public WxItemVoiceEntity(String mediaId, String format, String recognition) { super(); this.mediaId = mediaId; this.format = format; this.recognition = recognition; } @Override public String toString() { return "WxItemVoiceEntity [mediaId=" + mediaId + ", format=" + format + ", recognition=" + recognition + "]"; } @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((format == null) ? 0 : format.hashCode()); result = prime * result + ((mediaId == null) ? 0 : mediaId.hashCode()); result = prime * result + ((recognition == null) ? 0 : recognition.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; WxItemVoiceEntity other = (WxItemVoiceEntity) obj; if (format == null) { if (other.format != null) return false; } else if (!format.equals(other.format)) return false; if (mediaId == null) { if (other.mediaId != null) return false; } else if (!mediaId.equals(other.mediaId)) return false; if (recognition == null) { if (other.recognition != null) return false; } else if (!recognition.equals(other.recognition)) return false; return true; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/entity/menu/WxMenuBtnEntity.java ================================================ /** * */ package org.hamster.weixinmp.dao.entity.menu; import java.util.Date; import java.util.List; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.Table; import org.hamster.weixinmp.config.WxConfig; import org.hamster.weixinmp.dao.entity.base.WxBaseEntity; import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; /** * @author honey.zhao@aliyun.com * @version Aug 4, 2013 * */ @Entity @Table(name = WxConfig.TABLE_PREFIX + "menu_btn") public class WxMenuBtnEntity extends WxBaseEntity { @Column(name = "key_", length = 128, nullable = false) private String key; @Column(name = "url", length = 256, nullable = false) private String url; @Column(name = "name", length = 80, nullable = false) private String name; @Column(name = "type", length = WxConfig.COL_LEN_INDICATOR, nullable = false) private String type; @ManyToOne(cascade = { CascadeType.ALL }) @JoinColumn(name = "parent_button_id") @Expose(serialize = false, deserialize = false) private WxMenuBtnEntity parentButton; @OneToMany(mappedBy = "parentButton") @SerializedName("sub_button") private List subButtons; 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 String getName() { return name; } public void setName(String name) { this.name = name; } public String getType() { return type; } public void setType(String type) { this.type = type; } public WxMenuBtnEntity getParentButton() { return parentButton; } public void setParentButton(WxMenuBtnEntity parentButton) { this.parentButton = parentButton; } public List getSubButtons() { return subButtons; } public void setSubButtons(List subButtons) { this.subButtons = subButtons; } public WxMenuBtnEntity() { super(); // TODO Auto-generated constructor stub } public WxMenuBtnEntity(Long id, Date createdDate) { super(id, createdDate); // TODO Auto-generated constructor stub } public WxMenuBtnEntity(String key, String url, String name, String type, WxMenuBtnEntity parentButton, List subButtons) { super(); this.key = key; this.url = url; this.name = name; this.type = type; this.parentButton = parentButton; this.subButtons = subButtons; } @Override public String toString() { return "WxMenuBtnEntity [key=" + key + ", url=" + url + ", name=" + name + ", type=" + type + ", parentButton=" + parentButton + ", subButtons=" + subButtons + "]"; } @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((key == null) ? 0 : key.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((parentButton == null) ? 0 : parentButton.hashCode()); result = prime * result + ((subButtons == null) ? 0 : subButtons.hashCode()); result = prime * result + ((type == null) ? 0 : type.hashCode()); result = prime * result + ((url == null) ? 0 : url.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; WxMenuBtnEntity other = (WxMenuBtnEntity) obj; if (key == null) { if (other.key != null) return false; } else if (!key.equals(other.key)) return false; if (name == null) { if (other.name != null) return false; } else if (!name.equals(other.name)) return false; if (parentButton == null) { if (other.parentButton != null) return false; } else if (!parentButton.equals(other.parentButton)) return false; if (subButtons == null) { if (other.subButtons != null) return false; } else if (!subButtons.equals(other.subButtons)) return false; if (type == null) { if (other.type != null) return false; } else if (!type.equals(other.type)) return false; if (url == null) { if (other.url != null) return false; } else if (!url.equals(other.url)) return false; return true; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/entity/msg/WxMsgEventEntity.java ================================================ /** * */ package org.hamster.weixinmp.dao.entity.msg; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; import org.hamster.weixinmp.config.WxConfig; import org.hamster.weixinmp.dao.entity.base.WxBaseMsgEntity; /** * @author honey.zhao@aliyun.com * @version Jul 28, 2013 * */ @Entity @Table(name = WxConfig.TABLE_PREFIX + "msg_event") public class WxMsgEventEntity extends WxBaseMsgEntity { @Column(name = "event", length = WxConfig.COL_LEN_INDICATOR, nullable = false) private String event; @Column(name = "event_key", length = WxConfig.COL_LEN_TITLE, nullable = true) private String eventKey; @Column(name = "ticket", length = WxConfig.COL_LEN_TITLE, nullable = true) private String ticket; @Column(name = "latitude", nullable = true) private Double latitude; @Column(name = "longitude", nullable = true) private Double longitude; @Column(name = "precisions", nullable = true) private Double precisions; public String getEvent() { return event; } public void setEvent(String event) { this.event = event; } public String getEventKey() { return eventKey; } public void setEventKey(String eventKey) { this.eventKey = eventKey; } public String getTicket() { return ticket; } public void setTicket(String ticket) { this.ticket = ticket; } public Double getLatitude() { return latitude; } public void setLatitude(Double latitude) { this.latitude = latitude; } public Double getLongitude() { return longitude; } public void setLongitude(Double longitude) { this.longitude = longitude; } public Double getPrecisions() { return precisions; } public void setPrecisions(Double precisions) { this.precisions = precisions; } public WxMsgEventEntity() { super(); // TODO Auto-generated constructor stub } public WxMsgEventEntity(String toUserName, String fromUserName, Long createTime, String msgType, Long msgId) { super(toUserName, fromUserName, createTime, msgType, msgId); // TODO Auto-generated constructor stub } public WxMsgEventEntity(String toUserName, String fromUserName, Long createTime, String msgType, Long msgId, String event, String eventKey, String ticket, Double latitude, Double longitude, Double precisions) { super(toUserName, fromUserName, createTime, msgType, msgId); this.event = event; this.eventKey = eventKey; this.ticket = ticket; this.latitude = latitude; this.longitude = longitude; this.precisions = precisions; } @Override public String toString() { return "WxMsgEventEntity [event=" + event + ", eventKey=" + eventKey + ", ticket=" + ticket + ", latitude=" + latitude + ", longitude=" + longitude + ", precisions=" + precisions + "]"; } @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((event == null) ? 0 : event.hashCode()); result = prime * result + ((eventKey == null) ? 0 : eventKey.hashCode()); result = prime * result + ((latitude == null) ? 0 : latitude.hashCode()); result = prime * result + ((longitude == null) ? 0 : longitude.hashCode()); result = prime * result + ((precisions == null) ? 0 : precisions.hashCode()); result = prime * result + ((ticket == null) ? 0 : ticket.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; WxMsgEventEntity other = (WxMsgEventEntity) obj; if (event == null) { if (other.event != null) return false; } else if (!event.equals(other.event)) return false; if (eventKey == null) { if (other.eventKey != null) return false; } else if (!eventKey.equals(other.eventKey)) return false; if (latitude == null) { if (other.latitude != null) return false; } else if (!latitude.equals(other.latitude)) return false; if (longitude == null) { if (other.longitude != null) return false; } else if (!longitude.equals(other.longitude)) return false; if (precisions == null) { if (other.precisions != null) return false; } else if (!precisions.equals(other.precisions)) return false; if (ticket == null) { if (other.ticket != null) return false; } else if (!ticket.equals(other.ticket)) return false; return true; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/entity/msg/WxMsgImageEntity.java ================================================ /** * */ package org.hamster.weixinmp.dao.entity.msg; import javax.persistence.DiscriminatorValue; import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; import org.hamster.weixinmp.config.WxConfig; import org.hamster.weixinmp.constant.WxMsgType; import org.hamster.weixinmp.dao.entity.base.WxBaseMsgEntity; import org.hamster.weixinmp.dao.entity.item.WxItemImageEntity; /** * @author honey.zhao@aliyun.com * @version Jul 28, 2013 * */ @Entity @Table(name = WxConfig.TABLE_PREFIX + "msg_image") @DiscriminatorValue(WxMsgType.IMAGE) public class WxMsgImageEntity extends WxBaseMsgEntity { @ManyToOne @JoinColumn(name = "image_id") private WxItemImageEntity image; public WxItemImageEntity getImage() { return image; } public void setImage(WxItemImageEntity image) { this.image = image; } public WxMsgImageEntity() { super(); // TODO Auto-generated constructor stub } public WxMsgImageEntity(String toUserName, String fromUserName, Long createTime, String msgType, Long msgId) { super(toUserName, fromUserName, createTime, msgType, msgId); // TODO Auto-generated constructor stub } public WxMsgImageEntity(String toUserName, String fromUserName, Long createTime, String msgType, Long msgId, WxItemImageEntity image) { super(toUserName, fromUserName, createTime, msgType, msgId); this.image = image; } @Override public String toString() { return "WxMsgImageEntity [image=" + image + "]"; } @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((image == null) ? 0 : image.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; WxMsgImageEntity other = (WxMsgImageEntity) obj; if (image == null) { if (other.image != null) return false; } else if (!image.equals(other.image)) return false; return true; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/entity/msg/WxMsgLinkEntity.java ================================================ /** * */ package org.hamster.weixinmp.dao.entity.msg; import javax.persistence.Column; import javax.persistence.DiscriminatorValue; import javax.persistence.Entity; import javax.persistence.Table; import org.hamster.weixinmp.config.WxConfig; import org.hamster.weixinmp.constant.WxMsgType; import org.hamster.weixinmp.dao.entity.base.WxBaseMsgEntity; /** * @author honey.zhao@aliyun.com * @version Jul 28, 2013 * */ @Entity @Table(name = WxConfig.TABLE_PREFIX + "msg_link") @DiscriminatorValue(WxMsgType.LINK) public class WxMsgLinkEntity extends WxBaseMsgEntity { @Column(name = "title", length = WxConfig.COL_LEN_TITLE, nullable = false) private String title; @Column(name = "description", length = WxConfig.COL_LEN_CONTENT, nullable = false) private String description; @Column(name = "url", length = WxConfig.COL_LEN_URL, nullable = false) private String url; public WxMsgLinkEntity() { super(); // TODO Auto-generated constructor stub } public WxMsgLinkEntity(String toUserName, String fromUserName, Long createTime, String msgType, Long msgId) { super(toUserName, fromUserName, createTime, msgType, msgId); // TODO Auto-generated constructor stub } public WxMsgLinkEntity(String toUserName, String fromUserName, Long createTime, String msgType, Long msgId, String title, String description, String url) { super(toUserName, fromUserName, createTime, msgType, msgId); this.title = title; this.description = description; this.url = url; } @Override public String toString() { return "WxMsgLinkEntity [title=" + title + ", description=" + description + ", url=" + url + "]"; } @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((description == null) ? 0 : description.hashCode()); result = prime * result + ((title == null) ? 0 : title.hashCode()); result = prime * result + ((url == null) ? 0 : url.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; WxMsgLinkEntity other = (WxMsgLinkEntity) obj; if (description == null) { if (other.description != null) return false; } else if (!description.equals(other.description)) return false; if (title == null) { if (other.title != null) return false; } else if (!title.equals(other.title)) return false; if (url == null) { if (other.url != null) return false; } else if (!url.equals(other.url)) return false; return true; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public String getUrl() { return url; } public void setUrl(String url) { this.url = url; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/entity/msg/WxMsgLocEntity.java ================================================ /** * */ package org.hamster.weixinmp.dao.entity.msg; import javax.persistence.Column; import javax.persistence.DiscriminatorValue; import javax.persistence.Entity; import javax.persistence.Table; import org.hamster.weixinmp.config.WxConfig; import org.hamster.weixinmp.constant.WxMsgType; import org.hamster.weixinmp.dao.entity.base.WxBaseMsgEntity; /** * @author honey.zhao@aliyun.com * @version Jul 28, 2013 * */ @Entity @Table(name = WxConfig.TABLE_PREFIX + "msg_loc") @DiscriminatorValue(WxMsgType.LOCATION) public class WxMsgLocEntity extends WxBaseMsgEntity { @Column(name = "location_x", nullable = false) private Double locationX; @Column(name = "location_y", nullable = false) private Double locationY; @Column(name = "scale", nullable = false) private Double scale; @Column(name = "label", length = WxConfig.COL_LEN_TITLE, nullable = false) private String label; public Double getLocationX() { return locationX; } public void setLocationX(Double locationX) { this.locationX = locationX; } public Double getLocationY() { return locationY; } public void setLocationY(Double locationY) { this.locationY = locationY; } public Double getScale() { return scale; } public void setScale(Double scale) { this.scale = scale; } public String getLabel() { return label; } public void setLabel(String label) { this.label = label; } public WxMsgLocEntity() { super(); // TODO Auto-generated constructor stub } public WxMsgLocEntity(String toUserName, String fromUserName, Long createTime, String msgType, Long msgId) { super(toUserName, fromUserName, createTime, msgType, msgId); // TODO Auto-generated constructor stub } public WxMsgLocEntity(String toUserName, String fromUserName, Long createTime, String msgType, Long msgId, Double locationX, Double locationY, Double scale, String label) { super(toUserName, fromUserName, createTime, msgType, msgId); this.locationX = locationX; this.locationY = locationY; this.scale = scale; this.label = label; } @Override public String toString() { return "WxMsgLocEntity [locationX=" + locationX + ", locationY=" + locationY + ", scale=" + scale + ", label=" + label + "]"; } @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((label == null) ? 0 : label.hashCode()); result = prime * result + ((locationX == null) ? 0 : locationX.hashCode()); result = prime * result + ((locationY == null) ? 0 : locationY.hashCode()); result = prime * result + ((scale == null) ? 0 : scale.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; WxMsgLocEntity other = (WxMsgLocEntity) obj; if (label == null) { if (other.label != null) return false; } else if (!label.equals(other.label)) return false; if (locationX == null) { if (other.locationX != null) return false; } else if (!locationX.equals(other.locationX)) return false; if (locationY == null) { if (other.locationY != null) return false; } else if (!locationY.equals(other.locationY)) return false; if (scale == null) { if (other.scale != null) return false; } else if (!scale.equals(other.scale)) return false; return true; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/entity/msg/WxMsgTextEntity.java ================================================ /** * */ package org.hamster.weixinmp.dao.entity.msg; import javax.persistence.Column; import javax.persistence.DiscriminatorValue; import javax.persistence.Entity; import javax.persistence.Table; import org.hamster.weixinmp.config.WxConfig; import org.hamster.weixinmp.constant.WxMsgType; import org.hamster.weixinmp.dao.entity.base.WxBaseMsgEntity; /** * @author honey.zhao@aliyun.com * @version Jul 28, 2013 * * */ @Entity @Table(name = WxConfig.TABLE_PREFIX + "msg_text") @DiscriminatorValue(WxMsgType.TEXT) public class WxMsgTextEntity extends WxBaseMsgEntity { @Column(name = "content", length = WxConfig.COL_LEN_CONTENT, nullable = false) private String content; public String getContent() { return content; } public void setContent(String content) { this.content = content; } public WxMsgTextEntity() { super(); // TODO Auto-generated constructor stub } public WxMsgTextEntity(String content) { super(); this.content = content; } @Override public String toString() { return "WxMsgTextEntity [content=" + content + "]"; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/entity/msg/WxMsgVideoEntity.java ================================================ /** * */ package org.hamster.weixinmp.dao.entity.msg; import javax.persistence.DiscriminatorValue; import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; import org.hamster.weixinmp.config.WxConfig; import org.hamster.weixinmp.constant.WxMsgType; import org.hamster.weixinmp.dao.entity.base.WxBaseMsgEntity; import org.hamster.weixinmp.dao.entity.item.WxItemVideoEntity; /** * @author honey.zhao@aliyun.com * @version Dec 24, 2013 * */ @Entity @Table(name = WxConfig.TABLE_PREFIX + "msg_video") @DiscriminatorValue(WxMsgType.VIDEO) public class WxMsgVideoEntity extends WxBaseMsgEntity { @ManyToOne @JoinColumn(name="video_id") private WxItemVideoEntity video; public WxItemVideoEntity getVideo() { return video; } public void setVideo(WxItemVideoEntity video) { this.video = video; } public WxMsgVideoEntity() { super(); // TODO Auto-generated constructor stub } public WxMsgVideoEntity(String toUserName, String fromUserName, Long createTime, String msgType, Long msgId) { super(toUserName, fromUserName, createTime, msgType, msgId); // TODO Auto-generated constructor stub } public WxMsgVideoEntity(String toUserName, String fromUserName, Long createTime, String msgType, Long msgId, WxItemVideoEntity video) { super(toUserName, fromUserName, createTime, msgType, msgId); this.video = video; } @Override public String toString() { return "WxMsgVideoEntity [video=" + video + "]"; } @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((video == null) ? 0 : video.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; WxMsgVideoEntity other = (WxMsgVideoEntity) obj; if (video == null) { if (other.video != null) return false; } else if (!video.equals(other.video)) return false; return true; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/entity/msg/WxMsgVoiceEntity.java ================================================ /** * */ package org.hamster.weixinmp.dao.entity.msg; import javax.persistence.DiscriminatorValue; import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; import org.hamster.weixinmp.config.WxConfig; import org.hamster.weixinmp.constant.WxMsgType; import org.hamster.weixinmp.dao.entity.base.WxBaseMsgEntity; import org.hamster.weixinmp.dao.entity.item.WxItemVoiceEntity; /** * @author honey.zhao@aliyun.com * @version Dec 24, 2013 * */ @Entity @Table(name = WxConfig.TABLE_PREFIX + "msg_voice") @DiscriminatorValue(WxMsgType.VOICE) public class WxMsgVoiceEntity extends WxBaseMsgEntity { @ManyToOne @JoinColumn(name="voice_id") WxItemVoiceEntity voice; public WxItemVoiceEntity getVoice() { return voice; } public void setVoice(WxItemVoiceEntity voice) { this.voice = voice; } public WxMsgVoiceEntity() { super(); // TODO Auto-generated constructor stub } public WxMsgVoiceEntity(String toUserName, String fromUserName, Long createTime, String msgType, Long msgId) { super(toUserName, fromUserName, createTime, msgType, msgId); // TODO Auto-generated constructor stub } public WxMsgVoiceEntity(String toUserName, String fromUserName, Long createTime, String msgType, Long msgId, WxItemVoiceEntity voice) { super(toUserName, fromUserName, createTime, msgType, msgId); this.voice = voice; } @Override public String toString() { return "WxMsgVoiceEntity [voice=" + voice + "]"; } @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((voice == null) ? 0 : voice.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; WxMsgVoiceEntity other = (WxMsgVoiceEntity) obj; if (voice == null) { if (other.voice != null) return false; } else if (!voice.equals(other.voice)) return false; return true; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/entity/qr/WxQrEntity.java ================================================ /** * */ package org.hamster.weixinmp.dao.entity.qr; import java.util.Date; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; import org.hamster.weixinmp.config.WxConfig; import org.hamster.weixinmp.dao.entity.base.WxBaseEntity; import com.google.gson.annotations.SerializedName; /** * @author honey.zhao@aliyun.com * @version Jan 4, 2014 * */ @Entity @Table(name = WxConfig.TABLE_PREFIX + "qr") public class WxQrEntity extends WxBaseEntity { @Column(name = "ticket", length = WxConfig.COL_LEN_TITLE, nullable = true) private String ticket; @Column(name = "scene", nullable = false) private Long scene; @Column(name = "expire_seconds", nullable = true) @SerializedName("expire_seconds") private Long expireSeconds; public String getTicket() { return ticket; } public void setTicket(String ticket) { this.ticket = ticket; } public Long getScene() { return scene; } public void setScene(Long scene) { this.scene = scene; } public Long getExpireSeconds() { return expireSeconds; } public void setExpireSeconds(Long expireSeconds) { this.expireSeconds = expireSeconds; } public WxQrEntity() { super(); // TODO Auto-generated constructor stub } public WxQrEntity(Long id, Date createdDate) { super(id, createdDate); // TODO Auto-generated constructor stub } public WxQrEntity(String ticket, Long scene, Long expireSeconds) { super(); this.ticket = ticket; this.scene = scene; this.expireSeconds = expireSeconds; } @Override public String toString() { return "WxQrEntity [ticket=" + ticket + ", scene=" + scene + ", expireSeconds=" + expireSeconds + "]"; } @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((expireSeconds == null) ? 0 : expireSeconds.hashCode()); result = prime * result + ((scene == null) ? 0 : scene.hashCode()); result = prime * result + ((ticket == null) ? 0 : ticket.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; WxQrEntity other = (WxQrEntity) obj; if (expireSeconds == null) { if (other.expireSeconds != null) return false; } else if (!expireSeconds.equals(other.expireSeconds)) return false; if (scene == null) { if (other.scene != null) return false; } else if (!scene.equals(other.scene)) return false; if (ticket == null) { if (other.ticket != null) return false; } else if (!ticket.equals(other.ticket)) return false; return true; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/entity/resp/WxRespImageEntity.java ================================================ /** * */ package org.hamster.weixinmp.dao.entity.resp; import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; import org.hamster.weixinmp.config.WxConfig; import org.hamster.weixinmp.dao.entity.base.WxBaseRespEntity; import org.hamster.weixinmp.dao.entity.item.WxItemImageEntity; /** * @author honey.zhao@aliyun.com * @version Dec 29, 2013 * */ @Entity @Table(name = WxConfig.TABLE_PREFIX + "resp_music") public class WxRespImageEntity extends WxBaseRespEntity { @ManyToOne @JoinColumn(name = "image_id") WxItemImageEntity image; public WxItemImageEntity getImage() { return image; } public void setImage(WxItemImageEntity image) { this.image = image; } public WxRespImageEntity() { super(); // TODO Auto-generated constructor stub } public WxRespImageEntity(WxItemImageEntity image) { super(); this.image = image; } @Override public String toString() { return "WxRespImageEntity [image=" + image + "]"; } @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((image == null) ? 0 : image.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; WxRespImageEntity other = (WxRespImageEntity) obj; if (image == null) { if (other.image != null) return false; } else if (!image.equals(other.image)) return false; return true; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/entity/resp/WxRespMusicEntity.java ================================================ /** * */ package org.hamster.weixinmp.dao.entity.resp; import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; import org.hamster.weixinmp.config.WxConfig; import org.hamster.weixinmp.dao.entity.base.WxBaseRespEntity; import org.hamster.weixinmp.dao.entity.item.WxItemMusicEntity; import org.hamster.weixinmp.dao.entity.item.WxItemThumbEntity; /** * @author honey.zhao@aliyun.com * @version Jul 28, 2013 * */ @Entity @Table(name = WxConfig.TABLE_PREFIX + "resp_music") public class WxRespMusicEntity extends WxBaseRespEntity { @ManyToOne @JoinColumn(name = "music_id", nullable = false) private WxItemMusicEntity music; @ManyToOne @JoinColumn(name = "thumb_id", nullable = false) private WxItemThumbEntity thumb; public WxItemMusicEntity getMusic() { return music; } public void setMusic(WxItemMusicEntity music) { this.music = music; } public WxItemThumbEntity getThumb() { return thumb; } public void setThumb(WxItemThumbEntity thumb) { this.thumb = thumb; } public WxRespMusicEntity() { super(); // TODO Auto-generated constructor stub } public WxRespMusicEntity(WxItemMusicEntity music, WxItemThumbEntity thumb) { super(); this.music = music; this.thumb = thumb; } @Override public String toString() { return "WxRespMusicEntity [music=" + music + ", thumb=" + thumb + "]"; } @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((music == null) ? 0 : music.hashCode()); result = prime * result + ((thumb == null) ? 0 : thumb.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; WxRespMusicEntity other = (WxRespMusicEntity) obj; if (music == null) { if (other.music != null) return false; } else if (!music.equals(other.music)) return false; if (thumb == null) { if (other.thumb != null) return false; } else if (!thumb.equals(other.thumb)) return false; return true; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/entity/resp/WxRespPicDescEntity.java ================================================ /** * */ package org.hamster.weixinmp.dao.entity.resp; import java.util.List; import javax.persistence.Entity; import javax.persistence.JoinTable; import javax.persistence.ManyToMany; import javax.persistence.Table; import org.hamster.weixinmp.config.WxConfig; import org.hamster.weixinmp.dao.entity.base.WxBaseRespEntity; import org.hamster.weixinmp.dao.entity.item.WxItemPicDescEntity; /** * @author honey.zhao@aliyun.com * @version Jul 28, 2013 * */ @Entity @Table(name = WxConfig.TABLE_PREFIX + "resp_pic_desc") public class WxRespPicDescEntity extends WxBaseRespEntity { @ManyToMany @JoinTable(name = "wx_resp_pic_desc_item") private List articles; public List getArticles() { return articles; } public void setArticles(List articles) { this.articles = articles; } public WxRespPicDescEntity() { super(); // TODO Auto-generated constructor stub } public WxRespPicDescEntity(List articles) { super(); this.articles = articles; } @Override public String toString() { return "WxRespPicDescEntity [articles=" + articles + "]"; } @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((articles == null) ? 0 : articles.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; WxRespPicDescEntity other = (WxRespPicDescEntity) obj; if (articles == null) { if (other.articles != null) return false; } else if (!articles.equals(other.articles)) return false; return true; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/entity/resp/WxRespTextEntity.java ================================================ /** * */ package org.hamster.weixinmp.dao.entity.resp; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; import org.hamster.weixinmp.config.WxConfig; import org.hamster.weixinmp.dao.entity.base.WxBaseRespEntity; /** * @author honey.zhao@aliyun.com * @version Jul 28, 2013 * */ @Entity @Table(name = WxConfig.TABLE_PREFIX + "resp_text") public class WxRespTextEntity extends WxBaseRespEntity { @Column(name = "content", length = WxConfig.COL_LEN_CONTENT, nullable = false) private String content; public String getContent() { return content; } public void setContent(String content) { this.content = content; } public WxRespTextEntity() { super(); // TODO Auto-generated constructor stub } public WxRespTextEntity(String content) { super(); this.content = content; } @Override public String toString() { return "WxRespTextEntity [content=" + content + "]"; } @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((content == null) ? 0 : content.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; WxRespTextEntity other = (WxRespTextEntity) obj; if (content == null) { if (other.content != null) return false; } else if (!content.equals(other.content)) return false; return true; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/entity/resp/WxRespVideoEntity.java ================================================ /** * */ package org.hamster.weixinmp.dao.entity.resp; import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; import org.hamster.weixinmp.config.WxConfig; import org.hamster.weixinmp.dao.entity.base.WxBaseRespEntity; import org.hamster.weixinmp.dao.entity.item.WxItemVideoEntity; /** * @author honey.zhao@aliyun.com * @version Dec 29, 2013 * */ @Entity @Table(name = WxConfig.TABLE_PREFIX + "resp_video") public class WxRespVideoEntity extends WxBaseRespEntity { @ManyToOne @JoinColumn(name = "video_id") WxItemVideoEntity video; public WxItemVideoEntity getVideo() { return video; } public void setVideo(WxItemVideoEntity video) { this.video = video; } public WxRespVideoEntity() { super(); // TODO Auto-generated constructor stub } @Override public String toString() { return "WxRespVideoEntity [video=" + video + "]"; } public WxRespVideoEntity(WxItemVideoEntity video) { super(); this.video = video; } @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((video == null) ? 0 : video.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; WxRespVideoEntity other = (WxRespVideoEntity) obj; if (video == null) { if (other.video != null) return false; } else if (!video.equals(other.video)) return false; return true; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/entity/resp/WxRespVoiceEntity.java ================================================ /** * */ package org.hamster.weixinmp.dao.entity.resp; import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; import org.hamster.weixinmp.config.WxConfig; import org.hamster.weixinmp.dao.entity.base.WxBaseRespEntity; import org.hamster.weixinmp.dao.entity.item.WxItemVoiceEntity; /** * @author honey.zhao@aliyun.com * @version Dec 29, 2013 * */ @Entity @Table(name = WxConfig.TABLE_PREFIX + "resp_voice") public class WxRespVoiceEntity extends WxBaseRespEntity { @ManyToOne @JoinColumn(name = "voice_id") private WxItemVoiceEntity voice; public WxItemVoiceEntity getVoice() { return voice; } public void setVoice(WxItemVoiceEntity voice) { this.voice = voice; } public WxRespVoiceEntity() { super(); // TODO Auto-generated constructor stub } public WxRespVoiceEntity(WxItemVoiceEntity voice) { super(); this.voice = voice; } @Override public String toString() { return "WxRespVoiceEntity [voice=" + voice + "]"; } @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((voice == null) ? 0 : voice.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; WxRespVoiceEntity other = (WxRespVoiceEntity) obj; if (voice == null) { if (other.voice != null) return false; } else if (!voice.equals(other.voice)) return false; return true; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/entity/user/WxGroupEntity.java ================================================ /** * */ package org.hamster.weixinmp.dao.entity.user; import java.util.Date; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; import org.hamster.weixinmp.config.WxConfig; import org.hamster.weixinmp.dao.entity.base.WxBaseEntity; import com.google.gson.annotations.SerializedName; /** * @author honey.zhao@aliyun.com * @version Dec 30, 2013 * */ @Entity @Table(name = WxConfig.TABLE_PREFIX + "user_group") public class WxGroupEntity extends WxBaseEntity { @SerializedName("id") @Column(name="wx_id", nullable=false) private Long wxId; @Column(name="name", length=WxConfig.COL_LEN_TITLE, nullable=false) private String name; @Column(name="count", nullable=false) private String count; public Long getWxId() { return wxId; } public void setWxId(Long wxId) { this.wxId = wxId; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getCount() { return count; } public void setCount(String count) { this.count = count; } public WxGroupEntity() { super(); // TODO Auto-generated constructor stub } public WxGroupEntity(Long id, Date createdDate) { super(id, createdDate); // TODO Auto-generated constructor stub } public WxGroupEntity(Long wxId, String name, String count) { super(); this.wxId = wxId; this.name = name; this.count = count; } @Override public String toString() { return "WxGroupEntity [wxId=" + wxId + ", name=" + name + ", count=" + count + "]"; } @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((count == null) ? 0 : count.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((wxId == null) ? 0 : wxId.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; WxGroupEntity other = (WxGroupEntity) obj; if (count == null) { if (other.count != null) return false; } else if (!count.equals(other.count)) return false; if (name == null) { if (other.name != null) return false; } else if (!name.equals(other.name)) return false; if (wxId == null) { if (other.wxId != null) return false; } else if (!wxId.equals(other.wxId)) return false; return true; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/entity/user/WxUserEntity.java ================================================ /** * */ package org.hamster.weixinmp.dao.entity.user; import java.util.Date; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; import org.hamster.weixinmp.config.WxConfig; import org.hamster.weixinmp.dao.entity.base.WxBaseEntity; import com.google.gson.annotations.SerializedName; /** * @author honey.zhao@aliyun.com * @version Dec 30, 2013 * */ @Entity @Table(name = WxConfig.TABLE_PREFIX + "user") public class WxUserEntity extends WxBaseEntity { @SerializedName("openid") @Column(name = "open_id", length = WxConfig.COL_LEN_INDICATOR, nullable = false) private String openId; @Column(name = "subscribe", nullable = false) private Integer subscribe; @SerializedName("nickname") @Column(name = "nickname", length = WxConfig.COL_LEN_USER_NAME, nullable = false) private String nickName; @Column(name = "sex", nullable = false) private Integer sex; @Column(name = "language", length = WxConfig.COL_LEN_INDICATOR, nullable = false) private String language; @Column(name = "city", length = WxConfig.COL_LEN_INDICATOR, nullable = false) private String city; @Column(name = "province", length = WxConfig.COL_LEN_INDICATOR, nullable = false) private String province; @Column(name = "country", length = WxConfig.COL_LEN_INDICATOR, nullable = false) private String country; @SerializedName("headimgurl") @Column(name = "head_img_url", length = WxConfig.COL_LEN_URL, nullable = false) private String headImgUrl; @SerializedName("subscribe_time") @Column(name = "subscribe_time", nullable = false) private Long subscribeTime; public String getOpenId() { return openId; } public void setOpenId(String openId) { this.openId = openId; } public Integer getSubscribe() { return subscribe; } public void setSubscribe(Integer subscribe) { this.subscribe = subscribe; } public String getNickName() { return nickName; } public void setNickName(String nickName) { this.nickName = nickName; } public Integer getSex() { return sex; } public void setSex(Integer sex) { this.sex = sex; } public String getLanguage() { return language; } public void setLanguage(String language) { this.language = language; } public String getCity() { return city; } public void setCity(String city) { this.city = city; } public String getProvince() { return province; } public void setProvince(String province) { this.province = province; } public String getCountry() { return country; } public void setCountry(String country) { this.country = country; } public String getHeadImgUrl() { return headImgUrl; } public void setHeadImgUrl(String headImgUrl) { this.headImgUrl = headImgUrl; } public Long getSubscribeTime() { return subscribeTime; } public void setSubscribeTime(Long subscribeTime) { this.subscribeTime = subscribeTime; } public WxUserEntity() { super(); // TODO Auto-generated constructor stub } public WxUserEntity(Long id, Date createdDate) { super(id, createdDate); // TODO Auto-generated constructor stub } public WxUserEntity(String openId, Integer subscribe, String nickName, Integer sex, String language, String city, String province, String country, String headImgUrl, Long subscribeTime) { super(); this.openId = openId; this.subscribe = subscribe; this.nickName = nickName; this.sex = sex; this.language = language; this.city = city; this.province = province; this.country = country; this.headImgUrl = headImgUrl; this.subscribeTime = subscribeTime; } @Override public String toString() { return "WxUserEntity [openId=" + openId + ", subscribe=" + subscribe + ", nickName=" + nickName + ", sex=" + sex + ", language=" + language + ", city=" + city + ", province=" + province + ", country=" + country + ", headImgUrl=" + headImgUrl + ", subscribeTime=" + subscribeTime + "]"; } @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((city == null) ? 0 : city.hashCode()); result = prime * result + ((country == null) ? 0 : country.hashCode()); result = prime * result + ((headImgUrl == null) ? 0 : headImgUrl.hashCode()); result = prime * result + ((language == null) ? 0 : language.hashCode()); result = prime * result + ((nickName == null) ? 0 : nickName.hashCode()); result = prime * result + ((openId == null) ? 0 : openId.hashCode()); result = prime * result + ((province == null) ? 0 : province.hashCode()); result = prime * result + ((sex == null) ? 0 : sex.hashCode()); result = prime * result + ((subscribe == null) ? 0 : subscribe.hashCode()); result = prime * result + ((subscribeTime == null) ? 0 : subscribeTime.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; WxUserEntity other = (WxUserEntity) obj; if (city == null) { if (other.city != null) return false; } else if (!city.equals(other.city)) return false; if (country == null) { if (other.country != null) return false; } else if (!country.equals(other.country)) return false; if (headImgUrl == null) { if (other.headImgUrl != null) return false; } else if (!headImgUrl.equals(other.headImgUrl)) return false; if (language == null) { if (other.language != null) return false; } else if (!language.equals(other.language)) return false; if (nickName == null) { if (other.nickName != null) return false; } else if (!nickName.equals(other.nickName)) return false; if (openId == null) { if (other.openId != null) return false; } else if (!openId.equals(other.openId)) return false; if (province == null) { if (other.province != null) return false; } else if (!province.equals(other.province)) return false; if (sex == null) { if (other.sex != null) return false; } else if (!sex.equals(other.sex)) return false; if (subscribe == null) { if (other.subscribe != null) return false; } else if (!subscribe.equals(other.subscribe)) return false; if (subscribeTime == null) { if (other.subscribeTime != null) return false; } else if (!subscribeTime.equals(other.subscribeTime)) return false; return true; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/repository/auth/WxAuthDao.java ================================================ /** * */ package org.hamster.weixinmp.dao.repository.auth; import org.hamster.weixinmp.dao.entity.auth.WxAuth; import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.stereotype.Repository; /** * @author honey.zhao@aliyun.com * @version Aug 4, 2013 * */ @Repository public interface WxAuthDao extends PagingAndSortingRepository { } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/repository/auth/WxAuthReqDao.java ================================================ /** * */ package org.hamster.weixinmp.dao.repository.auth; import org.hamster.weixinmp.dao.entity.auth.WxAuthReq; import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.stereotype.Repository; /** * @author honey.zhao@aliyun.com * @version Jul 28, 2013 * */ @Repository public interface WxAuthReqDao extends PagingAndSortingRepository { } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/repository/item/WxItemImageDao.java ================================================ /** * */ package org.hamster.weixinmp.dao.repository.item; import org.hamster.weixinmp.dao.entity.item.WxItemImageEntity; import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.stereotype.Repository; /** * @author honey.zhao@aliyun.com * @version Jan 5, 2014 * */ @Repository public interface WxItemImageDao extends PagingAndSortingRepository { } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/repository/item/WxItemMusicDao.java ================================================ /** * */ package org.hamster.weixinmp.dao.repository.item; import org.hamster.weixinmp.dao.entity.item.WxItemMusicEntity; import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.stereotype.Repository; /** * @author honey.zhao@aliyun.com * @version Jul 28, 2013 * */ @Repository public interface WxItemMusicDao extends PagingAndSortingRepository { } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/repository/item/WxItemPicDescDao.java ================================================ /** * */ package org.hamster.weixinmp.dao.repository.item; import java.util.List; import org.hamster.weixinmp.dao.entity.item.WxItemPicDescEntity; import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.stereotype.Repository; /** * @author honey.zhao@aliyun.com * @version Jul 28, 2013 * */ @Repository public interface WxItemPicDescDao extends PagingAndSortingRepository { /** * * @param ids * @return */ List findByIdIn(List ids); } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/repository/item/WxItemThumbDao.java ================================================ /** * */ package org.hamster.weixinmp.dao.repository.item; import org.hamster.weixinmp.dao.entity.item.WxItemThumbEntity; import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.stereotype.Repository; /** * @author honey.zhao@aliyun.com * @version Jan 5, 2014 * */ @Repository public interface WxItemThumbDao extends PagingAndSortingRepository { } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/repository/item/WxItemVideoDao.java ================================================ /** * */ package org.hamster.weixinmp.dao.repository.item; import org.hamster.weixinmp.dao.entity.item.WxItemVideoEntity; import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.stereotype.Repository; /** * @author honey.zhao@aliyun.com * @version Jan 5, 2014 * */ @Repository public interface WxItemVideoDao extends PagingAndSortingRepository { } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/repository/item/WxItemVoiceDao.java ================================================ /** * */ package org.hamster.weixinmp.dao.repository.item; import org.hamster.weixinmp.dao.entity.item.WxItemVoiceEntity; import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.stereotype.Repository; /** * @author honey.zhao@aliyun.com * @version Jan 5, 2014 * */ @Repository public interface WxItemVoiceDao extends PagingAndSortingRepository { } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/repository/menu/WxMenuBtnDao.java ================================================ /** * */ package org.hamster.weixinmp.dao.repository.menu; import org.hamster.weixinmp.dao.entity.menu.WxMenuBtnEntity; import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.stereotype.Repository; /** * @author honey.zhao@aliyun.com * @version Aug 4, 2013 * */ @Repository public interface WxMenuBtnDao extends PagingAndSortingRepository { } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/repository/msg/WxBaseMsgDao.java ================================================ /** * */ package org.hamster.weixinmp.dao.repository.msg; import org.hamster.weixinmp.dao.entity.base.WxBaseMsgEntity; import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.stereotype.Repository; /** * @author honey.zhao@aliyun.com * @version Dec 30, 2013 * */ @Repository public interface WxBaseMsgDao extends PagingAndSortingRepository { } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/repository/msg/WxMsgEventDao.java ================================================ /** * */ package org.hamster.weixinmp.dao.repository.msg; import org.hamster.weixinmp.dao.entity.msg.WxMsgEventEntity; import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.stereotype.Repository; /** * @author honey.zhao@aliyun.com * @version Jul 28, 2013 * */ @Repository public interface WxMsgEventDao extends PagingAndSortingRepository { } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/repository/msg/WxMsgImageDao.java ================================================ /** * */ package org.hamster.weixinmp.dao.repository.msg; import org.hamster.weixinmp.dao.entity.msg.WxMsgImageEntity; import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.stereotype.Repository; /** * @author honey.zhao@aliyun.com * @version Jul 28, 2013 * */ @Repository public interface WxMsgImageDao extends PagingAndSortingRepository { } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/repository/msg/WxMsgLinkDao.java ================================================ /** * */ package org.hamster.weixinmp.dao.repository.msg; import org.hamster.weixinmp.dao.entity.msg.WxMsgLinkEntity; import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.stereotype.Repository; /** * @author honey.zhao@aliyun.com * @version Jul 28, 2013 * */ @Repository public interface WxMsgLinkDao extends PagingAndSortingRepository { } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/repository/msg/WxMsgLocDao.java ================================================ /** * */ package org.hamster.weixinmp.dao.repository.msg; import org.hamster.weixinmp.dao.entity.msg.WxMsgLocEntity; import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.stereotype.Repository; /** * @author honey.zhao@aliyun.com * @version Jul 28, 2013 * */ @Repository public interface WxMsgLocDao extends PagingAndSortingRepository { } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/repository/msg/WxMsgTextDao.java ================================================ /** * */ package org.hamster.weixinmp.dao.repository.msg; import org.hamster.weixinmp.dao.entity.msg.WxMsgTextEntity; import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.stereotype.Repository; /** * @author honey.zhao@aliyun.com * @version Jul 28, 2013 * */ @Repository public interface WxMsgTextDao extends PagingAndSortingRepository { } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/repository/msg/WxMsgVideoDao.java ================================================ /** * */ package org.hamster.weixinmp.dao.repository.msg; import org.hamster.weixinmp.dao.entity.msg.WxMsgVideoEntity; import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.stereotype.Repository; /** * @author honey.zhao@aliyun.com * @version Jul 28, 2013 * */ @Repository public interface WxMsgVideoDao extends PagingAndSortingRepository { } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/repository/msg/WxMsgVoiceDao.java ================================================ /** * */ package org.hamster.weixinmp.dao.repository.msg; import org.hamster.weixinmp.dao.entity.msg.WxMsgVoiceEntity; import org.springframework.data.repository.PagingAndSortingRepository; /** * @author honey.zhao@aliyun.com * @version Jan 5, 2014 * */ public interface WxMsgVoiceDao extends PagingAndSortingRepository { } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/repository/resp/WxRespImageDao.java ================================================ /** * */ package org.hamster.weixinmp.dao.repository.resp; import org.hamster.weixinmp.dao.entity.resp.WxRespImageEntity; import org.springframework.data.repository.PagingAndSortingRepository; /** * @author honey.zhao@aliyun.com * @version Jul 28, 2013 * */ public interface WxRespImageDao extends PagingAndSortingRepository { } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/repository/resp/WxRespMusicDao.java ================================================ /** * */ package org.hamster.weixinmp.dao.repository.resp; import org.hamster.weixinmp.dao.entity.resp.WxRespMusicEntity; import org.springframework.data.repository.PagingAndSortingRepository; /** * @author honey.zhao@aliyun.com * @version Jul 28, 2013 * */ public interface WxRespMusicDao extends PagingAndSortingRepository { } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/repository/resp/WxRespPicDescDao.java ================================================ /** * */ package org.hamster.weixinmp.dao.repository.resp; import org.hamster.weixinmp.dao.entity.resp.WxRespPicDescEntity; import org.springframework.data.repository.PagingAndSortingRepository; /** * @author honey.zhao@aliyun.com * @version Jul 28, 2013 * */ public interface WxRespPicDescDao extends PagingAndSortingRepository { } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/repository/resp/WxRespTextDao.java ================================================ /** * */ package org.hamster.weixinmp.dao.repository.resp; import org.hamster.weixinmp.dao.entity.resp.WxRespTextEntity; import org.springframework.data.repository.PagingAndSortingRepository; /** * @author honey.zhao@aliyun.com * @version Jul 28, 2013 * */ public interface WxRespTextDao extends PagingAndSortingRepository { } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/repository/resp/WxRespVideoDao.java ================================================ /** * */ package org.hamster.weixinmp.dao.repository.resp; import org.hamster.weixinmp.dao.entity.resp.WxRespVideoEntity; import org.springframework.data.repository.PagingAndSortingRepository; /** * @author honey.zhao@aliyun.com * @version Jul 28, 2013 * */ public interface WxRespVideoDao extends PagingAndSortingRepository { } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/repository/resp/WxRespVoiceDao.java ================================================ /** * */ package org.hamster.weixinmp.dao.repository.resp; import org.hamster.weixinmp.dao.entity.resp.WxRespVoiceEntity; import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.stereotype.Repository; /** * @author honey.zhao@aliyun.com * @version Jul 28, 2013 * */ @Repository public interface WxRespVoiceDao extends PagingAndSortingRepository { } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/repository/user/WxGroupDao.java ================================================ /** * */ package org.hamster.weixinmp.dao.repository.user; import org.hamster.weixinmp.dao.entity.user.WxGroupEntity; import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.stereotype.Repository; /** * @author honey.zhao@aliyun.com * @version Jul 28, 2013 * * */ @Repository public interface WxGroupDao extends PagingAndSortingRepository { } ================================================ FILE: src/main/java/org/hamster/weixinmp/dao/repository/user/WxUserDao.java ================================================ /** * */ package org.hamster.weixinmp.dao.repository.user; import org.hamster.weixinmp.dao.entity.user.WxUserEntity; import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.stereotype.Repository; /** * @author honey.zhao@aliyun.com * @version Jul 28, 2013 * * */ @Repository public interface WxUserDao extends PagingAndSortingRepository { } ================================================ FILE: src/main/java/org/hamster/weixinmp/exception/WxException.java ================================================ /** * */ package org.hamster.weixinmp.exception; import org.hamster.weixinmp.model.WxRespCode; /** * @author honey.zhao@aliyun.com * @version Jul 28, 2013 * */ public class WxException extends Exception { private static final long serialVersionUID = -5181800588832010641L; private WxRespCode error; /** * */ public WxException() { } /** * @param message */ public WxException(String message) { super(message); } /** * @param cause */ public WxException(Throwable cause) { super(cause); } /** * @param message * @param cause */ public WxException(String message, Throwable cause) { super(message, cause); } /** * */ public WxException(WxRespCode errorJson) { super(errorJson.getErrmsg()); this.error = errorJson; } public WxRespCode getError() { return error; } public void setError(WxRespCode error) { this.error = error; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/gson/WxMenuBtnSerializer.java ================================================ /** * */ package org.hamster.weixinmp.gson; import java.lang.reflect.Type; import org.hamster.weixinmp.constant.WxMenuBtnTypeEnum; import org.hamster.weixinmp.dao.entity.menu.WxMenuBtnEntity; import org.springframework.util.CollectionUtils; 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 honey.zhao@aliyun.com * @version Jan 4, 2014 * */ public class WxMenuBtnSerializer implements JsonSerializer { /* * (non-Javadoc) * * @see com.google.gson.JsonSerializer#serialize(java.lang.Object, * java.lang.reflect.Type, com.google.gson.JsonSerializationContext) */ public JsonElement serialize(WxMenuBtnEntity src, Type typeOfSrc, JsonSerializationContext context) { return recursiveParse(src); } public JsonObject recursiveParse(WxMenuBtnEntity parentEntity) { JsonObject parent = new JsonObject(); parent.addProperty("type", parentEntity.getType()); parent.addProperty("name", parentEntity.getName()); WxMenuBtnTypeEnum type = WxMenuBtnTypeEnum.valueOf(parentEntity .getType()); switch (type) { case CLICK: parent.addProperty("key", parentEntity.getKey()); break; case VIEW: parent.addProperty("url", parentEntity.getUrl()); break; default: break; } if (!CollectionUtils.isEmpty(parentEntity.getSubButtons())) { JsonArray children = new JsonArray(); for (WxMenuBtnEntity child : parentEntity.getSubButtons()) { children.add(recursiveParse(child)); } parent.add("sub_button", children); } return parent; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/model/WxAccessTokenJson.java ================================================ /** * */ package org.hamster.weixinmp.model; /** * @author honey.zhao@aliyun.com * @version Aug 4, 2013 * */ public class WxAccessTokenJson { private String access_token; private String expires_in; public String getAccess_token() { return access_token; } public void setAccess_token(String access_token) { this.access_token = access_token; } public String getExpires_in() { return expires_in; } public void setExpires_in(String expires_in) { this.expires_in = expires_in; } public WxAccessTokenJson() { super(); // TODO Auto-generated constructor stub } public WxAccessTokenJson(String access_token, String expires_in) { super(); this.access_token = access_token; this.expires_in = expires_in; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/model/WxRespCode.java ================================================ /** * */ package org.hamster.weixinmp.model; /** * @author honey.zhao@aliyun.com * @version Aug 4, 2013 * */ public class WxRespCode { private Integer errcode; private String errmsg; public Integer getErrcode() { return errcode; } public void setErrcode(Integer errcode) { this.errcode = errcode; } public String getErrmsg() { return errmsg; } public void setErrmsg(String errmsg) { this.errmsg = errmsg; } public WxRespCode() { super(); // TODO Auto-generated constructor stub } public WxRespCode(Integer errcode, String errmsg) { super(); this.errcode = errcode; this.errmsg = errmsg; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/model/menu/WxMenuCreateJson.java ================================================ /** * */ package org.hamster.weixinmp.model.menu; import java.util.List; import org.hamster.weixinmp.dao.entity.menu.WxMenuBtnEntity; /** * @author honey.zhao@aliyun.com * @version Aug 4, 2013 * */ public class WxMenuCreateJson { private List button; public List getButton() { return button; } public void setButton(List button) { this.button = button; } public WxMenuCreateJson() { super(); // TODO Auto-generated constructor stub } public WxMenuCreateJson(List button) { super(); this.button = button; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/model/menu/WxMenuGetJson.java ================================================ /** * */ package org.hamster.weixinmp.model.menu; /** * @author honey.zhao@aliyun.com * @version Jan 4, 2014 * */ public class WxMenuGetJson { private WxMenuCreateJson menu; public WxMenuCreateJson getMenu() { return menu; } public void setMenu(WxMenuCreateJson menu) { this.menu = menu; } public WxMenuGetJson() { super(); // TODO Auto-generated constructor stub } public WxMenuGetJson(WxMenuCreateJson menu) { super(); this.menu = menu; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/model/qr/WxQrActionInfoJson.java ================================================ /** * */ package org.hamster.weixinmp.model.qr; /** * @author honey.zhao@aliyun.com * @version Jan 4, 2014 * */ public class WxQrActionInfoJson { private WxQrSceneJson scene; public WxQrSceneJson getScene() { return scene; } public void setScene(WxQrSceneJson scene) { this.scene = scene; } public WxQrActionInfoJson(WxQrSceneJson scene) { super(); this.scene = scene; } public WxQrActionInfoJson() { super(); // TODO Auto-generated constructor stub } } ================================================ FILE: src/main/java/org/hamster/weixinmp/model/qr/WxQrCreateJson.java ================================================ /** * */ package org.hamster.weixinmp.model.qr; /** * @author honey.zhao@aliyun.com * @version Jan 4, 2014 * */ public class WxQrCreateJson { private String action_name; private Long expire_seconds; private WxQrActionInfoJson action_info; public String getAction_name() { return action_name; } public void setAction_name(String action_name) { this.action_name = action_name; } public Long getExpire_seconds() { return expire_seconds; } public void setExpire_seconds(Long expire_seconds) { this.expire_seconds = expire_seconds; } public WxQrActionInfoJson getAction_info() { return action_info; } public void setAction_info(WxQrActionInfoJson action_info) { this.action_info = action_info; } public WxQrCreateJson() { super(); // TODO Auto-generated constructor stub } public WxQrCreateJson(String action_name, Long expire_seconds, WxQrActionInfoJson action_info) { super(); this.action_name = action_name; this.expire_seconds = expire_seconds; this.action_info = action_info; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/model/qr/WxQrSceneJson.java ================================================ /** * */ package org.hamster.weixinmp.model.qr; /** * @author honey.zhao@aliyun.com * @version Jan 4, 2014 * */ public class WxQrSceneJson { private Long scene_id; public Long getScene_id() { return scene_id; } public void setScene_id(Long scene_id) { this.scene_id = scene_id; } public WxQrSceneJson() { super(); // TODO Auto-generated constructor stub } public WxQrSceneJson(Long scene_id) { super(); this.scene_id = scene_id; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/model/send/SendImageJson.java ================================================ /** * */ package org.hamster.weixinmp.model.send; import org.hamster.weixinmp.model.send.item.SendItemImageJson; /** * @author honey.zhao@aliyun.com * @version Dec 30, 2013 * */ public class SendImageJson { private String touser; private String msgtype; private SendItemImageJson image; public String getTouser() { return touser; } public void setTouser(String touser) { this.touser = touser; } public String getMsgtype() { return msgtype; } public void setMsgtype(String msgtype) { this.msgtype = msgtype; } public SendItemImageJson getImage() { return image; } public void setImage(SendItemImageJson image) { this.image = image; } public SendImageJson() { super(); // TODO Auto-generated constructor stub } public SendImageJson(String touser, String msgtype, SendItemImageJson image) { super(); this.touser = touser; this.msgtype = msgtype; this.image = image; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/model/send/SendItemPicDescJson.java ================================================ /** * */ package org.hamster.weixinmp.model.send; import org.hamster.weixinmp.model.send.item.wrapper.WxSendItemArticleWrapper; /** * @author honey.zhao@aliyun.com * @version Dec 30, 2013 * */ public class SendItemPicDescJson { private String touser; private String msgtype; private WxSendItemArticleWrapper news; public String getTouser() { return touser; } public void setTouser(String touser) { this.touser = touser; } public String getMsgtype() { return msgtype; } public void setMsgtype(String msgtype) { this.msgtype = msgtype; } public WxSendItemArticleWrapper getNews() { return news; } public void setNews(WxSendItemArticleWrapper news) { this.news = news; } public SendItemPicDescJson(String touser, String msgtype, WxSendItemArticleWrapper news) { super(); this.touser = touser; this.msgtype = msgtype; this.news = news; } public SendItemPicDescJson() { super(); // TODO Auto-generated constructor stub } } ================================================ FILE: src/main/java/org/hamster/weixinmp/model/send/SendMusicJson.java ================================================ /** * */ package org.hamster.weixinmp.model.send; import org.hamster.weixinmp.model.send.item.SendItemMusicJson; /** * @author honey.zhao@aliyun.com * @version Dec 30, 2013 * */ public class SendMusicJson { private String touser; private String msgtype; private SendItemMusicJson music; public String getTouser() { return touser; } public void setTouser(String touser) { this.touser = touser; } public String getMsgtype() { return msgtype; } public void setMsgtype(String msgtype) { this.msgtype = msgtype; } public SendItemMusicJson getMusic() { return music; } public void setMusic(SendItemMusicJson music) { this.music = music; } public SendMusicJson() { super(); // TODO Auto-generated constructor stub } public SendMusicJson(String touser, String msgtype, SendItemMusicJson music) { super(); this.touser = touser; this.msgtype = msgtype; this.music = music; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/model/send/SendTextJson.java ================================================ /** * */ package org.hamster.weixinmp.model.send; import org.hamster.weixinmp.model.send.item.SendItemTextJson; /** * @author honey.zhao@aliyun.com * @version Dec 30, 2013 * */ public class SendTextJson { private String touser; private String msgtype; private SendItemTextJson content; public String getTouser() { return touser; } public void setTouser(String touser) { this.touser = touser; } public String getMsgtype() { return msgtype; } public void setMsgtype(String msgtype) { this.msgtype = msgtype; } public SendItemTextJson getContent() { return content; } public void setContent(SendItemTextJson content) { this.content = content; } public SendTextJson() { super(); // TODO Auto-generated constructor stub } public SendTextJson(String touser, String msgtype, SendItemTextJson content) { super(); this.touser = touser; this.msgtype = msgtype; this.content = content; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/model/send/SendVideoJson.java ================================================ /** * */ package org.hamster.weixinmp.model.send; import org.hamster.weixinmp.model.send.item.SendItemVoiceJson; /** * @author honey.zhao@aliyun.com * @version Dec 30, 2013 * */ public class SendVideoJson { private String touser; private String msgtype; private SendItemVoiceJson voice; public String getTouser() { return touser; } public void setTouser(String touser) { this.touser = touser; } public String getMsgtype() { return msgtype; } public void setMsgtype(String msgtype) { this.msgtype = msgtype; } public SendItemVoiceJson getVoice() { return voice; } public void setVoice(SendItemVoiceJson voice) { this.voice = voice; } public SendVideoJson() { super(); // TODO Auto-generated constructor stub } public SendVideoJson(String touser, String msgtype, SendItemVoiceJson voice) { super(); this.touser = touser; this.msgtype = msgtype; this.voice = voice; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/model/send/SendVoiceJson.java ================================================ /** * */ package org.hamster.weixinmp.model.send; import org.hamster.weixinmp.model.send.item.SendItemVideoJson; /** * @author honey.zhao@aliyun.com * @version Dec 30, 2013 * */ public class SendVoiceJson { private String touser; private String msgtype; private SendItemVideoJson video; public String getTouser() { return touser; } public void setTouser(String touser) { this.touser = touser; } public String getMsgtype() { return msgtype; } public void setMsgtype(String msgtype) { this.msgtype = msgtype; } public SendItemVideoJson getVideo() { return video; } public void setVideo(SendItemVideoJson video) { this.video = video; } public SendVoiceJson(String touser, String msgtype, SendItemVideoJson video) { super(); this.touser = touser; this.msgtype = msgtype; this.video = video; } public SendVoiceJson() { super(); // TODO Auto-generated constructor stub } } ================================================ FILE: src/main/java/org/hamster/weixinmp/model/send/item/SendItemArticleJson.java ================================================ /** * */ package org.hamster.weixinmp.model.send.item; /** * @author honey.zhao@aliyun.com * @version Dec 30, 2013 * */ public class SendItemArticleJson { private String title; private String description; private String url; private String picurl; public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public String getUrl() { return url; } public void setUrl(String url) { this.url = url; } public String getPicurl() { return picurl; } public void setPicurl(String picurl) { this.picurl = picurl; } public SendItemArticleJson() { super(); // TODO Auto-generated constructor stub } public SendItemArticleJson(String title, String description, String url, String picurl) { super(); this.title = title; this.description = description; this.url = url; this.picurl = picurl; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/model/send/item/SendItemImageJson.java ================================================ /** * */ package org.hamster.weixinmp.model.send.item; /** * @author honey.zhao@aliyun.com * @version Dec 30, 2013 * */ public class SendItemImageJson { private String mediaId; public String getMediaId() { return mediaId; } public void setMediaId(String mediaId) { this.mediaId = mediaId; } public SendItemImageJson() { super(); // TODO Auto-generated constructor stub } public SendItemImageJson(String mediaId) { super(); this.mediaId = mediaId; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/model/send/item/SendItemMusicJson.java ================================================ /** * */ package org.hamster.weixinmp.model.send.item; /** * @author honey.zhao@aliyun.com * @version Dec 30, 2013 * */ public class SendItemMusicJson { private String title; private String description; private String musicurl; private String hqmusicurl; private String thumb_media_id; public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public String getMusicurl() { return musicurl; } public void setMusicurl(String musicurl) { this.musicurl = musicurl; } public String getHqmusicurl() { return hqmusicurl; } public void setHqmusicurl(String hqmusicurl) { this.hqmusicurl = hqmusicurl; } public String getThumb_media_id() { return thumb_media_id; } public void setThumb_media_id(String thumb_media_id) { this.thumb_media_id = thumb_media_id; } public SendItemMusicJson() { super(); // TODO Auto-generated constructor stub } public SendItemMusicJson(String title, String description, String musicurl, String hqmusicurl, String thumb_media_id) { super(); this.title = title; this.description = description; this.musicurl = musicurl; this.hqmusicurl = hqmusicurl; this.thumb_media_id = thumb_media_id; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/model/send/item/SendItemTextJson.java ================================================ /** * */ package org.hamster.weixinmp.model.send.item; /** * @author honey.zhao@aliyun.com * @version Dec 30, 2013 * */ public class SendItemTextJson { private String text; public String getText() { return text; } public void setText(String text) { this.text = text; } public SendItemTextJson() { super(); // TODO Auto-generated constructor stub } public SendItemTextJson(String text) { super(); this.text = text; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/model/send/item/SendItemVideoJson.java ================================================ /** * */ package org.hamster.weixinmp.model.send.item; /** * @author honey.zhao@aliyun.com * @version Dec 30, 2013 * */ public class SendItemVideoJson { private String mediaId; private String title; private String description; public String getMediaId() { return mediaId; } public void setMediaId(String mediaId) { this.mediaId = mediaId; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public SendItemVideoJson() { super(); // TODO Auto-generated constructor stub } public SendItemVideoJson(String mediaId, String title, String description) { super(); this.mediaId = mediaId; this.title = title; this.description = description; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/model/send/item/SendItemVoiceJson.java ================================================ /** * */ package org.hamster.weixinmp.model.send.item; /** * @author honey.zhao@aliyun.com * @version Dec 30, 2013 * */ public class SendItemVoiceJson { private String mediaId; public String getMediaId() { return mediaId; } public void setMediaId(String mediaId) { this.mediaId = mediaId; } public SendItemVoiceJson() { super(); // TODO Auto-generated constructor stub } public SendItemVoiceJson(String mediaId) { super(); this.mediaId = mediaId; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/model/send/item/wrapper/WxSendItemArticleWrapper.java ================================================ /** * */ package org.hamster.weixinmp.model.send.item.wrapper; import java.util.List; import org.hamster.weixinmp.model.send.item.SendItemArticleJson; /** * @author honey.zhao@aliyun.com * @version Dec 30, 2013 * */ public class WxSendItemArticleWrapper { private List articles; public List getArticles() { return articles; } public void setArticles(List articles) { this.articles = articles; } public WxSendItemArticleWrapper() { super(); // TODO Auto-generated constructor stub } public WxSendItemArticleWrapper(List articles) { super(); this.articles = articles; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/model/user/WxOpenIdListJson.java ================================================ /** * */ package org.hamster.weixinmp.model.user; import java.util.List; /** * @author honey.zhao@aliyun.com * @version Jan 4, 2014 * */ public class WxOpenIdListJson { private List openid; public List getOpenid() { return openid; } public void setOpenid(List openid) { this.openid = openid; } public WxOpenIdListJson() { super(); // TODO Auto-generated constructor stub } public WxOpenIdListJson(List openid) { super(); this.openid = openid; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/model/user/WxUserGetJson.java ================================================ /** * */ package org.hamster.weixinmp.model.user; /** * {"total":2,"count":2,"data":{"openid":["","OPENID1","OPENID2"]},"next_openid":"NEXT_OPENID"} * * @author honey.zhao@aliyun.com * @version Jan 4, 2014 * */ public class WxUserGetJson { private Long total; private Long count; WxOpenIdListJson data; private String next_openid; public Long getTotal() { return total; } public void setTotal(Long total) { this.total = total; } public Long getCount() { return count; } public void setCount(Long count) { this.count = count; } public WxOpenIdListJson getData() { return data; } public void setData(WxOpenIdListJson data) { this.data = data; } public String getNext_openid() { return next_openid; } public void setNext_openid(String next_openid) { this.next_openid = next_openid; } public WxUserGetJson() { super(); // TODO Auto-generated constructor stub } public WxUserGetJson(Long total, Long count, WxOpenIdListJson data, String next_openid) { super(); this.total = total; this.count = count; this.data = data; this.next_openid = next_openid; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/service/WxAuthService.java ================================================ /** * */ package org.hamster.weixinmp.service; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.ArrayList; import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import org.hamster.weixinmp.config.WxConfig; import org.hamster.weixinmp.dao.entity.auth.WxAuth; import org.hamster.weixinmp.dao.entity.auth.WxAuthReq; import org.hamster.weixinmp.exception.WxException; import org.hamster.weixinmp.util.WxUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpMethod; import org.springframework.stereotype.Service; /** * @author honey.zhao@aliyun.com * @version Jan 1, 2014 * */ @Service public class WxAuthService { private static final Logger log = LoggerFactory.getLogger(WxAuthService.class); @Autowired protected WxConfig config; public WxAuth getAccessToken(String appid, String appsecret) throws WxException { Map paramsJson = new HashMap(); paramsJson.put("grant_type", "client_credential"); paramsJson.put("appid", appid); paramsJson.put("secret", appsecret); WxAuth result = WxUtil.sendRequest(config.getAccessTokenCreateUrl(), HttpMethod.GET, paramsJson, null, WxAuth.class); result.setGrantType("client_credential"); result.setAppid(appid); result.setSecret(appsecret); return result; } public boolean validateAuth(String signature, String timestamp, String nonce, String echostr) throws WxException { WxAuthReq authReq = new WxAuthReq(); authReq.setCreatedDate(new Date()); authReq.setSignature(signature); authReq.setTimestamp(timestamp); authReq.setNonce(nonce); authReq.setEchostr(echostr); String excepted = hash(getStringToHash(timestamp, nonce, config.getToken())); if (signature == null || !signature.equals(excepted)) { log.error("Authentication failed! excepted echostr ->" + excepted); log.error(" actual ->" + signature); return false; } return true; } protected static String getStringToHash(String timestamp, String nonce, String token) { List list = new ArrayList(); list.add(timestamp); list.add(nonce); list.add(token); String result = ""; Collections.sort(list); for (int i = 0; i < list.size(); i++) { System.out.println(list.get(i)); result += list.get(i); } return result; } protected static String hash(String str) { try { MessageDigest md = MessageDigest.getInstance("SHA-1"); byte[] b = md.digest(str.getBytes()); StringBuffer sb = new StringBuffer(); for (int i = 0; i < b.length; i++) { sb.append(Integer.toString((b[i] & 0xff) + 0x100, 16) .substring(1)); } return sb.toString(); } catch (NoSuchAlgorithmException e) { // never happens } return null; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/service/WxMediaService.java ================================================ /** * */ package org.hamster.weixinmp.service; import java.util.Date; import java.util.Map; import org.apache.http.entity.ContentType; import org.apache.http.entity.mime.MultipartEntityBuilder; import org.apache.http.entity.mime.content.ByteArrayBody; import org.apache.http.entity.mime.content.ContentBody; import org.hamster.weixinmp.config.WxConfig; import org.hamster.weixinmp.constant.WxMediaTypeEnum; import org.hamster.weixinmp.dao.entity.base.WxBaseItemMediaEntity; import org.hamster.weixinmp.dao.entity.item.WxItemImageEntity; import org.hamster.weixinmp.dao.entity.item.WxItemThumbEntity; import org.hamster.weixinmp.dao.entity.item.WxItemVideoEntity; import org.hamster.weixinmp.dao.entity.item.WxItemVoiceEntity; import org.hamster.weixinmp.exception.WxException; import org.hamster.weixinmp.util.WxUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpMethod; import org.springframework.stereotype.Service; /** * @author honey.zhao@aliyun.com * @version Jan 4, 2014 * */ @Service public class WxMediaService { @Autowired WxConfig config; public WxBaseItemMediaEntity remoteMediaUpload(String accessToken, WxMediaTypeEnum type, byte[] content) throws WxException { MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create(); String typeString = null; switch (type) { case IMAGE: case THUMB: case VIDEO: case VOICE: typeString = type.toString().toLowerCase(); break; case MUSIC: case DEFAULT: case PIC_DESC: throw new WxException("Not supported upload type : " + type.toString()); default: break; } Map params = WxUtil.getAccessTokenParams(accessToken); System.out.println(typeString); params.put("type", typeString); ContentBody contentBody = new ByteArrayBody(content, ContentType.MULTIPART_FORM_DATA, "name.jpg"); entityBuilder.addPart("media", contentBody); MediaResultMapper result = WxUtil.sendRequest( config.getMediaUploadUrl(), HttpMethod.POST, params, entityBuilder.build(), MediaResultMapper.class); WxBaseItemMediaEntity resultEntity = null; switch (type) { case IMAGE: WxItemImageEntity imageEntity = new WxItemImageEntity(); imageEntity.setMediaId(result.getMedia_id()); imageEntity.setCreatedDate(new Date(result.getCreated_at() * 1000)); resultEntity = imageEntity; break; case THUMB: WxItemThumbEntity thumbEntity = new WxItemThumbEntity(); thumbEntity.setMediaId(result.getMedia_id()); thumbEntity.setCreatedDate(new Date(result.getCreated_at() * 1000)); resultEntity = thumbEntity; break; case VIDEO: WxItemVideoEntity videoEntity = new WxItemVideoEntity(); videoEntity.setMediaId(result.getMedia_id()); videoEntity.setCreatedDate(new Date(result.getCreated_at() * 1000)); resultEntity = videoEntity; break; case VOICE: WxItemVoiceEntity voiceEntity = new WxItemVoiceEntity(); voiceEntity.setMediaId(result.getMedia_id()); voiceEntity.setCreatedDate(new Date(result.getCreated_at() * 1000)); resultEntity = voiceEntity; break; case MUSIC: case DEFAULT: case PIC_DESC: throw new WxException("Not supported upload type : " + type.toString()); default: break; } return resultEntity; } } class MediaResultMapper { private String type; private String media_id; private Long created_at; public String getType() { return type; } public void setType(String type) { this.type = type; } public String getMedia_id() { return media_id; } public void setMedia_id(String media_id) { this.media_id = media_id; } public Long getCreated_at() { return created_at; } public void setCreated_at(Long created_at) { this.created_at = created_at; } public MediaResultMapper() { super(); // TODO Auto-generated constructor stub } public MediaResultMapper(String type, String media_id, Long created_at) { super(); this.type = type; this.media_id = media_id; this.created_at = created_at; } @Override public String toString() { return "MediaResultMapper [type=" + type + ", media_id=" + media_id + ", created_at=" + created_at + "]"; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((created_at == null) ? 0 : created_at.hashCode()); result = prime * result + ((media_id == null) ? 0 : media_id.hashCode()); result = prime * result + ((type == null) ? 0 : type.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; MediaResultMapper other = (MediaResultMapper) obj; if (created_at == null) { if (other.created_at != null) return false; } else if (!created_at.equals(other.created_at)) return false; if (media_id == null) { if (other.media_id != null) return false; } else if (!media_id.equals(other.media_id)) return false; if (type == null) { if (other.type != null) return false; } else if (!type.equals(other.type)) return false; return true; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/service/WxMenuService.java ================================================ /** * */ package org.hamster.weixinmp.service; import static org.hamster.weixinmp.util.WxUtil.getAccessTokenParams; import static org.hamster.weixinmp.util.WxUtil.sendRequest; import java.io.UnsupportedEncodingException; import java.util.List; import java.util.Map; import org.apache.http.entity.StringEntity; import org.hamster.weixinmp.config.WxConfig; import org.hamster.weixinmp.dao.entity.menu.WxMenuBtnEntity; import org.hamster.weixinmp.dao.entity.user.WxUserEntity; import org.hamster.weixinmp.exception.WxException; import org.hamster.weixinmp.gson.WxMenuBtnSerializer; import org.hamster.weixinmp.model.WxRespCode; import org.hamster.weixinmp.model.menu.WxMenuCreateJson; import org.hamster.weixinmp.model.menu.WxMenuGetJson; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpMethod; import org.springframework.stereotype.Service; import com.google.gson.Gson; import com.google.gson.GsonBuilder; /** * @author honey.zhao@aliyun.com * @version Jan 4, 2014 * */ @Service public class WxMenuService { @Autowired WxConfig config; public WxRespCode menuCreate(String accessToken, List entities) throws WxException { Map params = getAccessTokenParams(accessToken); GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.registerTypeAdapter(WxUserEntity.class, new WxMenuBtnSerializer()); Gson gson = gsonBuilder.create(); WxMenuCreateJson wrapper = new WxMenuCreateJson(); wrapper.setButton(entities); try { return sendRequest(config.getMenuCreateUrl(), HttpMethod.POST, params, new StringEntity(gson.toJson(wrapper)), WxRespCode.class); } catch (UnsupportedEncodingException e) { throw new WxException(e); } } public List menuGet(String accessToken) throws WxException { Map params = getAccessTokenParams(accessToken); return sendRequest(config.getMenuGetUrl(), HttpMethod.GET, params, null, WxMenuGetJson.class).getMenu().getButton(); } public WxRespCode menuDelete(String accessToken) throws WxException { Map params = getAccessTokenParams(accessToken); return sendRequest(config.getMenuDeleteUrl(), HttpMethod.GET, params, null, WxRespCode.class); } } ================================================ FILE: src/main/java/org/hamster/weixinmp/service/WxMessageService.java ================================================ /** * */ package org.hamster.weixinmp.service; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import org.dom4j.DocumentException; import org.dom4j.DocumentHelper; import org.dom4j.Element; import org.hamster.weixinmp.constant.WxMsgRespType; import org.hamster.weixinmp.constant.WxMsgRespTypeEnum; import org.hamster.weixinmp.constant.WxMsgTypeEnum; import org.hamster.weixinmp.controller.util.WxXmlUtil; import org.hamster.weixinmp.dao.entity.base.WxBaseMsgEntity; import org.hamster.weixinmp.dao.entity.base.WxBaseRespEntity; import org.hamster.weixinmp.dao.entity.resp.WxRespImageEntity; import org.hamster.weixinmp.dao.entity.resp.WxRespMusicEntity; import org.hamster.weixinmp.dao.entity.resp.WxRespPicDescEntity; import org.hamster.weixinmp.dao.entity.resp.WxRespTextEntity; import org.hamster.weixinmp.dao.entity.resp.WxRespVideoEntity; import org.hamster.weixinmp.dao.entity.resp.WxRespVoiceEntity; import org.hamster.weixinmp.exception.WxException; import org.hamster.weixinmp.service.handler.WxMessageHandlerIfc; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; /** * @author honey.zhao@aliyun.com * @version Dec 30, 2013 * */ @Service public class WxMessageService { @Autowired(required=false) List handlers; public WxBaseMsgEntity parseXML(String xml) throws DocumentException, WxException { Element ele = DocumentHelper.parseText(xml).getRootElement(); String msgType = null; if ((msgType = ele.elementText("MsgType")) == null) { throw new WxException("cannot find MsgType Node!\n" + xml); } WxMsgTypeEnum msgTypeEnum = WxMsgTypeEnum.inst(msgType); switch (msgTypeEnum) { case EVENT: return WxXmlUtil.getMsgEvent(ele); case IMAGE: return WxXmlUtil.getMsgImage(ele); case LINK: return WxXmlUtil.getMsgLink(ele); case LOCATION: return WxXmlUtil.getMsgLoc(ele); case TEXT: return WxXmlUtil.getMsgText(ele); case VIDEO: return WxXmlUtil.getMsgVideo(ele); case VOICE: return WxXmlUtil.getMsgVoice(ele); default: // never happens break; } return null; } public WxBaseRespEntity handleMessage(WxBaseMsgEntity msg) { List handlerList = new ArrayList(); if(handlers!=null){ handlerList.addAll(handlers); } Collections.sort(handlerList, new WxMessageHandlerComparator()); Map context = new HashMap(); WxBaseRespEntity result = null; for (WxMessageHandlerIfc handler : handlerList) { result = handler.handle(msg, context); } if (result == null) { result = defaultResult(msg.getToUserName(), msg.getFromUserName()); } return result; } public Element parseRespXML(WxBaseRespEntity resp) throws DocumentException { WxMsgRespTypeEnum type = WxMsgRespTypeEnum.inst(resp.getMsgType()); switch (type) { case IMAGE: return WxXmlUtil.getRespImage((WxRespImageEntity) resp); case MUSIC: return WxXmlUtil.getRespMusic((WxRespMusicEntity) resp, ((WxRespMusicEntity) resp).getThumb()); case NEWS: return WxXmlUtil.getRespPicDesc((WxRespPicDescEntity) resp); case TEXT: return WxXmlUtil.getRespTextXML((WxRespTextEntity) resp); case VIDEO: return WxXmlUtil.getRespVideo((WxRespVideoEntity) resp); case VOICE: return WxXmlUtil.getRespVoice((WxRespVoiceEntity) resp); default: break; } return null; } protected WxRespTextEntity defaultResult(String fromUserName, String toUserName) { WxRespTextEntity result = new WxRespTextEntity(); result.setContent("您好,您的消息已收到."); result.setCreatedDate(new Date()); result.setCreateTime(new Date().getTime() / 1000); result.setFromUserName(fromUserName); result.setMsgType(WxMsgRespType.TEXT); result.setToUserName(toUserName); return result; } } class WxMessageHandlerComparator implements Comparator { /* (non-Javadoc) * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) */ public int compare(WxMessageHandlerIfc o1, WxMessageHandlerIfc o2) { if (o1.priority() > o2.priority()) { return -1; } else if (o1.priority() < o2.priority()) { return 1; } else { return 0; } } } ================================================ FILE: src/main/java/org/hamster/weixinmp/service/WxQrService.java ================================================ /** * */ package org.hamster.weixinmp.service; import static org.hamster.weixinmp.util.WxUtil.getAccessTokenParams; import static org.hamster.weixinmp.util.WxUtil.sendRequest; import static org.hamster.weixinmp.util.WxUtil.toJsonStringEntity; import java.util.Map; import org.hamster.weixinmp.config.WxConfig; import org.hamster.weixinmp.dao.entity.qr.WxQrEntity; import org.hamster.weixinmp.exception.WxException; import org.hamster.weixinmp.model.qr.WxQrActionInfoJson; import org.hamster.weixinmp.model.qr.WxQrCreateJson; import org.hamster.weixinmp.model.qr.WxQrSceneJson; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpMethod; import org.springframework.stereotype.Service; /** * @author honey.zhao@aliyun.com * @version Jan 4, 2014 * */ @Service public class WxQrService { @Autowired private WxConfig config; public WxQrEntity remoteQrcodeCreate(String accessToken, boolean isTemporary, Long sceneId, Long expire_seconds) throws WxException { Map params = getAccessTokenParams(accessToken); WxQrSceneJson scene = new WxQrSceneJson(); scene.setScene_id(sceneId); WxQrActionInfoJson action = new WxQrActionInfoJson(); action.setScene(scene); WxQrCreateJson requestJson = new WxQrCreateJson(); requestJson.setAction_name(isTemporary ? "QR_LIMIT_SCENE" : "QR_SCENE"); requestJson.setAction_info(action); if (isTemporary) { requestJson.setExpire_seconds(expire_seconds); } WxQrEntity result = sendRequest(config.getQrcodeCreateUrl(), HttpMethod.POST, params, toJsonStringEntity(requestJson), WxQrEntity.class); result.setScene(sceneId); return result; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/service/WxStorageService.java ================================================ /** * */ package org.hamster.weixinmp.service; import java.util.Date; import java.util.List; import org.apache.log4j.Logger; import org.dom4j.DocumentException; import org.dom4j.Element; import org.hamster.weixinmp.config.WxConfig; import org.hamster.weixinmp.constant.WxMsgRespType; import org.hamster.weixinmp.controller.util.WxXmlUtil; import org.hamster.weixinmp.dao.entity.base.WxBaseMsgEntity; import org.hamster.weixinmp.dao.entity.base.WxBaseRespEntity; import org.hamster.weixinmp.dao.entity.item.WxItemMusicEntity; import org.hamster.weixinmp.dao.entity.item.WxItemPicDescEntity; import org.hamster.weixinmp.dao.entity.msg.WxMsgEventEntity; import org.hamster.weixinmp.dao.entity.msg.WxMsgImageEntity; import org.hamster.weixinmp.dao.entity.msg.WxMsgLinkEntity; import org.hamster.weixinmp.dao.entity.msg.WxMsgLocEntity; import org.hamster.weixinmp.dao.entity.msg.WxMsgTextEntity; import org.hamster.weixinmp.dao.entity.resp.WxRespMusicEntity; import org.hamster.weixinmp.dao.entity.resp.WxRespPicDescEntity; import org.hamster.weixinmp.dao.entity.resp.WxRespTextEntity; import org.hamster.weixinmp.dao.repository.auth.WxAuthDao; import org.hamster.weixinmp.dao.repository.auth.WxAuthReqDao; import org.hamster.weixinmp.dao.repository.item.WxItemImageDao; import org.hamster.weixinmp.dao.repository.item.WxItemMusicDao; import org.hamster.weixinmp.dao.repository.item.WxItemPicDescDao; import org.hamster.weixinmp.dao.repository.item.WxItemThumbDao; import org.hamster.weixinmp.dao.repository.item.WxItemVideoDao; import org.hamster.weixinmp.dao.repository.item.WxItemVoiceDao; import org.hamster.weixinmp.dao.repository.menu.WxMenuBtnDao; import org.hamster.weixinmp.dao.repository.msg.WxMsgEventDao; import org.hamster.weixinmp.dao.repository.msg.WxMsgImageDao; import org.hamster.weixinmp.dao.repository.msg.WxMsgLinkDao; import org.hamster.weixinmp.dao.repository.msg.WxMsgLocDao; import org.hamster.weixinmp.dao.repository.msg.WxMsgTextDao; import org.hamster.weixinmp.dao.repository.msg.WxMsgVideoDao; import org.hamster.weixinmp.dao.repository.msg.WxMsgVoiceDao; import org.hamster.weixinmp.dao.repository.resp.WxRespImageDao; import org.hamster.weixinmp.dao.repository.resp.WxRespMusicDao; import org.hamster.weixinmp.dao.repository.resp.WxRespPicDescDao; import org.hamster.weixinmp.dao.repository.resp.WxRespTextDao; import org.hamster.weixinmp.dao.repository.resp.WxRespVideoDao; import org.hamster.weixinmp.dao.repository.resp.WxRespVoiceDao; import org.hamster.weixinmp.dao.repository.user.WxGroupDao; import org.hamster.weixinmp.dao.repository.user.WxUserDao; import org.hamster.weixinmp.util.WxUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; /** * @author honey.zhao@aliyun.com * @version Jul 28, 2013 * */ @Service @Transactional(readOnly = true) public class WxStorageService { public static final Logger log = Logger.getLogger(WxStorageService.class); @Autowired(required = false) protected WxAuthDao authDao; @Autowired(required = false) protected WxAuthReqDao authReqDao; @Autowired(required = false) protected WxMsgTextDao msgTextDao; @Autowired(required = false) protected WxMsgImageDao msgImgDao; @Autowired(required = false) protected WxMsgLinkDao msgLinkDao; @Autowired(required = false) protected WxMsgLocDao msgLocDao; @Autowired(required = false) protected WxMsgEventDao msgEventDao; @Autowired(required = false) protected WxMsgVideoDao msgVideoDao; @Autowired(required = false) protected WxMsgVoiceDao msgVoiceDao; @Autowired(required = false) protected WxRespTextDao respTextDao; @Autowired(required = false) protected WxRespPicDescDao respPicDescDao; @Autowired(required = false) protected WxRespMusicDao respMusicDao; @Autowired(required = false) protected WxRespImageDao respImageDao; @Autowired(required = false) protected WxRespVideoDao respVideoDao; @Autowired(required = false) protected WxRespVoiceDao respVoiceDao; @Autowired(required = false) protected WxItemImageDao itemImageDao; @Autowired(required = false) protected WxItemMusicDao itemMusicDao; @Autowired(required = false) protected WxItemPicDescDao wxItemPicDescDao; @Autowired(required = false) protected WxItemThumbDao itemThumbDao; @Autowired(required = false) protected WxItemVideoDao itemVideoDao; @Autowired(required = false) protected WxItemVoiceDao itemVoiceDao; @Autowired(required = false) protected WxMenuBtnDao wxMenuBtnDao; @Autowired(required = false) protected WxGroupDao groupDao; @Autowired(required = false) protected WxUserDao userDao; protected String token; @Autowired(required = false) protected WxConfig wxConfig; public WxMsgTextEntity saveMsgText(Element ele) throws DocumentException { WxMsgTextEntity msgText = WxXmlUtil.getMsgText(ele); if (msgTextDao != null) { msgTextDao.save(msgText); } else { } return msgText; } public WxMsgImageEntity saveMsgImg(Element ele) throws DocumentException { WxMsgImageEntity msgImg = WxXmlUtil.getMsgImage(ele); if (msgImgDao != null) { msgImgDao.save(msgImg); } else { } return msgImg; } public WxMsgLinkEntity saveMsgLink(Element ele) throws DocumentException { WxMsgLinkEntity msgLink = WxXmlUtil.getMsgLink(ele); if (msgLinkDao != null) { msgLinkDao.save(msgLink); } else { } return msgLink; } public WxMsgLocEntity saveMsgLoc(Element ele) throws DocumentException { WxMsgLocEntity msgLoc = WxXmlUtil.getMsgLoc(ele); if (msgLocDao != null) { msgLocDao.save(msgLoc); } else { } return msgLoc; } public WxMsgEventEntity saveMsgEvent(Element ele) throws DocumentException { WxMsgEventEntity msgEvent = WxXmlUtil.getMsgEvent(ele); if (msgEventDao != null) { msgEventDao.save(msgEvent); } else { } return msgEvent; } public WxRespTextEntity createRespText(String content, String fromUserName, String toUserName, Integer funcFlag) { WxRespTextEntity respText = new WxRespTextEntity(); respText.setContent(content); respText.setCreatedDate(new Date()); respText.setCreateTime(WxUtil.currentTimeInSec()); respText.setFromUserName(fromUserName); respText.setToUserName(toUserName); respText.setFuncFlag(funcFlag); respText.setMsgType(WxMsgRespType.TEXT); if (respTextDao != null) { respTextDao.save(respText); } else { } return respText; } public WxRespPicDescEntity createRespPicDesc( List articles, String fromUserName, String toUserName, Integer funcFlag) { WxRespPicDescEntity respPicDesc = new WxRespPicDescEntity(); respPicDesc.setCreatedDate(new Date()); respPicDesc.setCreateTime(WxUtil.currentTimeInSec()); respPicDesc.setFromUserName(fromUserName); respPicDesc.setToUserName(toUserName); respPicDesc.setFuncFlag(funcFlag); respPicDesc.setMsgType(WxMsgRespType.NEWS); respPicDesc.setArticles(articles); if (respPicDescDao != null) { respPicDescDao.save(respPicDesc); } else { } return respPicDesc; } public WxRespPicDescEntity createRespPicDesc2(List articleIds, String fromUserName, String toUserName, Integer funcFlag) { WxRespPicDescEntity respPicDesc = new WxRespPicDescEntity(); respPicDesc.setCreatedDate(new Date()); respPicDesc.setCreateTime(WxUtil.currentTimeInSec()); respPicDesc.setFromUserName(fromUserName); respPicDesc.setToUserName(toUserName); respPicDesc.setFuncFlag(funcFlag); respPicDesc.setMsgType(WxMsgRespType.NEWS); respPicDesc.setArticles(wxItemPicDescDao.findByIdIn(articleIds)); if (respPicDescDao != null) { respPicDescDao.save(respPicDesc); } else { } return respPicDesc; } public WxRespMusicEntity createRespMusic(String fromUserName, String toUserName, Integer funcFlag, WxItemMusicEntity itemMusic) { WxRespMusicEntity respMusic = new WxRespMusicEntity(); respMusic.setCreatedDate(new Date()); respMusic.setCreateTime(WxUtil.currentTimeInSec()); respMusic.setFromUserName(fromUserName); respMusic.setToUserName(toUserName); respMusic.setFuncFlag(funcFlag); respMusic.setMsgType(WxMsgRespType.MUSIC); // respMusic.setMusic(itemMusic); if (respMusicDao != null) { respMusicDao.save(respMusic); } else { } return respMusic; } // /////////////// // common parts // // /////////////// public WxBaseRespEntity handleMessage(WxBaseMsgEntity msg) { WxRespTextEntity respText = createRespText( "Only test message, please ignore this.", msg.getToUserName(), msg.getFromUserName(), 1); return respText; } public WxAuthDao getAuthDao() { return authDao; } public void setAuthDao(WxAuthDao authDao) { this.authDao = authDao; } public WxAuthReqDao getAuthReqDao() { return authReqDao; } public void setAuthReqDao(WxAuthReqDao authReqDao) { this.authReqDao = authReqDao; } public WxMsgTextDao getMsgTextDao() { return msgTextDao; } public void setMsgTextDao(WxMsgTextDao msgTextDao) { this.msgTextDao = msgTextDao; } public WxMsgImageDao getMsgImgDao() { return msgImgDao; } public void setMsgImgDao(WxMsgImageDao msgImgDao) { this.msgImgDao = msgImgDao; } public WxMsgLinkDao getMsgLinkDao() { return msgLinkDao; } public void setMsgLinkDao(WxMsgLinkDao msgLinkDao) { this.msgLinkDao = msgLinkDao; } public WxMsgLocDao getMsgLocDao() { return msgLocDao; } public void setMsgLocDao(WxMsgLocDao msgLocDao) { this.msgLocDao = msgLocDao; } public WxMsgEventDao getMsgEventDao() { return msgEventDao; } public void setMsgEventDao(WxMsgEventDao msgEventDao) { this.msgEventDao = msgEventDao; } public WxMsgVideoDao getMsgVideoDao() { return msgVideoDao; } public void setMsgVideoDao(WxMsgVideoDao msgVideoDao) { this.msgVideoDao = msgVideoDao; } public WxMsgVoiceDao getMsgVoiceDao() { return msgVoiceDao; } public void setMsgVoiceDao(WxMsgVoiceDao msgVoiceDao) { this.msgVoiceDao = msgVoiceDao; } public WxRespTextDao getRespTextDao() { return respTextDao; } public void setRespTextDao(WxRespTextDao respTextDao) { this.respTextDao = respTextDao; } public WxRespPicDescDao getRespPicDescDao() { return respPicDescDao; } public void setRespPicDescDao(WxRespPicDescDao respPicDescDao) { this.respPicDescDao = respPicDescDao; } public WxRespMusicDao getRespMusicDao() { return respMusicDao; } public void setRespMusicDao(WxRespMusicDao respMusicDao) { this.respMusicDao = respMusicDao; } public WxRespImageDao getRespImageDao() { return respImageDao; } public void setRespImageDao(WxRespImageDao respImageDao) { this.respImageDao = respImageDao; } public WxRespVideoDao getRespVideoDao() { return respVideoDao; } public void setRespVideoDao(WxRespVideoDao respVideoDao) { this.respVideoDao = respVideoDao; } public WxRespVoiceDao getRespVoiceDao() { return respVoiceDao; } public void setRespVoiceDao(WxRespVoiceDao respVoiceDao) { this.respVoiceDao = respVoiceDao; } public WxItemImageDao getItemImageDao() { return itemImageDao; } public void setItemImageDao(WxItemImageDao itemImageDao) { this.itemImageDao = itemImageDao; } public WxItemMusicDao getItemMusicDao() { return itemMusicDao; } public void setItemMusicDao(WxItemMusicDao itemMusicDao) { this.itemMusicDao = itemMusicDao; } public WxItemPicDescDao getWxItemPicDescDao() { return wxItemPicDescDao; } public void setWxItemPicDescDao(WxItemPicDescDao wxItemPicDescDao) { this.wxItemPicDescDao = wxItemPicDescDao; } public WxItemThumbDao getItemThumbDao() { return itemThumbDao; } public void setItemThumbDao(WxItemThumbDao itemThumbDao) { this.itemThumbDao = itemThumbDao; } public WxItemVideoDao getItemVideoDao() { return itemVideoDao; } public void setItemVideoDao(WxItemVideoDao itemVideoDao) { this.itemVideoDao = itemVideoDao; } public WxItemVoiceDao getItemVoiceDao() { return itemVoiceDao; } public void setItemVoiceDao(WxItemVoiceDao itemVoiceDao) { this.itemVoiceDao = itemVoiceDao; } public WxMenuBtnDao getWxMenuBtnDao() { return wxMenuBtnDao; } public void setWxMenuBtnDao(WxMenuBtnDao wxMenuBtnDao) { this.wxMenuBtnDao = wxMenuBtnDao; } public WxGroupDao getGroupDao() { return groupDao; } public void setGroupDao(WxGroupDao groupDao) { this.groupDao = groupDao; } public WxUserDao getUserDao() { return userDao; } public void setUserDao(WxUserDao userDao) { this.userDao = userDao; } public String getToken() { return token; } public void setToken(String token) { this.token = token; } public WxConfig getWxConfig() { return wxConfig; } public void setWxConfig(WxConfig wxConfig) { this.wxConfig = wxConfig; } public static Logger getLog() { return log; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/service/WxUserGroupService.java ================================================ /** * */ package org.hamster.weixinmp.service; import static org.hamster.weixinmp.util.WxUtil.getAccessTokenParams; import static org.hamster.weixinmp.util.WxUtil.sendRequest; import static org.hamster.weixinmp.util.WxUtil.toJsonStringEntity; import java.util.HashMap; import java.util.List; import java.util.Map; import org.hamster.weixinmp.config.WxConfig; import org.hamster.weixinmp.dao.entity.user.WxGroupEntity; import org.hamster.weixinmp.exception.WxException; import org.hamster.weixinmp.model.WxRespCode; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpMethod; import org.springframework.stereotype.Service; /** * @author honey.zhao@aliyun.com * @version Jan 1, 2014 * */ @Service public class WxUserGroupService { @Autowired private WxConfig config; /** * http请求方式: POST(请使用https协议)
* https://api.weixin.qq.com/cgi-bin/groups/create?access_token=ACCESS_TOKEN
* POST数据格式:json
* POST数据例子:{"group":{"name":"test"}}
* * { "group": { "id": 107, "name": "test" } }
* * @param groupName * @return * @throws WxException */ public WxGroupEntity remoteGroupsCreate(String accessToken, String groupName) throws WxException { Map requestJson = new HashMap(); Map l1Json = new HashMap(); l1Json.put("name", groupName); requestJson.put("group", l1Json); ResultMapper result = sendRequest(config.getGroupsCreateUrl(), HttpMethod.POST, getAccessTokenParams(accessToken), toJsonStringEntity(requestJson), ResultMapper.class); return result.getGroup(); } /** * http请求方式: GET(请使用https协议)
* https://api.weixin.qq.com/cgi-bin/groups/get?access_token=ACCESS_TOKEN
* * { "groups": [ { "id": 0, "name": "未分组", "count": 72596 }, { "id": 1, * "name": "黑名单", "count": 36 }, { "id": 2, "name": "星标组", "count": 8 }, { * "id": 104, "name": "华东媒", "count": 4 }, { "id": 106, "name": "★不测试组★", * "count": 1 } ] }
* * @return * @throws WxException */ public List remoteGroupsGet(String accessToken) throws WxException { return sendRequest(config.getGroupsGetUrl(), HttpMethod.GET, getAccessTokenParams(accessToken), null, ResultMapper.class) .getGroups(); } /** * http请求方式: POST(请使用https协议)
* https://api.weixin.qq.com/cgi-bin/groups/getid?access_token=ACCESS_TOKEN
* POST数据格式:json POST数据例子:{"openid":"od8XIjsmk6QdVTETa9jLtGWA6KBc"}
* {"groupid": 102 }
* * @param openId * @return * @throws WxException */ public Long remoteGroupsGetId(String accessToken, String openId) throws WxException { Map requestJson = new HashMap(); requestJson.put("openid", openId); return sendRequest(config.getGroupsGetIdUrl(), HttpMethod.POST, getAccessTokenParams(accessToken), toJsonStringEntity(requestJson), ResultMapper.class).getGroupid(); } /** * http请求方式: POST(请使用https协议)
* https://api.weixin.qq.com/cgi-bin/groups/update?access_token=ACCESS_TOKEN
* POST数据格式:json
* POST数据例子:{"group":{"id":108,"name":"test2_modify2"}}
* * {"errcode": 0, "errmsg": "ok"}
* * @param id * @param name * @return * @throws WxException */ public WxRespCode remoteGroupsUpdate(String accessToken, Long id, String name) throws WxException { Map requestJson = new HashMap(); Map l1Json = new HashMap(); l1Json.put("id", id); l1Json.put("name", name); requestJson.put("group", l1Json); return sendRequest(config.getGroupsUpdateUrl(), HttpMethod.POST, getAccessTokenParams(accessToken), toJsonStringEntity(requestJson), WxRespCode.class); } /** * http请求方式: POST(请使用https协议)
* https://api.weixin.qq.com/cgi-bin/groups/members/update?access_token= * ACCESS_TOKEN
* POST数据格式:json
* POST数据例子:{"openid":"oDF3iYx0ro3_7jD4HFRDfrjdCM58","to_groupid":108}
* {"errcode": 0, "errmsg": "ok"}
* * @param openid * @param to_groupid * @return * @throws WxException */ public WxRespCode remoteGroupsMembersUpdate(String accessToken, String openid, Long to_groupid) throws WxException { Map requestJson = new HashMap(); requestJson.put("openid", openid); requestJson.put("to_groupid", to_groupid); return sendRequest(config.getGroupsMembersUpdateUrl(), HttpMethod.POST, getAccessTokenParams(accessToken), toJsonStringEntity(requestJson), WxRespCode.class); } } final class ResultMapper { private WxGroupEntity group; private List groups; private Long groupid; public WxGroupEntity getGroup() { return group; } public void setGroup(WxGroupEntity group) { this.group = group; } public List getGroups() { return groups; } public void setGroups(List groups) { this.groups = groups; } public Long getGroupid() { return groupid; } public void setGroupid(Long groupid) { this.groupid = groupid; } public ResultMapper() { super(); // TODO Auto-generated constructor stub } public ResultMapper(WxGroupEntity group, List groups, Long groupid) { super(); this.group = group; this.groups = groups; this.groupid = groupid; } @Override public String toString() { return "ResultMapper [group=" + group + ", groups=" + groups + ", groupid=" + groupid + "]"; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((group == null) ? 0 : group.hashCode()); result = prime * result + ((groupid == null) ? 0 : groupid.hashCode()); result = prime * result + ((groups == null) ? 0 : groups.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; ResultMapper other = (ResultMapper) obj; if (group == null) { if (other.group != null) return false; } else if (!group.equals(other.group)) return false; if (groupid == null) { if (other.groupid != null) return false; } else if (!groupid.equals(other.groupid)) return false; if (groups == null) { if (other.groups != null) return false; } else if (!groups.equals(other.groups)) return false; return true; } } ================================================ FILE: src/main/java/org/hamster/weixinmp/service/WxUserService.java ================================================ /** * */ package org.hamster.weixinmp.service; import static org.hamster.weixinmp.util.WxUtil.getAccessTokenParams; import static org.hamster.weixinmp.util.WxUtil.sendRequest; import java.util.Map; import org.apache.commons.lang3.StringUtils; import org.hamster.weixinmp.config.WxConfig; import org.hamster.weixinmp.dao.entity.user.WxUserEntity; import org.hamster.weixinmp.exception.WxException; import org.hamster.weixinmp.model.user.WxUserGetJson; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpMethod; import org.springframework.stereotype.Service; /** * @author honey.zhao@aliyun.com * @version Dec 31, 2013 * */ @Service public class WxUserService { @Autowired private WxConfig config; public WxUserEntity remoteUserInfo(String accessToken, String openId) throws WxException { Map params = getAccessTokenParams(accessToken); params.put("openid", openId); return sendRequest(config.getUserInfoUrl(), HttpMethod.GET, params, null, WxUserEntity.class); } public WxUserGetJson remoteUserGet(String accessToken, String nextOpenId) throws WxException { Map params = getAccessTokenParams(accessToken); if (!StringUtils.isBlank(nextOpenId)) { params.put("next_openid", nextOpenId); } return sendRequest(config.getUserGetUrl(), HttpMethod.GET, params, null, WxUserGetJson.class); } public WxUserGetJson remoteUserGet(String accessToken) throws WxException { return remoteUserGet(accessToken, ""); } } ================================================ FILE: src/main/java/org/hamster/weixinmp/service/handler/WxMessageHandlerIfc.java ================================================ /** * */ package org.hamster.weixinmp.service.handler; import java.util.Map; import org.hamster.weixinmp.constant.WxMsgTypeEnum; import org.hamster.weixinmp.dao.entity.base.WxBaseMsgEntity; import org.hamster.weixinmp.dao.entity.base.WxBaseRespEntity; /** * @author honey.zhao@aliyun.com * @version Jan 5, 2014 * */ public interface WxMessageHandlerIfc { WxMsgTypeEnum[] listIntetestedMessageType(); WxBaseRespEntity handle(WxBaseMsgEntity msg, Map context); Integer priority(); } ================================================ FILE: src/main/java/org/hamster/weixinmp/util/WxUtil.java ================================================ /** * */ package org.hamster.weixinmp.util; import java.io.IOException; import java.net.URISyntaxException; import java.util.Date; import java.util.HashMap; import java.util.Map; import org.apache.http.Consts; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpRequestBase; import org.apache.http.client.utils.URIBuilder; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.util.EntityUtils; import org.hamster.weixinmp.dao.entity.base.WxBaseEntity; import org.hamster.weixinmp.exception.WxException; import org.hamster.weixinmp.model.WxRespCode; import org.springframework.http.HttpMethod; import com.google.gson.Gson; /** * @author honey.zhao@aliyun.com * @version Jul 28, 2013 * */ public class WxUtil { private WxUtil() { } public static final Long currentTimeInSec() { return Long.valueOf(new Date().getTime() / 1000); } @SuppressWarnings("unchecked") public static final T sendRequest(String url, HttpMethod method, Map params, HttpEntity requestEntity, Class resultClass) throws WxException { HttpClient client = HttpClientBuilder.create().build(); HttpRequestBase request = null; try { if (HttpMethod.GET.equals(method)) { request = new HttpGet(); } else if (HttpMethod.POST.equals(method)) { request = new HttpPost(); if (requestEntity != null) { ((HttpPost) request).setEntity(requestEntity); } } URIBuilder builder = new URIBuilder(url); if (params != null) { for (Map.Entry entry : params.entrySet()) { builder.addParameter(entry.getKey(), entry.getValue()); } } request.setURI(builder.build()); HttpResponse response = client.execute(request); HttpEntity entity = response.getEntity(); String respBody = EntityUtils.toString(entity); if (entity != null) { EntityUtils.consume(entity); } if (String.class.isAssignableFrom(resultClass)) { return (T) respBody; } else { Gson gson = new Gson(); if (respBody.indexOf("{\"errcode\"") == 0 || respBody.indexOf("{\"errmsg\"") == 0) { WxRespCode exJson = gson.fromJson(respBody, WxRespCode.class); if (WxRespCode.class.getName().equals( resultClass.getName()) && exJson.getErrcode() == 0) { return (T) exJson; } else { throw new WxException(exJson); } } T result = gson.fromJson(respBody, resultClass); if (result instanceof WxBaseEntity) { ((WxBaseEntity) result).setCreatedDate(new Date()); } return result; } } catch (IOException e) { throw new WxException(e); } catch (URISyntaxException e) { throw new WxException(e); } } public static StringEntity toJsonStringEntity(Object obj) { Gson gson = new Gson(); return new StringEntity(gson.toJson(obj), Consts.UTF_8); } public static Map getAccessTokenParams(String accessToken) { Map result = new HashMap(); result.put("access_token", accessToken); return result; } public static String getParameterizedUrl(String url, String... args) { String result = url; for (int i = 0; i < args.length; i += 2) { String p = args[i]; String v = args[i + 1]; result = result.replaceAll(p, v); } return result; } } ================================================ FILE: src/main/resources/applicationContext-weixinmp.xml ================================================ WX Service Configration ================================================ FILE: src/main/resources/wx.properties ================================================ #(optional)override jdbc url for local development jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc\:mysql\://localhost\:3306/XXXXXX?useUnicode\=true&characterEncoding\=UTF-8 jdbc.username= jdbc.password= wx_token= wx_appid= wx_appsecret= wx_menu_create_url=https://api.weixin.qq.com/cgi-bin/menu/create wx_menu_get_url=https://api.weixin.qq.com/cgi-bin/menu/get #?access_token=ACCESS_TOKEN wx_menu_delete_url=https://api.weixin.qq.com/cgi-bin/menu/delete #?access_token=ACCESS_TOKEN wx_media_upload_url=http://file.api.weixin.qq.com/cgi-bin/media/upload #?access_token=ACCESS_TOKEN&type=TYPE wx_qrcode_create_url=https://api.weixin.qq.com/cgi-bin/qrcode/create #?access_token=TOKEN wx_showqrcode_url=https://mp.weixin.qq.com/cgi-bin/showqrcode #?ticket=TICKET wx_user_info_url=https://api.weixin.qq.com/cgi-bin/user/info #?access_token=ACCESS_TOKEN&openid=OPENID wx_user_get_url=https://api.weixin.qq.com/cgi-bin/user/get #?access_token=ACCESS_TOKEN&next_openid=NEXT_OPENID wx_access_token_create_url=https://api.weixin.qq.com/cgi-bin/token #?grant_type=client_credential&appid=APPID&secret=APPSECRET wx_custom_send_url=https://api.weixin.qq.com/cgi-bin/message/custom/send #?access_token=ACCESS_TOKEN wx_groups_create_url=https://api.weixin.qq.com/cgi-bin/groups/create #?access_token=ACCESS_TOKEN wx_groups_get_url=https://api.weixin.qq.com/cgi-bin/groups/get #?access_token=ACCESS_TOKEN wx_groups_getid_url=https://api.weixin.qq.com/cgi-bin/groups/getid #?access_token=ACCESS_TOKEN wx_groups_update_url=https://api.weixin.qq.com/cgi-bin/groups/update #?access_token=ACCESS_TOKEN wx_groups_members_update_url=https://api.weixin.qq.com/cgi-bin/groups/members/update #?access_token=ACCESS_TOKEN ================================================ FILE: src/main/webapp/META-INF/MANIFEST.MF ================================================ Manifest-Version: 1.0 Class-Path: ================================================ FILE: src/main/webapp/MyHtml.html ================================================ MyHtml.html This is my HTML page.
================================================ FILE: src/main/webapp/WEB-INF/classes/weixin/popular/example/pay_example.jsp.jsp ================================================ <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> pay js example ================================================ FILE: src/main/webapp/WEB-INF/web.xml ================================================ org.springframework.web.context.ContextLoaderListener contextConfigLocation classpath*:applicationContext*.xml 30 springmvc org.springframework.web.servlet.DispatcherServlet contextConfigLocation classpath*:applicationContext*.xml 1 springmvc /* encodingFilter org.springframework.web.filter.CharacterEncodingFilter encoding UTF-8 forceEncoding true encodingFilter /* /default/index.html ================================================ FILE: src/main/webapp/default/index.html ================================================ MyHtml.html This is my HTML page.
================================================ FILE: src/main/webapp/index.jsp ================================================

Hello World!

================================================ FILE: src/test/java/org/hamster/weixinmp/test/base/AbstractServiceTest.java ================================================ package org.hamster.weixinmp.test.base; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; /** * @author honey.zhao@aliyun.com * @version Mar 8, 2013 3:51:14 PM Change set */ @ContextConfiguration(locations = { "file:src/test/resources/applicationContext-test-weixinmp.xml"}) public abstract class AbstractServiceTest extends AbstractJUnit4SpringContextTests { } ================================================ FILE: src/test/java/org/hamster/weixinmp/test/base/AbstractWxServiceTest.java ================================================ /** * */ package org.hamster.weixinmp.test.base; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.Date; import org.apache.commons.lang3.StringUtils; import org.hamster.weixinmp.config.WxConfig; import org.hamster.weixinmp.dao.entity.auth.WxAuth; import org.hamster.weixinmp.exception.WxException; import org.hamster.weixinmp.service.WxAuthService; import org.junit.Before; import org.springframework.beans.factory.annotation.Autowired; /** * @author honey.zhao@aliyun.com * @version Jan 5, 2014 * */ public abstract class AbstractWxServiceTest extends AbstractServiceTest { public static final String TEST_FOLDER = "src/test/resources/tmp"; public static final String ACCESS_TOKEN_FILE = TEST_FOLDER + "/accessToken.txt"; protected String accessToken; @Autowired WxConfig config; @Autowired WxAuthService authService; @Before public void setUp() throws WxException, IOException { if (StringUtils.isBlank(accessToken)) { File testConfigFile = new File(ACCESS_TOKEN_FILE); Date currentDate = new Date(); if (!testConfigFile.exists() || currentDate.getTime() - testConfigFile.lastModified() > 86400000) { WxAuth auth = authService.getAccessToken(config.getAppid(), config.getAppsecret()); this.accessToken = auth.getAccessToken(); new File(TEST_FOLDER).mkdirs(); FileWriter writer = new FileWriter(ACCESS_TOKEN_FILE); writer.write(accessToken); writer.flush(); writer.close(); } else { BufferedReader reader = new BufferedReader(new FileReader(ACCESS_TOKEN_FILE)); this.accessToken = reader.readLine(); reader.close(); } } } } ================================================ FILE: src/test/java/org/hamster/weixinmp/test/controller/WxControllerManualTest.java ================================================ /** * */ package org.hamster.weixinmp.test.controller; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.List; import org.apache.commons.io.IOUtils; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.message.BasicNameValuePair; import org.hamster.weixinmp.test.xml.WxXMLUtilTest; import org.junit.Ignore; import org.junit.Test; /** * @author honey.zhao@aliyun.com * @version Jul 30, 2013 */ public class WxControllerManualTest { public static final String WX_URL = "http://localhost:8080/rest/weixinmp"; @Test @Ignore public void testPostMsgText() throws ClientProtocolException, IOException { HttpClient httpclient = HttpClientBuilder.create().build(); HttpPost httppost = new HttpPost(WX_URL); // Request parameters and other properties. List params = new ArrayList(2); params.add(new BasicNameValuePair("signature", "38f004a5f222473f3abd85fd8e4b1de2349119c6")); params.add(new BasicNameValuePair("timestamp", "1375192987")); params.add(new BasicNameValuePair("nonce", "1374785014")); httppost.setEntity(new StringEntity(WxXMLUtilTest.MSG_TEXT_XML)); //Execute and get the response. HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); if (entity != null) { InputStream instream = entity.getContent(); try { String result = IOUtils.toString(instream); System.out.println(result); } finally { instream.close(); } } } public static final void main(String[] args) { try { new WxControllerManualTest().testPostMsgText(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } ================================================ FILE: src/test/java/org/hamster/weixinmp/test/service/WxGroupServceTest.java ================================================ /** * */ package org.hamster.weixinmp.test.service; import java.util.List; import org.hamster.weixinmp.dao.entity.user.WxGroupEntity; import org.hamster.weixinmp.exception.WxException; import org.hamster.weixinmp.service.WxAuthService; import org.hamster.weixinmp.service.WxUserGroupService; import org.hamster.weixinmp.test.base.AbstractWxServiceTest; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; /** * @author honey.zhao@aliyun.com * @version Jan 1, 2014 * */ public class WxGroupServceTest extends AbstractWxServiceTest { @Autowired WxAuthService authService; @Autowired WxUserGroupService userGroupService; @Test public void testAll() throws WxException { WxGroupEntity newgroup = userGroupService.remoteGroupsCreate(accessToken, "API测试组"); List groups = userGroupService.remoteGroupsGet(accessToken); boolean found = false; for (WxGroupEntity group : groups) { if (group.getName().equals(newgroup.getName())) { found = true; } } if (found == false) { throw new WxException("not found newly created group!"); } userGroupService.remoteGroupsUpdate(accessToken, newgroup.getWxId(), "API测试组2"); } } ================================================ FILE: src/test/java/org/hamster/weixinmp/test/service/WxMediaServiceTest.java ================================================ /** * */ package org.hamster.weixinmp.test.service; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import org.apache.commons.io.IOUtils; import org.hamster.weixinmp.constant.WxMediaTypeEnum; import org.hamster.weixinmp.dao.entity.item.WxItemImageEntity; import org.hamster.weixinmp.exception.WxException; import org.hamster.weixinmp.service.WxAuthService; import org.hamster.weixinmp.service.WxMediaService; import org.hamster.weixinmp.test.base.AbstractWxServiceTest; import org.junit.Ignore; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; /** * @author honey.zhao@aliyun.com * @version Jan 4, 2014 * */ public class WxMediaServiceTest extends AbstractWxServiceTest { @Autowired WxAuthService authService; @Autowired WxMediaService mediaService; @Test @Ignore public void testMedia() throws WxException, FileNotFoundException, IOException { File imageFile = new File("src/test/resources/media/cat.jpg"); byte[] content = IOUtils.toByteArray(new FileReader(imageFile)); WxItemImageEntity imageMedia = (WxItemImageEntity) mediaService .remoteMediaUpload(accessToken, WxMediaTypeEnum.IMAGE, content); System.out.println(imageMedia); } } ================================================ FILE: src/test/java/org/hamster/weixinmp/test/service/WxMenuServiceTest.java ================================================ /** * */ package org.hamster.weixinmp.test.service; import org.hamster.weixinmp.exception.WxException; import org.hamster.weixinmp.model.menu.WxMenuCreateJson; import org.hamster.weixinmp.service.WxAuthService; import org.hamster.weixinmp.service.WxMenuService; import org.hamster.weixinmp.test.base.AbstractWxServiceTest; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import com.google.gson.Gson; /** * @author honey.zhao@aliyun.com * @version Jan 4, 2014 * */ public class WxMenuServiceTest extends AbstractWxServiceTest { public static final String MENU_CREATE_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\"" + " }]" + "}]" + "}"; @Autowired WxAuthService authService; @Autowired WxMenuService menuService; @Test public void testAll() throws WxException { Gson gson = new Gson(); WxMenuCreateJson dummyJson = gson.fromJson(MENU_CREATE_JSON, WxMenuCreateJson.class); menuService.menuCreate(accessToken, dummyJson.getButton()); System.out.println(menuService.menuGet(accessToken)); menuService.menuDelete(accessToken); } } ================================================ FILE: src/test/java/org/hamster/weixinmp/test/service/WxQrServiceTest.java ================================================ /** * */ package org.hamster.weixinmp.test.service; import org.hamster.weixinmp.exception.WxException; import org.hamster.weixinmp.service.WxAuthService; import org.hamster.weixinmp.service.WxQrService; import org.hamster.weixinmp.test.base.AbstractWxServiceTest; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; /** * @author honey.zhao@aliyun.com * @version Jan 5, 2014 * */ public class WxQrServiceTest extends AbstractWxServiceTest { @Autowired WxAuthService authService; @Autowired WxQrService qrService; @Test public void testAll() throws WxException { qrService.remoteQrcodeCreate(accessToken, true, 10000l, 1800l); qrService.remoteQrcodeCreate(accessToken, false, 500l, null); } } ================================================ FILE: src/test/java/org/hamster/weixinmp/test/service/WxServiceTest.java ================================================ /** * */ package org.hamster.weixinmp.test.service; import org.hamster.weixinmp.dao.repository.msg.WxBaseMsgDao; import org.hamster.weixinmp.exception.WxException; import org.hamster.weixinmp.service.WxAuthService; import org.hamster.weixinmp.test.base.AbstractServiceTest; import org.junit.Assert; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; /** * @author honey.zhao@aliyun.com * @version Jul 28, 2013 * */ public class WxServiceTest extends AbstractServiceTest { @Autowired WxAuthService authService; @Autowired WxBaseMsgDao wxBaseMsgDao; @Test public void testValidateAuth() throws WxException { Assert.assertTrue(authService.validateAuth( "9d31490b4386ad3bb9bbb8ac5150fb3e6230c171", "1375112572", "1375102247", "5906019193781128573")); } public static final String MSG_LOC_XML = "" + "" + "" + "1351776360" + "" + "23.134521" + "113.358803" + "20" + "" + "1234567890123456" + " "; // @Test // public void testMessageStorage() throws WxException, DocumentException { // wxService.saveMsgLoc(WxXmlUtil.toXML(MSG_LOC_XML)); // Iterable msgs = wxBaseMsgDao.findAll(); // for (WxBaseMsgEntity msg : msgs) { // System.out.println(msg.toString()); // } // } // // @Test // public void testCreateRespText() throws DocumentException { // WxRespTextEntity respText = wxService.createRespText("this is a content", "foo", "bar", 0); // WxXmlUtil.getRespTextXML(respText); // } } ================================================ FILE: src/test/java/org/hamster/weixinmp/test/service/WxUserServiceTest.java ================================================ /** * */ package org.hamster.weixinmp.test.service; import org.hamster.weixinmp.exception.WxException; import org.hamster.weixinmp.model.user.WxUserGetJson; import org.hamster.weixinmp.service.WxAuthService; import org.hamster.weixinmp.service.WxUserService; import org.hamster.weixinmp.test.base.AbstractWxServiceTest; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; /** * @author honey.zhao@aliyun.com * @version Jan 4, 2014 * */ public class WxUserServiceTest extends AbstractWxServiceTest { @Autowired WxAuthService authService; @Autowired WxUserService userService; @Test public void testAll() throws WxException { WxUserGetJson userGet = userService.remoteUserGet(accessToken); System.out.println(userGet); } } ================================================ FILE: src/test/java/org/hamster/weixinmp/test/xml/WxXMLUtilTest.java ================================================ /** * */ package org.hamster.weixinmp.test.xml; import org.dom4j.DocumentException; import org.hamster.weixinmp.controller.util.WxXmlUtil; import org.hamster.weixinmp.dao.entity.base.WxBaseMsgEntity; import org.hamster.weixinmp.dao.entity.msg.WxMsgEventEntity; import org.hamster.weixinmp.dao.entity.msg.WxMsgImageEntity; import org.hamster.weixinmp.dao.entity.msg.WxMsgLinkEntity; import org.hamster.weixinmp.dao.entity.msg.WxMsgLocEntity; import org.hamster.weixinmp.dao.entity.msg.WxMsgTextEntity; import org.junit.Assert; import org.junit.Test; /** * @author honey.zhao@aliyun.com * @version Jul 28, 2013 * */ public class WxXMLUtilTest { public static final String MSG_TEXT_XML = "" + "" + " " + "1348831860" + "" + "" + "1234567890123456" + ""; @Test public void testGetMsgText() throws DocumentException { WxMsgTextEntity msgText = WxXmlUtil.getMsgText(WxXmlUtil.toXML(MSG_TEXT_XML)); assertBaseFieldsWithMsgId(msgText); Assert.assertEquals("this is a test", msgText.getContent()); } public static final String MSG_IMG_XML = "" + "" + "" + "1348831860" + "" + "" + "" + "1234567890123456" + ""; @Test public void testGetMsgImg() throws DocumentException { WxMsgImageEntity msgImg = WxXmlUtil.getMsgImage(WxXmlUtil.toXML(MSG_IMG_XML)); assertBaseFieldsWithMsgId(msgImg); //Assert.assertEquals("this is a url", msgImg.getImage().getPicUrl()); } public static final String MSG_LOC_XML = "" + "" + "" + "1351776360" + "" + "23.134521" + "113.358803" + "20" + "" + "1234567890123456" + " "; @Test public void testGetMsgLoc() throws DocumentException { WxMsgLocEntity msgLoc = WxXmlUtil.getMsgLoc(WxXmlUtil.toXML(MSG_LOC_XML)); assertBaseFieldsWithMsgId(msgLoc); Assert.assertEquals(Double.valueOf(23.134521d), msgLoc.getLocationX()); Assert.assertEquals(Double.valueOf(113.358803d), msgLoc.getLocationY()); Assert.assertEquals(Double.valueOf(20), msgLoc.getScale()); Assert.assertEquals("位置信息", msgLoc.getLabel()); } public static final String MSG_LINK_XML = "" + "" + "" + "1351776360" + "" + "<![CDATA[公众平台官网链接]]>" + "" + "" + "1234567890123456" + " "; @Test public void testGetMsgLink() throws DocumentException { WxMsgLinkEntity msgLink = WxXmlUtil.getMsgLink(WxXmlUtil.toXML(MSG_LINK_XML)); assertBaseFieldsWithMsgId(msgLink); Assert.assertEquals("公众平台官网链接", msgLink.getTitle()); Assert.assertEquals("公众平台官网链接123", msgLink.getDescription()); Assert.assertEquals("url", msgLink.getUrl()); } public static final String MSG_EVENT_XML = "" + "" + "" + "123456789" + "" + "" + "" + ""; @Test public void testGetMsgEvent() throws DocumentException { WxMsgEventEntity msgEvent = WxXmlUtil.getMsgEvent(WxXmlUtil.toXML(MSG_EVENT_XML)); assertBaseFields(msgEvent); Assert.assertEquals("EVENT", msgEvent.getEvent()); Assert.assertEquals("EVENTKEY", msgEvent.getEventKey()); } private void assertBaseFields(WxBaseMsgEntity entity) { Assert.assertNotNull(entity.getFromUserName()); Assert.assertNotNull(entity.getToUserName()); Assert.assertNotNull(entity.getCreateTime()); Assert.assertNotNull(entity.getMsgType()); } private void assertBaseFieldsWithMsgId(WxBaseMsgEntity entity) { assertBaseFields(entity); Assert.assertNotNull(entity.getMsgId()); } } ================================================ FILE: src/test/resources/.gitignore ================================================ /tmp ================================================ FILE: src/test/resources/application.development.properties ================================================ #(optional)override jdbc url for local development jdbc.driver=com.mysql.jdbc.Driver jdbc.url= jdbc.username= jdbc.password= wx_token= wx_appid= wx_appsecret= wx_menu_create_url=https://api.weixin.qq.com/cgi-bin/menu/create wx_menu_get_url=https://api.weixin.qq.com/cgi-bin/menu/get #?access_token=ACCESS_TOKEN wx_menu_delete_url=https://api.weixin.qq.com/cgi-bin/menu/delete #?access_token=ACCESS_TOKEN wx_media_upload_url=http://file.api.weixin.qq.com/cgi-bin/media/upload #?access_token=ACCESS_TOKEN&type=TYPE wx_qrcode_create_url=https://api.weixin.qq.com/cgi-bin/qrcode/create #?access_token=TOKEN wx_showqrcode_url=https://mp.weixin.qq.com/cgi-bin/showqrcode #?ticket=TICKET wx_user_info_url=https://api.weixin.qq.com/cgi-bin/user/info #?access_token=ACCESS_TOKEN&openid=OPENID wx_user_get_url=https://api.weixin.qq.com/cgi-bin/user/get #?access_token=ACCESS_TOKEN&next_openid=NEXT_OPENID wx_access_token_create_url=https://api.weixin.qq.com/cgi-bin/token #?grant_type=client_credential&appid=APPID&secret=APPSECRET wx_custom_send_url=https://api.weixin.qq.com/cgi-bin/message/custom/send #?access_token=ACCESS_TOKEN wx_groups_create_url=https://api.weixin.qq.com/cgi-bin/groups/create #?access_token=ACCESS_TOKEN wx_groups_get_url=https://api.weixin.qq.com/cgi-bin/groups/get #?access_token=ACCESS_TOKEN wx_groups_getid_url=https://api.weixin.qq.com/cgi-bin/groups/getid #?access_token=ACCESS_TOKEN wx_groups_update_url=https://api.weixin.qq.com/cgi-bin/groups/update #?access_token=ACCESS_TOKEN wx_groups_members_update_url=https://api.weixin.qq.com/cgi-bin/groups/members/update #?access_token=ACCESS_TOKEN ================================================ FILE: src/test/resources/applicationContext-test-weixinmp.xml ================================================ Weixin-MP Testing Configuration classpath:/application.development.properties org.hibernate.cfg.ImprovedNamingStrategy create false false ================================================ FILE: src/test/resources/log4j.properties ================================================ # Output pattern : date [thread] priority category - message log4j.rootLogger=INFO, Console, RollingFile #Console log4j.appender.Console=org.apache.log4j.ConsoleAppender log4j.appender.Console.Target=System.out log4j.appender.Console.layout=org.apache.log4j.PatternLayout log4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n #RollingFile log4j.appender.RollingFile=org.apache.log4j.DailyRollingFileAppender log4j.appender.RollingFile.File=logs/candc.log log4j.appender.RollingFile.layout=org.apache.log4j.PatternLayout log4j.appender.RollingFile.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n #Task Configuration log4j.appender.Task=org.apache.log4j.DailyRollingFileAppender log4j.appender.Task.File=logs/candc-task.log log4j.appender.Task.layout=org.apache.log4j.PatternLayout log4j.appender.Task.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n #Project default level log4j.logger.com.hamster=INFO #Task level log4j.logger.com.hamster.service.task=INFO, Task log4j.logger.com.hamster.candc.task=INFO, Task #log4jdbc #log4j.logger.jdbc.sqltiming=INFO ================================================ FILE: src/test/resources/sql/import-data.sql ================================================