예제 #1
0
        /// <summary>
        /// 获取关注者OpenID集合
        /// </summary>
        public static List <string> GetOpenIDs(string access_token, string next_openid)
        {
            // 设置参数
            string url       = string.Format("https://api.weixin.qq.com/cgi-bin/user/get?access_token={0}&next_openid={1}", access_token, next_openid);
            string returnStr = CommonMethod.RequestUrl(url);
            int    count     = int.Parse(CommonMethod.GetJsonValue(returnStr, "count"));

            if (count > 0)
            {
                string startFlg = "\"openid\":[";
                int    start    = returnStr.IndexOf(startFlg) + startFlg.Length;
                int    end      = returnStr.IndexOf("]", start);
                string openids  = returnStr.Substring(start, end - start).Replace("\"", "");
                return(openids.Split(',').ToList <string>());
            }
            else
            {
                return(new List <string>());
            }
        }
예제 #2
0
        /// <summary>
        /// 用openid换取用户信息
        /// </summary>
        /// <param name="openid">微信标识id</param>
        /// <returns></returns>
        public Dictionary <string, object> GetUserInfoForopenid(string Appid, string Appsecret, string openid)
        {
            JavaScriptSerializer Jss = new JavaScriptSerializer();
            string access_token      = BasicApi.GetTokenSession(Appid, Appsecret); //获取access_token
            string url = string.Format("https://api.weixin.qq.com/cgi-bin/user/info?access_token={0}&openid={1}&lang=zh_CN", access_token, openid);
            Dictionary <string, object> respDic = (Dictionary <string, object>)Jss.DeserializeObject(CommonMethod.WebRequestPostOrGet(url, ""));

            return(respDic);
        }