package com.oceanzhang.bubblemovie;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.oceanzhang.bubblemovie.util.Base64;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.apache.commons.codec.binary.Hex;
import org.apache.http.util.TextUtils;
import javax.net.ssl.*;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.security.SecureRandom;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
public class MtopRequest {
static OkHttpClient httpClient = getTrustAllClient();
static final String IP = "192.168.102.10";
public static String getMtopApiSign(HashMap<String, String> data, String appKey, String authCode) throws IOException {
Request.Builder req = new Request.Builder()
.url("http://" + IP + ":3296/getMtopApiSign/");
FormBody formBody = new FormBody.Builder()
.add("appKey", appKey)
.add("data", Hex.encodeHexString(JSONObject.toJSONString(data).getBytes())).build();
String sign = httpClient.newCall(req.post(formBody).build()).execute().body().string();
System.out.println("sign->" + sign);
return sign;
}
public static String getSecBodyDataEx(HashMap<String, String> data, String time, String appKey, String authCode) throws IOException {
Request.Builder req = new Request.Builder()
.url("http://" + IP + ":3296/getSecBodyDataEx/");
FormBody formBody = new FormBody.Builder()
.add("time", time)
.add("appKey", appKey)
.add("data", Hex.encodeHexString(JSONObject.toJSONString(data).getBytes())).build();
String miua = httpClient.newCall(req.post(formBody).build()).execute().body().string();
System.out.println("miua->" + miua);
return miua;
}
public static String getAvmpSign(String sign, String authCode) throws IOException {
Request.Builder req = new Request.Builder()
.url("http://" + IP + ":3296/getAvmpSign/");
FormBody formBody = new FormBody.Builder()
.add("sign", sign).build();
String miua = httpClient.newCall(req.post(formBody).build()).execute().body().string();
System.out.println("avmpsign->" + miua);
return miua;
}
public static void main(String... args) throws Exception {
String mainItemId = "601263739214";
String cookie = "munb=3728076965; cookie2=160c27584179ebd097d17a6191f385a2; csg=c5e3a02a; t=8322e990376e064ab275707b3f5be0bc; _tb_token_=3838618e1147; munb=3728076965; cookie2=160c27584179ebd097d17a6191f385a2; csg=c5e3a02a; t=8322e990376e064ab275707b3f5be0bc; _tb_token_=3838618e1147";
String dm_header_loginkey = "fb3bc90ab42d4b8a8e1d57248ebfbbf7_3_2";
while (true) {
String buyParams = "";
try {
JSONObject data = JSONObject.parseObject("{\"appType\":\"1\",\"source\":\"10101\",\"itemId\":\"" + mainItemId + "\",\"osType\":\"2\",\"version\":\"6000051\",\"channel_from\":\"damai_market\"}");
Map<String, String> params = new HashMap<>();
params.put("source", "10101");
params.put("data", data.toJSONString());
params.put("appType", "1");
params.put("osType", "2");
params.put("version", "6000051");
params.put("channel_from", "damai_market");
params.put("type", "originaljson");
JSONObject obj = mtop("https://acs.m.taobao.com/gw/",
"mtop.alibaba.damai.detail.getdetail",
"1.2",
"POST",
cookie,
data.toJSONString(),
params
);
String result = obj.getString("result");
if (TextUtils.isEmpty(result)) {
continue;
}
obj = JSONObject.parseObject(result);
List<String> prices = new ArrayList<>();
// prices.add("221808001");
// prices.add("221789012");
//优先选择抢购的价格类型
prices.add("221800200");
prices.add("221800198");
prices.add("221800199");
prices.add("221800201");
prices.add("221800202");
prices.add("221800197");
System.out.println(obj.toJSONString());
JSONObject item = obj.getJSONObject("detailViewComponentMap").getJSONObject("item").getJSONObject("item");
System.out.println(item.getString("buyBtnText"));
// if (item.getString("buyBtnText").equals("即将开售")) {
if (item.getString("buyBtnText").equals("立即购买") || item.getString("buyBtnText").equals("立即预订")) {
//哪些座位类型
JSONArray skuList = item.getJSONArray("performBases").getJSONObject(0).getJSONArray("performs").getJSONObject(0).getJSONArray("skuList");
String itemId = item.getJSONArray("performBases").getJSONObject(0).getJSONArray("performs").getJSONObject(0).getString("itemId");
List<JSONObject> skus = new ArrayList<>();
for (int i = 0; i < skuList.size(); i++) {
JSONObject sku = skuList.getJSONObject(i);
boolean skuEnable = sku.getBooleanValue("skuEnable");
if (skuEnable) {
skus.add(sku);
} else {
System.out.println("没票了->" + sku.getDoubleValue("price"));
}
}
out:
for (String id : prices) {
for (JSONObject sku : skus) {
String skuId = sku.getString("skuId");
double price = sku.getDoubleValue("price");
String priceId = sku.getString("priceId");
System.out.println("priceId->" + priceId + " price->" + price);
if (priceId.equals(id)) {
System.out.println("抢:" + price);
buyParams = itemId + "_1_" + skuId;
break out;
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
if (TextUtils.isEmpty(buyParams)) {
continue;
}
try {
JSONObject _data = JSONObject.parseObject("{\"buyNow\":\"true\",\"exParams\":\"{\\\"seatInfo\\\":\\\"\\\",\\\"umpChannel\\\":\\\"10001\\\",\\\"atomSplit\\\":\\\"1\\\",\\\"channel\\\":\\\"damai_app\\\"}\",\"buyParam\":\"" + buyParams + "\"}");
Map<String, String> mainparams = new HashMap<>();
mainparams.put("source", "10101");
mainparams.put("appType", "1");
mainparams.put("osType", "2");
mainparams.put("version", "6000051");
mainparams.put("channel_from", "damai_market");
mainparams.put("type", "originaljson");
mainparams.put("data", _data.toJSONString());
JSONObject obj = mtop("https://mtop.damai.cn/gw/",
"mtop.tra
- 1
- 2
- 3
前往页