├── .gitignore ├── LICENSE ├── README.md ├── liucheng.jpg ├── logo.png ├── mine.jpg ├── pom.xml └── src └── main └── java ├── Demo.java ├── api └── base │ ├── ContactApi.java │ ├── DownloadApi.java │ ├── FavorApi.java │ ├── GroupApi.java │ ├── LabelApi.java │ ├── LoginApi.java │ ├── MessageApi.java │ └── PersonalApi.java └── util └── OkhttpUtil.java /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.nar 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | replay_pid* 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 |  Logo 3 |

4 | 5 | # 因相关法律原因,本项目不再维护及可用 6 | 7 | [针对违规获取及利用微信终端用户数据行为的打击公告](https://mp.weixin.qq.com/s/A6h4ZLTE2EPrY7kJ5fHE2g) 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /liucheng.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Devo919/Gewechat/ed096c9276c7f614a0c470c62d789d1cb2411595/liucheng.jpg -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Devo919/Gewechat/ed096c9276c7f614a0c470c62d789d1cb2411595/logo.png -------------------------------------------------------------------------------- /mine.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Devo919/Gewechat/ed096c9276c7f614a0c470c62d789d1cb2411595/mine.jpg -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | com 6 | gewei-demo 7 | 0.0.1-SNAPSHOT 8 | 9 | 10 | 11 | org.apache.maven.plugins 12 | maven-compiler-plugin 13 | 14 | 8 15 | 8 16 | 17 | 18 | 19 | 20 | gewei-demo 21 | 22 | 23 | 24 | 1.8 25 | 26 | 27 | 28 | 29 | com.alibaba.fastjson2 30 | fastjson2 31 | 2.0.25 32 | 33 | 34 | 35 | com.squareup.okhttp3 36 | okhttp 37 | 3.10.0 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /src/main/java/Demo.java: -------------------------------------------------------------------------------- 1 | import api.base.MessageApi; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | import java.util.Random; 6 | 7 | public class Demo { 8 | 9 | 10 | /** 11 | * 群发测试 12 | * @param args 13 | */ 14 | public static void main(String[] args) throws InterruptedException { 15 | String appid = ""; 16 | List toWxids = Arrays.asList("39002402513@chatroom", "24099789585@chatroom", "52873617987@chatroom"); 17 | for (String toWxid : toWxids) { 18 | MessageApi.postText(appid,toWxid,"test",""); 19 | int i = new Random().nextInt(6); 20 | Thread.sleep(i*1000); 21 | } 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/api/base/ContactApi.java: -------------------------------------------------------------------------------- 1 | package api.base; 2 | 3 | import com.alibaba.fastjson2.JSONObject; 4 | import util.OkhttpUtil; 5 | 6 | import java.util.Arrays; 7 | import java.util.List; 8 | 9 | /** 10 | * 联系人模块 11 | */ 12 | public class ContactApi { 13 | 14 | /** 15 | * 16 | * @param appId 17 | * @return 18 | */ 19 | public static JSONObject a(String appId){ 20 | JSONObject param = new JSONObject(); 21 | param.put("appId",appId); 22 | return OkhttpUtil.postJSON("/login/checkOnline",param); 23 | } 24 | 25 | /** 26 | * 获取通讯录列表 27 | * @param appId 28 | * @return 29 | */ 30 | public static JSONObject fetchContactsList(String appId){ 31 | JSONObject param = new JSONObject(); 32 | param.put("appId",appId); 33 | return OkhttpUtil.postJSON("/contacts/fetchContactsList",param); 34 | } 35 | 36 | /** 37 | * 获取群/好友简要信息 38 | * @param appId 39 | * @return 40 | */ 41 | public static JSONObject getBriefInfo(String appId, List wxids){ 42 | JSONObject param = new JSONObject(); 43 | param.put("appId",appId); 44 | param.put("wxids",wxids); 45 | return OkhttpUtil.postJSON("/contacts/getBriefInfo",param); 46 | } 47 | 48 | /** 49 | * 获取群/好友详细信息 50 | * @param appId 51 | * @return 52 | */ 53 | public static JSONObject getDetailInfo(String appId, List wxids){ 54 | JSONObject param = new JSONObject(); 55 | param.put("appId",appId); 56 | param.put("wxids",wxids); 57 | return OkhttpUtil.postJSON("/contacts/getDetailInfo",param); 58 | } 59 | 60 | /** 61 | * 搜索好友 62 | * @param appId 63 | * @return 64 | */ 65 | public static JSONObject search(String appId,String contactsInfo){ 66 | JSONObject param = new JSONObject(); 67 | param.put("appId",appId); 68 | param.put("contactsInfo",contactsInfo); 69 | return OkhttpUtil.postJSON("/contacts/search",param); 70 | } 71 | 72 | /** 73 | * 添加联系人/同意添加好友 74 | * @param appId 75 | * @return 76 | */ 77 | public static JSONObject search(String appId,Integer scene,Integer option,String v3, String v4,String content){ 78 | JSONObject param = new JSONObject(); 79 | param.put("appId",appId); 80 | param.put("scene",scene); 81 | param.put("option",option); 82 | param.put("v3",v3); 83 | param.put("v4",v4); 84 | param.put("content",content); 85 | return OkhttpUtil.postJSON("/contacts/addContacts",param); 86 | } 87 | 88 | /** 89 | * 删除好友 90 | * @param appId 91 | * @return 92 | */ 93 | public static JSONObject deleteFriend(String appId,String wxid){ 94 | JSONObject param = new JSONObject(); 95 | param.put("appId",appId); 96 | param.put("wxid",wxid); 97 | return OkhttpUtil.postJSON("/contacts/deleteFriend",param); 98 | } 99 | 100 | /** 101 | * 设置好友仅聊天 102 | * @param appId 103 | * @return 104 | */ 105 | public static JSONObject setFriendPermissions(String appId,String wxid,Boolean onlyChat){ 106 | JSONObject param = new JSONObject(); 107 | param.put("appId",appId); 108 | param.put("wxid",wxid); 109 | param.put("onlyChat",onlyChat); 110 | return OkhttpUtil.postJSON("/contacts/setFriendPermissions",param); 111 | } 112 | 113 | /** 114 | * 设置好友备注 115 | * @param appId 116 | * @return 117 | */ 118 | public static JSONObject setFriendRemark(String appId,String wxid,String remark){ 119 | JSONObject param = new JSONObject(); 120 | param.put("appId",appId); 121 | param.put("wxid",wxid); 122 | param.put("onlyChat",remark); 123 | return OkhttpUtil.postJSON("/contacts/setFriendRemark",param); 124 | } 125 | 126 | /** 127 | * 获取手机通讯录 128 | * @param appId 129 | * @return 130 | */ 131 | public static JSONObject getPhoneAddressList(String appId,List phones){ 132 | JSONObject param = new JSONObject(); 133 | param.put("appId",appId); 134 | param.put("wxid",phones); 135 | return OkhttpUtil.postJSON("/contacts/getPhoneAddressList",param); 136 | } 137 | 138 | /** 139 | * 上传手机通讯录 140 | * @param appId 141 | * @return 142 | */ 143 | public static JSONObject uploadPhoneAddressList(String appId,List phones,Integer opType){ 144 | JSONObject param = new JSONObject(); 145 | param.put("appId",appId); 146 | param.put("wxid",phones); 147 | param.put("opType",opType); 148 | return OkhttpUtil.postJSON("/contacts/uploadPhoneAddressList",param); 149 | } 150 | 151 | } 152 | -------------------------------------------------------------------------------- /src/main/java/api/base/DownloadApi.java: -------------------------------------------------------------------------------- 1 | package api.base; 2 | 3 | import com.alibaba.fastjson2.JSONObject; 4 | import util.OkhttpUtil; 5 | 6 | /** 7 | * 下载模块 8 | */ 9 | public class DownloadApi { 10 | 11 | /** 12 | * 下载图片 13 | */ 14 | public static JSONObject downloadImage(String appId, String xml, Integer type){ 15 | JSONObject param = new JSONObject(); 16 | param.put("appId",appId); 17 | param.put("xml",xml); 18 | param.put("type",type); 19 | return OkhttpUtil.postJSON("/message/downloadImage",param); 20 | } 21 | 22 | /** 23 | * 下载语音 24 | */ 25 | public static JSONObject downloadVoice(String appId, String xml, Long msgId){ 26 | JSONObject param = new JSONObject(); 27 | param.put("appId",appId); 28 | param.put("xml",xml); 29 | param.put("msgId",msgId); 30 | return OkhttpUtil.postJSON("/message/downloadVoice",param); 31 | } 32 | 33 | /** 34 | * 下载视频 35 | */ 36 | public static JSONObject downloadVideo(String appId, String xml){ 37 | JSONObject param = new JSONObject(); 38 | param.put("appId",appId); 39 | param.put("xml",xml); 40 | return OkhttpUtil.postJSON("/message/downloadVideo",param); 41 | } 42 | 43 | /** 44 | * 下载emoji 45 | */ 46 | public static JSONObject downloadEmojiMd5(String appId, String emojiMd5){ 47 | JSONObject param = new JSONObject(); 48 | param.put("appId",appId); 49 | param.put("emojiMd5",emojiMd5); 50 | return OkhttpUtil.postJSON("/message/downloadEmojiMd5",param); 51 | } 52 | /** 53 | * cdn下载 54 | */ 55 | public static JSONObject downloadImage(String appId, String aesKey, String fileId, String type, String totalSize, String suffix){ 56 | JSONObject param = new JSONObject(); 57 | param.put("appId",appId); 58 | param.put("aesKey",aesKey); 59 | param.put("fileId",fileId); 60 | param.put("totalSize",totalSize); 61 | param.put("type",type); 62 | param.put("suffix",suffix); 63 | return OkhttpUtil.postJSON("/message/downloadCdn",param); 64 | } 65 | 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/api/base/FavorApi.java: -------------------------------------------------------------------------------- 1 | package api.base; 2 | 3 | import com.alibaba.fastjson2.JSONObject; 4 | import util.OkhttpUtil; 5 | 6 | /** 7 | * 收藏夹模块 8 | */ 9 | public class FavorApi { 10 | 11 | /** 12 | * 同步收藏夹 13 | */ 14 | public static JSONObject sync(String appId, String syncKey) { 15 | JSONObject param = new JSONObject(); 16 | param.put("appId", appId); 17 | param.put("syncKey", syncKey); 18 | return OkhttpUtil.postJSON("/favor/sync", param); 19 | } 20 | 21 | /** 22 | * 获取收藏夹内容 23 | */ 24 | public static JSONObject getContent(String appId, Integer favId) { 25 | JSONObject param = new JSONObject(); 26 | param.put("appId", appId); 27 | param.put("favId", favId); 28 | return OkhttpUtil.postJSON("/favor/getContent", param); 29 | } 30 | 31 | /** 32 | * 删除收藏夹 33 | */ 34 | public static JSONObject delete(String appId, Integer favId) { 35 | JSONObject param = new JSONObject(); 36 | param.put("appId", appId); 37 | param.put("favId", favId); 38 | return OkhttpUtil.postJSON("/favor/delete", param); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/api/base/GroupApi.java: -------------------------------------------------------------------------------- 1 | package api.base; 2 | 3 | import com.alibaba.fastjson2.JSONObject; 4 | import util.OkhttpUtil; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * 群模块 10 | */ 11 | public class GroupApi { 12 | 13 | /** 14 | * 创建微信群 15 | * @param appId 16 | * @return 17 | */ 18 | public static JSONObject createChatroom(String appId, List wxids){ 19 | JSONObject param = new JSONObject(); 20 | param.put("appId",appId); 21 | param.put("wxid",wxids); 22 | return OkhttpUtil.postJSON("/group/createChatroom",param); 23 | } 24 | 25 | /** 26 | * 修改群名称 27 | * @param appId 28 | * @return 29 | */ 30 | public static JSONObject modifyChatroomName(String appId, String chatroomName,String chatroomId){ 31 | JSONObject param = new JSONObject(); 32 | param.put("appId",appId); 33 | param.put("chatroomName",chatroomName); 34 | param.put("chatroomId",chatroomId); 35 | return OkhttpUtil.postJSON("/group/modifyChatroomName",param); 36 | } 37 | 38 | /** 39 | * 修改群备注 40 | * @param appId 41 | * @return 42 | */ 43 | public static JSONObject modifyChatroomRemark(String appId, String chatroomRemark,String chatroomId){ 44 | JSONObject param = new JSONObject(); 45 | param.put("appId",appId); 46 | param.put("chatroomRemark",chatroomRemark); 47 | param.put("chatroomId",chatroomId); 48 | return OkhttpUtil.postJSON("/group/modifyChatroomRemark",param); 49 | } 50 | 51 | /** 52 | * 修改我在群内的昵称 53 | * @param appId 54 | * @return 55 | */ 56 | public static JSONObject modifyChatroomNickNameForSelf(String appId, String nickName,String chatroomId){ 57 | JSONObject param = new JSONObject(); 58 | param.put("appId",appId); 59 | param.put("nickName",nickName); 60 | param.put("chatroomId",chatroomId); 61 | return OkhttpUtil.postJSON("/group/modifyChatroomNickNameForSelf",param); 62 | } 63 | 64 | /** 65 | * 邀请/添加 进群 66 | * @param appId 67 | * @return 68 | */ 69 | public static JSONObject inviteMember(String appId, List wxids,String chatroomId, String reason){ 70 | JSONObject param = new JSONObject(); 71 | param.put("appId",appId); 72 | param.put("wxids",wxids); 73 | param.put("reason",reason); 74 | param.put("chatroomId",chatroomId); 75 | return OkhttpUtil.postJSON("/group/inviteMember",param); 76 | } 77 | 78 | /** 79 | * 删除群成员 80 | * @param appId 81 | * @return 82 | */ 83 | public static JSONObject removeMember(String appId, List wxids,String chatroomId){ 84 | JSONObject param = new JSONObject(); 85 | param.put("appId",appId); 86 | param.put("wxids",wxids); 87 | param.put("chatroomId",chatroomId); 88 | return OkhttpUtil.postJSON("/group/removeMember",param); 89 | } 90 | 91 | /** 92 | * 退出群聊 93 | * @param appId 94 | * @return 95 | */ 96 | public static JSONObject modifyChatroomName(String appId,String chatroomId){ 97 | JSONObject param = new JSONObject(); 98 | param.put("appId",appId); 99 | param.put("chatroomId",chatroomId); 100 | return OkhttpUtil.postJSON("/group/quitChatroom",param); 101 | } 102 | 103 | /** 104 | * 解散群聊 105 | * @param appId 106 | * @return 107 | */ 108 | public static JSONObject disbandChatroom(String appId,String chatroomId){ 109 | JSONObject param = new JSONObject(); 110 | param.put("appId",appId); 111 | param.put("chatroomId",chatroomId); 112 | return OkhttpUtil.postJSON("/group/disbandChatroom",param); 113 | } 114 | 115 | /** 116 | * 获取群信息 117 | * @param appId 118 | * @return 119 | */ 120 | public static JSONObject getChatroomInfo(String appId,String chatroomId){ 121 | JSONObject param = new JSONObject(); 122 | param.put("appId",appId); 123 | param.put("chatroomId",chatroomId); 124 | return OkhttpUtil.postJSON("/group/getChatroomInfo",param); 125 | } 126 | 127 | /** 128 | * 获取群成员列表 129 | * @param appId 130 | * @return 131 | */ 132 | public static JSONObject getChatroomMemberList(String appId,String chatroomId){ 133 | JSONObject param = new JSONObject(); 134 | param.put("appId",appId); 135 | param.put("chatroomId",chatroomId); 136 | return OkhttpUtil.postJSON("/group/getChatroomMemberList",param); 137 | } 138 | 139 | /** 140 | * 获取群成员详情 141 | * @param appId 142 | * @return 143 | */ 144 | public static JSONObject getChatroomMemberDetail(String appId,String chatroomId,List memberWxids){ 145 | JSONObject param = new JSONObject(); 146 | param.put("appId",appId); 147 | param.put("memberWxids",memberWxids); 148 | param.put("chatroomId",chatroomId); 149 | return OkhttpUtil.postJSON("/group/getChatroomMemberDetail",param); 150 | } 151 | 152 | /** 153 | * 获取群公告 154 | * @param appId 155 | * @return 156 | */ 157 | public static JSONObject getChatroomAnnouncement(String appId,String chatroomId){ 158 | JSONObject param = new JSONObject(); 159 | param.put("appId",appId); 160 | param.put("chatroomId",chatroomId); 161 | return OkhttpUtil.postJSON("/group/getChatroomAnnouncement",param); 162 | } 163 | 164 | /** 165 | * 设置群公告 166 | * @param appId 167 | * @return 168 | */ 169 | public static JSONObject setChatroomAnnouncement(String appId,String chatroomId, String content){ 170 | JSONObject param = new JSONObject(); 171 | param.put("appId",appId); 172 | param.put("chatroomId",chatroomId); 173 | param.put("content",content); 174 | return OkhttpUtil.postJSON("/group/setChatroomAnnouncement",param); 175 | } 176 | 177 | /** 178 | * 同意进群 179 | * @param appId 180 | * @return 181 | */ 182 | public static JSONObject agreeJoinRoom(String appId, String url){ 183 | JSONObject param = new JSONObject(); 184 | param.put("appId",appId); 185 | param.put("chatroomName",url); 186 | return OkhttpUtil.postJSON("/group/agreeJoinRoom",param); 187 | } 188 | 189 | /** 190 | * 添加群成员为好友 191 | * @param appId 192 | * @return 193 | */ 194 | public static JSONObject addGroupMemberAsFriend(String appId, String memberWxid,String chatroomId,String content){ 195 | JSONObject param = new JSONObject(); 196 | param.put("appId",appId); 197 | param.put("memberWxid",memberWxid); 198 | param.put("content",content); 199 | param.put("chatroomId",chatroomId); 200 | return OkhttpUtil.postJSON("/group/addGroupMemberAsFriend",param); 201 | } 202 | 203 | /** 204 | * 获取群二维码 205 | * @param appId 206 | * @return 207 | */ 208 | public static JSONObject getChatroomQrCode(String appId,String chatroomId){ 209 | JSONObject param = new JSONObject(); 210 | param.put("appId",appId); 211 | param.put("chatroomId",chatroomId); 212 | return OkhttpUtil.postJSON("/group/getChatroomQrCode",param); 213 | } 214 | 215 | /** 216 | * 群保存到通讯录 217 | * @param appId 218 | * @return 219 | */ 220 | public static JSONObject saveContractList(String appId, Integer operType,String chatroomId){ 221 | JSONObject param = new JSONObject(); 222 | param.put("appId",appId); 223 | param.put("chatroomName",operType); 224 | param.put("chatroomId",chatroomId); 225 | return OkhttpUtil.postJSON("/group/saveContractList",param); 226 | } 227 | 228 | /** 229 | * 管理员操作 230 | * @param appId 231 | * @return 232 | */ 233 | public static JSONObject adminOperate(String appId,String chatroomId,List wxids,Integer operType){ 234 | JSONObject param = new JSONObject(); 235 | param.put("appId",appId); 236 | param.put("wxids",wxids); 237 | param.put("operType",operType); 238 | param.put("chatroomId",chatroomId); 239 | return OkhttpUtil.postJSON("/group/adminOperate",param); 240 | } 241 | 242 | /** 243 | * 聊天置顶 244 | * @param appId 245 | * @return 246 | */ 247 | public static JSONObject pinChat(String appId, boolean top,String chatroomId){ 248 | JSONObject param = new JSONObject(); 249 | param.put("appId",appId); 250 | param.put("top",top); 251 | param.put("chatroomId",chatroomId); 252 | return OkhttpUtil.postJSON("/group/pinChat",param); 253 | } 254 | 255 | /** 256 | * 设置消息免打扰 257 | * @param appId 258 | * @return 259 | */ 260 | public static JSONObject setMsgSilence(String appId, boolean silence,String chatroomId){ 261 | JSONObject param = new JSONObject(); 262 | param.put("appId",appId); 263 | param.put("silence",silence); 264 | param.put("chatroomId",chatroomId); 265 | return OkhttpUtil.postJSON("/group/setMsgSilence",param); 266 | } 267 | 268 | /** 269 | * 扫码进群 270 | * @param appId 271 | * @return 272 | */ 273 | public static JSONObject joinRoomUsingQRCode(String appId, String qrUrl){ 274 | JSONObject param = new JSONObject(); 275 | param.put("appId",appId); 276 | param.put("qrUrl",qrUrl); 277 | return OkhttpUtil.postJSON("/group/joinRoomUsingQRCode",param); 278 | } 279 | 280 | /** 281 | * 确认进群申请 282 | * @param appId 283 | * @return 284 | */ 285 | public static JSONObject roomAccessApplyCheckApprove(String appId, String newMsgId,String chatroomId, String msgContent){ 286 | JSONObject param = new JSONObject(); 287 | param.put("appId",appId); 288 | param.put("newMsgId",newMsgId); 289 | param.put("msgContent",msgContent); 290 | param.put("chatroomId",chatroomId); 291 | return OkhttpUtil.postJSON("/group/roomAccessApplyCheckApprove",param); 292 | } 293 | 294 | } 295 | -------------------------------------------------------------------------------- /src/main/java/api/base/LabelApi.java: -------------------------------------------------------------------------------- 1 | package api.base; 2 | 3 | import com.alibaba.fastjson2.JSONObject; 4 | import util.OkhttpUtil; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * 标签模块 10 | */ 11 | public class LabelApi { 12 | 13 | /** 14 | * 添加标签 15 | */ 16 | public static JSONObject add(String appId, String labelName) { 17 | JSONObject param = new JSONObject(); 18 | param.put("appId", appId); 19 | param.put("labelName", labelName); 20 | return OkhttpUtil.postJSON("/label/add", param); 21 | } 22 | 23 | /** 24 | * 删除标签 25 | */ 26 | public static JSONObject delete(String appId, String labelIds) { 27 | JSONObject param = new JSONObject(); 28 | param.put("appId", appId); 29 | param.put("labelIds", labelIds); 30 | return OkhttpUtil.postJSON("/label/delete", param); 31 | } 32 | 33 | /** 34 | * 添加标签 35 | */ 36 | public static JSONObject list(String appId) { 37 | JSONObject param = new JSONObject(); 38 | param.put("appId", appId); 39 | return OkhttpUtil.postJSON("/label/list", param); 40 | } 41 | 42 | /** 43 | * 添加标签 44 | */ 45 | public static JSONObject modifyMemberList(String appId, String labelIds, List wxIds) { 46 | JSONObject param = new JSONObject(); 47 | param.put("appId", appId); 48 | param.put("labelIds", labelIds); 49 | param.put("wxIds", wxIds); 50 | return OkhttpUtil.postJSON("/label/modifyMemberList", param); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/api/base/LoginApi.java: -------------------------------------------------------------------------------- 1 | package api.base; 2 | 3 | import com.alibaba.fastjson2.JSONObject; 4 | import util.OkhttpUtil; 5 | 6 | /** 7 | * 登录模块 8 | */ 9 | public class LoginApi { 10 | 11 | 12 | /** 13 | * 获取tokenId 将tokenId 配置到OkhttpUtil 类中的token 属性 14 | * 15 | * @return 16 | */ 17 | public static JSONObject getToken() { 18 | return OkhttpUtil.postJSON("/tools/getTokenId", new JSONObject()); 19 | } 20 | 21 | /** 22 | * 设置微信消息的回调地址 23 | * 24 | * @return 25 | */ 26 | public static JSONObject setCallback(String token,String callbackUrl) { 27 | JSONObject param = new JSONObject(); 28 | param.put("token",token); 29 | param.put("callbackUrl",callbackUrl); 30 | return OkhttpUtil.postJSON("/tools/setCallback", param); 31 | } 32 | 33 | /** 34 | * 获取登录二维码 35 | * 36 | * @param appId 设备id 首次登录传空,后续登录传返回的appid 37 | * @return 38 | */ 39 | public static JSONObject getQr(String appId) { 40 | JSONObject param = new JSONObject(); 41 | param.put("appId", appId); 42 | return OkhttpUtil.postJSON("/login/getLoginQrCode", param); 43 | } 44 | 45 | /** 46 | * 确认登陆 47 | * 48 | * @param appId 49 | * @param uuid 取码返回的uuid 50 | * @param captchCode 登录验证码(跨省登录会出现此提示,使用同省代理ip能避免此问题,也能使账号更加稳定) 51 | * @return 52 | */ 53 | public static JSONObject checkQr(String appId, String uuid, String captchCode) { 54 | JSONObject param = new JSONObject(); 55 | param.put("appId", appId); 56 | param.put("uuid", uuid); 57 | param.put("captchCode", captchCode); 58 | return OkhttpUtil.postJSON("/login/checkLogin", param); 59 | } 60 | 61 | /** 62 | * 退出微信 63 | * 64 | * @param appId 65 | * @return 66 | */ 67 | public static JSONObject logOut(String appId) { 68 | JSONObject param = new JSONObject(); 69 | param.put("appId", appId); 70 | return OkhttpUtil.postJSON("/login/logout", param); 71 | } 72 | 73 | /** 74 | * 弹框登录 75 | * 76 | * @param appId 77 | * @return 78 | */ 79 | public static JSONObject dialogLogin(String appId) { 80 | JSONObject param = new JSONObject(); 81 | param.put("appId", appId); 82 | return OkhttpUtil.postJSON("/login/dialogLogin", param); 83 | } 84 | 85 | /** 86 | * 检查是否在线 87 | * 88 | * @param appId 89 | * @return 90 | */ 91 | public static JSONObject checkOnline(String appId) { 92 | JSONObject param = new JSONObject(); 93 | param.put("appId", appId); 94 | return OkhttpUtil.postJSON("/login/checkOnline", param); 95 | } 96 | 97 | /** 98 | * 退出 99 | * 100 | * @param appId 101 | * @return 102 | */ 103 | public static JSONObject logout(String appId) { 104 | JSONObject param = new JSONObject(); 105 | param.put("appId", appId); 106 | return OkhttpUtil.postJSON("/login/logout", param); 107 | } 108 | 109 | } 110 | -------------------------------------------------------------------------------- /src/main/java/api/base/MessageApi.java: -------------------------------------------------------------------------------- 1 | package api.base; 2 | 3 | import com.alibaba.fastjson2.JSONObject; 4 | import util.OkhttpUtil; 5 | 6 | /** 7 | * 消息模块 8 | */ 9 | public class MessageApi { 10 | 11 | /** 12 | * 发送文字消息 13 | */ 14 | public static JSONObject postText(String appId, String toWxid, String content, String ats) { 15 | JSONObject param = new JSONObject(); 16 | param.put("appId", appId); 17 | param.put("toWxid", toWxid); 18 | param.put("content", content); 19 | param.put("ats", ats); 20 | return OkhttpUtil.postJSON("/message/postText", param); 21 | } 22 | 23 | /** 24 | * 发送文件消息 25 | */ 26 | public static JSONObject postFile(String appId, String toWxid, String fileUrl, String fileName) { 27 | JSONObject param = new JSONObject(); 28 | param.put("appId", appId); 29 | param.put("toWxid", toWxid); 30 | param.put("fileUrl", fileUrl); 31 | param.put("fileName", fileName); 32 | return OkhttpUtil.postJSON("/message/postFile", param); 33 | } 34 | 35 | /** 36 | * 发送图片消息 37 | */ 38 | public static JSONObject postImage(String appId, String toWxid, String imgUrl) { 39 | JSONObject param = new JSONObject(); 40 | param.put("appId", appId); 41 | param.put("toWxid", toWxid); 42 | param.put("imgUrl", imgUrl); 43 | return OkhttpUtil.postJSON("/message/postImage", param); 44 | } 45 | 46 | /** 47 | * 发送语音消息 48 | */ 49 | public static JSONObject postVoice(String appId, String toWxid, String voiceUrl, Integer voiceDuration) { 50 | JSONObject param = new JSONObject(); 51 | param.put("appId", appId); 52 | param.put("toWxid", toWxid); 53 | param.put("voiceUrl", voiceUrl); 54 | param.put("voiceDuration", voiceDuration); 55 | return OkhttpUtil.postJSON("/message/postVoice", param); 56 | } 57 | 58 | /** 59 | * 发送视频消息 60 | */ 61 | public static JSONObject postVideo(String appId, String toWxid, String videoUrl, String thumbUrl,Integer videoDuration) { 62 | JSONObject param = new JSONObject(); 63 | param.put("appId", appId); 64 | param.put("toWxid", toWxid); 65 | param.put("videoUrl", videoUrl); 66 | param.put("thumbUrl", thumbUrl); 67 | param.put("videoDuration", videoDuration); 68 | return OkhttpUtil.postJSON("/message/postVideo", param); 69 | } 70 | 71 | /** 72 | * 发送链接消息 73 | */ 74 | public static JSONObject postLink(String appId, String toWxid, String title, String desc, String linkUrl, String thumbUrl) { 75 | JSONObject param = new JSONObject(); 76 | param.put("appId", appId); 77 | param.put("toWxid", toWxid); 78 | param.put("title", title); 79 | param.put("desc", desc); 80 | param.put("linkUrl", linkUrl); 81 | param.put("thumbUrl", thumbUrl); 82 | return OkhttpUtil.postJSON("/message/postLink", param); 83 | } 84 | 85 | /** 86 | * 发送名片消息 87 | */ 88 | public static JSONObject postNameCard(String appId, String toWxid, String nickName, String nameCardWxid) { 89 | JSONObject param = new JSONObject(); 90 | param.put("appId", appId); 91 | param.put("toWxid", toWxid); 92 | param.put("nickName", nickName); 93 | param.put("nameCardWxid", nameCardWxid); 94 | return OkhttpUtil.postJSON("/message/postNameCard", param); 95 | } 96 | 97 | /** 98 | * 发送emoji消息 99 | */ 100 | public static JSONObject postEmoji(String appId, String toWxid, String emojiMd5, String emojiSize) { 101 | JSONObject param = new JSONObject(); 102 | param.put("appId", appId); 103 | param.put("toWxid", toWxid); 104 | param.put("emojiMd5", emojiMd5); 105 | param.put("emojiSize", emojiSize); 106 | return OkhttpUtil.postJSON("/message/postEmoji", param); 107 | } 108 | 109 | /** 110 | * 发送appmsg消息 111 | */ 112 | public static JSONObject postAppMsg(String appId, String toWxid, String appmsg) { 113 | JSONObject param = new JSONObject(); 114 | param.put("appId", appId); 115 | param.put("toWxid", toWxid); 116 | param.put("appmsg", appmsg); 117 | return OkhttpUtil.postJSON("/message/postAppMsg", param); 118 | } 119 | 120 | /** 121 | * 发送小程序消息 122 | */ 123 | public static JSONObject postMiniApp(String appId, String toWxid, String miniAppId, String displayName, String pagePath, String coverImgUrl, String title, String userName) { 124 | JSONObject param = new JSONObject(); 125 | param.put("appId", appId); 126 | param.put("toWxid", toWxid); 127 | param.put("miniAppId", miniAppId); 128 | param.put("displayName", displayName); 129 | param.put("pagePath", pagePath); 130 | param.put("coverImgUrl", coverImgUrl); 131 | param.put("title", title); 132 | param.put("userName", userName); 133 | return OkhttpUtil.postJSON("/message/postMiniApp", param); 134 | } 135 | 136 | /** 137 | * 转发文件 138 | */ 139 | public static JSONObject forwardFile(String appId, String toWxid, String xml) { 140 | JSONObject param = new JSONObject(); 141 | param.put("appId", appId); 142 | param.put("toWxid", toWxid); 143 | param.put("xml", xml); 144 | return OkhttpUtil.postJSON("/message/forwardFile", param); 145 | } 146 | 147 | /** 148 | * 转发图片 149 | */ 150 | public static JSONObject forwardImage(String appId, String toWxid, String xml) { 151 | JSONObject param = new JSONObject(); 152 | param.put("appId", appId); 153 | param.put("toWxid", toWxid); 154 | param.put("xml", xml); 155 | return OkhttpUtil.postJSON("/message/forwardImage", param); 156 | } 157 | 158 | /** 159 | * 转发视频 160 | */ 161 | public static JSONObject forwardVideo(String appId, String toWxid, String xml) { 162 | JSONObject param = new JSONObject(); 163 | param.put("appId", appId); 164 | param.put("toWxid", toWxid); 165 | param.put("xml", xml); 166 | return OkhttpUtil.postJSON("/message/forwardVideo", param); 167 | } 168 | 169 | /** 170 | * 转发链接 171 | */ 172 | public static JSONObject forwardUrl(String appId, String toWxid, String xml) { 173 | JSONObject param = new JSONObject(); 174 | param.put("appId", appId); 175 | param.put("toWxid", toWxid); 176 | param.put("xml", xml); 177 | return OkhttpUtil.postJSON("/message/forwardUrl", param); 178 | } 179 | 180 | /** 181 | * 转发小程序 182 | */ 183 | public static JSONObject forwardMiniApp(String appId, String toWxid, String xml, String coverImgUrl) { 184 | JSONObject param = new JSONObject(); 185 | param.put("appId", appId); 186 | param.put("toWxid", toWxid); 187 | param.put("xml", xml); 188 | param.put("coverImgUrl", coverImgUrl); 189 | return OkhttpUtil.postJSON("/message/forwardMiniApp", param); 190 | } 191 | 192 | /** 193 | * 撤回消息 194 | */ 195 | public static JSONObject revokeMsg(String appId, String toWxid, String msgId, String newMsgId,String createTime) { 196 | JSONObject param = new JSONObject(); 197 | param.put("appId", appId); 198 | param.put("toWxid", toWxid); 199 | param.put("msgId", msgId); 200 | param.put("newMsgId", newMsgId); 201 | param.put("createTime", createTime); 202 | return OkhttpUtil.postJSON("/message/revokeMsg", param); 203 | } 204 | 205 | } 206 | -------------------------------------------------------------------------------- /src/main/java/api/base/PersonalApi.java: -------------------------------------------------------------------------------- 1 | package api.base; 2 | 3 | import com.alibaba.fastjson2.JSONObject; 4 | import util.OkhttpUtil; 5 | 6 | /** 7 | * 个人模块 8 | */ 9 | public class PersonalApi { 10 | 11 | /** 12 | * 获取个人资料 13 | */ 14 | public static JSONObject getProfile(String appId){ 15 | JSONObject param = new JSONObject(); 16 | param.put("appId",appId); 17 | return OkhttpUtil.postJSON("/personal/getProfile",param); 18 | } 19 | 20 | 21 | /** 22 | * 获取自己的二维码 23 | */ 24 | public static JSONObject getQrCode(String appId){ 25 | JSONObject param = new JSONObject(); 26 | param.put("appId",appId); 27 | return OkhttpUtil.postJSON("/personal/getQrCode",param); 28 | } 29 | 30 | /** 31 | * 获取设备记录 32 | */ 33 | public static JSONObject getSafetyInfo(String appId){ 34 | JSONObject param = new JSONObject(); 35 | param.put("appId",appId); 36 | return OkhttpUtil.postJSON("/personal/getSafetyInfo",param); 37 | } 38 | 39 | /** 40 | * 隐私设置 41 | */ 42 | public static JSONObject privacySettings(String appId,Integer option,boolean open){ 43 | JSONObject param = new JSONObject(); 44 | param.put("appId",appId); 45 | param.put("option",option); 46 | param.put("open",open); 47 | return OkhttpUtil.postJSON("/personal/privacySettings",param); 48 | } 49 | 50 | /** 51 | * 修改个人信息 52 | */ 53 | public static JSONObject updateProfile(String appId,String city,String country,String nickName,String province,String sex,String signature){ 54 | JSONObject param = new JSONObject(); 55 | param.put("appId",appId); 56 | param.put("city",city); 57 | param.put("country",country); 58 | param.put("nickName",nickName); 59 | param.put("province",province); 60 | param.put("sex",sex); 61 | param.put("signature",signature); 62 | return OkhttpUtil.postJSON("/personal/updateProfile",param); 63 | } 64 | 65 | /** 66 | * 修改头像 67 | */ 68 | public static JSONObject updateHeadImg(String appId,String headImgUrl){ 69 | JSONObject param = new JSONObject(); 70 | param.put("appId",appId); 71 | param.put("headImgUrl",headImgUrl); 72 | return OkhttpUtil.postJSON("/personal/updateHeadImg",param); 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/util/OkhttpUtil.java: -------------------------------------------------------------------------------- 1 | package util; 2 | 3 | import com.alibaba.fastjson2.JSONObject; 4 | import okhttp3.*; 5 | 6 | import javax.net.ssl.SSLContext; 7 | import javax.net.ssl.SSLSocketFactory; 8 | import javax.net.ssl.TrustManager; 9 | import javax.net.ssl.X509TrustManager; 10 | import java.io.IOException; 11 | import java.security.SecureRandom; 12 | import java.security.cert.CertificateException; 13 | import java.security.cert.X509Certificate; 14 | import java.util.HashMap; 15 | import java.util.Iterator; 16 | import java.util.Map; 17 | import java.util.concurrent.TimeUnit; 18 | 19 | public class OkhttpUtil { 20 | 21 | private final static String baseUrl = "http://服务ip:2531/v2/api"; 22 | private final static String token = ""; 23 | 24 | public static OkHttpClient okHttpClient() { 25 | TrustManager[] trustManagers = buildTrustManagers(); 26 | return new OkHttpClient.Builder() 27 | .connectTimeout(60, TimeUnit.SECONDS) 28 | .readTimeout(60, TimeUnit.SECONDS) 29 | .writeTimeout(60, TimeUnit.SECONDS) 30 | .sslSocketFactory(createSSLSocketFactory(trustManagers), (X509TrustManager) trustManagers[0]) 31 | .hostnameVerifier((hostName, sessino) -> true) 32 | .retryOnConnectionFailure(false)//是否开启缓存 33 | .build(); 34 | } 35 | 36 | private static TrustManager[] buildTrustManagers() { 37 | return new TrustManager[]{ 38 | new X509TrustManager() { 39 | @Override 40 | public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException { 41 | } 42 | 43 | @Override 44 | public void checkServerTrusted(X509Certificate[] chain, String authType) { 45 | } 46 | 47 | @Override 48 | public X509Certificate[] getAcceptedIssuers() { 49 | return new X509Certificate[]{}; 50 | } 51 | } 52 | }; 53 | } 54 | 55 | private static SSLSocketFactory createSSLSocketFactory(TrustManager[] trustAllCerts) { 56 | SSLSocketFactory ssfFactory = null; 57 | try { 58 | SSLContext sc = SSLContext.getInstance("SSL"); 59 | sc.init(null, trustAllCerts, new SecureRandom()); 60 | ssfFactory = sc.getSocketFactory(); 61 | } catch (Exception e) { 62 | e.printStackTrace(); 63 | } 64 | return ssfFactory; 65 | } 66 | 67 | public static JSONObject postJSON(String route,JSONObject param){ 68 | Map header = new HashMap<>(); 69 | if(token != null){ 70 | header.put("X-GEWE-TOKEN",token); 71 | } 72 | try { 73 | if(baseUrl == null || "".equals(baseUrl)){ 74 | throw new RuntimeException("baseUrl 未配置"); 75 | } 76 | String res = json(baseUrl + route, header, param.toJSONString(), okHttpClient()); 77 | System.out.println(res); 78 | JSONObject jsonObject = JSONObject.parse(res); 79 | if(jsonObject.getInteger("ret") == 200){ 80 | return jsonObject; 81 | }else{ 82 | throw new RuntimeException(res); 83 | } 84 | } catch (Exception e) { 85 | System.out.println("url="+baseUrl + route); 86 | throw new RuntimeException(e); 87 | } 88 | } 89 | 90 | private static String json(String url, Map header, String json, OkHttpClient client) throws IOException { 91 | // 创建一个请求 Builder 92 | Request.Builder builder = new Request.Builder(); 93 | // 创建一个 request 94 | Request request = builder.url(url).build(); 95 | 96 | // 创建一个 Headers.Builder 97 | Headers.Builder headerBuilder = request.headers().newBuilder(); 98 | 99 | // 装载请求头参数 100 | Iterator> headerIterator = header.entrySet().iterator(); 101 | headerIterator.forEachRemaining(e -> { 102 | headerBuilder.add(e.getKey(), (String) e.getValue()); 103 | }); 104 | headerBuilder.add("Content-Type", "application/json"); 105 | 106 | // application/octet-stream 107 | RequestBody requestBody = FormBody.create(MediaType.parse("application/json"), json); 108 | 109 | // 设置自定义的 builder 110 | builder.headers(headerBuilder.build()).post(requestBody); 111 | 112 | try (Response execute = client.newCall(builder.build()).execute()) { 113 | return execute.body().string(); 114 | } 115 | } 116 | 117 | } 118 | --------------------------------------------------------------------------------