Class: ThirdPartyWxa::Plugin

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#get_wxa_code

Methods included from Api::Member

#bind_tester, #get_experiencer, #unbind_tester

Methods included from Api::Login

#jscode2session

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

#appidObject

Returns the value of attribute appid.



12
13
14
# File 'lib/third_party_wxa/plugin.rb', line 12

def appid
  @appid
end

#appsecretObject

Returns the value of attribute appsecret.



12
13
14
# File 'lib/third_party_wxa/plugin.rb', line 12

def appsecret
  @appsecret
end

#component_access_tokenObject

2小时



14
15
16
# File 'lib/third_party_wxa/plugin.rb', line 14

def component_access_token
  @component_access_token
end

#component_expire_atObject

2小时



14
15
16
# File 'lib/third_party_wxa/plugin.rb', line 14

def component_expire_at
  @component_expire_at
end

#component_verify_ticketObject

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_codeObject

10分钟



15
16
17
# File 'lib/third_party_wxa/plugin.rb', line 15

def pre_auth_code
  @pre_auth_code
end

#pre_expire_atObject

10分钟



15
16
17
# File 'lib/third_party_wxa/plugin.rb', line 15

def pre_expire_at
  @pre_expire_at
end

#redis_keyObject

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_atObject

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_storeObject

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 get_authorizer_access_token options={}
	authorizer_access_token_api options.delete(:code)
end

#get_component_access_tokenObject



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_codeObject



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 options, scope, url, url_params={}
	url_params.merge! auth_token_params(options)
	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 options, scope, url, post_params={}, url_params={}
	url_params.merge! auth_token_params(options)
	ThirdPartyWxa.http_post_without_component_access_token scope, url, post_params, url_params
end

#pre_auth_code_valid?Boolean

Returns:

  • (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 refresh_authorizer_access_token options={}
	authorizer_access_token_fresh options.delete(:appid), options.delete(:refresh_token)
end

#set_pre_auth_codeObject



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

#token_store_initObject



58
59
60
# File 'lib/third_party_wxa/plugin.rb', line 58

def token_store_init
	Token::Store.init_with(self)
end