说到高级群发,微信的参考资料http://mp.weixin.qq.com/wiki/14/0c53fac3bdec3906aaa36987b91d64ea.html

首先我们先来讲解一下群发文本信息的过程,我个人开发程序是首先要有UI才能下手去写代码,界面如下,

看图我们也可以看出首先我们要获取该微信号本月还能群发几条信息,关于怎么计算,就是群发成功一条信息,就在本地数据库存储一条信息,用来计算条数,(这个我相信都会),大于4条就不能发送(这里我已经限制死了,因为服务号每月只能发送4条,多发送也没用,用户只能收到4条,除非使用预览功能,挨个发送,但预览功能也只能发送100次,或许可能使用开发者模式下群发信息可以多发送N次哦,因为我群发了两次之后,再进入到微信公众平台官网后台看到的居然还能群发4条,有点郁闷哦!),群发对象可选择为全部用户或分组用户,和由于节省群发次数,这里我就不测试群发文字信息了,具体参考如下代码:

  /// <summary>
/// 绑定本月剩余群发条数
/// </summary>
private void BindMassCount()
{
WxMassService wms = new WxMassService();
List<WxMassInfo> wxmaslist = wms.GetMonthMassCount();
//官方微信服务号每月只能群发4条信息,(订阅号每天1条)多余信息,将不会成功推送,这里已经设定为4
this.lbMassCounts.Text = ( - int.Parse(wxmaslist.Count.ToString())).ToString(); if (wxmaslist.Count >= )
{
this.LinkBtnSubSend.Enabled = false;
this.LinkBtnSubSend.Attributes.Add("Onclick", "return confirm('群发信息已达上限!请下月初再试!')");
}
else
{
this.LinkBtnSubSend.Enabled = true;
this.LinkBtnSubSend.Attributes.Add("Onclick", "return confirm('您确定要群发此条信息??')");
}
}
  /// <summary>
/// 绑定分组列表
/// </summary>
private void BindGroupList()
{
WeiXinServer wxs = new WeiXinServer(); ///从缓存读取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(), System.Web.Caching.Cache.NoSlidingExpiration);
} string Access_tokento = Access_token.Substring(, Access_token.Length - ); string jsonres = ""; string content = Cache["AllGroups_content"] as string; if (content == null)
{
jsonres = "https://api.weixin.qq.com/cgi-bin/groups/get?access_token=" + Access_tokento; HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(jsonres);
myRequest.Method = "GET";
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
content = reader.ReadToEnd();
reader.Close(); //设置缓存的数据7000秒后过期
Cache.Insert("AllGroups_content", content, null, DateTime.Now.AddSeconds(), System.Web.Caching.Cache.NoSlidingExpiration);
} //使用前需要引用Newtonsoft.json.dll文件
JObject jsonObj = JObject.Parse(content); int groupsnum = jsonObj["groups"].Count(); this.DDLGroupList.Items.Clear();//清除 for (int i = ; i < groupsnum; i++)
{
this.DDLGroupList.Items.Add(new ListItem(jsonObj["groups"][i]["name"].ToString() + "(" + jsonObj["groups"][i]["count"].ToString() + ")", jsonObj["groups"][i]["id"].ToString()));
}
}
/// <summary>
/// 选择群发对象类型,显示隐藏分组列表项
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void DDLMassType_SelectedIndexChanged(object sender, EventArgs e)
{
if (int.Parse(this.DDLMassType.SelectedValue.ToString()) > )
{
this.DDLGroupList.Visible = true;
}
else
{
this.DDLGroupList.Visible = false;
}
}
 /// <summary>
