好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁 > 知識庫 > asp.net微信開發(高級群發文本)

asp.net微信開發(高級群發文本)

熱門標簽:聊城智能電銷機器人電話 西寧電銷外呼系統公司 辦公用地圖標注網點怎么操作 海東防封電銷卡 南昌自動外呼系統線路 寧德防封版電銷卡 安陸市地圖標注app 云南外呼系統代理 上海市三維地圖標注

首先我們先來講解一下群發文本信息的過程,我個人開發程序是首先要有UI才能下手去寫代碼,界面如下,

 

看圖我們也可以看出首先我們要獲取該微信號本月還能群發幾條信息,關于怎么計算,就是群發成功一條信息,就在本地數據庫存儲一條信息,用來計算條數,(這個我相信都會),大于4條就不能發送(這里我已經限制死了,因為服務號每月只能發送4條,多發送也沒用,用戶只能收到4條,除非使用預覽功能,挨個發送,但預覽功能也只能發送100次,或許可能使用開發者模式下群發信息可以多發送N次哦,因為我群發了兩次之后,再進入到微信公眾平臺官網后臺看到的居然還能群發4條,有點郁悶哦!),群發對象可選擇為全部用戶或分組用戶,和由于節省群發次數,這里我就不測試群發文字信息了,具體參考如下代碼:

