Module: Wechat::ControllerApi

Extended by:
ActiveSupport::Concern
Included in:
Responder
Defined in:
lib/wechat/controller_api.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#wechat(account = nil) ⇒ Object



10
11
12
13
# File 'lib/wechat/controller_api.rb', line 10

def wechat( = nil)
  # Make sure user can continue access wechat at instance level similar to class level
  self.class.wechat()
end

#wechat_oauth2(scope = 'snsapi_base', page_url = nil, account = nil, &block) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/wechat/controller_api.rb', line 15

def wechat_oauth2(scope = 'snsapi_base', page_url = nil,  = nil, &block)
  # ensure wechat initialization
  self.class.corpid || self.class.appid || self.class.wechat

  api = wechat()
  if 
    config = Wechat.config()
    appid = config.corpid || config.appid
     = !!config.corpid
  else
    appid = self.class.corpid || self.class.appid
     = !!self.class.corpid
  end

  raise 'Can not get corpid or appid, so please configure it first to using wechat_oauth2' if appid.blank?

  oauth2_params = {
    appid: appid,
    redirect_uri: page_url || generate_redirect_uri(),
    scope: scope,
    response_type: 'code',
    state: api.jsapi_ticket.oauth2_state
  }

  return generate_oauth2_url(oauth2_params) unless block_given?
   ? wechat_corp_oauth2(oauth2_params, , &block) : wechat_public_oauth2(oauth2_params, , &block)
end