module WeixinAuthorize::Api::Oauth
Public Instance Methods
get_oauth_access_token(code)
click to toggle source
微信通过请求 authorize_url
方法后,会返回一个code到redirect_uri中
# File lib/weixin_authorize/api/oauth.rb, line 28 def get_oauth_access_token(code) WeixinAuthorize.http_get_without_token("/sns/oauth2/access_token?appid=#{app_id}&secret=#{app_secret}&code=#{code}&grant_type=authorization_code", {}, "api") end
get_oauth_userinfo(openid, oauth_token, lang="zh_CN")
click to toggle source
如果网页授权作用域为snsapi_userinfo,则此时开发者可以通过access_token和openid拉取用户信息了。
# File lib/weixin_authorize/api/oauth.rb, line 38 def get_oauth_userinfo(openid, oauth_token, lang="zh_CN") WeixinAuthorize.http_get_without_token("/sns/userinfo?access_token=#{oauth_token}&openid=#{openid}&lang=#{lang}", {}, "api") end
refresh_oauth2_token(refresh_token)
click to toggle source
refresh_token: 填写通过access_token获取到的refresh_token参数
# File lib/weixin_authorize/api/oauth.rb, line 33 def refresh_oauth2_token(refresh_token) WeixinAuthorize.http_get_without_token("/sns/oauth2/refresh_token?appid=#{app_id}&grant_type=refresh_token&refresh_token=#{refresh_token}", {}, "api") end
Private Instance Methods
encode_url(uri)
click to toggle source
# File lib/weixin_authorize/api/oauth.rb, line 44 def encode_url(uri) ERB::Util.url_encode(uri) end