asp.net微信开发(高级群发图文)

asp.net微信开发(高级群发图文)

我们先看从素材库中获取图文素材的代码,界面:

asp.net微信开发(高级群发图文)

素材列表,我是使用的repeater控件,

前台代码如下:

<!--弹出选择素材窗口--> <div> <div><span>选择素材</span> <span><a href="https://www.jb51.net/WxNewTuWen.aspx">新建图文素材</a></span> <a><img src="https://www.jb51.net/images/close1.png" alt="" /></a>&nbsp;&nbsp;</div> <div> <asp:UpdatePanel runat="server"> <ContentTemplate> <div><asp:LinkButton runat="server" ><div>确认选择</div></asp:LinkButton> <span><asp:LinkButton CssClass="LinkbtnRefresh" runat="server"><div>刷新</div></asp:LinkButton></span> <span><asp:LinkButton CssClass="LinkbtnRefresh" runat="server"><div>删除素材</div></asp:LinkButton></span> </div> <div runat="server"> <asp:Repeater runat="server" OnItemDataBound="Repeatersucailist_ItemDataBound"> <ItemTemplate> <table > <tr> <td><asp:Image CssClass="fenmianstyle2" runat="server" /></td> <td> <asp:Repeater runat="server"> <ItemTemplate> <ul> <li><%# Eval("title") %></li> </ul> </ItemTemplate> </asp:Repeater> </td> <td> <asp:Label runat="server" Text="Label"></asp:Label> </td> <td> <asp:CheckBox runat="server" /> <asp:Label runat="server" Visible="false" Text=""></asp:Label> </td> </tr> </table> </ItemTemplate> </asp:Repeater> <div> <span>本类型素材总数量为:</span><span><asp:Label runat="server" Text="0"></asp:Label></span>&nbsp;&nbsp; <span>本次获取的素材数量为:</span><span><asp:Label runat="server" Text="0"></asp:Label></span> </div> </div> </ContentTemplate> </asp:UpdatePanel> </div> </div> <div></div>

后台代码如下:

/// <summary> /// 绑定图文素材列表 /// </summary> private void BindNewsSucaiList() { WeiXinServer wxs = new WeiXinServer(); string res = ""; ///从缓存读取accesstoken string Access_token = Cache["Access_token"] as string; if (Access_token == null) { //如果为空,重新获取 Access_token = wxs.GetAccessToken(); //设置缓存的数据7000秒后过期 Cache.Insert("Access_token", Access_token, null, DateTime.Now.AddSeconds(7000), System.Web.Caching.Cache.NoSlidingExpiration); } string Access_tokento = Access_token.Substring(17, Access_token.Length - 37); string posturl = "https://api.weixin.qq.com/cgi-bin/material/batchget_material?access_token=" + Access_tokento; //POST数据例子: POST数据例子:{"type":TYPE,"offset":OFFSET,"count":COUNT} string postData = "{\"type\":\"news\",\"offset\":\"0\",\"count\":\"20\"}"; res = wxs.GetPage(posturl, postData); //使用前需要引用Newtonsoft.json.dll文件 JObject jsonObj = JObject.Parse(res); int groupsnum = jsonObj["item"].Count(); List<WxNewsSucaiIteminfo> newssucaiitemlist = new List<WxNewsSucaiIteminfo>(); List<WxNewsSuCaiItemlistinfo> WxNewsSuCaiItemlist = new List<WxNewsSuCaiItemlistinfo>(); for (int i = 0; i < groupsnum; i++) { WxNewsSucaiIteminfo newssucaiitem = new WxNewsSucaiIteminfo(); newssucaiitem.media_id = jsonObj["item"][i]["media_id"].ToString(); newssucaiitem.update_time = jsonObj["item"][i]["update_time"].ToString(); newssucaiitem.total_count = jsonObj["total_count"].ToString(); newssucaiitem.item_count = jsonObj["item_count"].ToString(); newssucaiitemlist.Add(newssucaiitem); int news_itemcount = jsonObj["item"][i]["content"]["news_item"].Count(); if (news_itemcount > 0) { for (int j = 0; j < news_itemcount; j++) { WxNewsSuCaiItemlistinfo wnscilinfo = new WxNewsSuCaiItemlistinfo(); wnscilinfo.title = jsonObj["item"][i]["content"]["news_item"][j]["title"].ToString(); wnscilinfo.thumb_media_id = jsonObj["item"][i]["content"]["news_item"][j]["thumb_media_id"].ToString(); wnscilinfo.show_cover_pic = int.Parse(jsonObj["item"][i]["content"]["news_item"][j]["show_cover_pic"].ToString()); wnscilinfo.author = jsonObj["item"][i]["content"]["news_item"][j]["author"].ToString(); wnscilinfo.digest = jsonObj["item"][i]["content"]["news_item"][j]["digest"].ToString(); wnscilinfo.content = jsonObj["item"][i]["content"]["news_item"][j]["content"].ToString(); wnscilinfo.url = jsonObj["item"][i]["content"]["news_item"][j]["url"].ToString(); wnscilinfo.content_source_url = jsonObj["item"][i]["content"]["news_item"][j]["content_source_url"].ToString(); wnscilinfo.media_id = newssucaiitem.media_id.ToString(); WxNewsSuCaiItemlist.Add(wnscilinfo); } } } Session["WxNewsSuCaiItemlist"] = WxNewsSuCaiItemlist; this.Repeatersucailist.DataSource = newssucaiitemlist; this.Repeatersucailist.DataBind(); }

再来看看,新建单图文信息界面:

asp.net微信开发(高级群发图文)

asp.net微信开发(高级群发图文)

新建单图文上传封面,删除封面的代码如下:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjwjxw.html