Commit 7ea61e50 by lanrion

添加定制token

parent 0199112f
......@@ -15,24 +15,28 @@ module WeixinAuthorize
include Api::Template
attr_accessor :app_id, :app_secret, :expired_at # Time.now + expires_in
attr_accessor :access_token, :redis_key
attr_accessor :access_token, :redis_key, :custom_access_token
attr_accessor :jsticket, :jsticket_expired_at, :jsticket_redis_key
def initialize(app_id, app_secret, redis_key=nil)
# options: redis_key, custom_access_token
def initialize(app_id, app_secret, options={})
@app_id = app_id
@app_secret = app_secret
@jsticket_expired_at = @expired_at = Time.now.to_i
@redis_key = security_redis_key(redis_key || "weixin_#{app_id}")
@redis_key = security_redis_key(options[:redis_key] || "weixin_#{app_id}")
@jsticket_redis_key = security_redis_key("js_sdk_#{app_id}")
@custom_access_token = options[:custom_access_token]
end
# return token
def get_access_token
return custom_access_token if !custom_access_token.nil?
token_store.access_token
end
# 检查appid和app_secret是否有效。
def is_valid?
return true if !custom_access_token.nil?
token_store.valid?
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