新增图文素材

本文介绍了一个使用C#实现的向微信公众平台发送图文消息的示例代码。通过构造特定的数据结构并序列化为JSON字符串,最终通过HTTP客户端发送到微信服务器,完成图文消息的创建。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  public ActionResult Index()
        {


            articles_DTO ato = new articles_DTO();


            List<_articles> alist = new List<_articles>();
            _articles ar = new _articles();
            ar.title = "图文标题";
            ar.thumb_media_id = "Y9rlpsfwqqi0p1dTVfGA4J7yVu52JYbTEjw97u9Tmxo"; //永久media_id图片
            ar.author = "作者";
            ar.show_cover_pic = 1;
            ar.content = "图文内容";
            ar.content_source_url = "www.baidu.com";//跳转路径
            alist.Add(ar);


            ato.articles = alist;






            //序列化
            JsonSerializerSettings jss = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
            string js = JsonConvert.SerializeObject(ato, jss);






            StringContent sc=new StringContent(js);
         
            HttpClient hc = new HttpClient();


            //调用接口
            string url = string.Format(@"https://api.weixin.qq.com/cgi-bin/material/add_news?access_token={0}", Access_token_Tool.access_token);


            //获取返回值
            string str = hc.PostAsync(url, sc).Result.Content.ReadAsStringAsync().Result;
            
            return View();
        }


实体类:
public class articles_DTO
    {
        public List<_articles> articles { get; set; }  
    }


    public class _articles 
    {
        public string title { get; set; }
        public string thumb_media_id { get; set; }
        public string author { get; set; }
        public int show_cover_pic { get; set; }
        public string content { get; set; }
        public string content_source_url { get; set; }
    }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值