/// <summary> /// 对手机端信息进行同步 /// </summary> /// <param name="FromUserName"></param> /// <param name="ToUserName"></param> public static void WebwxStatusNotify(string FromUserName, string ToUserName) { NotifyPhoneEntity Npe = new NotifyPhoneEntity(); BaseRequestEntity br = new BaseRequestEntity(); br.DeviceID = MethodsHelper.GetDeviceId(); br.Sid = CommonDefine.LoginResult.wxsid; br.Skey = CommonDefine.LoginResult.skey; br.Uin = CommonDefine.LoginResult.wxuin; Npe.BaseRequest = br; Random ran = new Random(); Npe.ClientMsgId = MethodsHelper.GetClientMsgId();// "1497590764" + ((int)ran.Next(0, 9)).ToString() + ((int)ran.Next(0, 9)).ToString() + ((int)ran.Next(0, 9)).ToString(); Npe.Code = "1"; Npe.FromUserName = FromUserName; Npe.ToUserName = ToUserName; string PostData = JsonConvert.SerializeObject(Npe); string list = HttpMethods.PostData(UrlDefine.WexNotifyUrl + CommonDefine.LoginResult.pass_ticket, PostData, CommonDefine.Cookies, Encoding.UTF8).ContentData.ToString(); if (list != null) { SendMsgResultEntity Sre = JsonConvert.DeserializeObject <SendMsgResultEntity>(list); if (Sre.BaseResponse.Ret == 0) { } //if (list.Count >= 1) //{ // Console.WriteLine(list[0].ToString()); //} } }
/// <summary> /// 请求艺龙接口 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="request"></param> /// <param name="method"></param> /// <returns></returns> private static string RequestInterface <T>(T request, string method) { var requestContent = new BaseRequestEntity <T>() { Local = EnumLocal.zh_CN, Version = 1.22, Request = request }; var str = JsonHelper.SerializeObject(requestContent); LogHelper.WriteLog("请求信息1:" + str, "ElongHotelInterface"); DateTime now = DateTime.Now; long timestamp = ConvertDateTimeInt(now); string sig = MD5(timestamp + MD5(str + ApiGatewayConfig.APPKEY) + ApiGatewayConfig.SECRETKEY); StringBuilder sb = new StringBuilder(); sb.Append("format=").Append("json").Append("&"); sb.Append("method=").Append(method).Append("&"); sb.Append("signature=").Append(sig).Append("&"); sb.Append("user="******"&"); sb.Append("timestamp=").Append(timestamp).Append("&"); str = Uri.EscapeDataString(str); sb.Append("data=").Append(str); string url = string.Format(ApiGatewayConfig.URL_HTTPS, sb.ToString()); LogHelper.WriteLog("请求信息2:" + url, "ElongHotelInterface"); string res = GetHelper.GetUrl(url); LogHelper.WriteLog("响应信息:" + res, "ElongHotelInterface"); return(res); }
/// <summary> /// 获取心跳key /// </summary> /// <returns></returns> public static string GetSyncKey() { BaseRequestEntity Bre = new BaseRequestEntity() { Uin = CommonDefine.LoginResult.wxuin, Sid = CommonDefine.LoginResult.wxsid, Skey = CommonDefine.LoginResult.skey, DeviceID = MethodsHelper.GetDeviceId() }; BaseRequestSubmitEntity le = new BaseRequestSubmitEntity() { BaseRequest = Bre }; string SyncKeyData = JsonConvert.SerializeObject(le); string SyncKeyUrl = UrlDefine.GetSyncKey + CommonDefine.LoginResult.pass_ticket; string SyncKeyList = HttpMethods.PostData(SyncKeyUrl, SyncKeyData, CommonDefine.Cookies, Encoding.UTF8).ContentData.ToString(); BaseContactEntity bce = JsonConvert.DeserializeObject <BaseContactEntity>(SyncKeyList); CommonDefine.SyncKey = bce.SyncKey; string SyncKey = string.Empty; for (int index = 0; index < bce.SyncKey.List.Count; index++) { if (!string.IsNullOrWhiteSpace(SyncKey)) { SyncKey = SyncKey + "|"; } SyncKey = SyncKey + bce.SyncKey.List[index].Key + "_" + bce.SyncKey.List[index].Val; } Thread.Sleep(5000); return(SyncKey); }
private HttpWebRequest CreateWebRequestV2(string url, BaseRequestEntity _ReqDetails) { System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Ssl3 | System.Net.SecurityProtocolType.Tls | System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls12; HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url); // // Soap action // //webRequest.Headers.Add(@"SOAP:Action"); webRequest.Headers.Add("SOAPAction", "http://webservices.luxottica.it/RXOService/rxoOrderRequest"); // //set compression // webRequest.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate"); webRequest.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; webRequest.ContentType = "text/xml;charset=\"utf-8\""; webRequest.Accept = "text/xml"; // //set connection properties // webRequest.KeepAlive = true; //15 sec on server side webRequest.Accept = "text/xml"; // //set verb // webRequest.Method = "POST"; // // Set HttpWebRequest timeout // if (_ReqDetails.HttpRequest > 0) { //webRequest.Timeout = Timeout.Infinite; webRequest.Timeout = (_ReqDetails.HttpRequest * 1000); } // // Add Basic Authentication // if (_ReqDetails.BasicAuth) { string username = _ReqDetails.BasicAuthUsername; string password = _ReqDetails.BasicAuthPassword; string svcCredentials = Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(username + ":" + password)); webRequest.Headers.Add("Authorization", "Basic " + svcCredentials); } return(webRequest); }
private HttpWebRequest CreateWebRequest(string url, BaseRequestEntity _ReqDetails) { //System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Ssl3 // | System.Net.SecurityProtocolType.Tls // | System.Net.SecurityProtocolType.Tls11 // | System.Net.SecurityProtocolType.Tls12; System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls | System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls12; HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url); // // Soap action // //webRequest.Headers.Add(@"SOAP:Action"); //webRequest.Headers.Add("SOAPAction", "http://webservices.luxottica.it/RXOService/rxoCheckOrderRequest"); webRequest.ContentType = "text/xml;charset=\"utf-8\""; webRequest.Accept = "text/xml"; webRequest.Method = "POST"; // // Set HttpWebRequest timeout // if (_ReqDetails.HttpRequest > 0) { webRequest.Timeout = (_ReqDetails.HttpRequest * 1000); } // // Add Basic Authentication // if (_ReqDetails.BasicAuth) { string username = _ReqDetails.BasicAuthUsername; string password = _ReqDetails.BasicAuthPassword; string svcCredentials = Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(username + ":" + password)); webRequest.Headers.Add("Authorization", "Basic " + svcCredentials); } // // eventually manage certificates // //X509Certificate Cert = X509Certificate.CreateFromCertFile("C:\\myluxotticacom.crt"); //AttachClientCertificate(webRequest, "a", "b"); return(webRequest); }
/// <summary> /// 设置API必要参数 /// </summary> /// <param name="request"></param> /// <param name="body"></param> private static void SetTokenParam(IRestRequest request, BaseRequestEntity body) { request.AddParameter("request_time", body.RequestTime); request.AddParameter("request_token", body.RequestToken); }
/// <summary> /// 登录 /// </summary> public static void Login() { string str = string.Empty; HttpMethods.ContentType = "application/json;charset=utf-8"; while (true) { if (!str.Contains("200")) { HttpResponseResult ResponseResult = HttpMethods.Get(UrlDefine.WaitingUrl(UrlDefine.Tickets), CommonDefine.Cookies, Encoding.UTF8); str = ResponseResult.ContentData.ToString(); Console.WriteLine("当前返回值是:" + str); if (str.Contains("201")) { //扫码登录中 string[] base64 = str.Split(','); CommonDefine.Base64 = base64[1]; byte[] arr = Convert.FromBase64String(CommonDefine.Base64.Replace("'", "").Replace(";", "").Trim()); File.WriteAllBytes(Environment.CurrentDirectory + "\\User.jpg", arr); MemoryStream ms = new MemoryStream(arr); BitmapImage bi = new BitmapImage(); bi.BeginInit(); bi.StreamSource = ms;// new FileStream(); bi.EndInit(); CommonDefine.UserImage = bi; CommonMethodCallBackHandlers.OnLoginScranQRCodeCompleted(Environment.CurrentDirectory + "\\User.jpg"); } } if (str.Contains("200")) { //扫码登录完成 LogWriter.Write("扫码登录成功...", LogPathDefine.WeChatLogPath); string[] strs = str.Split(';'); UrlDefine.LoginUrls = strs[1].Substring(strs[1].IndexOf("=\"") + 2, strs[1].Length - strs[1].IndexOf("=\"") - 3); string XmlList = HttpMethods.Get(UrlDefine.LoginUrls, CommonDefine.Cookies, Encoding.UTF8, true).ContentData.ToString(); CommonDefine.GetCookieDictionary = HttpMethods.SetCookieDictionary; CommonDefine.LoginResult = XMLHelper.DESerializer <LoginResultEntity>(XmlList); //此处可用于二次点击登录 LogWriter.Write(CommonDefine.LoginResult.wxuin, Environment.CurrentDirectory + "\\Data\\data.dat"); Random r = new Random(); BaseRequestEntity Bre = new BaseRequestEntity() { Uin = CommonDefine.LoginResult.wxuin, Sid = CommonDefine.LoginResult.wxsid, Skey = CommonDefine.LoginResult.skey, DeviceID = MethodsHelper.GetDeviceId() }; BaseRequestSubmitEntity le = new BaseRequestSubmitEntity() { BaseRequest = Bre }; string postdata = JsonConvert.SerializeObject(le); string MySelfList = HttpMethods.PostData(UrlDefine.GetLoginId + CommonDefine.LoginResult.pass_ticket, postdata, CommonDefine.Cookies, Encoding.UTF8).ContentData.ToString(); LogWriter.Write(string.Format("获取个人信息{0}...", MySelfList), LogPathDefine.WeChatLogPath); CommonDefine.BaseContact = JsonConvert.DeserializeObject <BaseContactEntity>(MySelfList); string ContentList = HttpMethods.Get(UrlDefine.GetContactUrl(CommonDefine.LoginResult.pass_ticket, CommonDefine.LoginResult.skey), CommonDefine.Cookies, Encoding.UTF8).ContentData.ToString(); CommonDefine.ContactsList = JsonConvert.DeserializeObject <ContactsListEntity>(ContentList); LogWriter.Write(string.Format("获取联系人信息{0}...", ContentList), LogPathDefine.WeChatLogPath); new Task(() => { GetGroupContactsMethod(CommonDefine.ContactsList.MemberList); }).Start(); new Task(() => { CommonDefine.ContactsList.MemberList.ForEach((p) => { p.DownloadImage(); }); }).Start(); CommonMethodCallBackHandlers.OnLoginCompleted(true); break; } Thread.Sleep(5000); } }