/// 群发
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void LinkBtnSubSend_Click(object sender, EventArgs e)
{
//根据单选按钮判断类型,发送
///如果选择的是文本消息
if (this.RadioBtnList.SelectedValue.ToString().Equals(""))
{
if (String.IsNullOrWhiteSpace(this.txtwenben.InnerText.ToString().Trim()))
{
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('请输入您要群发文本内容!');", true);
return;
}
if (this.txtwenben.InnerText.ToString().Trim().Length<)
{
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('文本内容至少需要10个字符以上!');", true);
return;
} WxMassService wms = new WxMassService();
List<WxMassInfo> wxmaslist = wms.GetMonthMassCount(); if (wxmaslist.Count >= )
{
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('本月可群发消息数量已达上限!');", true);
return;
}
else
{ //如何群发类型为全部用户,根据openID列表群发给全部用户,订阅号不可用,服务号认证后可用
if (this.DDLMassType.SelectedValue.ToString().Equals(""))
{
StringBuilder sbs = new StringBuilder();
sbs.Append(GetAllUserOpenIDList()); WeiXinServer wxs = new WeiXinServer(); ///从缓存读取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(), System.Web.Caching.Cache.NoSlidingExpiration);
} string Access_tokento = Access_token.Substring(, Access_token.Length - ); string posturl = "https://api.weixin.qq.com/cgi-bin/message/mass/send?access_token=" + Access_tokento; ///群发POST数据示例如下:
// {
// "touser":[
// "OPENID1",
// "OPENID2"
// ],
// "msgtype": "text",
// "text": { "content": "hello from boxer."}
//} string postData = "{\"touser\":[" + sbs.ToString() +
"],\"msgtype\":\"text\",\"text\":{\"content\":\"" + this.txtwenben.InnerText.ToString() +
"\"}"; string tuwenres = wxs.GetPage(posturl, postData); //使用前需药引用Newtonsoft.json.dll文件
JObject jsonObj = JObject.Parse(tuwenres); if (jsonObj["errcode"].ToString().Equals(""))
{
//群发成功后,保存记录
WxMassInfo wmi = new WxMassInfo(); wmi.ImageUrl = "";
wmi.type = "文本";
wmi.contents = this.txtwenben.InnerText.ToString().Trim();
wmi.title = this.txtwenben.InnerText.ToString().Substring(, ) + "..."; if (this.DDLMassType.SelectedValue.ToString().Equals(""))
{
wmi.massObject = this.DDLMassType.SelectedItem.Text.ToString();
}
else
{
wmi.massObject = this.DDLGroupList.SelectedItem.Text.ToString();
} wmi.massStatus = "成功";//群发成功之后返回的状态码
wmi.massMessageID = jsonObj["msg_id"].ToString();//群发成功之后返回的消息ID wmi.massDate = System.DateTime.Now.ToString(); int num = wms.AddWxMassInfo(wmi); if (num > )
{
Session["wmninfo"] = null;
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('群发任务已提交成功!!!数据已保存!');location='WxMassManage.aspx';", true);
return;
}
else
{
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('群发任务已提交成功!!!数据保存失败!');", true);
return;
}
}
else
{
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('群发任务提交失败!!');", true);
return;
}
}
else
{
string group_id = this.DDLGroupList.SelectedValue.ToString(); WeiXinServer wxs = new WeiXinServer(); ///从缓存读取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(), System.Web.Caching.Cache.NoSlidingExpiration);
} string Access_tokento = Access_token.Substring(, Access_token.Length - ); string posturl = "https://api.weixin.qq.com/cgi-bin/message/mass/send?access_token=" + Access_tokento; ///群发POST数据示例如下:
// {
// "filter":{
// "is_to_all":false
// "group_id":"2"
// },
// "text":{
// "content":"CONTENT"
// },
// "msgtype":"text"
//}
//} string postData = "{\"filter\":{\"is_to_all\":\"false\"\"group_id\":\"" + group_id +
"\"},\"text\":{\"content\":\"" + this.txtwenben.InnerText.ToString() +
"\"},\"msgtype\":\"text\"}"; string tuwenres = wxs.GetPage(posturl, postData); //使用前需药引用Newtonsoft.json.dll文件
JObject jsonObj = JObject.Parse(tuwenres); if (jsonObj["errcode"].ToString().Equals(""))
{
//群发成功后,保存记录
WxMassInfo wmi = new WxMassInfo(); wmi.ImageUrl = "";
wmi.type = "文本";
wmi.contents = this.txtwenben.InnerText.ToString().Trim();
wmi.title = this.txtwenben.InnerText.ToString().Substring(, ) + "..."; if (this.DDLMassType.SelectedValue.ToString().Equals(""))
{
wmi.massObject = this.DDLMassType.SelectedItem.Text.ToString();
}
else
{
wmi.massObject = this.DDLGroupList.SelectedItem.Text.ToString();
} wmi.massStatus = "成功";//群发成功之后返回的状态码
wmi.massMessageID = jsonObj["msg_id"].ToString();//群发成功之后返回的消息ID wmi.massDate = System.DateTime.Now.ToString(); int num = wms.AddWxMassInfo(wmi); if (num > )
{
Session["wmninfo"] = null;
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('群发任务已提交成功!!!数据已保存!');location='WxMassManage.aspx';", true);
return;
}
else
{
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('群发任务已提交成功!!!数据保存失败!');", true);
return;
}
}
else
{
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('群发任务提交失败!!');", true);
return;
}
} }
}
//如果选择的是图文消息
if (this.RadioBtnList.SelectedValue.ToString().Equals(""))
{
if (String.IsNullOrWhiteSpace(this.lbtuwenmedai_id.Text.ToString().Trim()))
{
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('请选择或新建图文素材再进行群发!');", true);
return;
} WxMassService wms = new WxMassService(); List<WxMassInfo> wxmaslist = wms.GetMonthMassCount(); if (wxmaslist.Count >= )
{
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('本月可群发消息数量已达上限!');", true);
return;
}
else
{ //如何群发类型为全部用户,根据openID列表群发给全部用户,订阅号不可用,服务号认证后可用
if (this.DDLMassType.SelectedValue.ToString().Equals(""))
{
StringBuilder sbs = new StringBuilder();
sbs.Append(GetAllUserOpenIDList()); WeiXinServer wxs = new WeiXinServer(); ///从缓存读取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(), System.Web.Caching.Cache.NoSlidingExpiration);
} string Access_tokento = Access_token.Substring(, Access_token.Length - ); string posturl = "https://api.weixin.qq.com/cgi-bin/message/mass/send?access_token=" + Access_tokento; ///群发POST数据示例如下:
// {
// "touser":[
// "OPENID1",
// "OPENID2"
// ],
// "mpnews":{
// "media_id":"123dsdajkasd231jhksad"
// },
// "msgtype":"mpnews"
//} string postData = "{\"touser\":[" + sbs.ToString() +
"],\"mpnews\":{\"media_id\":\"" + this.lbtuwenmedai_id.Text.ToString() +
"\"},\"msgtype\":\"mpnews\"}"; string tuwenres = wxs.GetPage(posturl, postData); //使用前需药引用Newtonsoft.json.dll文件
JObject jsonObj = JObject.Parse(tuwenres); if (jsonObj["errcode"].ToString().Equals(""))
{
Session["media_id"] = null;
WxMassInfo wmi = new WxMassInfo();
if (Session["wmninfo"] != null)
{
WxMpNewsInfo wmninfo = Session["wmninfo"] as WxMpNewsInfo; wmi.title = wmninfo.title.ToString();
wmi.contents = wmninfo.contents.ToString();
wmi.ImageUrl = wmninfo.ImageUrl.ToString(); wmi.type = "图文"; if (this.DDLMassType.SelectedValue.ToString().Equals(""))
{
wmi.massObject = this.DDLMassType.SelectedItem.Text.ToString();
}
else
{
wmi.massObject = this.DDLGroupList.SelectedItem.Text.ToString();
} wmi.massStatus = "成功";//群发成功之后返回的状态码
wmi.massMessageID = jsonObj["msg_id"].ToString();//群发成功之后返回的消息ID wmi.massDate = System.DateTime.Now.ToString(); int num = wms.AddWxMassInfo(wmi); if (num > )
{
Session["wmninfo"] = null;
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('群发任务已提交成功!!!数据已保存!');location='WxMassManage.aspx';", true);
return;
}
else
{
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('群发任务已提交成功!!!数据保存失败!');", true);
return;
}
}
else
{
wmi.title = "";
wmi.contents = "";
wmi.ImageUrl = "";
wmi.type = "图文"; if (this.DDLMassType.SelectedValue.ToString().Equals(""))
{
wmi.massObject = this.DDLMassType.SelectedItem.Text.ToString();
}
else
{
wmi.massObject = this.DDLGroupList.SelectedItem.Text.ToString();
} wmi.massStatus = "成功";//群发成功之后返回的状态码
wmi.massMessageID = jsonObj["msg_id"].ToString();//群发成功之后返回的消息ID wmi.massDate = System.DateTime.Now.ToString(); int num = wms.AddWxMassInfo(wmi); if (num > )
{
Session["wmninfo"] = null;
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('群发任务已提交成功!!!图文部分数据已保存!');location='WxMassManage.aspx';", true);
return;
}
else
{
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('群发任务已提交成功!!!数据保存失败!');", true);
return;
}
}
}
else
{
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('群发任务提交失败!!');", true);
return;
} }
else
{
//根据分组进行群发,订阅号和服务号认证后均可用 string group_id = this.DDLGroupList.SelectedValue.ToString(); WeiXinServer wxs = new WeiXinServer(); ///从缓存读取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(), System.Web.Caching.Cache.NoSlidingExpiration);
} string Access_tokento = Access_token.Substring(, Access_token.Length - ); string posturl = "https://api.weixin.qq.com/cgi-bin/message/mass/send?access_token=" + Access_tokento; ///群发POST数据示例如下:
// {
// "filter":{
// "is_to_all":false
// "group_id":"2"
// },
// "mpnews":{
// "media_id":"123dsdajkasd231jhksad"
// },
// "msgtype":"mpnews"
//} string postData = "{\"filter\":{\"is_to_all\":\"false\"\"group_id\":\""+group_id+
"\"},\"mpnews\":{\"media_id\":\"" + this.lbtuwenmedai_id.Text.ToString() +
"\"},\"msgtype\":\"mpnews\"}"; string tuwenres = wxs.GetPage(posturl, postData); //使用前需药引用Newtonsoft.json.dll文件
JObject jsonObj = JObject.Parse(tuwenres); if (jsonObj["errcode"].ToString().Equals(""))
{
Session["media_id"] = null;
WxMassInfo wmi = new WxMassInfo();
if (Session["wmninfo"] != null)
{
WxMpNewsInfo wmninfo = Session["wmninfo"] as WxMpNewsInfo; wmi.title = wmninfo.title.ToString();
wmi.contents = wmninfo.contents.ToString();
wmi.ImageUrl = wmninfo.ImageUrl.ToString(); wmi.type = "图文"; if (this.DDLMassType.SelectedValue.ToString().Equals(""))
{
wmi.massObject = this.DDLMassType.SelectedItem.Text.ToString();
}
else
{
wmi.massObject = this.DDLGroupList.SelectedItem.Text.ToString();
} wmi.massStatus = "成功";//群发成功之后返回的状态码
wmi.massMessageID = jsonObj["msg_id"].ToString();//群发成功之后返回的消息ID wmi.massDate = System.DateTime.Now.ToString(); int num = wms.AddWxMassInfo(wmi); if (num > )
{
Session["wmninfo"] = null;
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('群发任务已提交成功!!!数据已保存!');location='WxMassManage.aspx';", true);
return;
}
else
{
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('群发任务已提交成功!!!数据保存失败!');", true);
return;
}
}
else
{
wmi.title = "";
wmi.contents = "";
wmi.ImageUrl = "";
wmi.type = "图文"; if (this.DDLMassType.SelectedValue.ToString().Equals(""))
{
wmi.massObject = this.DDLMassType.SelectedItem.Text.ToString();
}
else
{
wmi.massObject = this.DDLGroupList.SelectedItem.Text.ToString();
} wmi.massStatus = "成功";//群发成功之后返回的状态码
wmi.massMessageID = jsonObj["msg_id"].ToString();//群发成功之后返回的消息ID wmi.massDate = System.DateTime.Now.ToString(); int num = wms.AddWxMassInfo(wmi); if (num > )
{
Session["wmninfo"] = null;
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('群发任务已提交成功!!!图文部分数据已保存!');location='WxMassManage.aspx';", true);
return;
}
else
{
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('群发任务已提交成功!!!数据保存失败!');", true);
return;
}
}
}
else
{
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('群发任务提交失败!!');", true);
return;
}
}
}
}
}
/// <summary>
/// 发送前预览
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void LinkBtnSendPreview_Click(object sender, EventArgs e)
{
WeiXinServer wxs = new WeiXinServer(); ///从缓存读取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(), System.Web.Caching.Cache.NoSlidingExpiration);
} string Access_tokento = Access_token.Substring(, Access_token.Length - ); string posturl = "https://api.weixin.qq.com/cgi-bin/message/mass/preview?access_token=" + Access_tokento; ///如果选择的是文本消息
if (this.RadioBtnList.SelectedValue.ToString().Equals(""))
{
if (String.IsNullOrWhiteSpace(this.txtwenben.InnerText.ToString().Trim()))
{
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('请输入您要发送预览的文本内容!');", true);
return;
}
if (this.txttoUserName.Value.ToString().Trim().Equals("请输入用户微信号"))
{
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('请输入接收消息的用户微信号!');", true);
return;
}
//文本消息的json数据{
// "touser":"OPENID", 可改为对微信号预览,例如towxname:zhangsan
// "text":{
// "content":"CONTENT"
// },
// "msgtype":"text"
//}
string postData = "{\"towxname\":\"" + this.txttoUserName.Value.ToString() +
"\",\"text\":{\"content\":\"" + this.txtwenben.InnerText.ToString() +
"\"},\"msgtype\":\"text\"}"; string tuwenres = wxs.GetPage(posturl, postData); //使用前需药引用Newtonsoft.json.dll文件
JObject jsonObj = JObject.Parse(tuwenres); if (jsonObj["errcode"].ToString().Equals(""))
{
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('发送预览成功!!');", true);
return;
}
else
{
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('发送预览失败!!');", true);
return;
}
}
//如果选择的是图文消息
if (this.RadioBtnList.SelectedValue.ToString().Equals(""))
{
if(String.IsNullOrWhiteSpace(this.lbtuwenmedai_id.Text.ToString().Trim()))
{
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('请选择要预览的图文素材!');", true);
return;
}
if (this.txttoUserName.Value.ToString().Trim().Equals("请输入用户微信号"))
{
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('请输入接收消息的用户微信号!');", true);
return;
}
//图文消息的json数据{
// "touser":"OPENID", 可改为对微信号预览,例如towxname:zhangsan
// "mpnews":{
// "media_id":"123dsdajkasd231jhksad"
// },
// "msgtype":"mpnews"
//}
string postData = "{\"towxname\":\"" + this.txttoUserName.Value.ToString() +
"\",\"mpnews\":{\"media_id\":\"" + this.lbtuwenmedai_id.Text.ToString() +
"\"},\"msgtype\":\"mpnews\"}"; string tuwenres = wxs.GetPage(posturl, postData); //使用前需药引用Newtonsoft.json.dll文件
JObject jsonObj = JObject.Parse(tuwenres); if (jsonObj["errcode"].ToString().Equals(""))
{
Session["media_id"] = null;
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('发送预览成功!!');", true);
return;
}
else
{
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('发送预览失败!!');", true);
return;
} } }

