'> 修改備注名稱<\/p><\/a>\r\n <\/td>\r\n <\/tr>\r\n <\/ItemTemplate>\r\n <\/asp:Repeater>\r\n <\/table>\r\n
\r\n 確定<\/asp:LinkButton>\r\n <\/asp:TextBox> \r\n >>|<\/span><\/asp:HyperLink> \r\n ><\/span><\/asp:HyperLink> \r\n <<\/span><\/asp:HyperLink> \r\n |<<<\/span><\/asp:HyperLink> \r\n 當(dāng)前第<\/span>\r\n <\/asp:Label><\/span>\r\n 頁\/<\/span>\r\n 共<\/span>\r\n <\/asp:Label><\/span>\r\n 頁<\/span>\r\n <\/asp:Label><\/span>\r\n 共搜索到 <\/span>\r\n <\/asp:Label><\/span>\r\n 條記錄.<\/span>\r\n <\/p>\r\n <\/ContentTemplate>\r\n <\/asp:UpdatePanel>\r\n <\/form>\r\n<\/body>\r\n<\/html><\/pre>Get the back-end code for binding user information to the user list, which is included. Modify the remark name, move the user to a group, and create a new group code<\/strong><\/p><\/p>
Group statistics, used to display the number of existing people in each group, no other function
<\/p>
Code: <\/p>
PagedDataSource pds = new PagedDataSource();\r\n protected void Page_Load(object sender, EventArgs e)\r\n {\r\n if(!Page.IsPostBack)\r\n {\r\n BindGroupList();\r\n BindGetAllUserOpenIdList();\r\n this.DataBind();\r\n this.CheckAll.AutoPostBack = true;\r\n this.DDlAddgroups.AutoPostBack = true;\r\n }\r\n \/\/this.DDlAddgroups.Enabled = false;\r\n \r\n }\r\n \/\/\/ \r\n \/\/\/ 獲取所有用戶的openId列表\r\n \/\/\/ <\/summary>\r\n private void BindGetAllUserOpenIdList()\r\n {\r\n WeiXinServer wxs = new WeiXinServer();\r\n\r\n \/\/\/從緩存讀取accesstoken\r\n string Access_token = Cache[\"Access_token\"] as string;\r\n\r\n if (Access_token == null)\r\n {\r\n \/\/如果為空,重新獲取\r\n Access_token = wxs.GetAccessToken();\r\n\r\n \/\/設(shè)置緩存的數(shù)據(jù)7000秒后過期\r\n Cache.Insert(\"Access_token\", Access_token, null, DateTime.Now.AddSeconds(7000), System.Web.Caching.Cache.NoSlidingExpiration);\r\n }\r\n\r\n string Access_tokento = Access_token.Substring(17, Access_token.Length - 37);\r\n\r\n string jsonres = \"\";\r\n\r\n string content = Cache[\"AllUserOpenList_content\"] as string;\r\n\r\n if (content == null)\r\n {\r\n jsonres = \"https:\/\/api.weixin.qq.com\/cgi-bin\/user\/get?access_token=\" + Access_tokento;\r\n\r\n HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(jsonres);\r\n myRequest.Method = \"GET\";\r\n HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();\r\n StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);\r\n content = reader.ReadToEnd();\r\n reader.Close();\r\n\r\n \/\/設(shè)置緩存的數(shù)據(jù)7000秒后過期\r\n Cache.Insert(\"AllUserOpenList_content\", content, null, DateTime.Now.AddSeconds(7000), System.Web.Caching.Cache.NoSlidingExpiration);\r\n }\r\n\r\n \/\/使用前需要引用Newtonsoft.json.dll文件\r\n JObject jsonObj = JObject.Parse(content);\r\n\r\n\r\n int totalnum = int.Parse(jsonObj[\"count\"].ToString());\r\n\r\n\r\n List openidlist = new List();\r\n\r\n\r\n for (int i = 0; i < totalnum;i++ )\r\n {\r\n WxOpenIdInfo wxopeninfo = new WxOpenIdInfo();\r\n wxopeninfo.WxopenId = jsonObj[\"data\"][\"openid\"][i].ToString();\r\n openidlist.Add(wxopeninfo);\r\n }\r\n\r\n\r\n pds.DataSource = openidlist;\r\n pds.AllowPaging = true;\r\n pds.PageSize = 20;\/\/每頁顯示為20條\r\n int CurrentPage;\r\n\r\n\r\n if (!String.IsNullOrWhiteSpace(this.txtPageIndex.Text.ToString().Trim()))\r\n {\r\n\r\n CurrentPage = Convert.ToInt32(this.txtPageIndex.Text.ToString().Trim());\r\n }\r\n else if (Request.QueryString[\"Page\"] != null)\r\n {\r\n CurrentPage = Convert.ToInt32(Request.QueryString[\"Page\"]);\r\n }\r\n else\r\n {\r\n CurrentPage = 1;\r\n }\r\n pds.CurrentPageIndex = CurrentPage - 1;\/\/當(dāng)前頁的索引就等于當(dāng)前頁碼-1;\r\n if (!pds.IsFirstPage)\r\n {\r\n \/\/Request.CurrentExecutionFilePath 為當(dāng)前請(qǐng)求的虛擬路徑\r\n this.lnkTop.NavigateUrl = Request.CurrentExecutionFilePath + \"?Page=\" + Convert.ToString(CurrentPage - 1);\r\n this.lnkFist.Enabled = this.lnkTop.Enabled = true;\r\n this.lnkNext.Enabled = this.lnkLast.Enabled = true;\r\n }\r\n else\r\n {\r\n this.lnkFist.Enabled = this.lnkTop.Enabled = false;\r\n this.lnkNext.Enabled = this.lnkLast.Enabled = true;\r\n this.lnkFist.Attributes.Add(\"style\", \"color:#ced9df;\");\r\n this.lnkTop.Attributes.Add(\"style\", \"color:#ced9df;\");\r\n this.lnkNext.Attributes.Remove(\"style\");\r\n this.lnkLast.Attributes.Remove(\"style\");\r\n }\r\n if (!pds.IsLastPage)\r\n {\r\n \/\/Request.CurrentExecutionFilePath 為當(dāng)前請(qǐng)求的虛擬路徑\r\n this.lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + \"?Page=\" + Convert.ToString(CurrentPage + 1);\r\n this.lnkFist.Enabled = this.lnkTop.Enabled = true;\r\n this.lnkNext.Enabled = this.lnkLast.Enabled = true;\r\n }\r\n else\r\n {\r\n this.lnkNext.Enabled = this.lnkLast.Enabled = false;\r\n this.lnkFist.Enabled = this.lnkTop.Enabled = true;\r\n this.lnkNext.Attributes.Add(\"style\", \"color:#ced9df;\");\r\n this.lnkLast.Attributes.Add(\"style\", \"color:#ced9df;\");\r\n this.lnkFist.Attributes.Remove(\"style\");\r\n this.lnkTop.Attributes.Remove(\"style\");\r\n }\r\n this.lnkFist.NavigateUrl = Request.CurrentExecutionFilePath + \"?Page=\" + Convert.ToString(1);\/\/跳轉(zhuǎn)至首頁\r\n this.lnkLast.NavigateUrl = Request.CurrentExecutionFilePath + \"?Page=\" + Convert.ToString(pds.PageCount);\/\/跳轉(zhuǎn)至末頁\r\n\r\n this.RepeaterWxUserList.DataSource = pds;\r\n this.RepeaterWxUserList.DataBind();\r\n\r\n this.lbCountData.Text = openidlist.Count.ToString();\r\n this.lbPageIndex.Text = (pds.CurrentPageIndex + 1).ToString();\r\n this.lbPageSize.Text = \"每頁\" + pds.PageSize.ToString() + \"條記錄\";\r\n this.lbCountPage.Text = pds.PageCount.ToString();\r\n this.txtPageIndex.Text = (pds.CurrentPageIndex + 1).ToString();\r\n\r\n if (int.Parse(openidlist.Count.ToString()) <= int.Parse(pds.PageSize.ToString()))\r\n {\r\n this.lnkFist.Visible = this.lnkTop.Visible = this.lnkNext.Visible = this.lnkLast.Visible = this.txtPageIndex.Visible = this.LinkBtnToPage.Visible = false;\r\n }\r\n else\r\n {\r\n this.lnkFist.Visible = this.lnkTop.Visible = this.lnkNext.Visible = this.lnkLast.Visible = this.txtPageIndex.Visible = this.LinkBtnToPage.Visible = true;\r\n }\r\n\r\n this.lbsubscribeCount.Text = openidlist.Count.ToString();\r\n }\r\n \/\/\/ \r\n \/\/\/ 綁定分組列表\r\n \/\/\/ <\/summary>\r\n private void BindGroupList()\r\n {\r\n WeiXinServer wxs = new WeiXinServer();\r\n\r\n \/\/\/從緩存讀取accesstoken\r\n string Access_token = Cache[\"Access_token\"] as string;\r\n\r\n if (Access_token == null)\r\n {\r\n \/\/如果為空,重新獲取\r\n Access_token = wxs.GetAccessToken();\r\n\r\n \/\/設(shè)置緩存的數(shù)據(jù)7000秒后過期\r\n Cache.Insert(\"Access_token\", Access_token, null, DateTime.Now.AddSeconds(7000), System.Web.Caching.Cache.NoSlidingExpiration);\r\n }\r\n\r\n string Access_tokento = Access_token.Substring(17, Access_token.Length - 37);\r\n\r\n string jsonres = \"\";\r\n\r\n string content = Cache[\"AllGroups_content\"] as string;\r\n\r\n if (content == null)\r\n {\r\n jsonres = \"https:\/\/api.weixin.qq.com\/cgi-bin\/groups\/get?access_token=\" + Access_tokento;\r\n\r\n HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(jsonres);\r\n myRequest.Method = \"GET\";\r\n HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();\r\n StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);\r\n content = reader.ReadToEnd();\r\n reader.Close();\r\n\r\n \/\/設(shè)置緩存的數(shù)據(jù)7000秒后過期\r\n Cache.Insert(\"AllGroups_content\", content, null, DateTime.Now.AddSeconds(7000), System.Web.Caching.Cache.NoSlidingExpiration);\r\n }\r\n\r\n \/\/使用前需要引用Newtonsoft.json.dll文件\r\n JObject jsonObj = JObject.Parse(content);\r\n\r\n\r\n int groupsnum = jsonObj[\"groups\"].Count();\r\n\r\n this.DDLgroups.Items.Clear();\/\/清除\r\n this.DDlAddgroups.Items.Clear();\r\n this.DDLgroups.Items.Insert(0, new ListItem(\"分組統(tǒng)計(jì)\", \"0\"));\/\/添加默認(rèn)第一個(gè)提示\r\n this.DDlAddgroups.Items.Insert(0, new ListItem(\"移動(dòng)用戶到分組\", \"0\"));\r\n for (int i = 0; i < groupsnum; i++)\r\n {\r\n this.DDLgroups.Items.Add(new ListItem(jsonObj[\"groups\"][i][\"name\"].ToString() + \"(\" + jsonObj[\"groups\"][i][\"count\"].ToString() + \")\", jsonObj[\"groups\"][i][\"id\"].ToString()));\r\n \r\n this.DDlAddgroups.Items.Add(new ListItem(jsonObj[\"groups\"][i][\"name\"].ToString(), jsonObj[\"groups\"][i][\"id\"].ToString()));\r\n }\r\n }\r\n \/\/\/ \r\n \/\/\/ 輸入頁碼提交跳轉(zhuǎn)\r\n \/\/\/ <\/summary>\r\n \/\/\/ <\/param>\r\n \/\/\/ <\/param>\r\n protected void LinkBtnToPage_Click(object sender, EventArgs e)\r\n {\r\n\r\n if (String.IsNullOrWhiteSpace(this.txtPageIndex.Text.ToString().Trim()))\r\n {\r\n ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), \"\", \"alert('頁碼不能為空!')\", true);\r\n this.txtPageIndex.Focus();\r\n return;\r\n }\r\n if (IsNum(this.txtPageIndex.Text.ToString().Trim()))\r\n {\r\n ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), \"\", \"alert('頁碼數(shù)只能輸入數(shù)字!')\", true);\r\n this.txtPageIndex.Focus();\r\n this.txtPageIndex.Text = this.lbPageIndex.Text.ToString();\r\n return;\r\n }\r\n if (int.Parse(this.txtPageIndex.Text.ToString().Trim()) > int.Parse(this.lbCountPage.Text.ToString().Trim()))\r\n {\r\n ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), \"\", \"alert('所輸頁數(shù)不能大于總頁數(shù)!')\", true);\r\n this.txtPageIndex.Focus();\r\n this.txtPageIndex.Text = this.lbPageIndex.Text.ToString();\r\n return;\r\n }\r\n\r\n BindGetAllUserOpenIdList();\r\n }\r\n \/\/\/ \r\n \/\/\/ 判斷是否是數(shù)字\r\n \/\/\/ <\/summary>\r\n \/\/\/ <\/param>\r\n \/\/\/ <\/returns>\r\n public static bool IsNum(string text) \/\/\r\n {\r\n for (int i = 0; i < text.Length; i++)\r\n {\r\n if (!Char.IsNumber(text, i))\r\n {\r\n return true; \/\/輸入的不是數(shù)字 \r\n }\r\n }\r\n return false; \/\/否則是數(shù)字\r\n }\r\n \/\/\/ \r\n \/\/\/ 綁定用戶基本信息事件\r\n \/\/\/ <\/summary>\r\n \/\/\/ <\/param>\r\n \/\/\/ <\/param>\r\n protected void RepeaterWxUserList_ItemDataBound(object sender, RepeaterItemEventArgs e)\r\n {\r\n \/\/CheckBox checkIn = e.Item.FindControl(\"CheckIn\") as CheckBox;\r\n\r\n \/\/checkIn.AutoPostBack = true;\r\n\r\n\r\n if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem)\r\n {\r\n WxOpenIdInfo wxopen = e.Item.DataItem as WxOpenIdInfo;\r\n\r\n\r\n Label lbwxopenID = e.Item.FindControl(\"lbwxopenID\") as Label;\r\n\r\n lbwxopenID.Text = wxopen.WxopenId.ToString();\r\n\r\n \/\/根據(jù)OpenID獲取用戶基本信息。緩存處理\r\n WeiXinServer wxs = new WeiXinServer();\r\n\r\n \/\/\/從緩存讀取accesstoken\r\n string Access_token = Cache[\"Access_token\"] as string;\r\n\r\n if (Access_token == null)\r\n {\r\n \/\/如果為空,重新獲取\r\n Access_token = wxs.GetAccessToken();\r\n\r\n \/\/設(shè)置緩存的數(shù)據(jù)7000秒后過期\r\n Cache.Insert(\"Access_token\", Access_token, null, DateTime.Now.AddSeconds(7000), System.Web.Caching.Cache.NoSlidingExpiration);\r\n }\r\n\r\n string Access_tokento = Access_token.Substring(17, Access_token.Length - 37);\r\n\r\n string jsonres =\"https:\/\/api.weixin.qq.com\/cgi-bin\/user\/info?access_token=\" + Access_tokento + \"&openid=\" + lbwxopenID.Text.ToString();\r\n\r\n HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(jsonres);\r\n myRequest.Method = \"GET\";\r\n HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();\r\n StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);\r\n string content = reader.ReadToEnd();\r\n reader.Close();\r\n\r\n \/\/使用前需要引用Newtonsoft.json.dll文件\r\n JObject jsonObj = JObject.Parse(content);\r\n\r\n\r\n Image ImgHeadUrl = e.Item.FindControl(\"ImgHeadUrl\") as Image;\r\n Label lbNickName = e.Item.FindControl(\"lbNickName\") as Label;\r\n Label lbRemark = e.Item.FindControl(\"lbRemark\") as Label;\r\n Label lbSubscrine_time = e.Item.FindControl(\"lbSubscrine_time\") as Label;\r\n\r\n Label lbgroupId = e.Item.FindControl(\"lbgroupId\") as Label;\r\n\r\n DropDownList DDlAddgroupss = e.Item.FindControl(\"DDlAddgroupss\") as DropDownList;\r\n\r\n lbNickName.Text = jsonObj[\"nickname\"].ToString();\r\n\r\n if (!String.IsNullOrWhiteSpace(jsonObj[\"remark\"].ToString()))\r\n {\r\n lbRemark.Text = \"(\" + jsonObj[\"remark\"].ToString() + \")\";\r\n }\r\n\r\n ImgHeadUrl.ImageUrl = jsonObj[\"headimgurl\"].ToString();\r\n lbgroupId.Text = jsonObj[\"groupid\"].ToString();\r\n\r\n \/\/獲取關(guān)注時(shí)間\r\n int totaltiem = int.Parse(jsonObj[\"subscribe_time\"].ToString());\r\n \/\/將整型格式時(shí)間轉(zhuǎn)換為時(shí)間格式\r\n DateTime t = new DateTime(1970, 1, 1).AddSeconds(totaltiem);\r\n \/\/轉(zhuǎn)換后的時(shí)間會(huì)比原有時(shí)間小8個(gè)小時(shí),因此需要加上8個(gè)小時(shí)\r\n lbSubscrine_time.Text = t.AddHours(8).ToString();\r\n\r\n\r\n string jjjjjjjjjddd = Cache[\"AllGroups_content\"] as string;\r\n\r\n if (jjjjjjjjjddd == null)\r\n {\r\n jsonres = \"https:\/\/api.weixin.qq.com\/cgi-bin\/groups\/get?access_token=\" + Access_tokento;\r\n\r\n HttpWebRequest myRequestss = (HttpWebRequest)WebRequest.Create(jsonres);\r\n myRequest.Method = \"GET\";\r\n HttpWebResponse myResponsess = (HttpWebResponse)myRequest.GetResponse();\r\n StreamReader readerss = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);\r\n jjjjjjjjjddd = reader.ReadToEnd();\r\n reader.Close();\r\n\r\n \/\/設(shè)置緩存的數(shù)據(jù)7000秒后過期\r\n Cache.Insert(\"AllGroups_content\", jjjjjjjjjddd, null, DateTime.Now.AddSeconds(7000), System.Web.Caching.Cache.NoSlidingExpiration);\r\n }\r\n\r\n \/\/使用前需要引用Newtonsoft.json.dll文件\r\n JObject jsonObjss = JObject.Parse(jjjjjjjjjddd);\r\n\r\n\r\n int groupsnumss = jsonObjss[\"groups\"].Count();\r\n\r\n for (int i = 0; i < groupsnumss;i++ )\r\n {\r\n if (jsonObjss[\"groups\"][i][\"id\"].ToString().Equals(lbgroupId.Text.ToString()))\r\n {\r\n DDlAddgroupss.SelectedItem.Text = jsonObjss[\"groups\"][i][\"name\"].ToString();\r\n }\r\n }\r\n\r\n }\r\n }\r\n \/\/\/ \r\n \/\/\/ 創(chuàng)建分組\r\n \/\/\/ <\/summary>\r\n \/\/\/ <\/param>\r\n \/\/\/ <\/param>\r\n protected void LinkBtnCreateGroup_Click(object sender, EventArgs e)\r\n {\r\n if (this.txtgroupsName.Value.ToString().Equals(\"分組名稱\"))\r\n {\r\n \/\/\/\/\r\n ScriptManager.RegisterClientScriptBlock(this.Page,this.GetType(),\"\",\"alert('不能為空!')\",true);\r\n this.txtgroupsName.Focus();\r\n return;\r\n }\r\n\r\n\r\n WeiXinServer wxs = new WeiXinServer();\r\n string res = \"\";\r\n\r\n \/\/\/從緩存讀取accesstoken\r\n string Access_token = Cache[\"Access_token\"] as string;\r\n\r\n if (Access_token == null)\r\n {\r\n \/\/如果為空,重新獲取\r\n Access_token = wxs.GetAccessToken();\r\n\r\n \/\/設(shè)置緩存的數(shù)據(jù)7000秒后過期\r\n Cache.Insert(\"Access_token\", Access_token, null, DateTime.Now.AddSeconds(7000), System.Web.Caching.Cache.NoSlidingExpiration);\r\n }\r\n\r\n string Access_tokento = Access_token.Substring(17, Access_token.Length - 37);\r\n\r\n\r\n string posturl = \"https:\/\/api.weixin.qq.com\/cgi-bin\/groups\/create?access_token=\" + Access_tokento;\r\n\r\n \/\/string postData = \"{\\\"group\\\":{\\\"name\\\":\\\"\"+this.txtgroupsName.Value.ToString().Trim()+\"\\\"}}\";\r\n\r\n string postData = \"{\\\"group\\\":{\\\"name\\\":\\\"\"+this.txtgroupsName.Value.ToString().Trim()+\"\\\"}}\";\r\n\r\n\r\n res = wxs.GetPage(posturl, postData);\r\n\r\n\r\n ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), \"\", \"alert('創(chuàng)建成功!如未顯示,請(qǐng)退出重新登錄即可!');location='WeiXinUserList.aspx';\", true);\r\n }\r\n \/\/\/ \r\n \/\/\/ 全選、全不選\r\n \/\/\/ <\/summary>\r\n \/\/\/ <\/param>\r\n \/\/\/ <\/param>\r\n protected void CheckAll_CheckedChanged(object sender, EventArgs e)\r\n {\r\n CheckBox checkAll = (CheckBox)sender;\r\n foreach (RepeaterItem item in this.RepeaterWxUserList.Items)\r\n {\r\n CheckBox checkIn = (CheckBox)item.FindControl(\"CheckIn\");\r\n checkIn.Checked = checkAll.Checked;\r\n }\r\n }\r\n\r\n \/\/\/ \r\n \/\/\/ 移動(dòng)用戶到分組\r\n \/\/\/ <\/summary>\r\n \/\/\/ <\/param>\r\n \/\/\/ <\/param>\r\n protected void DDlAddgroups_SelectedIndexChanged(object sender, EventArgs e)\r\n {\r\n \/\/\/取得分組ID\r\n string groupId = this.DDlAddgroups.SelectedValue.ToString();\r\n\r\n \/\/this.Label1.Text = groupId.ToString();\r\n\r\n Boolean bools = false;\r\n\r\n foreach (RepeaterItem item in this.RepeaterWxUserList.Items)\r\n {\r\n CheckBox checkIn = (CheckBox)item.FindControl(\"CheckIn\");\r\n\r\n if (checkIn.Checked)\r\n {\r\n bools = true;\r\n\r\n Label lbwxopenID = item.FindControl(\"lbwxopenID\") as Label;\r\n\r\n\r\n WeiXinServer wxs = new WeiXinServer();\r\n string res = \"\";\r\n\r\n \/\/\/從緩存讀取accesstoken\r\n string Access_token = Cache[\"Access_token\"] as string;\r\n\r\n if (Access_token == null)\r\n {\r\n \/\/如果為空,重新獲取\r\n Access_token = wxs.GetAccessToken();\r\n\r\n \/\/設(shè)置緩存的數(shù)據(jù)7000秒后過期\r\n Cache.Insert(\"Access_token\", Access_token, null, DateTime.Now.AddSeconds(7000), System.Web.Caching.Cache.NoSlidingExpiration);\r\n }\r\n\r\n string Access_tokento = Access_token.Substring(17, Access_token.Length - 37);\r\n\r\n\r\n string posturl = \"https:\/\/api.weixin.qq.com\/cgi-bin\/groups\/members\/update?access_token=\" + Access_tokento;\r\n\r\n\r\n \/\/POST數(shù)據(jù)例子:{\"openid\":\"oDF3iYx0ro3_7jD4HFRDfrjdCM58\",\"to_groupid\":108}\r\n \/\/string postData = \"{\\\"openid\\\":\\\"\" + openid.ToString().Trim() + \"\\\",\\\"remark\\\":\\\"\" + this.txtRemarkName.Value.ToString() + \"\\\"}\";\r\n\r\n string postData = \"{\\\"openid\\\":\\\"\" + lbwxopenID.Text.ToString() + \"\\\",\\\"to_groupid\\\":\\\"\" + groupId.ToString() + \"\\\"}\";\r\n\r\n\r\n res = wxs.GetPage(posturl, postData);\r\n\r\n\r\n \/\/使用前需要引用Newtonsoft.json.dll文件\r\n JObject jsonObj = JObject.Parse(res);\r\n\r\n \/\/\/獲取返回結(jié)果的正確|true|false,\r\n string isright = jsonObj[\"errcode\"].ToString();\/\/0\r\n string istrueorfalse = jsonObj[\"errmsg\"].ToString();\/\/ok\r\n if (isright.Equals(\"0\") && istrueorfalse.Equals(\"ok\"))\r\n {\r\n ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), \"\", \"alert('移動(dòng)用戶成功!');location='WeiXinUserList.aspx';\", true);\r\n }\r\n else\r\n {\r\n ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), \"\", \"alert('移動(dòng)用戶失??!');\", true);\r\n return;\r\n }\r\n }\r\n\r\n }\r\n if (!bools)\r\n {\r\n ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), \"\", \"alert('未選中項(xiàng)!');location='WeiXinUserList.aspx';\", true);\r\n return;\r\n }\r\n }<\/pre> <\/strong>WeiXinServer wxs = new WeiXinServer(); is a separately created class, mainly used to obtain passes and load streams. The code is as follows: <\/p> \/\/\/ \r\n \/\/\/ 微信服務(wù)類\r\n \/\/\/ <\/summary>\r\n public class WeiXinServer\r\n {\r\n \/\/\/ \r\n \/\/\/ 獲取通行證\r\n \/\/\/ <\/summary>\r\n \/\/\/ <\/returns>\r\n public string GetAccessToken()\r\n {\r\n string url_token = \"https:\/\/api.weixin.qq.com\/cgi-bin\/token?grant_type=client_credential&appid=此處應(yīng)該填寫公眾的appid&secret=此處應(yīng)該填寫公眾號(hào)的secret\";\r\n HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url_token);\r\n myRequest.Method = \"GET\";\r\n HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();\r\n StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);\r\n string content = reader.ReadToEnd();\r\n reader.Close();\r\n return content;\r\n }\r\n public string GetPage(string p, string postData)\r\n {\r\n Stream outstream = null;\r\n Stream instream = null;\r\n StreamReader sr = null;\r\n HttpWebResponse response = null;\r\n HttpWebRequest request = null;\r\n Encoding encoding = Encoding.UTF8;\r\n byte[] data = encoding.GetBytes(postData);\r\n \/\/ 準(zhǔn)備請(qǐng)求...\r\n try\r\n {\r\n \/\/ 設(shè)置參數(shù)\r\n request = WebRequest.Create(p) as HttpWebRequest;\r\n CookieContainer cookieContainer = new CookieContainer();\r\n request.CookieContainer = cookieContainer;\r\n request.AllowAutoRedirect = true;\r\n request.Method = \"POST\";\r\n request.ContentType = \"application\/x-www-form-urlencoded\";\r\n request.ContentLength = data.Length;\r\n outstream = request.GetRequestStream();\r\n outstream.Write(data, 0, data.Length);\r\n outstream.Close();\r\n \/\/發(fā)送請(qǐng)求并獲取相應(yīng)回應(yīng)數(shù)據(jù)\r\n response = request.GetResponse() as HttpWebResponse;\r\n \/\/直到request.GetResponse()程序才開始向目標(biāo)網(wǎng)頁發(fā)送Post請(qǐng)求\r\n instream = response.GetResponseStream();\r\n sr = new StreamReader(instream, encoding);\r\n \/\/返回結(jié)果網(wǎng)頁(html)代碼\r\n string content = sr.ReadToEnd();\r\n string err = string.Empty;\r\n return content;\r\n }\r\n catch (Exception ex)\r\n {\r\n string err = ex.Message;\r\n return string.Empty;\r\n }\r\n }\r\n }<\/pre><\/strong>Modify the code of the remarks page: <\/p> protected void Page_Load(object sender, EventArgs e)\r\n {\r\n if(Request.QueryString[\"id\"]!=null)\r\n {\r\n String openid = Request.QueryString[\"id\"].ToString();\r\n this.txtOpenId.Value = openid.ToString();\r\n\r\n \/\/根據(jù)OpenID獲取用戶基本信息。緩存處理\r\n WeiXinServer wxs = new WeiXinServer();\r\n\r\n \/\/\/從緩存讀取accesstoken\r\n string Access_token = Cache[\"Access_token\"] as string;\r\n\r\n if (Access_token == null)\r\n {\r\n \/\/如果為空,重新獲取\r\n Access_token = wxs.GetAccessToken();\r\n\r\n \/\/設(shè)置緩存的數(shù)據(jù)7000秒后過期\r\n Cache.Insert(\"Access_token\", Access_token, null, DateTime.Now.AddSeconds(7000), System.Web.Caching.Cache.NoSlidingExpiration);\r\n }\r\n\r\n string Access_tokento = Access_token.Substring(17, Access_token.Length - 37);\r\n\r\n string jsonres = \"https:\/\/api.weixin.qq.com\/cgi-bin\/user\/info?access_token=\" + Access_tokento + \"&openid=\" + openid;\r\n\r\n HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(jsonres);\r\n myRequest.Method = \"GET\";\r\n HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();\r\n StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);\r\n string content = reader.ReadToEnd();\r\n reader.Close();\r\n\r\n \/\/使用前需要引用Newtonsoft.json.dll文件\r\n JObject jsonObj = JObject.Parse(content);\r\n\r\n \/\/假如備注名不為空,給備注名文本框賦值,顯示原有的備注名\r\n if (!String.IsNullOrWhiteSpace(jsonObj[\"remark\"].ToString()))\r\n {\r\n this.txtRemarkName.Value = jsonObj[\"remark\"].ToString();\r\n }\r\n\r\n }\r\n }\r\n \/\/\/ \r\n \/\/\/ 設(shè)置備注名\r\n \/\/\/ <\/summary>\r\n \/\/\/ <\/param>\r\n \/\/\/ <\/param>\r\n protected void LinkBtnSet_Click(object sender, EventArgs e)\r\n {\r\n \r\n\r\n String openid = Request.QueryString[\"id\"].ToString();\r\n\r\n WeiXinServer wxs = new WeiXinServer();\r\n string res = \"\";\r\n\r\n \/\/\/從緩存讀取accesstoken\r\n string Access_token = Cache[\"Access_token\"] as string;\r\n\r\n if (Access_token == null)\r\n {\r\n \/\/如果為空,重新獲取\r\n Access_token = wxs.GetAccessToken();\r\n\r\n \/\/設(shè)置緩存的數(shù)據(jù)7000秒后過期\r\n Cache.Insert(\"Access_token\", Access_token, null, DateTime.Now.AddSeconds(7000), System.Web.Caching.Cache.NoSlidingExpiration);\r\n }\r\n\r\n string Access_tokento = Access_token.Substring(17, Access_token.Length - 37);\r\n\r\n\r\n string posturl = \"https:\/\/api.weixin.qq.com\/cgi-bin\/user\/info\/updateremark?access_token=\" + Access_tokento;\r\n\r\n string postData = \"{\\\"openid\\\":\\\"\" + openid.ToString().Trim() + \"\\\",\\\"remark\\\":\\\"\" + this.txtRemarkName.Value.ToString() + \"\\\"}\";\r\n\r\n\r\n res = wxs.GetPage(posturl, postData);\r\n\r\n\r\n \/\/使用前需藥引用Newtonsoft.json.dll文件\r\n JObject jsonObj = JObject.Parse(res);\r\n\r\n \/\/\/獲取返回結(jié)果的正確|true|false,\r\n string isright = jsonObj[\"errcode\"].ToString();\/\/0\r\n string istrueorfalse = jsonObj[\"errmsg\"].ToString();\/\/ok\r\n if (isright.Equals(\"0\") && istrueorfalse.Equals(\"ok\"))\r\n {\r\n ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), \"\", \"alert('修改備注成功!');location='WeiXinUserList.aspx';\", true);\r\n }\r\n else\r\n {\r\n ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), \"\", \"alert('修改備注失??!');\", true);\r\n }\r\n\r\n }<\/pre><\/strong><\/p>\n
<\/p>"}
Home
WeChat Applet
WeChat Development
Detailed explanation of following user management steps in asp.net WeChat development
Detailed explanation of following user management steps in asp.net WeChat development
Mar 20, 2017 pm 01:48 PM
asp.net
WeChat development
This article mainly introduces the related content of the followed user management in asp.net WeChat development. Friends in need can refer to the
public account through this Interface to obtain the account's follower list. The follower list consists of a string of OpenIDs (encrypted WeChat IDs, each user's OpenID for each official account is unique). A single pull call can pull up to 10,000 OpenIDs of followers, and you can pull multiple times to meet your needs.
Interface call request description
http request method: GET (please use https protocol)

Return description
Return JSON data packet when correct:

Return JSON data packet when incorrect (example is invalid AppID error):
{" errcode":40013,"errmsg":"invalid appid"}
Attachment: When the number of followers exceeds 10,000
When the number of followers of the official account exceeds 10,000, you can fill in next## The value of #_openid can be used to pull the list multiple times to meet the needs.
Specifically, when calling the interface, the next_openid value returned from the previous call is used as the next_openid value in the next call.
The example is as follows:
Public account A has 23,000 following people. If you want to get all the following people through the pull attention interface, then the respective request URLs are as follows:
https:// api.weixin.qq.com/cgi-bin/user/get?access_token=ACCESS_TOKEN
Return result:
{
"total":23000,
"count":10000,
"data":{"
openid":[
"OPENID1",
"OPENID2",
...,
"OPENID10000"
]
},
"next_openid":"OPENID10000"
}
https:/ /api.weixin.qq.com/cgi-bin/user/get?access_token=ACCESS_TOKEN&next_openid=NEXT_OPENID1
Return result:
##
{
"total":23000,
"count":10000,
"data":{
"openid":[
"OPENID10001",
"OPENID10002",
...,
"OPENID20000"
]
},
"next_openid":"OPENID20000"
}
##https://api.weixin.qq.com/cgi-bin/user/get?access_token=ACCESS_TOKEN&next_openid=NEXT_OPENID2
Return results (the follower list has been returned , return next_openid is empty):
{
"total":23000,
"count":3000,
"data":{"
"openid":[
"OPENID20001",
"OPENID20002",
...,
"OPENID23000"
]
},
"next_openid":"OPENID23000"
}
is called every day in the interface permission table of the WeChat official website background (taking service account as an example) to obtain users The list
can be obtained 500 times, and the user's basic information can be obtained 500,000 times. So next, when I obtain the user list, I will use
caching. Even though 500 times is a lot, But it is really fast to use. The rendering is as follows:
Let’s take a look at the user list first. The official website says that getting the user list returns: A group of openIDs. For this feature, I did this,
Create a class for storing openId
public class WxOpenIdInfo
{
public string WxopenId { get; set; }//用戶存放微信用戶的openId
}
And then create a basic class of user information
/// <summary>
/// 微信用戶基本信息類
/// </summary>
public class WxUserInfo
{
public int subscribe { get; set; }//關(guān)注狀態(tài)
public string openid { get; set; }//OpenID
public string nickname { get; set; }//昵稱
public string sex { get; set; }//性別
public string city { get; set; }//城市
public string province { get; set; }//省份
public string headimgurl { get; set; }//頭像圖片地址
public string subscribe_time { get; set; }//關(guān)注時(shí)間
public string remark { get; set; }//備注
public string groupid { get; set; }//分組ID
}
User list front-end code
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WeiXinUserList.aspx.cs" Inherits="DQWebSite.Administrator.WeiXinUserList" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<link href="css/style.css" rel="Stylesheet" type="text/css" />
<style type="text/css">
#title {width:100%; height:40px;margin-top:10px; text-indent:5px; line-height:40px;}
.checkstyle { float:left;}
#DDlAddgroups { text-align:center; width:161px; border:1px solid #d9d9d9; border-radius:5px; height:35px; line-height:35px; font-weight:bold; text-align:center; float:left; margin:auto 5px auto 5px;}
.DDlAddgroups{ text-align:center; width:161px; border:1px solid #d9d9d9; border-radius:5px; height:35px; line-height:35px; font-weight:bold; text-align:center; float:left; margin:auto 5px auto 5px;}
#DDLgroups { text-align:center; width:111px; border:1px solid #d9d9d9; border-radius:5px; height:35px; line-height:35px; font-weight:bold; text-align:center; float:left; margin:auto 5px auto 5px;}
.newGroups { margin:auto 5px auto 5px;}
.inputstyle { height:35px; line-height:35px; text-indent:5px; width:280px;background-image:url('images/inputbg.gif'); background-repeat:repeat-x;border-top:solid 1px #a7b5bc; border-left:solid 1px #a7b5bc; border-right:solid 1px #ced9df; border-bottom:solid 1px #ced9df; float:left; margin:auto 5px auto 5px;
}
.wxusertab { border:1px solid #d9d9d9; width:100%; text-align:left; text-indent:5px;
}
th { height:35px;background-image:url('images/th.gif'); background-repeat:repeat-x;
}
td {
border-bottom:1px solid #d9d9d9;
}
.trcolor { background-color:#ecd9df;
}
tr:hover { cursor:pointer;
}
#FenPage { width:1124px; height:25px; line-height:25px; text-align:center; margin:20px auto 20px auto;
}
.linka { color:#0094ff; cursor:pointer;
}
.fenyebtn {width:60px; height:25px; border:1px solid #ced9df; border-radius:5px; text-align:center; line-height:25px; float:right;
}
.fenyebtn2 { width:60px; height:25px; border:1px solid #ced9df; border-radius:5px; text-align:center; line-height:25px;margin-left:10px;float:right;
}
.toPageIndex { width:60px;height:25px; background-image:url('images/inputbg.gif'); margin-left:10px; background-repeat:repeat-x;border-top:solid 1px #a7b5bc; border-left:solid 1px #a7b5bc; border-right:solid 1px #ced9df; border-bottom:solid 1px #ced9df; text-align:center; float:right;
}
.gotoPagebtn { width:60px; height:25px; border:1px solid #ced9df; border-radius:5px; text-align:center; line-height:25px;margin-left:10px;float:right; background-color:#ced9df;
}
.deletebtn {float:left;width:100px; color:#000; height:25px; background-color:#ced9df; border:1px solid #ced9df; border-radius:5px; text-align:center;
}
a { color:#08a5e0;
}
.droplist { background-image:url('images/inputbg.gif'); background-repeat:repeat-x; width:120px; height:25px; border:1px solid #ced9df;
}
.checkstyle { float:left;
}
.imgheadstyle { width:50px; height:50px; margin-top:10px;
}
.lbsubscribeCount { font-size:26px;
}
#shownewgroup { width:300px; height:200px; background-color:white;z-index:9999; border:2px solid #DDD; top:40%; left:40%; background-color:#fff; position:fixed;margin:-100px auto auto -100px; display:none;
}
#shownewgroupzhezhaoceng { height:200%; width:200%; left:0px; top:0px;position:fixed; z-index:9998; background:rgb(50,50,50);background:rgba(0,0,0,0.5); display:none;
}
.closeLogin { height:30px; border-bottom:2px solid #31bb34; text-align:right; line-height:30px; font-size:14px; font-weight:bold;
}
a:hover { cursor:pointer;
}
#updateremark { width:300px; height:200px; background-color:white;z-index:9999; border:2px solid #DDD; top:40%; left:40%; background-color:#fff; position:fixed;margin:-100px auto auto -100px; display:none;
}
#updateremark_zhezhaoceng { height:100%; width:100%; left:0px; top:0px;position:fixed; z-index:9998; background:rgb(50,50,50);background:rgba(0,0,0,0.5); display:none;
}
</style>
<script src="../js/jquery-1.7.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$(".newGroups").click(function () {
$("#shownewgroupzhezhaoceng").show();
$("#shownewgroup").show();
}),
$('.closeloginpage').click(function () {
$("#shownewgroupzhezhaoceng").hide();
$("#shownewgroup").hide();
})
})
</script>
</head>
<body>
<form id="form1" runat="server">
<p class="place">
<span>位置:</span>
<ul class="placeul">
<li><a href="WelCome.aspx" target="rightFrame">首頁</a></li>
<li>微信管理</li>
<li>德橋員工服務(wù)中心--關(guān)注者列表管理</li>
</ul>
</p>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<p id="shownewgroup">
<p class="closeLogin"><a class="closeloginpage"><span style="float:left; color:#08a5e0; font-size:18px; text-indent:5px;">新建分組</span>關(guān)閉</a> </p>
<p style="font-size:12px; height:40px; color:red; line-height:40px;"> 30字符以內(nèi)</p>
<input type="text" id="txtgroupsName" name="txtgroupsName" class="inputstyle" maxlength="30" runat="server" value="分組名稱" onfocus="if(value==defaultValue){value='';this.style.color='#000'}" onblur="if(!value){value=defaultValue;this.style.color='#999'}" style="color:#999"/>
<asp:LinkButton ID="LinkBtnCreateGroup" runat="server" OnClick="LinkBtnCreateGroup_Click"><p style="background-image:url('images/buttonbg.png'); width:111px; height:35px; line-height:35px; font-weight:bold;float:left; margin-top:20px; margin-left:5px; text-align:center;color:#fff;"> 確定創(chuàng)建</p></asp:LinkButton>
</p>
<p id="shownewgroupzhezhaoceng"></p>
<p style=" border-bottom:2px solid #31bb34; height:30px; margin-top:10px; text-indent:10px; font-size:22px; line-height:30px; width:100%;"><span style="float:left; font-size:16px;">已關(guān)注人數(shù)</span><span style="color:red;"><asp:Label ID="lbsubscribeCount" CssClass="lbsubscribeCount" runat="server" Text="Label"></asp:Label> </span></p>
<p id="title">
<asp:CheckBox ID="CheckAll" runat="server" CssClass="checkstyle" OnCheckedChanged="CheckAll_CheckedChanged" /><span style="float:left;">全選 </span>
<asp:DropDownList ID="DDlAddgroups" CssClass="DDlAddgroups" runat="server" OnSelectedIndexChanged="DDlAddgroups_SelectedIndexChanged">
</asp:DropDownList>
<asp:DropDownList ID="DDLgroups" runat="server">
</asp:DropDownList>
<a class="newGroups"><p style="background-image:url('images/buttonbg.png'); width:111px; height:35px; line-height:35px; margin:auto 20px auto 10px; font-weight:bold;float:left; text-align:center;color:#fff;"> + 新建分組</p></a>
<a href="WxGroupManageList.aspx"><p style="background-image:url('images/buttonbg.png'); width:111px; height:35px; line-height:35px; margin:auto 20px auto 10px; font-weight:bold;float:left; text-align:center;color:#fff;">分組管理</p></a>
<a href="WeiXinUserList.aspx"><p style="background-image:url('images/buttonbg.png'); width:111px; height:35px; line-height:35px; margin:auto 20px auto 10px; font-weight:bold;float:left; text-align:center;color:#fff;">刷 新</p></a>
<%-- <input type="text" id="txtName" name="txtName" class="inputstyle" runat="server" value="用戶昵稱" onfocus="if(value==defaultValue){value='';this.style.color='#000'}" onblur="if(!value){value=defaultValue;this.style.color='#999'}" style="color:#999"/>
<asp:LinkButton ID="LinkButton1" runat="server"><p style="background-image:url('images/buttonbg.png'); width:111px; height:35px; line-height:35px; font-weight:bold;float:left; text-align:center;color:#fff;"> 查詢</p></asp:LinkButton>--%>
</p>
<table class="wxusertab">
<asp:Repeater ID="RepeaterWxUserList" runat="server" OnItemDataBound="RepeaterWxUserList_ItemDataBound">
<HeaderTemplate>
<tr>
<th></th>
<th>OpenID</th>
<th>頭像</th>
<th>昵稱(備注名)</th>
<th>關(guān)注時(shí)間</th>
<th>所屬分組</th>
<th>操作</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr style="width:100%; line-height:50px;">
<td style="width:30px;"> <asp:CheckBox ID="CheckIn" runat="server" CssClass="checkstyle" /> <%--OnCheckedChanged="CheckIn_CheckedChanged"--%></td>
<td style="width:150px;"><asp:Label ID="lbwxopenID" runat="server" Text=""></asp:Label>
</td>
<td style="width:80px;"><asp:Image ID="ImgHeadUrl" runat="server" CssClass="imgheadstyle" /> </td>
<td style="width:150px;"><asp:Label ID="lbNickName" runat="server" CssClass="checkstyle" Text=""></asp:Label>
<asp:Label ID="lbRemark" runat="server" Text=""></asp:Label>
</td>
<td style="width:130px;">
<asp:Label ID="lbSubscrine_time" runat="server" Text=""></asp:Label>
</td>
<td style="width:100px;">
<asp:Label ID="lbgroupId" runat="server" CssClass="checkstyle" Visible="false" Text=""></asp:Label>
<asp:DropDownList ID="DDlAddgroupss" Enabled="false" CssClass="DDlAddgroups" runat="server">
<asp:ListItem Value="0">分組名稱</asp:ListItem>
</asp:DropDownList>
</td>
<td style="width:110px;">
<a href='UpdateRemarkName.aspx?id=<%# Eval("WxopenId") %>'><p style=" border:1px solid #d9d9d9; border-radius:5px; width:111px; height:35px; line-height:35px; font-weight:bold;float:left; text-align:center;"> 修改備注名稱</p></a>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
<p id="FenPage">
<asp:LinkButton ID="LinkBtnToPage" CssClass="gotoPagebtn" runat="server" OnClick="LinkBtnToPage_Click">確定</asp:LinkButton>
<asp:TextBox ID="txtPageIndex" CssClass="toPageIndex" runat="server"></asp:TextBox>
<asp:HyperLink ID="lnkLast" runat="server"><span class="fenyebtn2">>>|</span></asp:HyperLink>
<asp:HyperLink ID="lnkNext" runat="server"><span class="fenyebtn2">></span></asp:HyperLink>
<asp:HyperLink ID="lnkTop" runat="server"><span class="fenyebtn2"><</span></asp:HyperLink>
<asp:HyperLink ID="lnkFist" runat="server"><span class="fenyebtn">|<<</span></asp:HyperLink>
<span style="float:left;">當(dāng)前第</span>
<span style="float:left; color:red;"><asp:Label ID="lbPageIndex" runat="server" Text=""></asp:Label></span>
<span style="float:left;margin-left:5px;">頁/</span>
<span style="float:left;margin-left:5px;">共</span>
<span style="float:left;color:red;"><asp:Label ID="lbCountPage" runat="server" Text=""></asp:Label></span>
<span style="float:left;margin-left:5px;">頁</span>
<span style="float:left;margin-left:10px;"><asp:Label ID="lbPageSize" runat="server" Text=""></asp:Label></span>
<span style="float:left;margin-left:10px;">共搜索到 </span>
<span style="float:left;margin-left:5px; color:red;"><asp:Label ID="lbCountData" runat="server" Text=""></asp:Label></span>
<span style="float:left;margin-left:5px;">條記錄.</span>
</p>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
Get the back-end code for binding user information to the user list, which is included. Modify the remark name, move the user to a group, and create a new group codeGroup statistics, used to display the number of existing people in each group, no other function
Code:
PagedDataSource pds = new PagedDataSource();
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
BindGroupList();
BindGetAllUserOpenIdList();
this.DataBind();
this.CheckAll.AutoPostBack = true;
this.DDlAddgroups.AutoPostBack = true;
}
//this.DDlAddgroups.Enabled = false;
}
/// <summary>
/// 獲取所有用戶的openId列表
/// </summary>
private void BindGetAllUserOpenIdList()
{
WeiXinServer wxs = new WeiXinServer();
///從緩存讀取accesstoken
string Access_token = Cache["Access_token"] as string;
if (Access_token == null)
{
//如果為空,重新獲取
Access_token = wxs.GetAccessToken();
//設(shè)置緩存的數(shù)據(jù)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();
//設(shè)置緩存的數(shù)據(jù)7000秒后過期
Cache.Insert("AllUserOpenList_content", content, null, DateTime.Now.AddSeconds(7000), System.Web.Caching.Cache.NoSlidingExpiration);
}
//使用前需要引用Newtonsoft.json.dll文件
JObject jsonObj = JObject.Parse(content);
int totalnum = int.Parse(jsonObj["count"].ToString());
List<WxOpenIdInfo> openidlist = new List<WxOpenIdInfo>();
for (int i = 0; i < totalnum;i++ )
{
WxOpenIdInfo wxopeninfo = new WxOpenIdInfo();
wxopeninfo.WxopenId = jsonObj["data"]["openid"][i].ToString();
openidlist.Add(wxopeninfo);
}
pds.DataSource = openidlist;
pds.AllowPaging = true;
pds.PageSize = 20;//每頁顯示為20條
int CurrentPage;
if (!String.IsNullOrWhiteSpace(this.txtPageIndex.Text.ToString().Trim()))
{
CurrentPage = Convert.ToInt32(this.txtPageIndex.Text.ToString().Trim());
}
else if (Request.QueryString["Page"] != null)
{
CurrentPage = Convert.ToInt32(Request.QueryString["Page"]);
}
else
{
CurrentPage = 1;
}
pds.CurrentPageIndex = CurrentPage - 1;//當(dāng)前頁的索引就等于當(dāng)前頁碼-1;
if (!pds.IsFirstPage)
{
//Request.CurrentExecutionFilePath 為當(dāng)前請(qǐng)求的虛擬路徑
this.lnkTop.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurrentPage - 1);
this.lnkFist.Enabled = this.lnkTop.Enabled = true;
this.lnkNext.Enabled = this.lnkLast.Enabled = true;
}
else
{
this.lnkFist.Enabled = this.lnkTop.Enabled = false;
this.lnkNext.Enabled = this.lnkLast.Enabled = true;
this.lnkFist.Attributes.Add("style", "color:#ced9df;");
this.lnkTop.Attributes.Add("style", "color:#ced9df;");
this.lnkNext.Attributes.Remove("style");
this.lnkLast.Attributes.Remove("style");
}
if (!pds.IsLastPage)
{
//Request.CurrentExecutionFilePath 為當(dāng)前請(qǐng)求的虛擬路徑
this.lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurrentPage + 1);
this.lnkFist.Enabled = this.lnkTop.Enabled = true;
this.lnkNext.Enabled = this.lnkLast.Enabled = true;
}
else
{
this.lnkNext.Enabled = this.lnkLast.Enabled = false;
this.lnkFist.Enabled = this.lnkTop.Enabled = true;
this.lnkNext.Attributes.Add("style", "color:#ced9df;");
this.lnkLast.Attributes.Add("style", "color:#ced9df;");
this.lnkFist.Attributes.Remove("style");
this.lnkTop.Attributes.Remove("style");
}
this.lnkFist.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(1);//跳轉(zhuǎn)至首頁
this.lnkLast.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(pds.PageCount);//跳轉(zhuǎn)至末頁
this.RepeaterWxUserList.DataSource = pds;
this.RepeaterWxUserList.DataBind();
this.lbCountData.Text = openidlist.Count.ToString();
this.lbPageIndex.Text = (pds.CurrentPageIndex + 1).ToString();
this.lbPageSize.Text = "每頁" + pds.PageSize.ToString() + "條記錄";
this.lbCountPage.Text = pds.PageCount.ToString();
this.txtPageIndex.Text = (pds.CurrentPageIndex + 1).ToString();
if (int.Parse(openidlist.Count.ToString()) <= int.Parse(pds.PageSize.ToString()))
{
this.lnkFist.Visible = this.lnkTop.Visible = this.lnkNext.Visible = this.lnkLast.Visible = this.txtPageIndex.Visible = this.LinkBtnToPage.Visible = false;
}
else
{
this.lnkFist.Visible = this.lnkTop.Visible = this.lnkNext.Visible = this.lnkLast.Visible = this.txtPageIndex.Visible = this.LinkBtnToPage.Visible = true;
}
this.lbsubscribeCount.Text = openidlist.Count.ToString();
}
/// <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();
//設(shè)置緩存的數(shù)據(jù)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();
//設(shè)置緩存的數(shù)據(jù)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.DDLgroups.Items.Clear();//清除
this.DDlAddgroups.Items.Clear();
this.DDLgroups.Items.Insert(0, new ListItem("分組統(tǒng)計(jì)", "0"));//添加默認(rèn)第一個(gè)提示
this.DDlAddgroups.Items.Insert(0, new ListItem("移動(dòng)用戶到分組", "0"));
for (int i = 0; i < groupsnum; i++)
{
this.DDLgroups.Items.Add(new ListItem(jsonObj["groups"][i]["name"].ToString() + "(" + jsonObj["groups"][i]["count"].ToString() + ")", jsonObj["groups"][i]["id"].ToString()));
this.DDlAddgroups.Items.Add(new ListItem(jsonObj["groups"][i]["name"].ToString(), jsonObj["groups"][i]["id"].ToString()));
}
}
/// <summary>
/// 輸入頁碼提交跳轉(zhuǎn)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void LinkBtnToPage_Click(object sender, EventArgs e)
{
if (String.IsNullOrWhiteSpace(this.txtPageIndex.Text.ToString().Trim()))
{
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('頁碼不能為空!')", true);
this.txtPageIndex.Focus();
return;
}
if (IsNum(this.txtPageIndex.Text.ToString().Trim()))
{
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('頁碼數(shù)只能輸入數(shù)字!')", true);
this.txtPageIndex.Focus();
this.txtPageIndex.Text = this.lbPageIndex.Text.ToString();
return;
}
if (int.Parse(this.txtPageIndex.Text.ToString().Trim()) > int.Parse(this.lbCountPage.Text.ToString().Trim()))
{
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('所輸頁數(shù)不能大于總頁數(shù)!')", true);
this.txtPageIndex.Focus();
this.txtPageIndex.Text = this.lbPageIndex.Text.ToString();
return;
}
BindGetAllUserOpenIdList();
}
/// <summary>
/// 判斷是否是數(shù)字
/// </summary>
/// <param name="text"></param>
/// <returns></returns>
public static bool IsNum(string text) //
{
for (int i = 0; i < text.Length; i++)
{
if (!Char.IsNumber(text, i))
{
return true; //輸入的不是數(shù)字
}
}
return false; //否則是數(shù)字
}
/// <summary>
/// 綁定用戶基本信息事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void RepeaterWxUserList_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
//CheckBox checkIn = e.Item.FindControl("CheckIn") as CheckBox;
//checkIn.AutoPostBack = true;
if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem)
{
WxOpenIdInfo wxopen = e.Item.DataItem as WxOpenIdInfo;
Label lbwxopenID = e.Item.FindControl("lbwxopenID") as Label;
lbwxopenID.Text = wxopen.WxopenId.ToString();
//根據(jù)OpenID獲取用戶基本信息。緩存處理
WeiXinServer wxs = new WeiXinServer();
///從緩存讀取accesstoken
string Access_token = Cache["Access_token"] as string;
if (Access_token == null)
{
//如果為空,重新獲取
Access_token = wxs.GetAccessToken();
//設(shè)置緩存的數(shù)據(jù)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 ="https://api.weixin.qq.com/cgi-bin/user/info?access_token=" + Access_tokento + "&openid=" + lbwxopenID.Text.ToString();
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(jsonres);
myRequest.Method = "GET";
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
string content = reader.ReadToEnd();
reader.Close();
//使用前需要引用Newtonsoft.json.dll文件
JObject jsonObj = JObject.Parse(content);
Image ImgHeadUrl = e.Item.FindControl("ImgHeadUrl") as Image;
Label lbNickName = e.Item.FindControl("lbNickName") as Label;
Label lbRemark = e.Item.FindControl("lbRemark") as Label;
Label lbSubscrine_time = e.Item.FindControl("lbSubscrine_time") as Label;
Label lbgroupId = e.Item.FindControl("lbgroupId") as Label;
DropDownList DDlAddgroupss = e.Item.FindControl("DDlAddgroupss") as DropDownList;
lbNickName.Text = jsonObj["nickname"].ToString();
if (!String.IsNullOrWhiteSpace(jsonObj["remark"].ToString()))
{
lbRemark.Text = "(" + jsonObj["remark"].ToString() + ")";
}
ImgHeadUrl.ImageUrl = jsonObj["headimgurl"].ToString();
lbgroupId.Text = jsonObj["groupid"].ToString();
//獲取關(guān)注時(shí)間
int totaltiem = int.Parse(jsonObj["subscribe_time"].ToString());
//將整型格式時(shí)間轉(zhuǎn)換為時(shí)間格式
DateTime t = new DateTime(1970, 1, 1).AddSeconds(totaltiem);
//轉(zhuǎn)換后的時(shí)間會(huì)比原有時(shí)間小8個(gè)小時(shí),因此需要加上8個(gè)小時(shí)
lbSubscrine_time.Text = t.AddHours(8).ToString();
string jjjjjjjjjddd = Cache["AllGroups_content"] as string;
if (jjjjjjjjjddd == null)
{
jsonres = "https://api.weixin.qq.com/cgi-bin/groups/get?access_token=" + Access_tokento;
HttpWebRequest myRequestss = (HttpWebRequest)WebRequest.Create(jsonres);
myRequest.Method = "GET";
HttpWebResponse myResponsess = (HttpWebResponse)myRequest.GetResponse();
StreamReader readerss = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
jjjjjjjjjddd = reader.ReadToEnd();
reader.Close();
//設(shè)置緩存的數(shù)據(jù)7000秒后過期
Cache.Insert("AllGroups_content", jjjjjjjjjddd, null, DateTime.Now.AddSeconds(7000), System.Web.Caching.Cache.NoSlidingExpiration);
}
//使用前需要引用Newtonsoft.json.dll文件
JObject jsonObjss = JObject.Parse(jjjjjjjjjddd);
int groupsnumss = jsonObjss["groups"].Count();
for (int i = 0; i < groupsnumss;i++ )
{
if (jsonObjss["groups"][i]["id"].ToString().Equals(lbgroupId.Text.ToString()))
{
DDlAddgroupss.SelectedItem.Text = jsonObjss["groups"][i]["name"].ToString();
}
}
}
}
/// <summary>
/// 創(chuàng)建分組
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void LinkBtnCreateGroup_Click(object sender, EventArgs e)
{
if (this.txtgroupsName.Value.ToString().Equals("分組名稱"))
{
////
ScriptManager.RegisterClientScriptBlock(this.Page,this.GetType(),"","alert('不能為空!')",true);
this.txtgroupsName.Focus();
return;
}
WeiXinServer wxs = new WeiXinServer();
string res = "";
///從緩存讀取accesstoken
string Access_token = Cache["Access_token"] as string;
if (Access_token == null)
{
//如果為空,重新獲取
Access_token = wxs.GetAccessToken();
//設(shè)置緩存的數(shù)據(jù)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/groups/create?access_token=" + Access_tokento;
//string postData = "{\"group\":{\"name\":\""+this.txtgroupsName.Value.ToString().Trim()+"\"}}";
string postData = "{\"group\":{\"name\":\""+this.txtgroupsName.Value.ToString().Trim()+"\"}}";
res = wxs.GetPage(posturl, postData);
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('創(chuàng)建成功!如未顯示,請(qǐng)退出重新登錄即可!');location='WeiXinUserList.aspx';", true);
}
/// <summary>
/// 全選、全不選
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void CheckAll_CheckedChanged(object sender, EventArgs e)
{
CheckBox checkAll = (CheckBox)sender;
foreach (RepeaterItem item in this.RepeaterWxUserList.Items)
{
CheckBox checkIn = (CheckBox)item.FindControl("CheckIn");
checkIn.Checked = checkAll.Checked;
}
}
/// <summary>
/// 移動(dòng)用戶到分組
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void DDlAddgroups_SelectedIndexChanged(object sender, EventArgs e)
{
///取得分組ID
string groupId = this.DDlAddgroups.SelectedValue.ToString();
//this.Label1.Text = groupId.ToString();
Boolean bools = false;
foreach (RepeaterItem item in this.RepeaterWxUserList.Items)
{
CheckBox checkIn = (CheckBox)item.FindControl("CheckIn");
if (checkIn.Checked)
{
bools = true;
Label lbwxopenID = item.FindControl("lbwxopenID") as Label;
WeiXinServer wxs = new WeiXinServer();
string res = "";
///從緩存讀取accesstoken
string Access_token = Cache["Access_token"] as string;
if (Access_token == null)
{
//如果為空,重新獲取
Access_token = wxs.GetAccessToken();
//設(shè)置緩存的數(shù)據(jù)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/groups/members/update?access_token=" + Access_tokento;
//POST數(shù)據(jù)例子:{"openid":"oDF3iYx0ro3_7jD4HFRDfrjdCM58","to_groupid":108}
//string postData = "{\"openid\":\"" + openid.ToString().Trim() + "\",\"remark\":\"" + this.txtRemarkName.Value.ToString() + "\"}";
string postData = "{\"openid\":\"" + lbwxopenID.Text.ToString() + "\",\"to_groupid\":\"" + groupId.ToString() + "\"}";
res = wxs.GetPage(posturl, postData);
//使用前需要引用Newtonsoft.json.dll文件
JObject jsonObj = JObject.Parse(res);
///獲取返回結(jié)果的正確|true|false,
string isright = jsonObj["errcode"].ToString();//0
string istrueorfalse = jsonObj["errmsg"].ToString();//ok
if (isright.Equals("0") && istrueorfalse.Equals("ok"))
{
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('移動(dòng)用戶成功!');location='WeiXinUserList.aspx';", true);
}
else
{
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('移動(dòng)用戶失敗!');", true);
return;
}
}
}
if (!bools)
{
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('未選中項(xiàng)!');location='WeiXinUserList.aspx';", true);
return;
}
}
WeiXinServer wxs = new WeiXinServer(); is a separately created class, mainly used to obtain passes and load streams. The code is as follows:
/// <summary>
/// 微信服務(wù)類
/// </summary>
public class WeiXinServer
{
/// <summary>
/// 獲取通行證
/// </summary>
/// <returns></returns>
public string GetAccessToken()
{
string url_token = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=此處應(yīng)該填寫公眾的appid&secret=此處應(yīng)該填寫公眾號(hào)的secret";
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url_token);
myRequest.Method = "GET";
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
string content = reader.ReadToEnd();
reader.Close();
return content;
}
public string GetPage(string p, string postData)
{
Stream outstream = null;
Stream instream = null;
StreamReader sr = null;
HttpWebResponse response = null;
HttpWebRequest request = null;
Encoding encoding = Encoding.UTF8;
byte[] data = encoding.GetBytes(postData);
// 準(zhǔn)備請(qǐng)求...
try
{
// 設(shè)置參數(shù)
request = WebRequest.Create(p) as HttpWebRequest;
CookieContainer cookieContainer = new CookieContainer();
request.CookieContainer = cookieContainer;
request.AllowAutoRedirect = true;
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
outstream = request.GetRequestStream();
outstream.Write(data, 0, data.Length);
outstream.Close();
//發(fā)送請(qǐng)求并獲取相應(yīng)回應(yīng)數(shù)據(jù)
response = request.GetResponse() as HttpWebResponse;
//直到request.GetResponse()程序才開始向目標(biāo)網(wǎng)頁發(fā)送Post請(qǐng)求
instream = response.GetResponseStream();
sr = new StreamReader(instream, encoding);
//返回結(jié)果網(wǎng)頁(html)代碼
string content = sr.ReadToEnd();
string err = string.Empty;
return content;
}
catch (Exception ex)
{
string err = ex.Message;
return string.Empty;
}
}
}
Modify the code of the remarks page:
protected void Page_Load(object sender, EventArgs e)
{
if(Request.QueryString["id"]!=null)
{
String openid = Request.QueryString["id"].ToString();
this.txtOpenId.Value = openid.ToString();
//根據(jù)OpenID獲取用戶基本信息。緩存處理
WeiXinServer wxs = new WeiXinServer();
///從緩存讀取accesstoken
string Access_token = Cache["Access_token"] as string;
if (Access_token == null)
{
//如果為空,重新獲取
Access_token = wxs.GetAccessToken();
//設(shè)置緩存的數(shù)據(jù)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 = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=" + Access_tokento + "&openid=" + openid;
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(jsonres);
myRequest.Method = "GET";
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
string content = reader.ReadToEnd();
reader.Close();
//使用前需要引用Newtonsoft.json.dll文件
JObject jsonObj = JObject.Parse(content);
//假如備注名不為空,給備注名文本框賦值,顯示原有的備注名
if (!String.IsNullOrWhiteSpace(jsonObj["remark"].ToString()))
{
this.txtRemarkName.Value = jsonObj["remark"].ToString();
}
}
}
/// <summary>
/// 設(shè)置備注名
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void LinkBtnSet_Click(object sender, EventArgs e)
{
String openid = Request.QueryString["id"].ToString();
WeiXinServer wxs = new WeiXinServer();
string res = "";
///從緩存讀取accesstoken
string Access_token = Cache["Access_token"] as string;
if (Access_token == null)
{
//如果為空,重新獲取
Access_token = wxs.GetAccessToken();
//設(shè)置緩存的數(shù)據(jù)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/user/info/updateremark?access_token=" + Access_tokento;
string postData = "{\"openid\":\"" + openid.ToString().Trim() + "\",\"remark\":\"" + this.txtRemarkName.Value.ToString() + "\"}";
res = wxs.GetPage(posturl, postData);
//使用前需藥引用Newtonsoft.json.dll文件
JObject jsonObj = JObject.Parse(res);
///獲取返回結(jié)果的正確|true|false,
string isright = jsonObj["errcode"].ToString();//0
string istrueorfalse = jsonObj["errmsg"].ToString();//ok
if (isright.Equals("0") && istrueorfalse.Equals("ok"))
{
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('修改備注成功!');location='WeiXinUserList.aspx';", true);
}
else
{
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('修改備注失敗!');", true);
}
}
The above is the detailed content of Detailed explanation of following user management steps in asp.net WeChat development. For more information, please follow other related articles on the PHP Chinese website!
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP WeChat development: How to implement message encryption and decryption
May 13, 2023 am 11:40 AM
PHP is an open source scripting language that is widely used in web development and server-side programming, especially in WeChat development. Today, more and more companies and developers are starting to use PHP for WeChat development because it has become a truly easy-to-learn and easy-to-use development language. In WeChat development, message encryption and decryption are a very important issue because they involve data security. For messages without encryption and decryption methods, hackers can easily obtain the data, posing a threat to users.
PHP WeChat development: How to implement voting function
May 14, 2023 am 11:21 AM
In the development of WeChat public accounts, the voting function is often used. The voting function is a great way for users to quickly participate in interactions, and it is also an important tool for holding events and surveying opinions. This article will introduce you how to use PHP to implement WeChat voting function. Obtain the authorization of the WeChat official account. First, you need to obtain the authorization of the WeChat official account. On the WeChat public platform, you need to configure the API address of the WeChat public account, the official account, and the token corresponding to the public account. In the process of our development using PHP language, we need to use the PH officially provided by WeChat
Using PHP to develop WeChat mass messaging tools
May 13, 2023 pm 05:00 PM
With the popularity of WeChat, more and more companies are beginning to use it as a marketing tool. The WeChat group messaging function is one of the important means for enterprises to conduct WeChat marketing. However, if you only rely on manual sending, it is an extremely time-consuming and laborious task for marketers. Therefore, it is particularly important to develop a WeChat mass messaging tool. This article will introduce how to use PHP to develop WeChat mass messaging tools. 1. Preparation work To develop WeChat mass messaging tools, we need to master the following technical points: Basic knowledge of PHP WeChat public platform development Development tools: Sub
PHP WeChat development: How to implement customer service chat window management
May 13, 2023 pm 05:51 PM
WeChat is currently one of the social platforms with the largest user base in the world. With the popularity of mobile Internet, more and more companies are beginning to realize the importance of WeChat marketing. When conducting WeChat marketing, customer service is a crucial part. In order to better manage the customer service chat window, we can use PHP language for WeChat development. 1. Introduction to PHP WeChat development PHP is an open source server-side scripting language that is widely used in the field of Web development. Combined with the development interface provided by WeChat public platform, we can use PHP language to conduct WeChat
PHP WeChat development: How to implement user tag management
May 13, 2023 pm 04:31 PM
In the development of WeChat public accounts, user tag management is a very important function, which allows developers to better understand and manage their users. This article will introduce how to use PHP to implement the WeChat user tag management function. 1. Obtain the openid of the WeChat user. Before using the WeChat user tag management function, we first need to obtain the user's openid. In the development of WeChat public accounts, it is a common practice to obtain openid through user authorization. After the user authorization is completed, we can obtain the user through the following code
PHP WeChat development: How to implement group message sending records
May 13, 2023 pm 04:31 PM
As WeChat becomes an increasingly important communication tool in people's lives, its agile messaging function is quickly favored by a large number of enterprises and individuals. For enterprises, developing WeChat into a marketing platform has become a trend, and the importance of WeChat development has gradually become more prominent. Among them, the group sending function is even more widely used. So, as a PHP programmer, how to implement group message sending records? The following will give you a brief introduction. 1. Understand the development knowledge related to WeChat public accounts. Before understanding how to implement group message sending records, I
Steps to implement WeChat public account development using PHP
Jun 27, 2023 pm 12:26 PM
How to use PHP to develop WeChat public accounts WeChat public accounts have become an important channel for promotion and interaction for many companies, and PHP, as a commonly used Web language, can also be used to develop WeChat public accounts. This article will introduce the specific steps to use PHP to develop WeChat public accounts. Step 1: Obtain the developer account of the WeChat official account. Before starting the development of the WeChat official account, you need to apply for a developer account of the WeChat official account. For the specific registration process, please refer to the official website of WeChat public platform
How to use PHP for WeChat development?
May 21, 2023 am 08:37 AM
With the development of the Internet and mobile smart devices, WeChat has become an indispensable part of the social and marketing fields. In this increasingly digital era, how to use PHP for WeChat development has become the focus of many developers. This article mainly introduces the relevant knowledge points on how to use PHP for WeChat development, as well as some of the tips and precautions. 1. Development environment preparation Before developing WeChat, you first need to prepare the corresponding development environment. Specifically, you need to install the PHP operating environment and the WeChat public platform
See all articles