private async void sendRequst(Dictionary <string, string> template, Uri requestUrl)
        {
            string ur = $"{string.Format("0")}\"\",\"\"";
            string openId, userId, timestamp, nonce, trade_source, signature, qrcodeid, longitude, latitude;

            template.TryGetValue("openid", out openId);
            template.TryGetValue("userid", out userId);
            template.TryGetValue("timestamp", out timestamp);
            template.TryGetValue("nonce", out nonce);
            template.TryGetValue("trade_source", out trade_source);
            template.TryGetValue("signature", out signature);
            template.TryGetValue("attach", out qrcodeid);

            var member = MemberCheckInSingletonService.Instance.membercheckinlist.Single(m => m.openId == openId);

            longitude = member.longitude.ToString();
            latitude  = member.latitude.ToString();

            string customParams = $"{{\"openid\":\"{openId}\",\"userid\":\"{userId}\",\"timestamp\":\"{timestamp}\",\"nonce\":\"{nonce}\",\"trade_source\":\"{trade_source}\",\"signature\":\"{signature}\",\"qrcodeid\":\"{qrcodeid}\",\"attentype\":\"morning\",\"longitude\":{longitude},\"latitude\":{latitude},\"cacheflag\":\"0\"}}";
            //"openid":"","userid":"510129760","timestamp":"1555230703033","nonce":"b422fca3-6745-45fb-942e-3277e4c2872f","trade_source":"HXQYH","signature":"C5B39A04405C819AB045BD54A3376D59","qrcodeid":"00000000000000105723","attentype":"morning","longitude":104.07,"latitude":30.67,"cacheflag":"0"
            string url = $"http://kqapi.hxlife.com/tms/api/QRcodeSign?callbackparam=success_jsonpCallback&params={customParams}&_={DateTimeOffset.UtcNow.ToUnixTimeSeconds()}";

            string retString = await HttpUtil.Request(url);

            Regex regex = new Regex("success_jsonpCallback\\((.*)\\)");

            if (regex.IsMatch(retString))
            {
                var result        = regex.Match(retString).Groups[1].Value;
                var checkInResult = JsonConvert.DeserializeObject <CheckInServerResponse>(result);

                MemberCheckInSingletonService.updateMemberCheckInInformation(openId, checkInResult.result == "success" ? CheckInStatus.Success : CheckInStatus.Error, checkInResult.result, checkInResult.message, requestUrl.ToString());
            }
            else
            {
                MemberCheckInSingletonService.updateMemberCheckInInformation(openId, CheckInStatus.Error, null, retString, requestUrl.ToString());
            }
        }
