/// <summary> /// 获取好友列表 /// </summary> /// <returns></returns> public JObject GetContact() { byte[] bytes = Wc2.SendGetRequest(_getcontact_url); string contact_str = Encoding.UTF8.GetString(bytes); return(JsonConvert.DeserializeObject(contact_str) as JObject); }
/// <summary> /// 发送消息 /// </summary> /// <param name="msg"></param> /// <param name="from"></param> /// <param name="to"></param> /// <param name="type"></param> public void SendMsg(string msg, string from, string to, int type) { string msg_json = "{{" + "\"BaseRequest\":{{" + "\"DeviceID\" : \"e441551176\"," + "\"Sid\" : \"{0}\"," + "\"Skey\" : \"{6}\"," + "\"Uin\" : \"{1}\"" + "}}," + "\"Msg\" : {{" + "\"ClientMsgId\" : {8}," + "\"Content\" : \"{2}\"," + "\"FromUserName\" : \"{3}\"," + "\"LocalID\" : {9}," + "\"ToUserName\" : \"{4}\"," + "\"Type\" : {5}" + "}}," + "\"rr\" : {7}" + "}}"; Cookie sid = Wc2.GetCookie("wxsid"); Cookie uin = Wc2.GetCookie("wxuin"); if (sid != null && uin != null) { msg_json = string.Format(msg_json, sid.Value, uin.Value, msg, from, to, type, Login.SKey, DateTime.Now.Millisecond, DateTime.Now.Millisecond, DateTime.Now.Millisecond); byte[] bytes = Wc2.SendPostRequest(_sendmsg_url + sid.Value + "&lang=zh_CN&pass_ticket=" + Login.Pass_Ticket, msg_json); string send_result = Encoding.UTF8.GetString(bytes); } }
/// <summary> /// 微信初始化 /// </summary> /// <returns></returns> public JObject WxInit() { string init_json = "{{\"BaseRequest\":{{\"Uin\":\"{0}\",\"Sid\":\"{1}\",\"Skey\":\"\",\"DeviceID\":\"e1615250492\"}}}}"; Cookie sid = Wc2.GetCookie("wxsid"); Cookie uin = Wc2.GetCookie("wxuin"); if (sid != null && uin != null) { init_json = string.Format(init_json, uin.Value, sid.Value); byte[] bytes = Wc2.SendPostRequest(_init_url + "&pass_ticket=" + Login.Pass_Ticket, init_json); string init_str = Encoding.UTF8.GetString(bytes); JObject init_result = JsonConvert.DeserializeObject(init_str) as JObject; foreach (JObject synckey in init_result["SyncKey"]["List"]) //同步键值 { _syncKey.Add(synckey["Key"].ToString(), synckey["Val"].ToString()); } return(init_result); } else { return(null); } }
/// <summary> /// 微信同步检测 /// </summary> /// <returns></returns> public string WxSyncCheck() { string sync_key = ""; foreach (KeyValuePair <string, string> p in _syncKey) { sync_key += p.Key + "_" + p.Value + "%7C"; } sync_key = sync_key.TrimEnd('%', '7', 'C'); Cookie sid = Wc2.GetCookie("wxsid"); Cookie uin = Wc2.GetCookie("wxuin"); if (sid != null && uin != null) { _synccheck_url = string.Format(_synccheck_url, sid.Value, uin.Value, sync_key, (long)(DateTime.Now.ToUniversalTime() - new System.DateTime(1970, 1, 1)).TotalMilliseconds, Login.SKey.Replace("@", "%40"), "e1615250492"); byte[] bytes = Wc2.SendGetRequest(_synccheck_url + "&_=" + DateTime.Now.Ticks); if (bytes != null) { return(Encoding.UTF8.GetString(bytes)); } else { return(null); } } else { return(null); } }
/// <summary> /// 登录扫描检测 /// </summary> /// <returns></returns> public object LoginCheck() { if (_session_id == null) { return(null); } byte[] bytes = Wc2.SendGetRequest(_login_check_url + _session_id); string login_result = Encoding.UTF8.GetString(bytes); if (login_result.Contains("=201")) //已扫描 未登录 { string base64_image = login_result.Split(new string[] { "\'" }, StringSplitOptions.None)[1].Split(',')[1]; byte[] base64_image_bytes = Convert.FromBase64String(base64_image); MemoryStream memoryStream = new MemoryStream(base64_image_bytes, 0, base64_image_bytes.Length); memoryStream.Write(base64_image_bytes, 0, base64_image_bytes.Length); //转成图片 return(Image.FromStream(memoryStream)); } else if (login_result.Contains("=200")) //已扫描 已登录 { string login_redirect_url = login_result.Split(new string[] { "\"" }, StringSplitOptions.None)[1]; return(login_redirect_url); } else { return(null); } }
/// <summary> /// 获取sid uid 结果存放在cookies中 /// </summary> public void GetSidUid(string login_redirect) { byte[] bytes = Wc2.SendGetRequest(login_redirect + "&fun=new&version=v2&lang=zh_CN"); string pass_ticket = Encoding.UTF8.GetString(bytes); Pass_Ticket = pass_ticket.Split(new string[] { "pass_ticket" }, StringSplitOptions.None)[1].TrimStart('>').TrimEnd('<', '/'); SKey = pass_ticket.Split(new string[] { "skey" }, StringSplitOptions.None)[1].TrimStart('>').TrimEnd('<', '/'); }
private static string _login_check_url = "https://login.weixin.qq.com/cgi-bin/mmwebwx-bin/login?loginicon=true&uuid="; //后面增加会话id /// <summary> /// 获取登录二维码 /// </summary> /// <returns></returns> public Image GetQRCode() { byte[] bytes = Wc2.SendGetRequest(_session_id_url); _session_id = Encoding.UTF8.GetString(bytes).Split(new string[] { "\"" }, StringSplitOptions.None)[1]; bytes = Wc2.SendGetRequest(_qrcode_url + _session_id); return(Image.FromStream(new MemoryStream(bytes))); }
/// <summary> /// 获取微信讨论组头像 /// </summary> /// <param name="usename"></param> /// <returns></returns> public Image GetHeadImg(string usename) { byte[] bytes = Wc2.SendGetRequest(_getheadimg_url + usename); if (bytes.Length == 0) { return(null); } return(Image.FromStream(new MemoryStream(bytes))); }
/// <summary> /// 获取好友头像 /// </summary> /// <param name="username"></param> /// <returns></returns> public Image GetIcon(string username) { byte[] bytes = Wc2.SendGetRequest(_geticon_url + username); if (bytes.Length == 0) { return(null); } return(Image.FromStream(new MemoryStream(bytes))); }
/// <summary> /// 微信同步 /// </summary> /// <returns></returns> public JObject WxSync() { string sync_json = "{{\"BaseRequest\" : {{\"DeviceID\":\"e1615250492\",\"Sid\":\"{1}\", \"Skey\":\"{5}\", \"Uin\":\"{0}\"}},\"SyncKey\" : {{\"Count\":{2},\"List\":[{3}]}},\"rr\" :{4}}}"; Cookie sid = Wc2.GetCookie("wxsid"); Cookie uin = Wc2.GetCookie("wxuin"); string sync_keys = ""; foreach (KeyValuePair <string, string> p in _syncKey) { sync_keys += "{\"Key\":" + p.Key + ",\"Val\":" + p.Value + "},"; } sync_keys = sync_keys.TrimEnd(','); sync_json = string.Format(sync_json, uin.Value, sid.Value, _syncKey.Count, sync_keys, (long)(DateTime.Now.ToUniversalTime() - new System.DateTime(1970, 1, 1)).TotalMilliseconds, Login.SKey); if (sid != null && uin != null) { byte[] bytes = Wc2.SendPostRequest(_sync_url + sid.Value + "&lang=zh_CN&skey=" + Login.SKey + "&pass_ticket=" + Login.Pass_Ticket, sync_json); string sync_str = Encoding.UTF8.GetString(bytes); JObject sync_resul = JsonConvert.DeserializeObject(sync_str) as JObject; if (sync_resul["SyncKey"]["Count"].ToString() != "0") { _syncKey.Clear(); foreach (JObject key in sync_resul["SyncKey"]["List"]) { _syncKey.Add(key["Key"].ToString(), key["Val"].ToString()); } } return(sync_resul); } else { return(null); } }