示例#1
0
        /// <summary>
        /// 选择同步域名
        /// </summary>
        /// <returns></returns>
        private string SyncCheck()
        {
            var robot = Global.robot;

            List <string> hostList = new List <string>();

            hostList.Add("webpush.wx.qq.com");
            hostList.Add("webpush.weixin.qq.com");
            hostList.Add("webpush2.weixin.qq.com");
            hostList.Add("webpush.wechat.com");
            hostList.Add("webpush1.wechat.com");
            hostList.Add("webpush2.wechat.com");
            hostList.Add("webpush1.wechatapp.com");
            string host = string.Empty;

            foreach (var hostName in hostList)
            {
                SyncCheckResult checkResult = protocol.SyncCheck(hostName, robot.Cookie, robot.CookieStr, robot.SynckeyStr);
                if (checkResult.retcode == "0")
                {
                    host = hostName;
                    break;
                }
            }
            return(host);
        }
示例#2
0
        /// <summary>
        /// 获取消息前同步(轮询同步有消息后执行Sync)
        /// </summary>
        /// <param name="host"></param>
        public SyncCheckResult SyncCheck(string host, WechatCookie wechatCookie, string cookieStr, string SynckeyStr)
        {
            string url = string.Format(WechatUrl.SnycCheckUrl, WechatCommon.GetTicks(),
                                       HttpHelper.URLEncode(wechatCookie.Skey), wechatCookie.Wxsid,
                                       wechatCookie.Wxuin, DeviceID, SynckeyStr, WechatCommon.GetTicks(), host);

            string html = HttpCommon.instance.Login(url, cookieStr);

            AppLog.WriteInfo(string.Format("协议:{0},结果:{1}", "SyncCheck", html));

            //HttpItem item = new HttpItem()
            //{
            //    URL = url,//URL     必需项
            //    Method = "GET",//URL     可选项 默认为Get
            //    UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36",//用户的浏览器类型,版本,操作系统     可选项有默认值
            //    Accept = "application/json, text/plain, */*",//    可选项有默认值
            //    ContentType = "application/json; charset=UTF-8",//返回类型    可选项有默认值
            //                                                    // Encoding = Encoding.UTF8,
            //    Cookie = syncCookie,//字符串Cookie     可选项
            //    Referer = "https://wx.qq.com/?&lang=zh_CN",

            //};
            //HttpResult result = http.GetHtml(item);
            //string html = result.Html;

            SyncCheckResult syncCheck = new SyncCheckResult();

            try
            {
                if (!string.IsNullOrEmpty(html) && html != "请求超时")
                {
                    if (html.IndexOf('{') != -1)
                    {
                        string sycheck = html.Substring(html.IndexOf('{'));
                        syncCheck = JsonConvert.DeserializeObject <SyncCheckResult>(sycheck);
                    }
                }
            }
            catch (Exception ex)
            {
                AppLog.WriteError(ex.Message);
            }
            return(syncCheck);
        }