示例#2
0
        private void Instance_OnMessage(object sender, CustomEventArgs e)
        {
            Console.WriteLine("Handling SocketService.OnMessage................................");
            Console.WriteLine(JsonConvert.SerializeObject(e.Data));
            //MessageBox.Show(e.Data.op.ToString());
            //this.m_SyncContext.Post((data) =>
            //{
            //    MessageBox.Show(e.Data.op.ToString());
            //}, null);

            this.m_SyncContext.Post((data) =>
            {
                var checkInUrl = GetCheckInLocation()?.url;

                switch (e.Data.op)
                {
                case SocketOp.ACK:
                case SocketOp.PLAIN:
                    this.toolStripProgressBar1.Value      = 0;
                    this.toolStripStatusLabelPercent.Text = "";
                    this.toolStripStatusLabel1.Text       = $"[{e.Data.data.message}]";
                    break;

                case SocketOp.CHECK_IN_CREATED:
                    MemberCheckInSingletonService.createNewMemberCheckInformation(e.Data.data);
                    this.toolStripProgressBar1.Value      = 100;
                    this.toolStripStatusLabelPercent.Text = $"{this.toolStripProgressBar1.Value}%";
                    this.toolStripStatusLabel1.Text       = $"[{e.Data.data.name}]绑定完成";
                    break;

                case SocketOp.CHECK_IN_STARTED:
                    this.toolStripStatusLabelPercent.Text = $"{this.toolStripProgressBar1.Value}%";
                    this.toolStripStatusLabel1.Text       = $"[{e.Data.data.name}]开始打卡";
                    break;

                case SocketOp.CHECK_IN_SKIP:
                    if (Mode == CheckInMode.Batch && IsSomeoneWaiting(e.Data.data.id))
                    {
                        this.toolStripProgressBar1.ProgressBar.PerformStep();
                        this.toolStripStatusLabelPercent.Text = $"{this.toolStripProgressBar1.Value}%";
                        this.toolStripStatusLabel1.Text       = $"[{e.Data.data.name}]跳过";
                        SwitchCheckInMember();
                        var sleepMS = random.Next(lowerTimeSpan, higherTimeSpan);
                        Thread.Sleep(sleepMS);
                        CheckInSingleMember(checkInUrl);
                    }
                    else if (Mode == CheckInMode.Register)
                    {
                        this.toolStripProgressBar1.Value      = 100;
                        this.toolStripStatusLabelPercent.Text = $"{this.toolStripProgressBar1.Value}%";
                        this.toolStripStatusLabel1.Text       = $"[{e.Data.data.name}]重复绑定";
                    }
                    else if (this.IsWatcher)
                    {
                        this.toolStripProgressBar1.ProgressBar.PerformStep();
                        this.toolStripStatusLabelPercent.Text = $"{this.toolStripProgressBar1.Value}%";
                        this.toolStripStatusLabel1.Text       = $"[{e.Data.data.name}]跳过";
                    }
                    else
                    {
                        this.toolStripProgressBar1.Value      = 100;
                        this.toolStripStatusLabelPercent.Text = $"{this.toolStripProgressBar1.Value}%";
                        this.toolStripStatusLabel1.Text       = "当前打卡完成";
                    }
                    break;

                case SocketOp.CHECK_IN_UPDATED:
                    Task.Run(async() =>
                    {
                        await MemberCheckInSingletonService.updateMemberCheckInInformation(e.Data.data);
                        if (Mode == CheckInMode.Register)
                        {
                            this.m_SyncContext.Post(context =>
                            {
                                this.toolStripProgressBar1.Value      = 100;
                                this.toolStripStatusLabelPercent.Text = $"{this.toolStripProgressBar1.Value}%";
                                this.toolStripStatusLabel1.Text       = $"[{e.Data.data.name}]完成注册";
                            }, this);
                        }
                        else if (Mode == CheckInMode.Batch && IsSomeoneWaiting(e.Data.data.id))
                        {
                            this.m_SyncContext.Post(context =>
                            {
                                this.toolStripProgressBar1.PerformStep();
                                this.toolStripStatusLabelPercent.Text = $"{this.toolStripProgressBar1.Value}%";
                                this.toolStripStatusLabel1.Text       = $"[{e.Data.data.name}]完成打卡";
                            }, this);
                            SwitchCheckInMember();
                            var sleepMS = random.Next(lowerTimeSpan, higherTimeSpan);
                            Thread.Sleep(sleepMS);
                            CheckInSingleMember(checkInUrl);
                        }
                        else if (NeedFace(e.Data.data.id))
                        {
                            this.m_SyncContext.Post(context =>
                            {
                                this.toolStripStatusLabelPercent.Text = $"{this.toolStripProgressBar1.Value}%";
                                this.toolStripStatusLabel1.Text       = $"[{e.Data.data.name}]开始打脸";
                            }, this);

                            if (MemberCheckInSingletonService.Instance.checkedInIds.Contains(e.Data.data.id))
                            {
                                MemberCheckInSingletonService.Instance.checkedInIds.Remove(e.Data.data.id);
                            }
                            MemberCheckIn memberCheckIn = MemberCheckInSingletonService.Instance.membercheckinlist.SingleOrDefault(m => m._id == e.Data.data.id);

                            if (!this.IsWatcher)
                            {
                                MonitorFaceDialog(memberCheckIn.faceList);
                            }
                        }
                        else
                        {
                            this.m_SyncContext.Post(context =>
                            {
                                this.toolStripProgressBar1.Value      = 100;
                                this.toolStripStatusLabelPercent.Text = $"{this.toolStripProgressBar1.Value}%";
                                this.toolStripStatusLabel1.Text       = $"当前打卡完成";
                            }, this);
                        }
                    });
                    break;

                case SocketOp.MEMBER_NEED_CHECK_IN_UPDATED:
                    if (!this.IsWatcher)
                    {
                        // only Watcher need to refresh member list again.
                        RefreshMemberListPassively();
                        return;
                    }
                    break;
                }
            }, this);
        }