Beispiel #1
0
        public string UploadVideo(string path, string From, string To)
        {
            Cookie        sid         = HttpServer.GetCookie("wxsid");
            Cookie        uin         = HttpServer.GetCookie("wxuin");
            FileInfo      file        = new FileInfo(path);
            string        send_result = string.Empty;
            StringBuilder sb          = new StringBuilder();

            sb.AppendFormat("{{\"UploadType\":2,\"BaseRequest\":{{\"Uin\":{0},\"Sid\":\"{1}\",\"Skey\":\"{2}\",\"DeviceID\":\"e{3}\"}},", uin.Value, sid.Value, LoginService.SKey, Utils.GetTimeSpan());
            sb.AppendFormat("\"ClientMediaId\":{3},\"TotalLen\":{0},\"StartPos\":0,\"DataLen\":{1},\"MediaType\":4,\"FromUserName\":\"{4}\",\"ToUserName\":\"{5}\",\"FileMd5\":\"{2}\"}}", file.Length, file.Length, GetFileMD5Hash.GetMD5Hash(path), Utils.GetTimeSpan(), From, To);
            FileStream fs = file.OpenRead();

            byte[] buffer    = new byte[1024 * 512];
            int    bytesRead = 0;
            var    d         = fs.Length / (512 * 1024.0);
            //分块上传
            double chunks = Math.Ceiling(Convert.ToDouble(d));
            int    chunk  = 0;
            int    length = 512 * 1024;

            while ((bytesRead = fs.Read(buffer, 0, buffer.Length)) != 0)
            {
                if (chunk == chunks - 1)
                {
                    length = (int)(fs.Length - (chunks - 1) * length);
                }
                byte[] bytes = HttpServer.SendPostRequestByVideo2(_uplpadFileUrl, sb.ToString(), file, buffer, chunks, chunk, length);
                if (bytes != null)
                {
                    send_result = Encoding.UTF8.GetString(bytes);
                }
                chunk++;
            }
            fs.Close();
            return(send_result);
        }
Beispiel #2
0
        public string UploadFile(string path)
        {
            Cookie        sid  = HttpServer.GetCookie("wxsid");
            Cookie        uin  = HttpServer.GetCookie("wxuin");
            FileInfo      file = new FileInfo(path);
            StringBuilder sb   = new StringBuilder();

            sb.AppendFormat("{{\"UploadType\":2,\"BaseRequest\":{{\"Uin\":{0},\"Sid\":\"{1}\",\"Skey\":\"{2}\",\"DeviceID\":\"e{3}\"}},", uin.Value, sid.Value, LoginService.SKey, Utils.GetTimeSpan());
            sb.AppendFormat("\"ClientMediaId\":{3},\"TotalLen\":{0},\"StartPos\":0,\"DataLen\":{1},\"MediaType\":4,\"FileMd5\":\"{2}\"}}", file.Length, file.Length, GetFileMD5Hash.GetMD5Hash(path), Utils.GetTimeSpan());
            UpoladType uploadType = GetUpooadType(file);

            uploadType.uploadmediarequest = sb.ToString();
            uploadType.Url = _uplpadFileUrl;
            byte[] bytes       = HttpServer.SendPostRequestByFile(uploadType);
            string send_result = string.Empty;

            if (bytes != null)
            {
                send_result = Encoding.UTF8.GetString(bytes);
            }
            return(send_result);
        }