7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/wechat/api_loader.rb', line 7
def self.with(options)
account = options[:account] || :default
c = ApiLoader.config(account)
token_file = options[:token_file] || c.access_token.presence || '/var/tmp/wechat_access_token'
js_token_file = options[:js_token_file] || c.jsapi_ticket.presence || '/var/tmp/wechat_jsapi_ticket'
type = options[:type] || c.type
if c.appid && c.secret && token_file.present?
if type == 'mp'
qcloud_env = options[:qcloud_env] || c.qcloud_env
qcloud_token_file = options[:qcloud_token_file] || c.qcloud_token_file.presence || '/var/tmp/qcloud_access_token'
qcloud_token_lifespan = options[:qcloud_token_lifespan] || c.qcloud_token_lifespan
Wechat::MpApi.new(c.appid, c.secret, token_file, c.timeout, c.skip_verify_ssl, js_token_file, qcloud_env, qcloud_token_file, qcloud_token_lifespan)
else
Wechat::Api.new(c.appid, c.secret, token_file, c.timeout, c.skip_verify_ssl, js_token_file)
end
elsif c.corpid && c.corpsecret && token_file.present?
Wechat::CorpApi.new(c.corpid, c.corpsecret, token_file, c.agentid, c.timeout, c.skip_verify_ssl, js_token_file)
else
raise 'Need create ~/.wechat.yml with wechat appid and secret or running at rails root folder so wechat can read config/wechat.yml'
end
end
|