public void SyncCheck(SyncItem[] syncItems, BaseRequest baseReq, long syncCheckTimes, Action <SyncCheckResponse> CallBack)
        {
            string synckey = "";

            for (int i = 0; i < syncItems.Length; i++)
            {
                if (i != 0)
                {
                    synckey += "|";
                }
                synckey += syncItems[i].Key + "_" + syncItems[i].Val;
            }
            string url = "https://webpush.wx2.qq.com/cgi-bin/mmwebwx-bin/synccheck?skey={0}&sid={1}&uin={2}&deviceid={3}&synckey={4}&_={5}&r={6}";

            url = string.Format(url, UrlEncode(baseReq.Skey), UrlEncode(baseReq.Sid), baseReq.Uin, baseReq.DeviceID, synckey, syncCheckTimes, Util.GetTimeStamp());
            http.Item.Request.HeadersDic["Accept"] = "application/json, text/plain, */*";
            http.GetHtml(url, referer: "https://wx2.qq.com/", callBack: (x) => {
                string repStr = x.response.DataString();
                if (repStr == null)
                {
                    CallBack?.Invoke(null);
                }
                SyncCheckResponse rep = new SyncCheckResponse();
                if (repStr.StartsWith("window.synccheck="))
                {
                    repStr = repStr.Substring("window.synccheck=".Length);
                    rep    = JsonConvert.DeserializeObject <SyncCheckResponse>(repStr);
                }
                CallBack?.Invoke(rep);
            });
        }
Ejemplo n.º 2
0
        public SyncCheckResponse SyncCheck(SyncItem[] syncItems, BaseRequest baseReq)
        {
            string synckey = "";

            for (int i = 0; i < syncItems.Length; i++)
            {
                if (i != 0)
                {
                    synckey += "|";
                }
                synckey += syncItems[i].Key + "_" + syncItems[i].Val;
            }
            string url = "https://webpush.wx.qq.com/cgi-bin/mmwebwx-bin/synccheck?skey={0}&sid={1}&uin={2}&deviceid={3}&synckey={4}&_={5}&r={6}";

            url = string.Format(url, baseReq.Skey.Replace("@", "%40"), baseReq.Sid, baseReq.Uin, baseReq.DeviceID, synckey, getTimestamp(DateTime.Now) - 10, getTimestamp(DateTime.Now));
            string            repStr = http.GET_UTF8String(url);
            SyncCheckResponse rep    = new SyncCheckResponse();

            if (repStr.StartsWith("window.synccheck="))
            {
                repStr = repStr.Substring("window.synccheck=".Length);
                rep    = JsonConvert.DeserializeObject <SyncCheckResponse>(repStr);
            }

            return(rep);
        }
Ejemplo n.º 3
0
        public SyncCheckResponse SyncCheck(SyncItem[] syncItems, BaseRequest baseReq, long syncCheckTimes)
        {
            SetHttpHeader("Accept", "*/*");
            SetHttpHeader("Connection", "keep-alive");
            SetHttpHeader("Accept-Encoding", "gzip, deflate, br");

            string synckey = "";

            for (int i = 0; i < syncItems.Length; i++)
            {
                if (i != 0)
                {
                    synckey += "|";
                }
                synckey += syncItems[i].Key + "_" + syncItems[i].Val;
            }
            string url = "https://webpush.wx2.qq.com/cgi-bin/mmwebwx-bin/synccheck?skey={0}&sid={1}&uin={2}&deviceid={3}&synckey={4}&_={5}&r={6}";

            url = string.Format(url, UrlEncode(baseReq.Skey), UrlEncode(baseReq.Sid), baseReq.Uin, baseReq.DeviceID, synckey, syncCheckTimes, Util.GetTimeStamp());
            string repStr = GetString(url);

            if (repStr == null)
            {
                return(null);
            }
            SyncCheckResponse rep = new SyncCheckResponse();

            if (repStr.StartsWith("window.synccheck="))
            {
                repStr = repStr.Substring("window.synccheck=".Length);
                rep    = JsonConvert.DeserializeObject <SyncCheckResponse>(repStr);
            }

            return(rep);
        }
