├── 1.png ├── 2.png ├── LICENSE ├── README.md ├── pom.xml └── src └── main └── java └── com └── xatu └── jdkill └── test ├── HttpUrlConnectionUtil.java ├── Login.java ├── RushToPurchase.java └── Start.java /1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mcpadso2rek/183917134345/8250b90edf60aa05b4ffd78cbf1d02e22d00a9ec/1.png -------------------------------------------------------------------------------- /2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mcpadso2rek/183917134345/8250b90edf60aa05b4ffd78cbf1d02e22d00a9ec/2.png -------------------------------------------------------------------------------- /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 | # Jd-Pruchase-Kill-dev 2 | 京东茅台抢购最新优化Java版本,京东秒杀,添加误差时间调整,优化了茅台抢购进程队列 . 在程序开始运行后,会检测本地时间与京东服务器时间,输出的差值为本地时间-京东服务器时间,即-50为本地时间比京东服务器时间慢50ms。 本代码的执行的抢购时间以本地电脑/服务器时间为准 3 | 4 | # Jd-Pruchase-Kill 5 | 6 | ### 扫码登陆 7 | 8 | Start.class是程序入口 9 | 10 | 11 | ### 需要设置 12 | 13 | 商品id pid; 14 | 15 | eid = ""; 16 | 17 | fp = ""; 18 | 19 | 商品id为商品详情url中的一串数字 20 | 21 | eid以及fp在订单结算页面 https://trade.jd.com/shopping/order/getOrderInfo.action 22 | 23 | F12打开console,输入_JdTdudfp 24 | 25 | 26 | 或者F12打开Sources,添加_JdTdudfp参数 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | Jd-Pruchase-Kill 8 | Jd-Pruchase-Kill 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 13 | org.apache.maven.plugins 14 | maven-compiler-plugin 15 | 16 | 8 17 | 8 18 | 19 | 20 | 21 | 22 | 23 | 24 | net.java.dev.jna 25 | jna 26 | 5.0.0 27 | 28 | 29 | net.java.dev.jna 30 | jna-platform 31 | 5.0.0 32 | 33 | 34 | com.alibaba 35 | fastjson 36 | 1.2.62 37 | 38 | 39 | org.apache.httpcomponents 40 | httpclient 41 | 4.5.13 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /src/main/java/com/xatu/jdkill/test/HttpUrlConnectionUtil.java: -------------------------------------------------------------------------------- 1 | package com.xatu.jdkill.test; 2 | 3 | import com.alibaba.fastjson.JSONObject; 4 | 5 | import java.io.*; 6 | import java.net.HttpURLConnection; 7 | import java.net.URL; 8 | import java.text.ParseException; 9 | import java.text.SimpleDateFormat; 10 | import java.util.ArrayList; 11 | import java.util.Date; 12 | import java.util.Iterator; 13 | 14 | /** 15 | * @author: lianghuan 16 | * @date: 2021/1/5 22:26 17 | */ 18 | public class HttpUrlConnectionUtil { 19 | /** 20 | * get请求 21 | * 22 | * @param headers 请求头,可为空 23 | * @param url 24 | * @return 25 | * @throws IOException 26 | */ 27 | public static String get(JSONObject headers, String url) throws IOException { 28 | String response = ""; 29 | HttpURLConnection httpURLConnection = (HttpURLConnection) (new URL(url).openConnection()); 30 | httpURLConnection.setRequestMethod("GET"); 31 | if (headers != null) { 32 | Iterator iterator = headers.keySet().iterator(); 33 | while (iterator.hasNext()) { 34 | String headerName = iterator.next(); 35 | httpURLConnection.setRequestProperty(headerName, headers.get(headerName).toString()); 36 | } 37 | } 38 | httpURLConnection.connect(); 39 | if (httpURLConnection.getResponseCode() == 200) { 40 | InputStream inputStream = httpURLConnection.getInputStream(); 41 | byte[] buffer; 42 | buffer = new byte[1024]; 43 | int length = 0; 44 | while ((length = inputStream.read(buffer)) != -1) { 45 | response = response + new String(buffer, 0, length, "UTF-8"); 46 | } 47 | httpURLConnection.disconnect(); 48 | } 49 | return response; 50 | } 51 | 52 | /** 53 | * post请求 54 | * 55 | * @param headers 请求头,可为空 56 | * @param url 57 | * @param params post请求体,可为空 58 | * @return 59 | * @throws IOException 60 | */ 61 | public static String post(JSONObject headers, String url, JSONObject params) throws IOException { 62 | String response = ""; 63 | HttpURLConnection httpURLConnection = (HttpURLConnection) (new URL(url).openConnection()); 64 | httpURLConnection.setRequestMethod("POST"); 65 | if (headers != null) { 66 | Iterator iterator = headers.keySet().iterator(); 67 | while (iterator.hasNext()) { 68 | String headerName = iterator.next(); 69 | httpURLConnection.setRequestProperty(headerName, headers.get(headerName).toString()); 70 | } 71 | } 72 | httpURLConnection.setDoOutput(true); 73 | httpURLConnection.connect(); 74 | if (params != null) { 75 | httpURLConnection.getOutputStream().write(params.toJSONString().getBytes("UTF-8")); 76 | } 77 | httpURLConnection.getInputStream(); 78 | if (httpURLConnection.getResponseCode() == 200) { 79 | InputStream inputStream = httpURLConnection.getInputStream(); 80 | byte[] buffer; 81 | buffer = new byte[1024]; 82 | int length = 0; 83 | while ((length = inputStream.read(buffer)) != -1) { 84 | response = response + new String(buffer, 0, length, "UTF-8"); 85 | } 86 | httpURLConnection.disconnect(); 87 | } 88 | httpURLConnection.disconnect(); 89 | return response; 90 | } 91 | 92 | /** 93 | * 获取并保存二维码 94 | * 95 | * @param headers 96 | * @param url 97 | * @return 98 | * @throws IOException 99 | */ 100 | public static String getQCode(JSONObject headers, String url) throws IOException { 101 | String response = ""; 102 | HttpURLConnection httpURLConnection = (HttpURLConnection) (new URL(url).openConnection()); 103 | httpURLConnection.setRequestMethod("GET"); 104 | if (headers != null) { 105 | Iterator iterator = headers.keySet().iterator(); 106 | while (iterator.hasNext()) { 107 | String headerName = iterator.next(); 108 | httpURLConnection.setRequestProperty(headerName, headers.get(headerName).toString()); 109 | } 110 | } 111 | httpURLConnection.connect(); 112 | if (httpURLConnection.getResponseCode() == 200) { 113 | InputStream inputStream = httpURLConnection.getInputStream(); 114 | OutputStream outputStream = new FileOutputStream("QCode.png"); 115 | byte[] buffer; 116 | int length; 117 | buffer = new byte[1024]; 118 | while ((length = inputStream.read(buffer)) != -1) { 119 | outputStream.write(buffer, 0, length); 120 | response = response + new String(buffer, 0, length, "UTF-8"); 121 | } 122 | outputStream.close(); 123 | httpURLConnection.disconnect(); 124 | } 125 | return response; 126 | } 127 | 128 | /** 129 | * date字符串转时间戳 130 | * 131 | * @param date 132 | * @return 133 | */ 134 | public static Long dateToTime(String date) throws ParseException { 135 | SimpleDateFormat sdfTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 136 | Date data = sdfTime.parse(date); 137 | Long time = data.getTime(); 138 | return time; 139 | } 140 | 141 | /** 142 | * time时间戳转Date 143 | * 144 | * @param time 145 | * @return 146 | */ 147 | public static Date timeToDate(String time) { 148 | SimpleDateFormat sdfTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 149 | String str = sdfTime.format(Long.valueOf(time)); 150 | try { 151 | Date date = sdfTime.parse(str); 152 | return date; 153 | } catch (ParseException e) { 154 | e.printStackTrace(); 155 | } 156 | return null; 157 | } 158 | 159 | public static ArrayList ips() throws IOException { 160 | String path = "http://api.xiequ.cn/VAD/GetIp.aspx?act=get&num=1&time=30&plat=1&re=0&type=0&so=1&ow=1&spl=1&addr=&db=1";// 要获得html页面内容的地址 161 | 162 | URL url = new URL(path);// 创建url对象 163 | 164 | HttpURLConnection conn = (HttpURLConnection) url.openConnection();// 打开连接 165 | conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)"); 166 | conn.setRequestProperty("contentType", "GBK"); // 设置url中文参数编码 167 | 168 | conn.setConnectTimeout(5 * 1000);// 请求的时间 169 | 170 | conn.setRequestMethod("GET");// 请求方式 171 | 172 | InputStream inStream = conn.getInputStream(); 173 | // readLesoSysXML(inStream); 174 | 175 | BufferedReader in = new BufferedReader(new InputStreamReader(inStream, "GBK")); 176 | StringBuffer buffer = new StringBuffer(); 177 | ArrayList ipp = new ArrayList(); 178 | String line = ""; 179 | // 读取获取到内容的最后一行,写入 180 | while ((line = in.readLine()) != null) { 181 | buffer.append(line); 182 | ipp.add(line); 183 | System.out.println(line); 184 | } 185 | String str = buffer.toString(); 186 | // JSONObject json1 = JSONObject.parseObject(str); 187 | // JSONArray jsons = JSONArray.parseArray(json1.get("data").toString()); 188 | 189 | // for(Object json:jsons){ 190 | // JSONObject ips = JSONObject.parseObject(json.toString()); 191 | // String ip = ips.get("IP").toString(); 192 | // System.out.println(ip); 193 | // ipp.add(ip); 194 | // } 195 | return ipp; 196 | 197 | } 198 | 199 | } 200 | -------------------------------------------------------------------------------- /src/main/java/com/xatu/jdkill/test/Login.java: -------------------------------------------------------------------------------- 1 | package com.xatu.jdkill.test; 2 | 3 | import com.alibaba.fastjson.JSONObject; 4 | import com.sun.jna.Native; 5 | import com.sun.jna.Pointer; 6 | import com.sun.jna.platform.win32.User32; 7 | import com.sun.jna.platform.win32.WinDef; 8 | import com.sun.jna.platform.win32.WinUser; 9 | 10 | import java.io.IOException; 11 | import java.net.URI; 12 | import java.net.URISyntaxException; 13 | import java.util.HashMap; 14 | import java.util.List; 15 | import java.util.Map; 16 | 17 | /** 18 | * @author: lianghuan 19 | * @date: 2021/1/9 18:59 20 | */ 21 | public class Login { 22 | static String venderId = ""; 23 | static Map> requestHeaders = new HashMap>(16); 24 | static String ticket = ""; 25 | 26 | public static void Login() throws IOException, URISyntaxException, InterruptedException { 27 | JSONObject headers = new JSONObject(); 28 | headers.put(Start.headerAgent, Start.headerAgentArg); 29 | headers.put(Start.Referer, Start.RefererArg); 30 | //获取二维码 31 | Long now = System.currentTimeMillis(); 32 | HttpUrlConnectionUtil.getQCode(headers, "https://qr.m.jd.com/show?appid=133&size=147&t=" + now); 33 | //打开二维码 34 | Runtime.getRuntime().exec("cmd /c QCode.png"); 35 | URI url = new URI("https://qr.m.jd.com/show?appid=133&size=147&t=" + now); 36 | Map> stringListMap = new HashMap>(); 37 | stringListMap = Start.manager.get(url, requestHeaders); 38 | List cookieList = stringListMap.get("Cookie"); 39 | String cookies = cookieList.get(0).toString(); 40 | String token = cookies.split("wlfstk_smdl=")[1]; 41 | headers.put("Cookie", cookies); 42 | //判断是否扫二维码 43 | while (true) { 44 | String checkUrl = "https://qr.m.jd.com/check?appid=133&callback=jQuery" + (int) ((Math.random() * (9999999 - 1000000 + 1)) + 1000000) + "&token=" + token + "&_=" + System.currentTimeMillis(); 45 | String qrCode = HttpUrlConnectionUtil.get(headers, checkUrl); 46 | if (qrCode.indexOf("二维码未扫描") != -1) { 47 | System.out.println("二维码未扫描,请扫描二维码登录"); 48 | } else if (qrCode.indexOf("请手机客户端确认登录") != -1) { 49 | System.out.println("请手机客户端确认登录"); 50 | } else { 51 | ticket = qrCode.split("\"ticket\" : \"")[1].split("\"\n" + 52 | "}\\)")[0]; 53 | System.out.println("已完成二维码扫描登录"); 54 | close(); 55 | break; 56 | } 57 | Thread.sleep(3000); 58 | } 59 | //验证,获取cookie 60 | String qrCodeTicketValidation = HttpUrlConnectionUtil.get(headers, "https://passport.jd.com/uc/qrCodeTicketValidation?t=" + ticket); 61 | stringListMap = Start.manager.get(url, requestHeaders); 62 | cookieList = stringListMap.get("Cookie"); 63 | cookies = cookieList.get(0).toString(); 64 | headers.put("Cookie", cookies); 65 | } 66 | 67 | public static void close() throws IOException, InterruptedException { 68 | // 通过窗口标题获取窗口句柄 69 | WinDef.HWND hWnd; 70 | final User32 user32 = User32.INSTANCE; 71 | user32.EnumWindows(new WinUser.WNDENUMPROC() { 72 | @Override 73 | public boolean callback(WinDef.HWND hWnd, Pointer arg1) { 74 | char[] windowText = new char[512]; 75 | user32.GetWindowText(hWnd, windowText, 512); 76 | String wText = Native.toString(windowText); 77 | // get rid of this if block if you want all windows regardless of whether 78 | // or not they have text 79 | if (wText.isEmpty()) { 80 | return true; 81 | } 82 | if (wText.contains("照片")) { 83 | hWnd = User32.INSTANCE.FindWindow(null, wText); 84 | WinDef.LRESULT lresult = User32.INSTANCE.SendMessage(hWnd, 0X10, null, null); 85 | } 86 | return true; 87 | } 88 | }, null); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/main/java/com/xatu/jdkill/test/RushToPurchase.java: -------------------------------------------------------------------------------- 1 | package com.xatu.jdkill.test; 2 | 3 | import com.alibaba.fastjson.JSONObject; 4 | 5 | import java.io.IOException; 6 | import java.net.URI; 7 | import java.net.URISyntaxException; 8 | import java.util.HashMap; 9 | import java.util.List; 10 | import java.util.Map; 11 | 12 | 13 | /** 14 | * @author: lianghuan 15 | * @date: 2021/1/8 20:51 16 | */ 17 | public class RushToPurchase implements Runnable { 18 | //请求头 19 | volatile static Integer times = 0; 20 | static Map> stringListMap = new HashMap>(); 21 | 22 | public void run() { 23 | JSONObject headers = new JSONObject(); 24 | while (times < Start.ok) { 25 | //获取ip,使用的是免费的 携趣代理 ,不需要或者不会用可以注释掉 26 | setIpProxy(); 27 | 28 | headers.put(Start.headerAgent, Start.headerAgentArg); 29 | headers.put(Start.Referer, Start.RefererArg); 30 | //抢购 31 | String gate = null; 32 | try { 33 | gate = HttpUrlConnectionUtil.get(headers, "https://cart.jd.com/gate.action?pcount=1&ptype=1&pid=" + Start.pid); 34 | } catch (IOException e) { 35 | e.printStackTrace(); 36 | } 37 | //订单信息 38 | stringListMap.clear(); 39 | try { 40 | stringListMap = Start.manager.get(new URI("https://trade.jd.com/shopping/order/getOrderInfo.action"), stringListMap); 41 | } catch (URISyntaxException e) { 42 | e.printStackTrace(); 43 | } 44 | List cookie = stringListMap.get("Cookie"); 45 | headers.put("Cookie", cookie.get(0).toString()); 46 | try { 47 | String orderInfo = HttpUrlConnectionUtil.get(headers, "https://trade.jd.com/shopping/order/getOrderInfo.action"); 48 | } catch (IOException e) { 49 | e.printStackTrace(); 50 | } 51 | //提交订单 52 | JSONObject subData = new JSONObject(); 53 | headers = new JSONObject(); 54 | subData.put("overseaPurchaseCookies", ""); 55 | subData.put("vendorRemarks", "[]"); 56 | subData.put("submitOrderParam.sopNotPutInvoice", "false"); 57 | subData.put("submitOrderParam.ignorePriceChange", "1"); 58 | subData.put("submitOrderParam.btSupport", "0"); 59 | subData.put("submitOrderParam.isBestCoupon", "1"); 60 | subData.put("submitOrderParam.jxj", "1"); 61 | subData.put("submitOrderParam.trackID", Login.ticket); 62 | subData.put("submitOrderParam.eid", Start.eid); 63 | subData.put("submitOrderParam.fp", Start.fp); 64 | subData.put("submitOrderParam.needCheck", "1"); 65 | 66 | headers.put("Referer", "http://trade.jd.com/shopping/order/getOrderInfo.action"); 67 | headers.put("origin", "https://trade.jd.com"); 68 | headers.put("Content-Type", "application/json"); 69 | headers.put("x-requested-with", "XMLHttpRequest"); 70 | headers.put("upgrade-insecure-requests", "1"); 71 | headers.put("sec-fetch-user", "?1"); 72 | stringListMap.clear(); 73 | try { 74 | stringListMap = Start.manager.get(new URI("https://trade.jd.com/shopping/order/getOrderInfo.action"), stringListMap); 75 | } catch (URISyntaxException e) { 76 | e.printStackTrace(); 77 | } 78 | cookie = stringListMap.get("Cookie"); 79 | headers.put("Cookie", cookie.get(0).toString()); 80 | String submitOrder = null; 81 | try { 82 | if (times < Start.ok) { 83 | submitOrder = HttpUrlConnectionUtil.post(headers, "https://trade.jd.com/shopping/order/submitOrder.action", null); 84 | } else { 85 | System.out.println("已抢购" + Start.ok + "件,请尽快完成付款"); 86 | break; 87 | } 88 | } catch (IOException e) { 89 | e.printStackTrace(); 90 | } 91 | if (submitOrder.contains("刷新太频繁了") || submitOrder.contains("抱歉,您访问的内容不存在")) { 92 | System.out.println("刷新太频繁了,您访问的内容不存在"); 93 | continue; 94 | } 95 | JSONObject jsonObject = JSONObject.parseObject(submitOrder); 96 | String success = null; 97 | String message = null; 98 | if (jsonObject != null && jsonObject.get("success") != null) { 99 | success = jsonObject.get("success").toString(); 100 | } 101 | if (jsonObject != null && jsonObject.get("message") != null) { 102 | message = jsonObject.get("message").toString(); 103 | } 104 | 105 | if (success == "true") { 106 | System.out.println("抢购成功,请尽快完成付款"); 107 | times++; 108 | } else { 109 | if (message != null) { 110 | System.out.println(message); 111 | } else if (submitOrder.contains("很遗憾没有抢到")) { 112 | System.out.println("很遗憾没有抢到,再接再厉哦"); 113 | } else if (submitOrder.contains("抱歉,您提交过快,请稍后再提交订单!")) { 114 | System.out.println("抱歉,您提交过快,请稍后再提交订单!"); 115 | } else if (submitOrder.contains("系统正在开小差,请重试~~")) { 116 | System.out.println("系统正在开小差,请重试~~"); 117 | } else if (submitOrder.contains("您多次提交过快")) { 118 | System.out.println("您多次提交过快,请稍后再试"); 119 | } else { 120 | System.out.println("获取用户订单信息失败"); 121 | } 122 | } 123 | } 124 | } 125 | 126 | public static void setIpProxy() { 127 | String ip = null; 128 | try { 129 | ip = HttpUrlConnectionUtil.ips().get(0); 130 | } catch (IOException e) { 131 | e.printStackTrace(); 132 | } 133 | String[] r1 = ip.split(":"); 134 | System.out.println(ip); 135 | System.getProperties().setProperty("http.proxyHost", r1[0]); 136 | System.getProperties().setProperty("http.proxyPort", r1[1]); 137 | System.err.println(r1[0] + ":" + r1[1]); 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /src/main/java/com/xatu/jdkill/test/Start.java: -------------------------------------------------------------------------------- 1 | package com.xatu.jdkill.test; 2 | 3 | import com.alibaba.fastjson.JSONObject; 4 | import com.sun.webkit.network.CookieManager; 5 | 6 | import java.io.IOException; 7 | import java.net.CookieHandler; 8 | import java.net.URISyntaxException; 9 | import java.text.ParseException; 10 | import java.util.concurrent.Executors; 11 | import java.util.concurrent.PriorityBlockingQueue; 12 | import java.util.concurrent.ThreadPoolExecutor; 13 | import java.util.concurrent.TimeUnit; 14 | 15 | /** 16 | * @author: lianghuan 17 | * @date: 2021/1/8 20:59 18 | */ 19 | public class Start { 20 | final static String headerAgent = "User-Agent"; 21 | final static String headerAgentArg = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.135 Safari/537.36"; 22 | final static String Referer = "Referer"; 23 | final static String RefererArg = "https://passport.jd.com/new/login.aspx"; 24 | //商品id 25 | static String pid = "30425081079"; 26 | //eid 27 | static String eid = "W2HEXZSRULGOBXAMFF6J44UTIGCP5QGKRQO5M7KZHYUAU7RT2JBTXRG2ZNRUWHKYX2PHNKRJI2KOM7BZIZ2V3F3C64"; 28 | //fp 29 | static String fp = "4ce08fcab2f99f47724c9c7cdf771d9f"; 30 | //抢购数量 31 | volatile static Integer ok = 2; 32 | 33 | static CookieManager manager = new CookieManager(); 34 | 35 | 36 | public static void main(String[] args) throws IOException, URISyntaxException, InterruptedException, ParseException { 37 | CookieHandler.setDefault(manager); 38 | //获取venderId 39 | // String shopDetail = util.get(null, "https://item.jd.com/" + RushToPurchase.pid + ".html"); 40 | // String venderID = shopDetail.split("isClosePCShow: false,\n" + 41 | // " venderId:")[1].split(",")[0]; 42 | // RushToPurchase.venderId = venderID; 43 | //登录 44 | Login.Login(); 45 | //判断是否开始抢购 46 | judgePruchase(); 47 | //开始抢购 48 | ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(5, 10, 1000, TimeUnit.MILLISECONDS, new PriorityBlockingQueue(), Executors.defaultThreadFactory(), new ThreadPoolExecutor.AbortPolicy()); 49 | for (int i = 0; i < 5; i++) { 50 | threadPoolExecutor.execute(new RushToPurchase()); 51 | } 52 | new RushToPurchase().run(); 53 | } 54 | 55 | public static void judgePruchase() throws IOException, ParseException, InterruptedException { 56 | //获取开始时间 57 | JSONObject headers = new JSONObject(); 58 | headers.put(Start.headerAgent, Start.headerAgentArg); 59 | headers.put(Start.Referer, Start.RefererArg); 60 | JSONObject shopDetail = JSONObject.parseObject(HttpUrlConnectionUtil.get(headers, "https://item-soa.jd.com/getWareBusiness?skuId=" + pid)); 61 | if (shopDetail.get("yuyueInfo") != null) { 62 | String buyDate = JSONObject.parseObject(shopDetail.get("yuyueInfo").toString()).get("buyTime").toString(); 63 | String startDate = buyDate.split("-202")[0] + ":00"; 64 | Long startTime = HttpUrlConnectionUtil.dateToTime(startDate); 65 | //开始抢购 66 | while (true) { 67 | //获取京东时间 68 | JSONObject jdTime = JSONObject.parseObject(HttpUrlConnectionUtil.get(headers, "https://a.jd.com//ajax/queryServerData.html")); 69 | Long serverTime = Long.valueOf(jdTime.get("serverTime").toString()); 70 | if (startTime >= serverTime) { 71 | System.out.println("正在等待抢购时间"); 72 | Thread.sleep(300); 73 | } else { 74 | break; 75 | } 76 | } 77 | } 78 | } 79 | } 80 | --------------------------------------------------------------------------------