<!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> <style type="text/css"> .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; } </style> </head> <body> <form runat="server"> <table> <tr> <td>分组编号:</td> <td> <asp:TextBox CssClass="inputstyle" Enabled="false" runat="server"></asp:TextBox></td> </tr> <tr> <td>分组名称:</td> <td> <asp:TextBox CssClass="inputstyle" runat="server"></asp:TextBox> </td> </tr> <tr> <td></td> <td> <asp:LinkButton runat="server" ><div> 设 置</div></asp:LinkButton></td> </tr> </table> </form> </body> </html>
后台代码:
protected void Page_Load(object sender, EventArgs e) { if(!Page.IsPostBack) { if (Request.QueryString["id"] != null) { string group_id = Request.QueryString["id"].ToString(); string group_name = Request.QueryString["name"].ToString(); this.txtGroupId.Text = group_id.ToString(); this.txtGroupName.Text = group_name.ToString(); this.txtGroupName.Focus(); } } } /// <summary> /// 设置 /// </summary> /// <param></param> /// <param></param> protected void LinkBtnSet_Click(object sender, EventArgs e) { if(String.IsNullOrWhiteSpace(this.txtGroupName.Text.ToString().Trim())) { ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('不能为空!');", true); this.txtGroupName.Focus(); return; } if (this.txtGroupName.Text.ToString().Trim().Length>30) { ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('组名称应在30个字符之内!');", true); this.txtGroupName.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(); //设置缓存的数据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/update?access_token=" + Access_tokento; //POST数据例子:POST数据例子:{"group":{"id":108,"name":"test2_modify2"}} //string postData = "{\"group\":{\"name\":\"" + this.txtgroupsName.Value.ToString().Trim() + "\"}}"; string postData = "{\"group\":{\"id\":\"" + txtGroupId.Text.ToString() +"\",\"name\":\""+this.txtGroupName.Text.ToString()+"\"}}"; res = wxs.GetPage(posturl, postData); //使用前需药引用Newtonsoft.json.dll文件 JObject jsonObj = JObject.Parse(res); ///获取返回结果的正确|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('修改成功!如未正常显示,属缓存问题,请重新登录即可!');window.opener.location.reload();this.close();", true); } else { ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('修改失败!');this.close();", true); } }
本文已被整理到了《ASP.NET微信开发教程汇总》,欢迎大家学习阅读。
以上就是用户分组管理的全部核心代码,仅供参考,希望对大家的学习有所帮助。
您可能感兴趣的文章: