void GetVerifyKey(WebChatLoginTocken tocken, string deviceId, CookieContainer cookieContainer) {//此处需要一个定时作业进行消息管理 //将数据填入到查询接口中 string queryMsgUrlFormat = webChatSampleCfg["QueryWebChatMsgUrlPost"]; string msgUrl = tocken.GenerateQueryWebChatMsgUrl(queryMsgUrlFormat); QueryWebChatBaseRequestParam bp = new QueryWebChatBaseRequestParam() { DeviceID = deviceId, Sid = tocken.wxsid, //此参数绑定不正确 Skey = tocken.skey, Uin = tocken.wxuin // wxuin new TestClass().GetJsNewData() }; Uin = tocken.wxuin;//获取验证 //首先获取查询消息列表的参数 string keyParamFromUrl = webChatSampleCfg["WebChatMsgSyncKeyPost"]; string requestUrl = keyParamFromUrl.Replace("{newDate}", new TestClass().GetJsNewData()).Replace("{pass_ticket}", tocken.pass_ticket); QueryWebChatMsgObjectParam param = new QueryWebChatMsgObjectParam() { BaseRequest = bp, rr = new TestClass().DateTimeToStamp(DateTime.Now) //此处时间戳获得的数据不对 }; string paramJson = param.ConvertJson(); string SyncKey = HttpClientExt.RunPosterContainerHeaderHavaParam(requestUrl, header, paramJson, cookieContainer); //HttpClientExt.RunPost(requestUrl, paramJson); //getFormateSyncCheckKey TecentWebChatMsgSyncKey syncKeyObj = SyncKey.ConvertObject <TecentWebChatMsgSyncKey>(); //经常出现返回的验证状态错误 1101 采集不到消息ID if (syncKeyObj.BaseResponse.Ret > 0) {//没有待采集的消息 paramJson.CreateLog(ELogType.ParamLog); SyncKey.CreateLog(ELogType.ErrorLog); return; } //string msg= HttpClientExt.RunPost(msgUrl, paramJson); SyncKey.CreateLog(ELogType.ParamLog); //msg.CreateLog(ELogType.DataLog); string url = webChatSampleCfg["QueryWebChatMsgUrlPost"]; string msgQueryUrl = tocken.FillStringFromObject(url);//查询消息的URL param.SyncKey = syncKeyObj.SyncKey; string msgQueryPAramJson = param.ConvertJson(); string msgResponse = HttpClientExt.RunPosterContainerHeaderHavaParam(msgQueryUrl, header, msgQueryPAramJson, cookieContainer); WebChatMsg msg = msgResponse.ConvertObject <WebChatMsg>(); if (msg.AddMsgList.Count > 0) { msgResponse.CreateLog(ELogType.DataInDBLog); //消息入库 List <TecentMsgDataItem> msgs = msg.AddMsgList.Select <MsgContent, TecentMsgDataItem>(s => (TecentMsgDataItem)s).ToList(); //hack list<派生类> 不能直接转换为 list<父类> WebChatMsgService msgService = new WebChatMsgService(); msgService.AddList(msgs); } }
private void redirect_uri_fun() { ShowMsg("redirect_uri_fun"); if (__4) { HttpWebRequest h = (HttpWebRequest)HttpWebRequest.Create(redirect_uri); h.AllowAutoRedirect = false; h.CookieContainer = cookieContainer; HttpWebResponse r = (HttpWebResponse)h.GetResponse(); //此时进行cookie提取 // CookieCollection cookies = r.Cookies; //// cookieContainer.Add(cookies); // foreach (Cookie item in cookies) // { // cookieContainer.Add(new Cookie(item.Name, item.Value,item.Path,item.Domain)); // } COOKIES = GetAllCookiesA(cookieContainer);// 'webwxuvid' 'webwx_auth_ticket' 'wxuin' 'mm_lang' 'wxloadtime' 五项 cookie // 然而实际的请求需要项 'pgv_pvi' 'webwxuvid' 'webwx_auth_ticket' 'wxloadtime' 'wxpluginkey' 'wxuin' 'mm_lang' #region 登录成功就查询相关信息 string loginIdUrl = "https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxinit?r=$r$ "; loginIdUrl = loginIdUrl.Replace("$r$", new TestClass().GenerateJsNegate()); RequestHttp(loginIdUrl, cookieContainer); #endregion using (System.IO.StreamReader read = new System.IO.StreamReader(r.GetResponseStream())) { string value = read.ReadToEnd(); if (value.IndexOf("pass_ticket") == -1) { throw new Exception("没有得到wxsid信息"); } step4xml = Xml2Json <Step4XML>(value); } r.Close(); if (!string.IsNullOrEmpty(GetLoginVerifyCodeUrl) && GetLoginVerifyCodeUrl.Contains("webwxnewloginpage"))//登陆成功之后获取登录者的登录tocken { WebChatLoginTocken tocken = GetLoginTocken(GetLoginVerifyCodeUrl, DeviceID); if (tocken == null) { return; } //开启新线程进行调度 AsyncThreadDoEvent async = new Infrastructure.ExtService.AsyncThreadDoEvent(); async.OpenNewThreadWithRun(new AsyncThreadDoEvent.CallEvent(NewThreadDoQueryMsg), new object[] { tocken, DeviceID, cookieContainer }); } /* * https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxnewloginpage?ticket=A-UlGlrnWCqys2myqayFNghP@qrticket_0&uuid=oY-3-4EsAg==&lang=zh_CN&scan=1510751386&fun=new&version=v2&lang=zh_CN */ // GetVerifyKey(GetLoginVerifyCodeUrl, DeviceID); } }
WebChatLoginTocken GetLoginTocken(string loginerVerifyCodeUrl, string deviceId) { /* * https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxnewloginpage?ticket=A-UlGlrnWCqys2myqayFNghP@qrticket_0&uuid=oY-3-4EsAg==&lang=zh_CN&scan=1510751386&fun=new&version=v2&lang=zh_CN * */ loginerVerifyCodeUrl += "&fun=new&version=v2&lang=zh_CN"; string text = HttpClientExt.RunPosterContainerHeader(loginerVerifyCodeUrl, header, cookieContainer); text.CreateLog(ELogType.LogicLog); WebChatLoginTocken tocken = new WebChatLoginTocken(); tocken.GetWebChatLoginTocket(text); if (tocken.ret != 0) {//实际上登录凭证只需要获取一次即可 return(null); } return(tocken); }