关键部分,获取全部用户的openID并串联成字符串:

 /// <summary>
/// 获取所有微信用户的OpenID
/// </summary>
/// <returns></returns>
protected string GetAllUserOpenIDList()
{
StringBuilder sb = new StringBuilder(); WeiXinServer wxs = new WeiXinServer(); ///从缓存读取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(), System.Web.Caching.Cache.NoSlidingExpiration);
} string Access_tokento = Access_token.Substring(, Access_token.Length - ); string jsonres = ""; string content = Cache["AllUserOpenList_content"] as string; if (content == null)
{
jsonres = "https://api.weixin.qq.com/cgi-bin/user/get?access_token=" + Access_tokento; HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(jsonres);
myRequest.Method = "GET";
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
content = reader.ReadToEnd();
reader.Close(); //设置缓存的数据7000秒后过期
Cache.Insert("AllUserOpenList_content", content, null, DateTime.Now.AddSeconds(), System.Web.Caching.Cache.NoSlidingExpiration);
} //使用前需要引用Newtonsoft.json.dll文件
JObject jsonObj = JObject.Parse(content); if (jsonObj.ToString().Contains("count"))
{
int totalnum = int.Parse(jsonObj["count"].ToString()); for (int i = ; i < totalnum; i++)
{
sb.Append('"');
sb.Append(jsonObj["data"]["openid"][i].ToString());
sb.Append('"');
sb.Append(",");
}
} return sb.Remove(sb.ToString().LastIndexOf(","),).ToString();
}

