/// <summary> /// 上传到微信素材库 /// </summary> /// <returns></returns> public ActionResult UploadToWeixinMaterial() { HttpRequestBase request = this.HttpContext.Request; string strFileId = request.Form["txtFileUpload_Id"]; string cachingKey = "fsUploadResult:" + strFileId; ApiResult <WeixinAddMaterialResult> apiResult = new ApiResult <WeixinAddMaterialResult>(); FileUploadResult saveResult = SaveFile(); if (saveResult.Success == false) { apiResult.Message = saveResult.Message; _cachingService.Set(cachingKey, apiResult, _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 <WeixinAddMaterialResult> addNormalMaterialResult = MaterialApiWrapper.AddNormalMaterial(domainContext, file, MaterialType.Image); apiResult.Success = addNormalMaterialResult.Success; if (addNormalMaterialResult.Success) { FileInfo fileInfo = new FileInfo(request.Files[0].FileName); addNormalMaterialResult.ApiResult.FileName = fileInfo.Name; apiResult.Message = saveResult.StoreFilePath; } else { apiResult.Message = addNormalMaterialResult.Message; } apiResult.Data = addNormalMaterialResult.ApiResult; _cachingService.Set(cachingKey, apiResult, _uploadResultExpiresIn); return(new HttpStatusCodeResult(200)); }
/// <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)); }