Beispiel #1
0
///	获取用户列表并报错到redis数据库中 KEY=wx_UserList
func GetUserList() {
	url := "https://api.weixin.qq.com/cgi-bin/user/get?access_token=" + GetAccessToken()
	key := "wx_UserList"
	var v WXUserList
	c, status := global.HttpGet(url)
	if status >= 0 {
		dec := json.NewDecoder(strings.NewReader(c))
		for {
			if err := dec.Decode(&v); err == io.EOF {
				break
			} else if err != nil {
				log.Fatal(err)
			}
		}

		var redcli redis.Client
		redcli.Addr = beego.AppConfig.String("redis_addr")

		if ok, err := redcli.Exists(key); err != nil {
			log.Println(err.Error())
		} else {
			if ok {
				redcli.Del(key)
			}
		}
		for _, value := range v.Data.Openid {
			redcli.Rpush(key, []byte(value))
		}
		log.Println("Successful: Add Userlist ")
	}
}