Commit 29f216fc by lanrion

refactor user.rb with "http_get" and "http_post" method

parent 45a505f9
...@@ -7,21 +7,21 @@ module WeixinAuthorize ...@@ -7,21 +7,21 @@ module WeixinAuthorize
# https://api.weixin.qq.com/cgi-bin/user/info?access_token=ACCESS_TOKEN&openid=OPENID&lang=zh_CN # https://api.weixin.qq.com/cgi-bin/user/info?access_token=ACCESS_TOKEN&openid=OPENID&lang=zh_CN
# lang: zh_CN, zh_TW, en # lang: zh_CN, zh_TW, en
def user(openid, lang="zh_CN") def user(openid, lang="zh_CN")
user_info_url = "#{user_base_url}/info?#{access_token_param}&openid=#{openid}&lang=#{lang}" user_info_url = "#{user_base_url}/info"
JSON.parse(RestClient.get(user_info_url)) http_get(user_info_url, {openid: openid, lang: lang})
end end
# https://api.weixin.qq.com/cgi-bin/user/get?access_token=ACCESS_TOKEN&next_openid=NEXT_OPENID # https://api.weixin.qq.com/cgi-bin/user/get?access_token=ACCESS_TOKEN&next_openid=NEXT_OPENID
# 获取关注者列表 # 获取关注者列表
def followers(next_openid=nil) def followers(next_openid=nil)
users_url = "#{user_base_url}/get?#{access_token_param}&next_openid#{next_openid}" followers_url = "#{user_base_url}/get"
JSON.parse(RestClient.get(users_url)) http_get(followers_url, {next_openid: next_openid})
end end
private private
def user_base_url def user_base_url
"#{endpoint}/user" "/user"
end end
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