[Java] 小米抢购源码 →→→→→进入此内容的聊天室

来自 , 2020-06-02, 写在 Java, 查看 147 次.
URL http://www.code666.cn/view/f4dd765c
  1. using System;
  2. using System.Threading.Tasks;
  3. using System.Windows.Forms;
  4. using System.Timers;
  5. using Newtonsoft.Json;
  6. using System.Text.RegularExpressions;
  7. using System.Configuration;
  8. using System.Linq;
  9. using HtmlAgilityPack;
  10. using System.Collections.Generic;
  11. using System.Web;
  12. namespace xiaomi
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.         private static System.Timers.Timer _queuetimer;
  17.         private static string cookies = string.Empty;      //公有Cookie
  18.         private static string codeCookie = string.Empty;
  19.         public Form1()
  20.         {
  21.             InitializeComponent();
  22.             txtUserName.Text = ConfigurationManager.AppSettings["userName"].ToString();
  23.             txtPwd.Text = ConfigurationManager.AppSettings["userPwd"].ToString();
  24.         }
  25.  
  26.         private void btnStart_Click(object sender, EventArgs e)
  27.         {
  28.             if (checkBox1.Checked)
  29.             {
  30.                 int t = Convert.ToInt32(txtMilliseconds.Text);
  31.                 TimerStart(t);
  32.             }
  33.             else
  34.             {
  35.                 QiangGou();
  36.             }
  37.  
  38.             btnStart.Enabled = false;
  39.             btnStop.Enabled = true;
  40.         }
  41.  
  42.         private void btnStop_Click(object sender, EventArgs e)
  43.         {
  44.             TimerStop();
  45.             btnStart.Enabled = true;
  46.             btnStop.Enabled = false;
  47.         }
  48.  
  49.         public void TimerStart(int Interval)
  50.         {
  51.             if (_queuetimer == null)
  52.             {
  53.                 _queuetimer = new System.Timers.Timer();
  54.             }
  55.             else
  56.             {
  57.                 _queuetimer.Close(); _queuetimer = new System.Timers.Timer();
  58.             }
  59.  
  60.  
  61.  
  62.             _queuetimer.Interval = Interval;
  63.             _queuetimer.Elapsed += (sender, e) => _queuetimer_Elapsed(sender, e);
  64.  
  65.             _queuetimer.AutoReset = true;
  66.             _queuetimer.Enabled = true;
  67.         }
  68.  
  69.  
  70.         public void TimerStop()
  71.         {
  72.             if (_queuetimer != null)
  73.             {
  74.                 _queuetimer.Enabled = false;
  75.                 _queuetimer.Stop();
  76.                 _queuetimer.Close();
  77.             }
  78.  
  79.         }
  80.  
  81.         void _queuetimer_Elapsed(object sender, ElapsedEventArgs e)
  82.         {
  83.             Parallel.Invoke(CreateTaskArray(10, QiangGou));
  84.         }
  85.  
  86.         /// <summary>
  87.         /// 创建多个任务
  88.         /// </summary>
  89.         /// <param name="taskCount"></param>
  90.         /// <returns></returns>
  91.         private static Action[] CreateTaskArray(int taskCount, Action Dequeue)
  92.         {
  93.             var actions = new Action[taskCount];
  94.             for (int i = 0; i < taskCount; i++)
  95.             {
  96.                 actions[i] = Dequeue;
  97.             }
  98.             return actions;
  99.         }
  100.  
  101.         public void QiangGou()
  102.         {
  103.  
  104.             //AppendText(cookies);//打印
  105.             HttpHelper http = new HttpHelper();
  106.             HttpItem item = new HttpItem()
  107.             {
  108.                 URL = "http://tc.hd.xiaomi.com/hdget?callback=hdcontrol",
  109.                 UserAgent = "Mozilla/5.0 (Linux; U; Android 4.0.4; zh-cn; MI-ONE C1 Build/IMM76D) UC AppleWebKit/534.31 (KHTML, like Gecko) Mobile Safari/534.31",
  110.                 Host = "tc.hd.xiaomi.com",
  111.                 Cookie = cookies
  112.             };
  113.             HttpResult result = http.GetHtml(item);
  114.             string strJson = result.Html;
  115.             if (strJson.Contains("hdcontrol"))
  116.             {
  117.                 strJson = strJson.Replace("hdcontrol(", "").Replace(")", "");
  118.                 xiaomiEntity xm = JsonConvert.DeserializeObject<xiaomiEntity>(strJson);
  119.                 bool allow = xm.Status.Allow;
  120.                 string Hdurl = xm.Status.Miphone.Hdurl;
  121.  
  122.                 if (!string.IsNullOrEmpty(Hdurl))
  123.                 {
  124.                     string url = "http://t.hd.xiaomi.com/s/" + xm.Status.Miphone.Hdurl + "&_m=1";
  125.                     if (allow)
  126.                     {
  127.                         lblAllow.Invoke(new Action(delegate() { lblAllow.Text = allow.ToString(); }));
  128.                         txtUrl.Invoke(new Action(delegate() { txtUrl.Text = url; }));
  129.  
  130.                         TimerStop();
  131.                     }
  132.                     else
  133.                     {
  134.                         bool allowchecked = false;
  135.                         ckbAllow.Invoke(new Action(delegate() { allowchecked = ckbAllow.Checked; }));
  136.                         if (allowchecked == true)
  137.                         {
  138.                             txtUrl.Invoke(new Action(delegate() { txtUrl.Text = url; }));
  139.  
  140.                         }
  141.                     }
  142.                 }
  143.             }
  144.  
  145.             else
  146.             {
  147.                 lblAllow.Invoke(new Action(delegate() { lblAllow.Text = "尚未开放"; }));
  148.             }
  149.  
  150.  
  151.  
  152.  
  153.  
  154.         }
  155.  
  156.         private void btnLogin_Click(object sender, EventArgs e)
  157.         {
  158.             string username = txtUserName.Text;
  159.             string password = txtPwd.Text;
  160.  
  161.             HttpItem itemSign = new HttpItem()
  162.             {
  163.                 URL = "https://account.xiaomi.com/pass/serviceLogin",
  164.             };
  165.             HttpHelper helperSign = new HttpHelper();
  166.             HttpResult resultSign = helperSign.GetHtml(itemSign);
  167.             string signHtml = resultSign.Html;
  168.             HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
  169.             doc.LoadHtml(signHtml);
  170.             var htmlnodes = doc.DocumentNode.Descendants("input");
  171.             Dictionary<string, string> dict = new Dictionary<string, string>();
  172.             foreach (var item in htmlnodes)
  173.             {
  174.                 if (item.Attributes["name"] != null && item.Attributes["value"] != null)
  175.                 {
  176.                     dict.Add(item.Attributes["name"].Value, item.Attributes["value"].Value);
  177.                 }
  178.             }
  179.             string passToken = HttpUtility.UrlEncode(dict["passToken"]);
  180.             string callback = HttpUtility.UrlEncode(dict["callback"]);
  181.             string sid = HttpUtility.UrlEncode(dict["sid"]);
  182.             string qs = HttpUtility.UrlEncode(dict["qs"]);
  183.             string hidden = HttpUtility.UrlEncode(dict["hidden"]);
  184.             string _sign = HttpUtility.UrlEncode(dict["_sign"]);
  185.             string auto = HttpUtility.UrlEncode(dict["auto"]);
  186.  
  187.             cookies = resultSign.Cookie;
  188.  
  189.             HttpItem itemLogin = new HttpItem()         //登陆Post
  190.             {
  191.                 URL = "https://account.xiaomi.com/pass/serviceLoginAuth2",
  192.                 Method = "POST",
  193.                 Cookie = cookies,
  194.                 Referer = "https://account.xiaomi.com/pass/serviceLogin",
  195.                 ContentType = "application/x-www-form-urlencoded",
  196.                 Postdata = string.Format("passToken={0}&user={1}&pwd={2}&callback={3}&sid={4}&qs={5}&hidden={6}&_sign={7}&auto={8}", passToken, username, password, callback, sid, qs, hidden, _sign, auto)
  197.             };
  198.             HttpHelper helperLogin = new HttpHelper();
  199.             HttpResult resultLogin = helperLogin.GetHtml(itemLogin);
  200.  
  201.             if (resultLogin.Html.Contains("小米帐户 - 登录"))
  202.             {
  203.                 AppendText(username + "登陆失败\n"); return;
  204.             }
  205.             AppendText(username + "登陆成功");
  206.             cookies += ";" + resultLogin.Cookie;
  207.             // AppendText(cookies);
  208.  
  209.         }
  210.  
  211.  
  212.  
  213.  
  214.  
  215.         private void btnCopy_Click(object sender, EventArgs e)
  216.         {
  217.             if (!string.IsNullOrEmpty(txtUrl.Text))
  218.             {
  219.                 Clipboard.SetDataObject(txtUrl.Text, true);
  220.             }
  221.         }
  222.  
  223.  
  224.         protected void AppendText(string info)
  225.         {
  226.             txtInfo.Invoke((MethodInvoker)delegate
  227.             {
  228.                 txtInfo.AppendText(info + Environment.NewLine);
  229.  
  230.                 txtInfo.SelectionStart = txtInfo.Text.Length;
  231.                 txtInfo.ScrollToCaret();
  232.             });
  233.         }
  234.  
  235.     }
  236. }
  237.  

回复 "小米抢购源码"

这儿你可以回复上面这条便签

captcha