.NET微信公众号 用户分组管理(4)

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Edit.aspx.cs" Inherits="test.Edit" %> <html > <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>&nbsp;设&nbsp;置</div></asp:LinkButton></td> </tr> </table> </form> </body> </html>

Edit.aspx.cs代码:

public partial class Edit : System.Web.UI.Page { 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.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\":{\"id\":\"" + txtGroupId.Text + "\",\"name\":\"" + this.txtGroupName.Text + "\"}}"; res = wxs.GetPage(posturl, postData); //使用Newtonsoft.json 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.open![这里写图片描述]()er.location.reload();this.close();", true); } else { ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('修改失败!');this.close();", true); } } }

buttonbg.png

.NET微信公众号 用户分组管理

结果如图:

.NET微信公众号 用户分组管理

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

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