Ejemplo n.º 1
0
        /// <summary>
        ///  上传永久素材接口
        /// </summary>
        /// <param name="mediaReq"></param>
        /// <returns></returns>
        public WxMediaUploadResp UploadMedia(WxMediaUploadReq mediaReq)
        {
            var req = new OsHttpRequest();

            req.HttpMothed = HttpMothed.POST;
            req.AddressUrl = string.Concat(m_ApiUrl, "/cgi-bin/material/add_material?type=", mediaReq.type.ToString());
            req.FileParameterList.Add(new FileParameter("media", mediaReq.file_stream, mediaReq.file_name, mediaReq.content_type));

            if (mediaReq.type == WxMediaType.video)
            {
                req.Parameters.Add(new Parameter("description", $"{{\"title\":\"{mediaReq.title}\", \"introduction\":\"{mediaReq.introduction}\"}}", ParameterType.Form));
            }

            return(RestCommonOffcial <WxMediaUploadResp>(req));
        }
Ejemplo n.º 2
0
        /// <summary>
        ///  上传永久素材接口
        /// </summary>
        /// <param name="mediaReq"></param>
        /// <returns></returns>
        public async Task <WxMediaUploadResp> UploadMediaAsync(WxMediaUploadReq mediaReq)
        {
            var req = new OsHttpRequest
            {
                HttpMothed = HttpMothed.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 RestCommonOffcialAsync <WxMediaUploadResp>(req));
        }
Ejemplo n.º 3
0
        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
        }
Ejemplo n.º 4
0
        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"}
        }
Ejemplo n.º 5
0
        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_Api.UploadMedia(req);

            Assert.IsTrue(res.IsSuccess);

            // 1xOBXsBtRgetSsO8INAcQxiKCT1JD-5toVEOzrnJ2r0
        }