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, account = nil, &block)
self.class.corpid || self.class.appid || self.class.wechat
api = wechat(account)
if account
config = Wechat.config(account)
appid = config.corpid || config.appid
is_crop_account = !!config.corpid
else
appid = self.class.corpid || self.class.appid
is_crop_account = !!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(account),
scope: scope,
response_type: 'code',
state: api.jsapi_ticket.oauth2_state
}
return generate_oauth2_url(oauth2_params) unless block_given?
is_crop_account ? wechat_corp_oauth2(oauth2_params, account, &block) : wechat_public_oauth2(oauth2_params, account, &block)
end
|