Ejemplo n.º 1
0
        /// <summary>
        /// 获取所有订阅者的OpenId
        /// </summary>
        /// <param name="accessToken"></param>
        /// <returns></returns>
        public static async Task <List <string> > GetAllOpenIds(string accessToken)
        {
            List <string> openids = new List <string>();

            string nextOpenId = "";

            do
            {
                UserGetJson followerResult = await UserApi.Get(accessToken, nextOpenId);

                int count = followerResult.count;
                if (count > 0)
                {
                    openids.AddRange(followerResult.data.openid);
                }
                nextOpenId = followerResult.next_openid;
            } while (!string.IsNullOrEmpty(nextOpenId));

            return(openids);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取所有订阅者的资料
        /// </summary>
        /// <param name="accessToken"></param>
        /// <returns></returns>
        public static async Task <List <UserInfoJson> > GetAllUserInfo(string accessToken)
        {
            List <UserInfoJson> subscribers = new List <UserInfoJson>();

            List <string> openids = await GetAllOpenIds(accessToken);

            foreach (string openid in openids)
            {
                try
                {
                    UserInfoJson userInfo = await UserApi.Info(accessToken, openid);

                    if (userInfo != null)
                    {
                        subscribers.Add(userInfo);
                    }
                }
                catch { }
            }

            return(subscribers);
        }