This commit is contained in:
parent
c9d32ca69b
commit
817fdad21d
|
@ -132,11 +132,11 @@ module Wechat
|
|||
grant_type: 'refresh_token',
|
||||
refresh_token: user_refresh_token
|
||||
}
|
||||
get 'oauth2/refresh_token', params: params, base: OAUTH2_BASE
|
||||
get 'refresh_token', params: params, base: OAUTH2_BASE
|
||||
end
|
||||
|
||||
def web_userinfo(web_access_token, openid, lang = 'zh_CN')
|
||||
get 'userinfo', params: { access_token: web_access_token, openid: openid, lang: lang }, base: OAUTH2_BASE
|
||||
get 'userinfo', params: { access_token: web_access_token, openid: openid, lang: lang }, base: OAUTH2_USERINFO
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -2,31 +2,19 @@ require 'wechat/token/access_token_base'
|
|||
|
||||
module Wechat
|
||||
module Token
|
||||
class AuthAccessToken
|
||||
class AuthAccessToken < AccessTokenBase
|
||||
|
||||
def refresh
|
||||
data = client.get('token', params: { grant_type: 'client_credential', appid: appid, secret: secret })
|
||||
write_token_to_file(data)
|
||||
read_token_from_file
|
||||
end
|
||||
# def refresh
|
||||
# params = {
|
||||
# appid: access_token.appid,
|
||||
# grant_type: 'refresh_token',
|
||||
# refresh_token: user_refresh_token
|
||||
# }
|
||||
# data = client.get 'oauth2/refresh_token', params: params, base: OAUTH2_BASE
|
||||
# write_token_to_file(data)
|
||||
# read_token_from_file
|
||||
# end
|
||||
|
||||
def read_token_from_file
|
||||
td = JSON.parse(CacheFile.read(token_file))
|
||||
@got_token_at = td.fetch('got_token_at').to_i
|
||||
@token_life_in_seconds = td.fetch('expires_in').to_i
|
||||
@access_token = td.fetch('access_token')
|
||||
rescue JSON::ParserError, Errno::ENOENT, KeyError
|
||||
refresh
|
||||
end
|
||||
|
||||
def write_token_to_file(token_hash)
|
||||
token_hash.merge!('got_token_at'.freeze => Time.now.to_i)
|
||||
CacheFile.write(token_file, token_hash.to_json)
|
||||
end
|
||||
|
||||
def remain_life_seconds
|
||||
token_life_in_seconds - (Time.now.to_i - got_token_at)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue