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; }
}
{
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; }
}