微信公众号素材管理新增其他类型永久素材

前台:


    素材管理
    
    
	


    
图片素材:

备注说明:

图片上传:

后台:
	/// 
        /// 上传图片永久素材,获取media_id和url
        /// 失败返回举例{"errcode":40007,"errmsg":"invalid media_id"}
        /// 
        /// 
        /// 
        protected void UploadImage(object sender, EventArgs e)
        {
            string result = string.Empty;
            string filename = FileUpload1.FileName;
            string strRemark = Remark.Text.ToString().Trim();

            #region 图片的判断
            //不选择图片判定
            if (string.IsNullOrEmpty(filename))
            {
                ShowMsgHelper.Error("请选择要上传的图片");
                return;
            }

            //判断图片格式
            string FileType = Path.GetExtension(filename).ToLower();
            if (!(FileType.Equals(".jpg") || FileType.Equals(".png") || FileType.Equals(".bmp") || FileType.Equals(".jpeg") || FileType.Equals(".gif")))
            {
                ShowMsgHelper.Error("图片仅支持bmp/png/jpeg/jpg/gif格式");
                return;
            }

            //判断大小
            int ImgSize = FileUpload1.PostedFile.ContentLength;//此处取得的文件大小的单位是byte 
            if ((ImgSize / 1024) >= (1024 * 2))//转换为kb  
            {
                ShowMsgHelper.Error("图片大小必须在2MB以下");
                return;
            }
            #endregion
            string newFilename = System.DateTime.Now.ToString("yyyyMMddHHmmssffff") + filename;
            HttpPostedFile myFile = FileUpload1.PostedFile;
            myFile.SaveAs(Server.MapPath("~/UploadPicture/") + newFilename);
            string filepath = Server.MapPath("UploadPicture\\") + newFilename;//(本地服务器的地址)  

            HttpPostedFile file = Request.Files[0];
            HttpPostedFileBase isFile = new HttpPostedFileWrapper(file) as HttpPostedFileBase;

            MaterialManager MateMng = new MaterialManager();
			//该类的方法见http://download.csdn.net/detail/u010304557/9380447
            result = MateMng.MaterialUploads(AccessToken.Instance.access_token, isFile, "image", "", "");
            if (result.Contains("media_id"))
            {
                //发送成功
				//根据自己的业务逻辑使用media_id和url
				//public struct StructMaterial
				//{
				//    public string media_id { get; set; }
				//    public string url { get; set; }
				//}
                //StructMaterial StrMate = new StructMaterial();
                //StrMate = JsonConvert.DeserializeObject(result);
                
            }
            else
            { 
                //上传失败			
				//根据自己的业务逻辑使用errcode和errmsg
				//public struct StructErrReturn
				//{
				//	public string errcode { get; set; }
				//	public string errmsg { get; set; } 
				//}
                //StructErrReturn StruErrRet = new StructErrReturn();
                //StruErrRet = JsonConvert.DeserializeObject(result);
            }
        }

你可能感兴趣的:(微信)