public bool GetUserList() { WeiXinSDK.Followers allFollower = new WeiXinSDK.Followers(); //第一步:获取所有关注者列表 allFollower = WeiXinSDK.WeiXin.GetAllFollowers(); if (allFollower.error == null) { int count = allFollower.data.openid.Count; //第二步:将关注者列表的用户数据更新回数据库 MZZ.BLL.tb_user userBLL = new MZZ.BLL.tb_user(); try { List<string> openids = new List<string>(); for (int i = 0; i < count; i++) { //获取用户数据 string openid = allFollower.data.openid[i]; openids.Add(openid); WeiXinSDK.UserInfo userinfo = WeiXinSDK.WeiXin.GetUserInfo(openid, WeiXinSDK.LangType.zh_CN); if (userinfo.error == null) { //添加或更新到用户表 InsertOrUpdateUsers(userinfo, null); } } var usersList = userBLL.GetModelList("user_status>0"); //更改用户状态为未关注 for (int i = 0; i < usersList.Count; i++) { if (!openids.Contains(usersList[i].user_openid)) { usersList[i].user_sub_scribe = false; userBLL.Update(usersList[i]); } } return true; } catch (Exception ex) { return false; } } else { return false; } }
/// <summary> /// 获取关注者列表 /// </summary> /// <param name="next_openid"></param> /// <param name="appId"></param> /// <param name="appSecret"></param> /// <returns></returns> public static Followers GetFollowers(string next_openid, string appId, string appSecret) { string url = "https://api.weixin.qq.com/cgi-bin/user/get?access_token="; string access_token = GetAccessToken(appId, appSecret); url = url + access_token; if (!string.IsNullOrEmpty(next_openid)) { url = url + "&next_openid=" + next_openid; } var json = Util.HttpGet2(url); if (json.IndexOf("errcode") > 0) { var fs = new Followers(); fs.error = Util.JsonTo <ReturnCode>(json); return(fs); } else { return(Util.JsonTo <Followers>(json)); } }