Beispiel #1
0
        /// <summary>
        /// 在图文消息的具体内容中,将过滤外部的图片链接,开发者可以通过下述接口上传图片得到URL,放到图文内容中使用
        /// 本接口所上传的图片不占用公众号的素材库中图片数量的5000个的限制。图片仅支持jpg/png格式,大小必须在1MB以下。
        /// https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444738729&token=&lang=zh_CN
        /// </summary>
        /// <returns></returns>
        public ActionResult UploadToWeixinImg()
        {
            HttpRequestBase request = this.HttpContext.Request;

            string strFileId  = request.Form["txtFileUpload_Id"];
            string cachingKey = "fsUploadResult:" + strFileId;

            UploadToWeixinImgResult uploadToWeixinImgResult = new UploadToWeixinImgResult();

            FileUploadResult saveResult = SaveFile();

            if (saveResult.Success == false)
            {
                uploadToWeixinImgResult.Message = saveResult.Message;
                _cachingService.Set(cachingKey, uploadToWeixinImgResult, _uploadResultExpiresIn);
                return(new HttpStatusCodeResult(200));
            }

            string        domainId      = request.Form["txtFileUpload_Domain"];
            DomainContext domainContext = _fileDomainPool.GetDomainContext(Guid.Parse(domainId));

            string file = Server.MapPath("/") + saveResult.StoreFilePath;

            RequestApiResult <WeixinUploadImgResult> weixinUploadImgResult =
                MaterialApiWrapper.UploadImg(domainContext, file);

            uploadToWeixinImgResult.Success = weixinUploadImgResult.Success;
            if (weixinUploadImgResult.Success == false)
            {
                uploadToWeixinImgResult.Message = weixinUploadImgResult.Message;
            }
            else
            {
                uploadToWeixinImgResult.Id            = saveResult.Id;
                uploadToWeixinImgResult.WeixinUrl     = weixinUploadImgResult.ApiResult.Url;
                uploadToWeixinImgResult.StoreFilePath = saveResult.StoreFilePath;
            }
            _cachingService.Set(cachingKey, uploadToWeixinImgResult, _uploadResultExpiresIn);

            return(new HttpStatusCodeResult(200));
        }
Beispiel #2
0
        public ActionResult GetUploadToWeixinImgResult()
        {
            HttpRequestBase request = this.HttpContext.Request;

            string strFileId = request.QueryString["fileId"];

            string cachingKey = "fsUploadResult:" + strFileId;

            UploadToWeixinImgResult uploadToWeixinImgResult = _cachingService.Get <UploadToWeixinImgResult>(cachingKey);

            if (uploadToWeixinImgResult == null)
            {
                return(RespondResult(false, "指定的上传信息不存在。"));
            }

            if (uploadToWeixinImgResult.Success)
            {
                return(RespondDataResult(uploadToWeixinImgResult));
            }
            else
            {
                return(RespondResult(false, uploadToWeixinImgResult.Message));
            }
        }