Class: ThirdPartyWxa::Plugin
- Inherits:
-
Object
- Object
- ThirdPartyWxa::Plugin
- Includes:
- Api::Authorize, Api::Code, Api::Login, Api::Member, Api::Qrcode, Api::Server, Api::Template
- Defined in:
- lib/third_party_wxa/plugin.rb
Instance Attribute Summary collapse
-
#appid ⇒ Object
Returns the value of attribute appid.
-
#appsecret ⇒ Object
Returns the value of attribute appsecret.
-
#component_access_token ⇒ Object
2小时.
-
#component_expire_at ⇒ Object
2小时.
-
#component_verify_ticket ⇒ Object
Returns the value of attribute component_verify_ticket.
-
#pre_auth_code ⇒ Object
10分钟.
-
#pre_expire_at ⇒ Object
10分钟.
-
#redis_key ⇒ Object
Returns the value of attribute redis_key.
-
#ticket_expire_at ⇒ Object
Returns the value of attribute ticket_expire_at.
-
#token_store ⇒ Object
Returns the value of attribute token_store.
Instance Method Summary collapse
- #get_authorizer_access_token(options = {}) ⇒ Object
- #get_component_access_token ⇒ Object
- #get_pre_auth_code ⇒ Object
- #http_get(scope, url, url_params = {}) ⇒ Object
- #http_get_with_token(options, scope, url, url_params = {}) ⇒ Object
- #http_post(scope, url, post_params = {}, url_params = {}) ⇒ Object
- #http_post_with_token(options, scope, url, post_params = {}, url_params = {}) ⇒ Object
-
#initialize(ticket = nil) ⇒ Plugin
constructor
A new instance of Plugin.
- #pre_auth_code_valid? ⇒ Boolean
- #refresh_authorizer_access_token(options = {}) ⇒ Object
- #set_pre_auth_code ⇒ Object
- #set_tickect(ticket, expire_in) ⇒ Object
- #token_store_init ⇒ Object
Methods included from Api::Template
#add_to_template, #delete_template, #get_template_draft_list, #get_template_list
Methods included from Api::Server
#modify_domain, #setwebviewdomain
Methods included from Api::Qrcode
Methods included from Api::Member
#bind_tester, #get_experiencer, #unbind_tester
Methods included from Api::Login
Methods included from Api::Code
#change_visitstatus, #commit, #get_auditstatus, #get_category, #get_latest_auditstatus, #get_page, #get_qrcode, #release, #revertcoderelease, #submit_audit
Methods included from Api::Authorize
#authorizer_access_token_api, #authorizer_access_token_fresh, #bindcomponent, #component_access_token_api, #componentloginpage_url, #pre_auth_code_api
Constructor Details
#initialize(ticket = nil) ⇒ Plugin
Returns a new instance of Plugin.
18 19 20 21 22 23 24 25 |
# File 'lib/third_party_wxa/plugin.rb', line 18 def initialize ticket = nil @appid = ThirdPartyWxa.appid @appsecret = ThirdPartyWxa.appsecret @component_verify_ticket = ticket @token_store = token_store_init @redis_key = ThirdPartyWxa.redis_key || 'third_party_wxa_component_token' p "third party wxa use #{@token_store.class.to_s}" end |
Instance Attribute Details
#appid ⇒ Object
Returns the value of attribute appid.
12 13 14 |
# File 'lib/third_party_wxa/plugin.rb', line 12 def appid @appid end |
#appsecret ⇒ Object
Returns the value of attribute appsecret.
12 13 14 |
# File 'lib/third_party_wxa/plugin.rb', line 12 def appsecret @appsecret end |
#component_access_token ⇒ Object
2小时
14 15 16 |
# File 'lib/third_party_wxa/plugin.rb', line 14 def component_access_token @component_access_token end |
#component_expire_at ⇒ Object
2小时
14 15 16 |
# File 'lib/third_party_wxa/plugin.rb', line 14 def component_expire_at @component_expire_at end |
#component_verify_ticket ⇒ Object
Returns the value of attribute component_verify_ticket.
13 14 15 |
# File 'lib/third_party_wxa/plugin.rb', line 13 def component_verify_ticket @component_verify_ticket end |
#pre_auth_code ⇒ Object
10分钟
15 16 17 |
# File 'lib/third_party_wxa/plugin.rb', line 15 def pre_auth_code @pre_auth_code end |
#pre_expire_at ⇒ Object
10分钟
15 16 17 |
# File 'lib/third_party_wxa/plugin.rb', line 15 def pre_expire_at @pre_expire_at end |
#redis_key ⇒ Object
Returns the value of attribute redis_key.
16 17 18 |
# File 'lib/third_party_wxa/plugin.rb', line 16 def redis_key @redis_key end |
#ticket_expire_at ⇒ Object
Returns the value of attribute ticket_expire_at.
13 14 15 |
# File 'lib/third_party_wxa/plugin.rb', line 13 def ticket_expire_at @ticket_expire_at end |
#token_store ⇒ Object
Returns the value of attribute token_store.
16 17 18 |
# File 'lib/third_party_wxa/plugin.rb', line 16 def token_store @token_store end |
Instance Method Details
#get_authorizer_access_token(options = {}) ⇒ Object
62 63 64 |
# File 'lib/third_party_wxa/plugin.rb', line 62 def ={} .delete(:code) end |
#get_component_access_token ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/third_party_wxa/plugin.rb', line 33 def get_component_access_token m = Mutex.new m.synchronize{ token_store.set_token if !token_store.valid? token_store.get_token } end |
#get_pre_auth_code ⇒ Object
46 47 48 49 |
# File 'lib/third_party_wxa/plugin.rb', line 46 def get_pre_auth_code set_pre_auth_code if !pre_auth_code_valid? @pre_auth_code end |
#http_get(scope, url, url_params = {}) ⇒ Object
70 71 72 73 |
# File 'lib/third_party_wxa/plugin.rb', line 70 def http_get scope, url, url_params={} url_params.merge! token_params ThirdPartyWxa.http_get_without_component_access_token scope, url, url_params end |
#http_get_with_token(options, scope, url, url_params = {}) ⇒ Object
80 81 82 83 |
# File 'lib/third_party_wxa/plugin.rb', line 80 def http_get_with_token , scope, url, url_params={} url_params.merge! auth_token_params() ThirdPartyWxa.http_get_without_component_access_token scope, url, url_params end |
#http_post(scope, url, post_params = {}, url_params = {}) ⇒ Object
75 76 77 78 |
# File 'lib/third_party_wxa/plugin.rb', line 75 def http_post scope, url, post_params={}, url_params={} url_params.merge! token_params ThirdPartyWxa.http_post_without_component_access_token scope, url, post_params, url_params end |
#http_post_with_token(options, scope, url, post_params = {}, url_params = {}) ⇒ Object
85 86 87 88 |
# File 'lib/third_party_wxa/plugin.rb', line 85 def http_post_with_token , scope, url, post_params={}, url_params={} url_params.merge! auth_token_params() ThirdPartyWxa.http_post_without_component_access_token scope, url, post_params, url_params end |
#pre_auth_code_valid? ⇒ Boolean
41 42 43 44 |
# File 'lib/third_party_wxa/plugin.rb', line 41 def pre_auth_code_valid? return false if @pre_auth_code.nil? || @pre_expire_at.nil? Time.now.to_i <= @pre_expire_at end |
#refresh_authorizer_access_token(options = {}) ⇒ Object
66 67 68 |
# File 'lib/third_party_wxa/plugin.rb', line 66 def ={} .delete(:appid), .delete(:refresh_token) end |
#set_pre_auth_code ⇒ Object
51 52 53 54 55 56 |
# File 'lib/third_party_wxa/plugin.rb', line 51 def set_pre_auth_code res = pre_auth_code_api @pre_auth_code = res['pre_auth_code'] @pre_expire_at = ThirdPartyWxa.cal_expire_at res['expires_in']#, 60 self end |
#set_tickect(ticket, expire_in) ⇒ Object
27 28 29 30 31 |
# File 'lib/third_party_wxa/plugin.rb', line 27 def set_tickect ticket, expire_in @component_verify_ticket = ticket @ticket_expire_at = ThirdPartyWxa.cal_expire_at expire_in self end |