Class: WeixinAuthorize::Client
- Inherits:
-
Object
- Object
- WeixinAuthorize::Client
- Includes:
- Api::Custom, Api::Groups, Api::Menu, Api::User
- Defined in:
- lib/weixin_authorize/client.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#app_id ⇒ Object
Time.now + expires_in.
-
#app_secret ⇒ Object
Time.now + expires_in.
-
#expired_at ⇒ Object
Time.now + expires_in.
Instance Method Summary collapse
-
#authenticate ⇒ Object
authenticate access_token.
-
#get_access_token ⇒ Object
return token.
-
#initialize(app_id = "", app_secret = "", expired_at = nil) {|_self| ... } ⇒ Client
constructor
A new instance of Client.
Methods included from Api::Groups
#create_group, #get_group_for, #groups, #update_group_for_openid, #update_group_name
Methods included from Api::Custom
#send_image_custom, #send_music_custom, #send_news_custom, #send_text_custom, #send_video_custom, #send_voice_custom
Methods included from Api::Menu
#create_menu, #delete_menu, #menu
Methods included from Api::User
Constructor Details
#initialize(app_id = "", app_secret = "", expired_at = nil) {|_self| ... } ⇒ Client
Returns a new instance of Client.
14 15 16 17 18 19 |
# File 'lib/weixin_authorize/client.rb', line 14 def initialize(app_id="", app_secret="", expired_at=nil) @app_id = app_id @app_secret = app_secret @expired_at = (expired_at.to_i || Time.now.to_i) yield self if block_given? end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
12 13 14 |
# File 'lib/weixin_authorize/client.rb', line 12 def access_token @access_token end |
#app_id ⇒ Object
Time.now + expires_in
11 12 13 |
# File 'lib/weixin_authorize/client.rb', line 11 def app_id @app_id end |
#app_secret ⇒ Object
Time.now + expires_in
11 12 13 |
# File 'lib/weixin_authorize/client.rb', line 11 def app_secret @app_secret end |
#expired_at ⇒ Object
Time.now + expires_in
11 12 13 |
# File 'lib/weixin_authorize/client.rb', line 11 def expired_at @expired_at end |
Instance Method Details
#authenticate ⇒ Object
authenticate access_token
31 32 33 34 35 |
# File 'lib/weixin_authorize/client.rb', line 31 def authenticate hash_infos = JSON.parse(RestClient.get(authenticate_url)) self.access_token = hash_infos["access_token"] self.expired_at = Time.now.to_i + hash_infos["expires_in"] end |
#get_access_token ⇒ Object
return token
22 23 24 25 26 27 28 |
# File 'lib/weixin_authorize/client.rb', line 22 def get_access_token # 如果当前token过期时间小于现在的时间,则重新获取一次 if @expired_at <= Time.now.to_i authenticate end @access_token end |