Exemple #1
0
        public static void UploadMedia(string fromUserName, string toUserName, string mediaName)
        {
            var len = DataUtil.GetLength(mediaName);

            var md5 = DataUtil.GetMD5(mediaName);

            string uploadmediarequest = "{\"UploadType\":2,\"BaseRequest\":{\"Uin\":" + LoginHelper.LoginPageCookie.wxuin + ",\"Sid\":\"" + LoginHelper.LoginPageCookie.wxsid + "\",\"Skey\":\"" + LoginHelper.LoginPageXml.skey + "\",\"DeviceID\":\"e828447528404774\"},\"ClientMediaId\":" + RandomUtil.GetRandom(13) + ",\"TotalLen\":" + len + ",\"StartPos\":0,\"DataLen\":" + len + ",\"MediaType\":4,\"FromUserName\":\"" + fromUserName + "\",\"ToUserName\":\"" + toUserName + "\",\"FileMd5\":\"" + md5 + "\"}";

            var wxUploadMedia = SerializeUtil.Deserialize <WXUploadMedia>(WebClientUtil.UploadMediaOnCookie(UploadMediaUrl, mediaName, uploadmediarequest, LoginHelper.LoginPageCookie.webwx_data_ticket, LoginHelper.LoginPageXml.pass_ticket));

            if (wxUploadMedia != null && !string.IsNullOrEmpty(wxUploadMedia.MediaId))
            {
                SendImage(fromUserName, toUserName, wxUploadMedia.MediaId);
            }
        }