public static HttpTaskParams GetUploadImage(string host, WxAccount account, string toUserNameId, string imagePath) { string url = string.Format("{0}?f=json", WxHttpApi.GetFileUploadUrl(host, WxHttpApi.URL_WX_FILE_UPLOAD)); HttpTaskParams htp = HttpTaskParams.NewPost(url); FileInfo info = new FileInfo(imagePath); htp.AddStringParam("id", "WU_FILE_" + fileCount); htp.AddStringParam("name", info.Name); htp.AddStringParam("type", "image/jpeg"); htp.AddStringParam("lastModifiedDate", info.LastWriteTime.ToString("r", DateTimeFormatInfo.InvariantInfo)); htp.AddStringParam("size", info.Length.ToString()); htp.AddStringParam("mediatype", "pic"); htp.AddStringParam("webwx_data_ticket", account.DataTicket); htp.AddStringParam("pass_ticket", account.PassTicket); htp.AddFileParam("filename", imagePath, WxReqUtil.GetImageMimeType(info)); htp.AddStringParam("uploadmediarequest", WxReqUtil.GetUploadMediaRequestBody(account, toUserNameId, info, imagePath)); return(htp); }
/// <summary> /// 上传视频文件 /// </summary> /// <param name="host"></param> /// <param name="account"></param> /// <param name="toUserNameId"></param> /// <param name="videoPath"></param> /// <returns></returns> /// https://file.wx.qq.com/cgi-bin/mmwebwx-bin/webwxuploadmedia?f=json public static HttpTaskParams GetUploadVideo(string host, WxAccount account, string toUserNameId, string videoPath) { string url = string.Format("{0}?f=json", WxHttpApi.GetFileUploadUrl(host, WxHttpApi.URL_WX_FILE_UPLOAD)); HttpTaskParams htp = HttpTaskParams.NewPost(url); FileInfo info = new FileInfo(videoPath); htp.AddStringParam("id", "WU_FILE_" + fileCount); htp.AddStringParam("name", info.Name); htp.AddStringParam("type", WxReqUtil.GetVideoMimeType(info));//"video/mp4" htp.AddStringParam("lastModifiedDate", info.LastWriteTime.ToString("r", DateTimeFormatInfo.InvariantInfo)); htp.AddStringParam("size", info.Length.ToString()); htp.AddStringParam("chunks", "1"); //分段数,这里一次上传,不分段 htp.AddStringParam("chunk", "0"); //第几段 htp.AddStringParam("mediatype", "video"); htp.AddStringParam("uploadmediarequest", WxReqUtil.GetUploadMediaRequestBody(account, toUserNameId, info, videoPath)); htp.AddStringParam("webwx_data_ticket", account.DataTicket); htp.AddStringParam("pass_ticket", account.PassTicket); htp.AddFileParam("filename", videoPath); return(htp); }