至此结束,下一章将继续讲解群发图文信息,因群发图文信息之前,需要先上传图文信息所需的素材,获取media_id,所以本章不做介绍,下一章将介绍新建单图文信息并群发。

asp.net微信开发第六篇----高级群发(文本)的更多相关文章

  1. asp.net微信开发第七篇----高级群发(图文)

    上一篇介绍了如何群发文本消息,本篇将介绍如何群发图文信息,上传图文信息所需的素材,界面如下: 我们先看从素材库中获取图文素材的代码,界面: 素材列表,我是使用的repeater控件, 前台代码如下: ...

  2. asp.net微信开发第四篇----已关注用户管理

    公众号可通过本接口来获取帐号的关注者列表,关注者列表由一串OpenID(加密后的微信号,每个用户对每个公众号的OpenID是唯一的)组成.一次拉取调用最多拉取10000个关注者的OpenID,可以通过 ...

  3. asp.net微信开发第五篇----用户分组管理

    上一篇已讲解到新建用户分组,移动用户到分组的功能,这一章主要讲解修改分组名称和删除分组 开发者可以使用接口,对公众平台的分组进行查询.创建.修改.删除等操作,也可以使用接口在需要时移动用户到某个分组. ...

  4. asp.net微信开发第三篇----自定义会话管理

    和微信用户的沟通少不了,总觉得看起来微信官网后台管理中的会话回复消息有点呆板,所以我这里就自定义了一个会话管理功能,最终效果图如下: 因为我试使用富文本文件CKEDITOR来进行编写,你看到稳中可能会 ...

  5. asp.net微信开发第八篇----永久素材管理

    除了3天就会失效的临时素材外,开发者有时需要永久保存一些素材,届时就可以通过本接口新增永久素材. 最近更新,永久图片素材新增后,将带有URL返回给开发者,开发者可以在腾讯系域名内使用(腾讯系域名外使用 ...

  6. asp.net微信开发第十篇----使用百度编辑器编辑图文消息,上传图片、微信视频

    经过几天的资料收集,终于完成了该编辑器的图片上传,视频插入功能,视频插入功能主要借用了该编辑器的插入iframe功能,如原始插件图: 修改后的插件图如下(其中我隐藏掉了一些不需要使用的插件功能): 配 ...

  7. asp.net 微信开发(二)

    本节我们主要讲解微信的调试: 前言:平时我们开发项目都是在本地就能进行项目的开发调试,但是在微信上就有难度了,因为微信的数据需要从微信服务器上面拿,所以就需要直接在网站上调试了,接下来就相关的一些个人 ...

  8. asp.net微信开发第二篇----消息应答

    当普通微信用户向公众账号发消息时,微信服务器将POST消息的XML数据包到开发者填写的URL上. 请注意: 1.关于重试的消息排重,推荐使用msgid排重. 2.微信服务器在五秒内收不到响应会断掉连接 ...

  9. asp.net微信开发第一篇----开发者接入

    在项目的根目录或者特定的文件夹内,创建一个ashx文件(一般处理程序文件),如图 public void ProcessRequest(HttpContext context) { context.R ...

随机推荐

  1. [HTML5 Canvas学习]绘制矩形

    1.使用strokeRect和fillRect方法绘制矩形 a.strokeRect是绘制一个不填充的矩形 b.fillRect是绘制一个填充的矩形 代码: <script> var ca ...

  2. 下拉列表框 select 动态赋值

    <tr> <td class="label">所属群组:</td> <td> <select name="group ...

  3. 插入数据前设置字符编码为utf8

    xxx.php保存时选择utf8编码,页头最好加上 header('conten-type:text/html;charset=utf-8'); 在执行CRUD操作前先执行一下 mysql_query ...

  4. python:UnboundLocalError: local variable 'xxx' referenced before assignment

    近来一直都在学习python语言,偶然在伯乐在线看到2017年京东C/C++的面试题.就打算用python+ST3 IDE顺便敲下面试题代码. 原题 C语言: #include <stdio.h ...

  5. UVA - 12627 Erratic Expansion 奇怪的气球膨胀 (分治)

    紫书例题p245 Piotr found a magical box in heaven. Its magic power is that if you place any red balloon i ...

  6. IIS6中ASP.NET实现对静态文件的授权控制

    后台使用html+ashx+js开发 在VS2008调试并未发现问题 发布到IIS6才发现不需要验证也能访问html文件 解决这个问题配置IIS即可了 方法如下: IIS配置:网站->属性-&g ...

  7. Scut:从PackageReader分析客户端协议规则

    看第一个解析API: private void ParseData(byte[] data) { var paramBytes = SplitBuffer(data); RawParam = _enc ...

  8. cypress的EZ-USB对于USB的介绍

    Host is MasterThis is a fundamental USB concept. There is exactly onemaster in a USB system: the hos ...

  9. Matlab 符号运算

    root(p):多项式求根.多项式等于0时对应方程的根. 例:,则输入p=[5 4 3 2 1]; root(p) 注:多项式系数都是按幂指数递减形式的. poly([a,b,c]):求已知根为a,b ...

  10. convex optimization

    ##凸优化总结所有这些想法基本是来自于书籍[convex optimization](http://book.douban.com/subject/1888111/),主要包括凸优化的基本理论,主要的 ...