/// <summary> /// 获取好友头像 /// </summary> /// <param name="username"></param> /// <returns></returns> public Image GetIcon(string username) { byte[] bytes = BaseService.SendGetRequest(_geticon_url + username); return(Image.FromStream(new MemoryStream(bytes))); }
/// <summary> /// 获取微信讨论组头像 /// </summary> /// <param name="usename"></param> /// <returns></returns> public Image GetHeadImg(string usename) { byte[] bytes = BaseService.SendGetRequest(_getheadimg_url + usename); return(Image.FromStream(new MemoryStream(bytes))); }
/// <summary> /// /// 发送图片,png格式 /// </summary> /// <param name="ToUserName"></param> /// <param name="filePath"></param> public void Wx_SendFile(string ToUserName, string filePath) { Cookie sid = BaseService.GetCookie("wxsid"); Cookie uin = BaseService.GetCookie("wxuin"); Cookie webwx_data_ticket = BaseService.GetCookie("webwx_data_ticket"); string[] fileTypes = new string[] { "image/jpeg", "image/png", "image/bmp", "image/jpeg", "text/plain", "application/msword", "application/vnd.ms-excel" }; string[] mediaTypes = new string[] { "pic", "pic", "pic", "doc", "doc", "doc" }; //string ClientMsgId = DateTime.Now.Millisecond.ToString(); long ClientMsgId = (long)(DateTime.Now.ToUniversalTime() - new System.DateTime(1970, 1, 1)).TotalMilliseconds; FileInfo file = new FileInfo(filePath); if (!file.Exists) { return; } string fileMd5 = GetMD5HashFromFile(file.FullName); byte[] fileData = File.ReadAllBytes(file.FullName); #region data string data = @"------WebKitFormBoundaryqmAlcppnh4tFP6al Content-Disposition: form-data; name=""id"" WU_FILE_0 ------WebKitFormBoundaryqmAlcppnh4tFP6al Content-Disposition: form-data; name=""name"" " + file.FullName + @" ------WebKitFormBoundaryqmAlcppnh4tFP6al Content-Disposition: form-data; name=""type"" " + "image/png" + @" ------WebKitFormBoundaryqmAlcppnh4tFP6al Content-Disposition: form-data; name=""lastModifiedDate"" " + DateTime.Now.ToString("r").Replace(",", "") + @"+0800 ------WebKitFormBoundaryqmAlcppnh4tFP6al Content-Disposition: form-data; name=""size"" " + fileData.Length.ToString() + @" ------WebKitFormBoundaryqmAlcppnh4tFP6al Content-Disposition: form-data; name=""mediatype"" " + "pic" + @" ------WebKitFormBoundaryqmAlcppnh4tFP6al Content-Disposition: form-data; name=""uploadmediarequest"" {""UploadType"":2,""BaseRequest"":{""Uin"":" + uin.Value + @",""Sid"":""" + sid.Value + @""",""Skey"":""" + LoginService.SKey + @""",""DeviceID"":""" + "e831645047756137" + @"""},""ClientMediaId"":" + ClientMsgId + @",""TotalLen"":" + fileData.Length.ToString() + @",""StartPos"":0,""DataLen"":" + fileData.Length.ToString() + @",""MediaType"":4,""FromUserName"":""" + frmMain.usernameid + @""",""ToUserName"":""" + ToUserName + @""",""FileMd5"":""" + fileMd5 + @"""} ------WebKitFormBoundaryqmAlcppnh4tFP6al Content-Disposition: form-data; name=""webwx_data_ticket"" " + webwx_data_ticket.Value + @" ------WebKitFormBoundaryqmAlcppnh4tFP6al Content-Disposition: form-data; name=""pass_ticket"" " + LoginService.Pass_Ticket + @" ------WebKitFormBoundaryqmAlcppnh4tFP6al Content-Disposition: form-data; name=""filename""; filename=""" + file.Name + @""" Content-Type: " + "image/png" + @" "; #endregion byte[] postData = Encoding.UTF8.GetBytes(data); byte[] endData = Encoding.UTF8.GetBytes("\r\n------WebKitFormBoundaryqmAlcppnh4tFP6al--\r\n"); List <byte[]> lt = new List <byte[]>(); lt.Add(postData); lt.Add(fileData); lt.Add(endData); byte[] tmp = new byte[postData.Length + fileData.Length]; System.Buffer.BlockCopy(postData, 0, tmp, 0, postData.Length); System.Buffer.BlockCopy(fileData, 0, tmp, postData.Length, fileData.Length); byte[] body = new byte[tmp.Length + endData.Length]; System.Buffer.BlockCopy(tmp, 0, body, 0, tmp.Length); System.Buffer.BlockCopy(endData, 0, body, tmp.Length, endData.Length); string url = _image_url; byte[] bytes = BaseService.SendPostRequestByByte(url, body, "----WebKitFormBoundaryqmAlcppnh4tFP6al"); string send_result = Encoding.UTF8.GetString(bytes); if (send_result.IndexOf("\"Ret\": 1,") > 0) { return; } /////string ret = http.PostBytes(url, lt, "https://" + info.fun + ".qq.com/", "*/*", "multipart/form-data; boundary=----WebKitFormBoundaryqmAlcppnh4tFP6al"); ///// /////Hashtable json = (Hashtable)ClsJson.Decode(ret); /////if (json == null) /////{ ///// return; /////} string MediaId = send_result.Substring(send_result.IndexOf("\"MediaId\":"), send_result.IndexOf("\"StartPos\":") - send_result.IndexOf("\"MediaId\":")).Replace("\"MediaId\": \"", "").Replace("\",", "").Replace(" ", "").Replace("\n", ""); //SendMsg(MediaId, frmMain.usernameid, ToUserName,3); Wx_SendPicByMediaId(ToUserName, MediaId); }