綁定本月剩余群發條數

 /// summary> 
 /// 綁定本月剩余群發條數
 /// /summary>
 private void BindMassCount()
 {
 WxMassService wms = new WxMassService();
 ListWxMassInfo> wxmaslist = wms.GetMonthMassCount();
 //官方微信服務號每月只能群發4條信息,(訂閱號每天1條)多余信息,將不會成功推送,這里已經設定為4
 this.lbMassCounts.Text = (4 - int.Parse(wxmaslist.Count.ToString())).ToString();

 if (wxmaslist.Count >= 4)
 {
 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(7000), System.Web.Caching.Cache.NoSlidingExpiration);
 }

 string Access_tokento = Access_token.Substring(17, Access_token.Length - 37);

 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(7000), 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 = 0; 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()) > 0)
 {
 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("0"))
 {
 if (String.IsNullOrWhiteSpace(this.txtwenben.InnerText.ToString().Trim()))
 {
  ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('請輸入您要群發文本內容!');", true);
  return;
 }
 if (this.txtwenben.InnerText.ToString().Trim().Length10)
 {
  ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('文本內容至少需要10個字符以上!');", true);
  return;
 }

 WxMassService wms = new WxMassService();
 ListWxMassInfo> wxmaslist = wms.GetMonthMassCount();

 if (wxmaslist.Count >= 4)
 {
  ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('本月可群發消息數量已達上限!');", true);
  return;
 }
 else
 {


  //如何群發類型為全部用戶,根據openID列表群發給全部用戶,訂閱號不可用,服務號認證后可用
  if (this.DDLMassType.SelectedValue.ToString().Equals("0"))
  {
  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(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/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("0"))
  {
   //群發成功后,保存記錄
  WxMassInfo wmi = new WxMassInfo();

  wmi.ImageUrl = "";
  wmi.type = "文本";
  wmi.contents = this.txtwenben.InnerText.ToString().Trim();
  wmi.title = this.txtwenben.InnerText.ToString().Substring(0, 10) + "...";

  if (this.DDLMassType.SelectedValue.ToString().Equals("0"))
  {
  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 > 0)
  {
  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(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/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("0"))
  {
  //群發成功后,保存記錄
  WxMassInfo wmi = new WxMassInfo();

  wmi.ImageUrl = "";
  wmi.type = "文本";
  wmi.contents = this.txtwenben.InnerText.ToString().Trim();
  wmi.title = this.txtwenben.InnerText.ToString().Substring(0, 10) + "...";

  if (this.DDLMassType.SelectedValue.ToString().Equals("0"))
  {
  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 > 0)
  {
  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("1"))
 {
 if (String.IsNullOrWhiteSpace(this.lbtuwenmedai_id.Text.ToString().Trim()))
 {
  ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('請選擇或新建圖文素材再進行群發!');", true);
  return;
 }

 WxMassService wms = new WxMassService();

 ListWxMassInfo> wxmaslist = wms.GetMonthMassCount();

 if (wxmaslist.Count >= 4)
 {
  ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('本月可群發消息數量已達上限!');", true);
  return;
 }
 else
 {
  
  //如何群發類型為全部用戶,根據openID列表群發給全部用戶,訂閱號不可用,服務號認證后可用
  if (this.DDLMassType.SelectedValue.ToString().Equals("0"))
  {
  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(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/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("0"))
  {
  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("0"))
  {
   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 > 0)
  {
   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("0"))
  {
   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 > 0)
  {
   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(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/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("0"))
  {
  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("0"))
  {
   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 > 0)
  {
   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("0"))
  {
   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 > 0)
  {
   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(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/message/mass/preview?access_token=" + Access_tokento;

 ///如果選擇的是文本消息
 if (this.RadioBtnList.SelectedValue.ToString().Equals("0"))
 {
 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("0"))
 {
  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("1"))
 {
 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("0"))
 {
  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(7000), System.Web.Caching.Cache.NoSlidingExpiration);
 }

 string Access_tokento = Access_token.Substring(17, Access_token.Length - 37);

 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(7000), 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 = 0; i  totalnum; i++)
 {
  sb.Append('"');
  sb.Append(jsonObj["data"]["openid"][i].ToString());
  sb.Append('"');
  sb.Append(",");
 }
 }

 return sb.Remove(sb.ToString().LastIndexOf(","),1).ToString();
 }


本文已被整理到了《ASP.NET微信開發教程匯總》,歡迎大家學習閱讀。

至此結束,下一章將繼續講解群發圖文信息,因群發圖文信息之前,需要先上傳圖文信息所需的素材,獲取media_id,所以本章不做介紹,下一章將介紹新建單圖文信息并群發,希望大家喜歡。

您可能感興趣的文章:
  • 微信公眾平臺開發——群發信息
  • php微信公眾平臺開發之微信群發信息
  • php微信高級接口群發 多客服
  • C#微信公眾平臺開發之高級群發接口
  • asp.net微信開發(高級群發圖文)
  • php實現微信公眾號無限群發
  • C#實現微信公眾號群發消息(解決一天只能發一次的限制)實例分享
  • php微信公眾號開發(4)php實現自定義關鍵字回復
  • php微信公眾號開發(3)php實現簡單微信文本通訊
  • 微信公眾號模板消息群發php代碼示例

標簽:南寧 青海 汕尾 洛陽 崇左 贛州 衢州 平涼

巨人網絡通訊聲明:本文標題《asp.net微信開發(高級群發文本)》,本文關鍵詞  asp.net,微信,開發,高級,群發,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《asp.net微信開發(高級群發文本)》相關的同類信息!
  • 本頁收集關于asp.net微信開發(高級群發文本)的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 国产区精品福利在线观看精品| 18禁裸体爆乳?网站动漫| 97国产精品人人爽人人做| 99精品久久精品一区二区小说| jzzijzzij亚洲成熟少妇在线| 国产精品国产三级国产普通话三级| 1特别黄的视频在线观看| 女女性恋爱免费| 国产又爽?又黄?免费软件| 日本特黄特色A大片免费| 夜夜性| 麻豆E奶女教师国产剧情| 啊灬嗯灬啊灬用力点灬水女女游戏| 亚洲国产精品无码乱码三区时间| 浪荡人妻共32部黑人大| 亚洲高清综合| 台湾全黄hd播放片| 免费在线crm毛片| 动漫美女被吸乳羞羞网站动漫| 亚洲老奶老太videos| 免费欧洲毛片**无风险| 午夜在线精品偷拍一区二| 亚洲精品国产电影午夜| 男人曰女人| 亚洲一区=区三区四区大尺度影视| 紫轩小说吧老师的奶水| 总攻NP一攻多受| 男人日母鸡| 无码做爰欢H肉动漫网站在线看| 国产精品久久久久久久久免费| 美女视频在线观看免费高清完整版| b超被十个医生高| 国产伦精品一区二区三区网站 | 用力操好爽| 另类小说欧美| 国精产品自偷自偷综合| 人妻~日本夫の上司犯感との| 欧美丰满性久久久久久久 | 跟40岁的少妇做一次就不硬了 | japanesegay男男gay同| 日日爽夜夜爽|