Ejemplo n.º 4
0
        public IResult <SyncCheckResponse> SyncCheck(LoginResponse loginResponse, string syncKey)
        {
            var    result  = new Result <SyncCheckResponse>();
            string respage = string.Empty;

            try
            {
                var timeStamp    = DateTimeHelper.Default.GetTimestamp(13);
                var syncCheckUrl = string.Format(UrlEndPoints.SyncCheckUrl,
                                                 loginResponse.WxSid,
                                                 loginResponse.WxUin,
                                                 syncKey,
                                                 timeStamp,
                                                 loginResponse.Skey.Replace("@", "%40"),
                                                 SystemInfo.DeviceId,
                                                 timeStamp);
                respage = _HttpClient.GetStringAsync(syncCheckUrl).Result;
                var match = Regex.Match(respage, "retcode:\"(\\d+)\",selector:\"(\\d+)\"");
                if (match.Success)
                {
                    var syncCheckResponse = new SyncCheckResponse()
                    {
                        RetCode  = match.Groups[1].Value,
                        Selector = match.Groups[2].Value
                    };

                    result.SetSuccess();
                    result.SetData(syncCheckResponse);
                    return(result);
                }
                else
                {
                    LogHelper.Default.LogDay($"同步消息检测失败,{respage}");
                    LogHelper.Default.LogPrint($"同步消息检测失败,{respage}", 3);

                    result.SetFailed();
                    result.SetDesc("同步消息检测失败");
                    return(result);
                }
            }
            catch (Exception ex)
            {
                LogHelper.Default.LogDay($"同步消息检测异常,{ex},rspage={respage}");
                LogHelper.Default.LogPrint($"同步消息检测异常,{ex.Message}", 4);

                result.SetFailed();
                result.SetDesc("同步消息检测异常," + ex.Message);
                return(result);
            }
        }
Ejemplo n.º 5
0
        private void SyncCheckResponseParser(SyncCheckResponse syncCheckResponse, IWeChatLoginClient weChatLoginClient)
        {
            try
            {
                if (syncCheckResponse.RetCode == "0")
                {
                    if (syncCheckResponse.Selector == "0")
                    {
                        //没有任何消息
                        LogHelper.Default.LogPrint($"没有新消息,空循环", 1);
                    }
                    else if (syncCheckResponse.Selector == "2")
                    {
                        LogHelper.Default.LogPrint("接收到新消息", 2);

                        //拉取消息
                        var resultFetchMessageResponse = _WeChatHttpClient.FetchMessage(weChatLoginClient.LoginResponse, weChatLoginClient.SyncKey);
                        if (resultFetchMessageResponse.Success)
                        {
                            //更新synckey
                            weChatLoginClient.SyncKey = resultFetchMessageResponse.Data.SyncKey;

                            //提取消息
                            GetMessages(resultFetchMessageResponse.Data, weChatLoginClient);
                        }
                        else
                        {
                            LogHelper.Default.LogDay("消息拉取失败");
                            LogHelper.Default.LogPrint("消息拉取失败", 3);
                        }
                    }
                    else if (syncCheckResponse.Selector == "4")
                    {
                        LogHelper.Default.LogPrint("通讯列表更新", 3);

                        //拉取通讯录更新消息
                        var resultFetchMessageResponse = _WeChatHttpClient.FetchMessage(weChatLoginClient.LoginResponse, weChatLoginClient.SyncKey);
                        if (resultFetchMessageResponse.Success)
                        {
                            //更新synckey
                            weChatLoginClient.SyncKey = resultFetchMessageResponse.Data.SyncKey;

                            //提取通讯录更新消息
                            GetMessages(resultFetchMessageResponse.Data, weChatLoginClient);
                        }
                        else
                        {
                            LogHelper.Default.LogDay("通讯列表更新消息拉取失败");
                            LogHelper.Default.LogPrint("通讯列表更新消息拉取失败", 3);
                        }
                    }
                    else if (syncCheckResponse.Selector == "6")
                    {
                        LogHelper.Default.LogDay("0-6:暂停5S");
                        LogHelper.Default.LogPrint("0-6:暂停5S", 1);
                        Task.Delay(5000).Wait();
                    }
                    else if (syncCheckResponse.Selector == "7")
                    {
                        LogHelper.Default.LogDay("0-7:暂停5S");
                        LogHelper.Default.LogPrint("0-7:暂停5S", 1);
                        Task.Delay(5000).Wait();
                    }
                    else
                    {
                        LogHelper.Default.LogDay($"未知情况,RetCode={syncCheckResponse.RetCode},Selector={syncCheckResponse.Selector}");
                        LogHelper.Default.LogPrint($"未知情况,RetCode={syncCheckResponse.RetCode},Selector={syncCheckResponse.Selector}", 3);
                    }

                    _LogoutTimes = 0;
                }
                else if (syncCheckResponse.RetCode == "1101")
                {
                    _LogoutTimes++;
                    if (_LogoutTimes > _LogoutTimesLimit)
                    {
                        _Logout = true;
                    }

                    LogHelper.Default.LogDay($"从微信客户端上登出,{_LogoutTimes}/{_LogoutTimesLimit}");
                    LogHelper.Default.LogPrint($"从微信客户端上登出,{_LogoutTimes}/{_LogoutTimesLimit}", 3);
                }
                else
                {
                    LogHelper.Default.LogDay($"未解析的同步消息,RetCode={syncCheckResponse.RetCode},Selector={syncCheckResponse.Selector}");
                    LogHelper.Default.LogPrint($"未解析的同步消息,RetCode={syncCheckResponse.RetCode},Selector={syncCheckResponse.Selector}", 3);
                    Task.Delay(5000).Wait();
                }
            }
            catch (Exception ex)
            {
                LogHelper.Default.LogDay($"消息类型解析异常,{ex}");
                LogHelper.Default.LogPrint($"消息类型解析异常,{ex.Message}", 4);
            }
        }