Beispiel #1
0
        public void MaterialOtherPermanentAdd()
        {
            string    type       = Request["type"];
            WebClient wxUpload   = new WebClient();
            string    uploadPath = "/uploads/";
            string    folder     = Server.MapPath(uploadPath);

            //自动创建目录
            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
            }
            HttpPostedFile file     = Request.Files.Get(0);
            string         filename = folder + file.FileName;

            file.SaveAs(filename);
            //API所需的媒体信息
            wxUpload.Headers.Add("Content-Type", file.ContentType);
            wxUpload.Headers.Add("filename", file.FileName);
            wxUpload.Headers.Add("filelength", file.ContentLength.ToString());
            string videopams = "";

            if (type == "video")
            {
                videopams = "{\"title\":\"test\",\"introduction\":\"testcontent\"}";
                wxUpload.Headers.Add("description", videopams);
            }

            byte[] result1 =
                wxUpload.UploadFile(
                    new Uri(string.Format(
                                "https://api.weixin.qq.com/cgi-bin/material/add_material?access_token={0}&type={1}",
                                getAccessToken(), "image")), filename);
            string resultjson = Encoding.UTF8.GetString(result1); //在这里获取json数据,获得图片URL

            UploadJsonResult str = JsonConvert.DeserializeObject <UploadJsonResult>(resultjson);

            if (str.errcode == 0)
            {
                Response.Write("<script>alert('新增成功');window.location='materialmanager.aspx';</script>");
            }
            else
            {
                Response.Write("<script>alert('新增失败:" + resultjson + "');window.location='materialmanager.aspx';</script>");
            }
        }
Beispiel #2
0
        public void MaterialTemporaryAdd()
        {
            string type = Request["type"];

            WebClient wxUpload   = new WebClient();
            string    uploadPath = "~/uploads/";
            string    folder     = Server.MapPath(uploadPath);

            //自动创建目录
            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
            }
            HttpPostedFile file     = Request.Files.Get(0);
            string         filename = folder + file.FileName;

            file.SaveAs(filename);
            //API所需的媒体信息
            wxUpload.Headers.Add("Content-Type", file.ContentType);
            wxUpload.Headers.Add("filename", file.FileName);
            wxUpload.Headers.Add("filelength", file.ContentLength.ToString());
            byte[] result1 =
                wxUpload.UploadFile(
                    new Uri(string.Format(
                                "https://api.weixin.qq.com/cgi-bin/media/upload?access_token={0}&type={1}",
                                getAccessToken(),
                                type)), filename);
            string resultjson = Encoding.UTF8.GetString(result1); //在这里获取json数据,获得图片URL

            UploadJsonResult str = JsonConvert.DeserializeObject <UploadJsonResult>(resultjson);

            if (str.errcode == 0)
            {
                Response.Write("<script>alert('新增成功');window.location='materialmanager.aspx';</script>");
            }
            else
            {
                Response.Write("<script>alert('新增失败:" + str.errmsg + "');window.location='materialmanager.aspx';</script>");
            }
        }
Beispiel #3
0
        public void MassUploadImgText()
        {
            string title = Request["title"];

            if (string.IsNullOrEmpty(title))
            {
                throw new Exception("标题不能为空");
            }
            string mediaid = Request["mediaid"];

            if (string.IsNullOrEmpty(mediaid))
            {
                throw new Exception("素材id不能为空");
            }
            string author = Request["author"];

            if (string.IsNullOrEmpty(author))
            {
                throw new Exception("作者不能为空");
            }

            string digest = Request["digest"];


            int isshow = Convert.ToInt32(Request["isshow"]);

            string content = Request["content"];

            if (string.IsNullOrEmpty(content))
            {
                throw new Exception("具体内容不能为空");
            }
            string sourceurl = Request["sourceurl"];

            if (string.IsNullOrEmpty(sourceurl))
            {
                throw new Exception("原文地址不能为空");
            }
            articles item = new articles();

            item.title              = title;
            item.author             = author;
            item.thumb_media_id     = mediaid;
            item.digest             = digest;
            item.show_cover_pic     = isshow;
            item.content            = content;
            item.content_source_url = sourceurl;

            string pams = "{\"articles\": [" + JsonConvert.SerializeObject(item) + "]}";

            string data = RequestType.HttpPost("https://api.weixin.qq.com/cgi-bin/media/uploadnews?access_token=" + getAccessToken(), pams);

            UploadJsonResult str = JsonConvert.DeserializeObject <UploadJsonResult>(data);

            if (str.errcode == 0)
            {
                result = Return_Msg(Enum_ReturnStatus.成功, "上传成功", data);
            }
            else
            {
                throw new Exception("上传失败:" + str.errmsg);
            }
        }