/// <summary> /// 上传永久素材接口 /// </summary> /// <param name="mediaReq"></param> /// <returns></returns> public async Task <WXMediaUploadResp> UploadMediaAsync(WXMediaUploadReq mediaReq) { var req = new OssHttpRequest { HttpMethod = HttpMethod.Post, AddressUrl = string.Concat(m_ApiUrl, "/cgi-bin/material/add_material?type=", mediaReq.type.ToString()) }; req.FileParameters.Add(new FileParameter("media", mediaReq.file_stream, mediaReq.file_name, mediaReq.content_type)); if (mediaReq.type == WXMediaType.video) { req.FormParameters.Add(new FormParameter("description", $"{{\"title\":\"{mediaReq.title}\", \"introduction\":\"{mediaReq.introduction}\"}}")); } return(await RestCommonPlatAsync <WXMediaUploadResp>(req)); }
public void UploadMediaTest() { var imageFile = new FileStream("E:\\1.jpg", FileMode.Open, FileAccess.Read); var req = new WXMediaUploadReq(); req.type = WXMediaType.image; req.content_type = "image/jpeg"; req.file_name = "1.jpg"; req.file_stream = imageFile; var res = m_MediaApi.UploadMediaAsync(req).WaitResult(); Assert.IsTrue(res.IsSuccess()); // 1xOBXsBtRgetSsO8INAcQ1x8rkSc5MGMXuFfWXkGRDg // http://mmbiz.qpic.cn/mmbiz_jpg/N3louEAebXzhBzgsstFNBicyF1j1ZFIGgOaIEfWE2ra8KrwHvT5xuPlloMONKoj4rp5E5rFmfI8ZEz0qbSC4GFw/0?wx_fmt=jpeg }
public void UploadVedioMediaTest() { var imageFile = new FileStream("E:\\11.mp4", FileMode.Open, FileAccess.Read); var req = new WXMediaUploadReq(); req.type = WXMediaType.video; req.content_type = "video/mpeg4"; req.file_name = "11.mp4"; req.file_stream = imageFile; req.introduction = "只是试一试好不好玩!"; req.title = "只是个视频"; var res = m_MediaApi.UploadMediaAsync(req).WaitResult(); Assert.IsTrue(res.IsSuccess()); //{ "media_id":"zXOYSQS_A3op3R9ZW0EYKwbjgQ544KTICzLWYAUgpfU"} }