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



12
13
14
15
# File 'lib/wechat/controller_api.rb', line 12

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



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
42
43
44
45
46
47
# File 'lib/wechat/controller_api.rb', line 17

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
    agentid = config.agentid
     = config.corpid.present?
  else
    appid = self.class.corpid || self.class.appid
    agentid = self.class.agentid
     = self.class.corpid.present?
  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
  }
  oauth2_params[:agentid] = agentid if 

  return generate_oauth2_url(oauth2_params) unless block_given?

   ? wechat_corp_oauth2(oauth2_params, , &block) : wechat_public_oauth2(oauth2_params, , &block)
end