Commit 2810c024 by lanrion

added User apis

parent b91ae9a5
require "rest-client"
require "weixin_authorize/version"
require "weixin_authorize/api/user"
require "weixin_authorize/client"
module WeixinAuthorize
......
# encoding: utf-8
module WeixinAuthorize
module Api
module User
# 获取用户基本信息
# https://api.weixin.qq.com/cgi-bin/user/info?access_token=ACCESS_TOKEN&openid=OPENID&lang=zh_CN
# lang: zh_CN, zh_TW, en
def user(openid, lang="zh_CN")
user_info_url = "#{user_base_url}/info?#{access_token_param}&openid=#{openid}&lang=#{lang}"
JSON.parse(RestClient.get(user_info_url))
end
# https://api.weixin.qq.com/cgi-bin/user/get?access_token=ACCESS_TOKEN&next_openid=NEXT_OPENID
# 获取关注者列表
def users(next_openid=nil)
users_url = "#{user_base_url}/get?#{access_token_param}&next_openid#{next_openid}"
JSON.parse(RestClient.get(users_url))
end
private
def user_base_url
"#{endpoint}/user"
end
end
end
end
......@@ -4,6 +4,7 @@ module WeixinAuthorize
class Client
attr_accessor :app_id, :app_secret, :expired_at # Time.now + expires_in
include Api::User
attr_accessor :access_token
......
require "spec_helper"
describe WeixinAuthorize::Api::User do
it "can get a weixin User info" do
user_info = $client.user(ENV["OPENID"])
puts user_info
end
it "can get followers infos" do
followers = $client.users
puts followers
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment