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 jslogin() { ShowMsg("islogin"); if (__1) { SendHeader(httpclient, url_jslogin[1]); // var task = httpclient.GetStreamAsync(ReplaceKey(url_jslogin[0])); var result = HttpClientExt.RunGet(ReplaceKey(url_jslogin[0])); // var result = GetDeflateByStream(task.Result, "GBK"); UUID = GetCodeString(result, "200", "\"(.*?)\""); } }
private void webwxinit_new() { ShowMsg("webwxinit_new"); if (__5) { SendHeader(httpclient, ReplaceHeaderKey(url_webwxinit[1])); byte[] bs = Encoding.UTF8.GetBytes(ReplaceHeaderKey(@"{""BaseRequest"":{""Uin"":""{UIN}"",""Sid"":""{SID}"",""Skey"":""{SKEY}"",""DeviceID"":""{DeviceID}""}}")); string json = ReplaceHeaderKey(@"{""BaseRequest"":{""Uin"":""{UIN}"",""Sid"":""{SID}"",""Skey"":""{SKEY}"",""DeviceID"":""{DeviceID}""}}"); string url = ReplaceKey(url_webwxinit[0]); //var task = httpclient.PostAsync(ReplaceKey(url_webwxinit[0]), new ByteArrayContent(bs)); { // string value = GetDeflateByStream(task.Result.Content.ReadAsStreamAsync().Result); string value = HttpClientExt.RunPost(url, json); //pick up loginer Loginer loginer = value.ConvertJson <Loginer>(); BaseUser me = loginer.User.ConvertMapModel <User, BaseUser>(); mySelf = me.ConvertMapModel <BaseUser, Friend>(); mySelf.IsOwner = 1; //"Ret": 1100, if (!value.Contains("\"Ret\": 0")) { ShowMsg("没有返回正确的数据,webwxinit错误!"); // throw new Exception("没有返回正确的数据,webwxinit错误!"); } //USER_INFO USER_INFO = SubString(value.Replace("\r", "").Replace("\n", ""), "\"User\": {", "NickName"); USER_INFO = SubString(USER_INFO, "\"UserName\": \"", "\","); USER_NICKNAME = SubString(value.Replace("\r", "").Replace("\n", ""), "\"User\": {", "HeadImgUrl"); USER_NICKNAME = SubString(USER_NICKNAME, "\"NickName\": \"", "\","); label1.Text = USER_INFO; USER_DI.Add(USER_INFO, USER_NICKNAME); this.Text = USER_NICKNAME + ">>>转发微信机器人 V0.5.1 20170502"; //SyncKey SyncKey = SubString(value.Replace("\r", "").Replace("\n", ""), "\"SyncKey\": ", "}]}"); SyncKey += "}]}"; #if DEBUG this.txtTip.Text = SyncKey; #endif } } }
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); }