本帖最后由 qiucx 于 2021-4-2 14:06 编辑
关于某仙网抢茅台的协议分析和源代码 https://www.52pojie.cn/thread-1396064-1-1.html
发布后,得到很多网友的支持,但很多网友不理解怎么写,现提供部分源码供研究,请勿用于商业用途,否则后果自负。
[Java] 纯文本查看 复制代码 Date deadDate = getDeadline();
String token = "";
while (true) {
// login the system before buying 12 seconds.
if ((deadDate.getTime() - new Date().getTime()) / 1000 > 20) {
System.out.println("Going to sleep 5 second...");
Thread.sleep(5000);
continue;
}
System.out.println("Starting to login system...");
token = login();
cookie = cookie + token;
// preReservationOrderUrl = (preReservationOrderUrl +
// token).replace("APPKEYXXX", appkey).replace("PUSHTOKENXXX",
// pushToken);
settlementUrl = (settlementUrl + token).replace("APPKEYXXX", appkey).replace("PUSHTOKENXXX", pushToken);
// getAccountSecurityUrl = (getAccountSecurityUrl+
// token).replace("APPKEYXXX", appkey).replace("PUSHTOKENXXX",
// pushToken);
// collectUrl = (collectUrl + token).replace("APPKEYXXX",
// appkey);//.replace("PUSHTOKENXXX", pushToken);
System.out.println("ANDROID" + URLDecoder.decode(appkey, "UTF-8") + DEVICE_ID);
// //System.out.println(MD5Util.encode("ANDROID" +
// URLDecoder.decode(appkey, "UTF-8") + DEVICE_ID));
orderUrl = (orderUrl + token)
.replace("APPKEYXXX", appkey)
.replace("PUSHTOKENXXX", pushToken)
.replace("RESERVATIONTOKENXXX",
JiuXianWebMd5.encode("ANDROID" + URLDecoder.decode(appkey, "UTF-8") + DEVICE_ID));
// reservationProDetailURL = (reservationProDetailURL +
// token).replace("APPKEYXXX", appkey).replace("PUSHTOKENXXX",
// pushToken);
// cookie = cookie+token;
System.out.println("settlementUrl= " + settlementUrl);
System.out.println("ordertUrl= " + orderUrl);
break;
}
while (true) {
System.out.println("========The server date is ===========" + new Date());
// long internal = sysTime - new Date().getTime();
if (new Date().getTime() > deadDate.getTime()) {
settlement(settlementUrl);
// for (int i = 0; i < 100; i++) {
while (true) {
JiuXianWebAndroid.getInstance().httpAsyncSendByMap();
// Thread.sleep(1111111);
}
} }
[Java] 纯文本查看 复制代码 private static String login() {
String url = "";
String urlConf = config.get("LoginURL");
if (urlConf != null && urlConf.trim().length() > 0) {
url = urlConf;
}
url = url.replace("APPKEYXXX", appkey).replace("PUSHTOKENXXX", pushToken);
//System.out.println("loginUrl==" + url);
HttpPost post = new HttpPost(url);
post.setHeader("Content-Type", contentType);
post.setHeader("Accept", accept);
post.setHeader("User-Agent", agent);
post.setHeader("Cookie", cookie);
try {
HttpResponse response = httpClient.execute(post);
HttpEntity entitys = response.getEntity();
if (entitys != null) {
InputStream instream = entitys.getContent();
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
byte[] data = new byte[1024];
int count = -1;
while ((count = instream.read(data, 0, 1024)) != -1)
outStream.write(data, 0, count);
data = null;
String ret = new String(outStream.toByteArray(), "utf-8");
//System.out.println(ret);
JSONObject jsonArray = JSONObject.fromObject(ret);
String token = "";
try {
token = jsonArray.getJSONObject("result").getJSONObject("userInfo").getString("token");
} catch (Exception e) {
int idx = ret.indexOf("\"token\":\"");
token = ret.substring(idx + 9, idx + 50);
}
System.out.println("Login successfully and the return token is : " + token);
return token;
}
} catch (Exception e) {
e.printStackTrace();
// break;
}
return null;
}
[Java] 纯文本查看 复制代码 private static void settlement(String setUrl) {
HttpPost post = new HttpPost(setUrl);
post.setHeader("Content-Type", contentType);
post.setHeader("Accept", accept);
post.setHeader("User-Agent", agent);
post.setHeader("Cookie", cookie);
try {
while (true) {
HttpResponse response = httpClient.execute(post);
HttpEntity entitys = response.getEntity();
if (entitys != null) {
InputStream instream = entitys.getContent();
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
byte[] data = new byte[1024];
int count = -1;
while ((count = instream.read(data, 0, 1024)) != -1)
outStream.write(data, 0, count);
data = null;
String ret = new String(outStream.toByteArray(), "utf-8");
JSONObject jsonArray = JSONObject.fromObject(ret);
System.out.println("settlement response============" + ret);
JSONArray arr = jsonArray.getJSONObject("result").getJSONObject("productsList").getJSONArray("unableProducts");
if(arr.size() == 0) {
break;
}
}
Thread.sleep(80);
}
} catch (Exception e) {
e.printStackTrace();
}
}
[Java] 纯文本查看 复制代码 private static void order(String orderUrl) {
//System.out.println("settlementUrl=" + setUrl + ", orderUrl=" + orderUrl);
/* HttpPost post = new HttpPost(setUrl);
post.setHeader("Content-Type", contentType);
post.setHeader("Accept", accept);
post.setHeader("User-Agent", agent);
post.setHeader("Cookie", cookie);
try {
HttpResponse response = httpClient.execute(post);
HttpEntity entitys = response.getEntity();
if (entitys != null) {
InputStream instream = entitys.getContent();
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
byte[] data = new byte[1024];
int count = -1;
while ((count = instream.read(data, 0, 1024)) != -1)
outStream.write(data, 0, count);
data = null;
String ret = new String(outStream.toByteArray(), "utf-8");
System.out.println("settlement response============" + ret);
}
} catch (Exception e) {
e.printStackTrace();
}*/
HttpPost post = new HttpPost(orderUrl);
post.setHeader("Content-Type", contentType);
post.setHeader("Accept", accept);
post.setHeader("User-Agent", agent);
post.setHeader("Cookie", cookie);
try {
HttpResponse response = httpClient.execute(post);
HttpEntity entitys = response.getEntity();
if (entitys != null) {
InputStream instream = entitys.getContent();
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
byte[] data = new byte[1024];
int count = -1;
while ((count = instream.read(data, 0, 1024)) != -1)
outStream.write(data, 0, count);
data = null;
String ret = new String(outStream.toByteArray(), "utf-8");
System.out.println("Order response============" + ret);
}
} catch (Exception e) {
e.printStackTrace();
}
}
打字不易,有帮助就点个赞,加个分。 |