热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

asp.net微信开发用户分组管理的示例代码

这篇文章主要介绍了asp.net微信开发中有关用户分组管理的相关内容,需要的朋友可以参考下
这篇文章主要介绍了asp.net微信开发中有关用户分组管理的相关内容,需要的朋友可以参考下

上一篇已讲解到新建用户分组,移动用户到分组的功能,这一章主要讲解修改分组名称和删除分组

 /// 
 /// 微信分组类
 /// 
 public class WxGroupsInfo
 {
  public string Group_ID { get; set; }//分组编号
  public string Group_Name { get; set; }//分组名称
  public string Group_Count { get; set; }//分组人数
 }

前台代码:





  
  
 
  
  


 
  

位置:

  • 首页
  • 微信管理
  • 德桥员工服务中心----分组管理

分组管理

新建分组关闭

30字符以内

确定创建

'>
序号 ID编号 分组名称 分组人数 操作
<%# Eval("Group_ID") %> <%# Eval("Group_Name") %> <%# Eval("Group_Count") %> &#39;,&#39;<%# Eval("Group_Name") %>&#39;);">修改分组名称 &#39; >删除分组

┼ 新建分组

后台代码如下:

protected void Page_Load(object sender, EventArgs e)
  {
   if(!Page.IsPostBack)
   {
    BindGroupList();
    this.DataBind();
   }
  }

  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();


   List wxgrouplist = new List();
   
   for (int i = 0; i 
  /// 绑定事件
  /// 
  /// 
  /// 
  protected void RepeaterGroupList_ItemDataBound(object sender, RepeaterItemEventArgs e)
  {
   if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem)
   {
    Label lbXuHao = e.Item.FindControl("lbXuHao") as Label;

    int num = 1;

    lbXuHao.Text = num.ToString();

    for (int i = 0; i 
  /// 执行事件
  /// 
  /// 
  /// 
  protected void RepeaterGroupList_ItemCommand(object source, RepeaterCommandEventArgs e)
  {

   //ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert(&#39;删除接口已关闭!&#39;);location=&#39;WxGroupManageList.aspx&#39;;", true);
   if (e.CommandName == "DeleteGroups")
   {
    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/delete?access_token=" + Access_tokento;


    //POST数据例子: POST数据例子:{"group":{"id":108}}

    string groupid = e.CommandArgument.ToString();

    string postData = "{\"group\":{\"id\":\"" + groupid.ToString() + "\"}}";

    res = wxs.GetPage(posturl, postData);

    ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert(&#39;删除成功!由于缓存问题,您可能需要重新登录才能看到效果!&#39;);location=&#39;WxGroupManageList.aspx&#39;;", true);
   }
  }
  /// 
  /// 创建分组
  /// 
  /// 
  /// 
  protected void LinkBtnCreateGroup_Click(object sender, EventArgs e)
  {
   if (this.txtgroupsName.Value.ToString().Equals("分组名称"))
   {
    ////
    ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert(&#39;不能为空!&#39;)", 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();

    //设置缓存的数据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() + "\"}}";


   res = wxs.GetPage(posturl, postData);


   ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert(&#39;创建成功!如未显示,请退出重新登录即可!&#39;);location=&#39;WxGroupManageList.aspx&#39;;", true);
  }

修改分组名称的页面





 
 


 
  
分组编号:
分组名称:

设 置

后台代码:

 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();
    }
   }
  }
  /// 
  /// 设置
  /// 
  /// 
  /// 
  protected void LinkBtnSet_Click(object sender, EventArgs e)
  {
   if(String.IsNullOrWhiteSpace(this.txtGroupName.Text.ToString().Trim()))
   {
    ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert(&#39;不能为空!&#39;);", true);
    this.txtGroupName.Focus();
    return;
   }
   if (this.txtGroupName.Text.ToString().Trim().Length>30)
   {
    ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert(&#39;组名称应在30个字符之内!&#39;);", 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(&#39;修改成功!如未正常显示,属缓存问题,请重新登录即可!&#39;);window.opener.location.reload();this.close();", true);
   }
   else
   {
    ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert(&#39;修改失败!&#39;);this.close();", true);
   }


  }

以上就是用户分组管理的全部核心代码,仅供参考,希望对大家的学习有所帮助。

以上就是asp.net微信开发用户分组管理的示例代码的详细内容,更多请关注php中文网其它相关文章!


推荐阅读
  • Java验证码——kaptcha的使用配置及样式
    本文介绍了如何使用kaptcha库来实现Java验证码的配置和样式设置,包括pom.xml的依赖配置和web.xml中servlet的配置。 ... [详细]
  • 本文介绍了前端人员必须知道的三个问题,即前端都做哪些事、前端都需要哪些技术,以及前端的发展阶段。初级阶段包括HTML、CSS、JavaScript和jQuery的基础知识。进阶阶段涵盖了面向对象编程、响应式设计、Ajax、HTML5等新兴技术。高级阶段包括架构基础、模块化开发、预编译和前沿规范等内容。此外,还介绍了一些后端服务,如Node.js。 ... [详细]
  • VScode格式化文档换行或不换行的设置方法
    本文介绍了在VScode中设置格式化文档换行或不换行的方法,包括使用插件和修改settings.json文件的内容。详细步骤为:找到settings.json文件,将其中的代码替换为指定的代码。 ... [详细]
  • 本文讨论了Alink回归预测的不完善问题,指出目前主要针对Python做案例,对其他语言支持不足。同时介绍了pom.xml文件的基本结构和使用方法,以及Maven的相关知识。最后,对Alink回归预测的未来发展提出了期待。 ... [详细]
  • 使用在线工具jsonschema2pojo根据json生成java对象
    本文介绍了使用在线工具jsonschema2pojo根据json生成java对象的方法。通过该工具,用户只需将json字符串复制到输入框中,即可自动将其转换成java对象。该工具还能解析列表式的json数据,并将嵌套在内层的对象也解析出来。本文以请求github的api为例,展示了使用该工具的步骤和效果。 ... [详细]
  • Ihavethefollowingonhtml我在html上有以下内容<html><head><scriptsrc..3003_Tes ... [详细]
  • 本文介绍了如何使用jQuery和AJAX来实现动态更新两个div的方法。通过调用PHP文件并返回JSON字符串,可以将不同的文本分别插入到两个div中,从而实现页面的动态更新。 ... [详细]
  • Android实战——jsoup实现网络爬虫,糗事百科项目的起步
    本文介绍了Android实战中使用jsoup实现网络爬虫的方法,以糗事百科项目为例。对于初学者来说,数据源的缺乏是做项目的最大烦恼之一。本文讲述了如何使用网络爬虫获取数据,并以糗事百科作为练手项目。同时,提到了使用jsoup需要结合前端基础知识,以及如果学过JS的话可以更轻松地使用该框架。 ... [详细]
  • 本文介绍了互联网思维中的三个段子,涵盖了餐饮行业、淘品牌和创业企业的案例。通过这些案例,探讨了互联网思维的九大分类和十九条法则。其中包括雕爷牛腩餐厅的成功经验,三只松鼠淘品牌的包装策略以及一家创业企业的销售额增长情况。这些案例展示了互联网思维在不同领域的应用和成功之道。 ... [详细]
  • 本文介绍了在满足特定条件时如何在输入字段中使用默认值的方法和相应的代码。当输入字段填充100或更多的金额时,使用50作为默认值;当输入字段填充有-20或更多(负数)时,使用-10作为默认值。文章还提供了相关的JavaScript和Jquery代码,用于动态地根据条件使用默认值。 ... [详细]
  • 本文介绍了Java后台Jsonp处理方法及其应用场景。首先解释了Jsonp是一个非官方的协议,它允许在服务器端通过Script tags返回至客户端,并通过javascript callback的形式实现跨域访问。然后介绍了JSON系统开发方法,它是一种面向数据结构的分析和设计方法,以活动为中心,将一连串的活动顺序组合成一个完整的工作进程。接着给出了一个客户端示例代码,使用了jQuery的ajax方法请求一个Jsonp数据。 ... [详细]
  • Jquery 跨域问题
    为什么80%的码农都做不了架构师?JQuery1.2后getJSON方法支持跨域读取json数据,原理是利用一个叫做jsonp的概念。当然 ... [详细]
  • 前言对于从事技术的人员来说ajax是这好东西,都会使用,而且乐于使用。但对于新手,开发一个ajax实例,还有是难度的,必竟对于他们这是新东西。leo开发一个简单的ajax实例,用的是 ... [详细]
  • 表单提交前的最后验证:通常在表单提交前,我们必须确认用户是否都把必须填选的做了,如果没有,就不能被提交到服务器,这里我们用到表单的formname.submit()看演示,其实这个对于我们修炼道 ... [详细]
  • Itwasworkingcorrectly,butyesterdayitstartedgiving401.IhavetriedwithGooglecontactsAPI ... [详细]
author-avatar
天晴的故事_665
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有