示例#1
0
        public void Go(ElemeLuckyMoney eleme, Action <int> onResult, Action onExpired)
        {
            int tryCount = 0;

            RequestBody["group_sn"] = eleme.Sn;
            string         body    = jsSerializer.Serialize(RequestBody);
            RequestBuilder request = null;

            request = Http.Post(Url)
                      .Body("json", body)
                      .OnSuccess((result) => {
                try {
                    dynamic ret = jsSerializer.Deserialize <dynamic>(result);
                    if (ret["promotion_items"].Length > 0)
                    {
                        eleme.Amount = ret["promotion_items"][0]["amount"];
                    }
                    onResult(eleme.LuckyNum - ret["promotion_records"].Length);
                } catch {
                    onExpired();
                }
            }).OnFail((resp) => {
                if (tryCount++ <= 5)
                {
                    Thread.Sleep(4000);
                    request.Go();
                }
            });
            request.Go();
        }
示例#2
0
        public override void Sync(Action <ElemeLuckyMoney> onReceived, Action onExpired)
        {
            StringBuilder synckey = new StringBuilder();

            foreach (dynamic o in SyncKey["List"])
            {
                synckey.Append(o["Key"] + "_" + o["Val"] + "|");
            }
            if (synckey.Length > 0)
            {
                synckey.Remove(synckey.Length - 1, 1);
            }
            string synccheck = "https://webpush.wx2.qq.com/cgi-bin/mmwebwx-bin/synccheck?r=" + Eval.JScriptEvaluate("~new Date();", vsaEngine).ToString() + "&skey=" + HttpUtility.UrlEncode(Skey) + "&sid=" + HttpUtility.UrlEncode(Sid) + "&uin=" + Uin + "&deviceid=" + DeviceID + "&synckey=" + HttpUtility.UrlEncode(synckey.ToString());

            Http.Get(synccheck)
            .OnSuccess((result) => {
                Match match = Regex.Match(result, "retcode:\"(\\d+)\"");
                if (match.Success && match.Groups.Count > 1 && match.Groups[1].Value == "0")
                {
                    match = Regex.Match(result, "selector:\"(\\d+)\"");
                    if (match.Success && match.Groups.Count > 1 && match.Groups[1].Value != "0")
                    {
                        Http.Post("https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxsync?sid=" + Sid + "&skey=" + Skey + "&lang=zh_CN&pass_ticket=" + PassTicket)
                        .Body("json", jsSerializer.Serialize(
                                  new {
                            BaseRequest = new {
                                Uin      = Uin,
                                Sid      = Sid,
                                Skey     = Skey,
                                DeviceID = DeviceID
                            },
                            SyncKey = SyncKey,
                            rr      = Eval.JScriptEvaluate("~new Date();", vsaEngine).ToString()
                        }))
                        .OnSuccess((header, result_1) => {
                            if (!header.AllKeys.Contains("Set-Cookie"))
                            {
                                onExpired();
                                return;
                            }
                            dynamic obj       = jsSerializer.Deserialize <dynamic>(result_1);
                            SyncKey           = obj["SyncKey"];
                            dynamic[] msgList = obj["AddMsgList"];
                            foreach (dynamic msg in msgList)
                            {
                                if (!string.IsNullOrEmpty(msg["Url"]) && ((string)msg["Url"]).StartsWith("https://h5.ele.me/hongbao"))
                                {
                                    ElemeLuckyMoney eleme = new ElemeLuckyMoney();
                                    eleme.Url             = msg["Url"];
                                    Match match1          = Regex.Match(msg["Url"], "sn=([^&]+)&");
                                    if (match1.Success && match1.Groups.Count > 1)
                                    {
                                        eleme.Sn = match1.Groups[1].Value;
                                    }
                                    match1 = Regex.Match(msg["Url"], "lucky_number=(\\d+)&");
                                    if (match1.Success && match1.Groups.Count > 1)
                                    {
                                        eleme.LuckyNum = int.Parse(match1.Groups[1].Value);
                                    }
                                    onReceived(eleme);
                                }
                                else if (!string.IsNullOrEmpty(msg["Content"]))
                                {
                                    MatchCollection matchCollection = Regex.Matches(msg["Content"], "https://h5\\.ele\\.me/hongbao/#hardware_id=&amp;is_lucky_group=True&amp;lucky_number=(\\d+)&amp;track_id=&amp;platform=\\d+&amp;sn=([^&]+)&amp;theme_id=\\d+&amp;device_id=");
                                    foreach (Match m in matchCollection)
                                    {
                                        if (m.Success && m.Groups.Count > 2)
                                        {
                                            ElemeLuckyMoney eleme = new ElemeLuckyMoney();
                                            eleme.Url             = m.Groups[0].Value;
                                            eleme.LuckyNum        = int.Parse(m.Groups[1].Value);
                                            eleme.Sn = m.Groups[2].Value;
                                            onReceived(eleme);
                                        }
                                    }
                                }
                            }
                        }).Go();
                    }
                    Sync(onReceived, onExpired);
                }
                else
                {
                    onExpired();
                }
            }).Go();
        }