module ActionController::WechatResponder
Public Instance Methods
wechat(account = nil)
click to toggle source
# File lib/action_controller/wechat_responder.rb, line 20 def wechat(account = nil) if account && account != wechat_cfg_account Wechat.api(account) else self.wechat_api_client ||= load_controller_wechat(wechat_cfg_account) end end
wechat_api(opts = {})
click to toggle source
# File lib/action_controller/wechat_responder.rb, line 5 def wechat_api(opts = {}) include Wechat::ControllerApi account = opts.delete(:account) self.wechat_cfg_account = account ? account.to_sym : :default self.wechat_api_client = load_controller_wechat(wechat_cfg_account, opts) end
wechat_responder(opts = {})
click to toggle source
# File lib/action_controller/wechat_responder.rb, line 12 def wechat_responder(opts = {}) include Wechat::Responder account = opts.delete(:account) self.account_from_request = opts.delete(:account_from_request) self.wechat_cfg_account = account ? account.to_sym : :default self.wechat_api_client = load_controller_wechat(wechat_cfg_account, opts) end
Private Instance Methods
get_wechat_api(api_type, corpid, appid, secret, access_token, agentid, network_setting, jsapi_ticket, qcloud_setting)
click to toggle source
# File lib/action_controller/wechat_responder.rb, line 64 def get_wechat_api(api_type, corpid, appid, secret, access_token, agentid, network_setting, jsapi_ticket, qcloud_setting) if api_type && api_type.to_sym == :mp Wechat::MpApi.new(appid, secret, access_token, network_setting, jsapi_ticket, qcloud_setting) elsif corpid.present? Wechat::CorpApi.new(corpid, secret, access_token, agentid, network_setting, jsapi_ticket) else Wechat::Api.new(appid, secret, access_token, network_setting, jsapi_ticket) end end
load_controller_wechat(account, opts = {})
click to toggle source
# File lib/action_controller/wechat_responder.rb, line 30 def load_controller_wechat(account, opts = {}) cfg = Wechat.config(account) self.token = opts[:token] || cfg.token self.appid = opts[:appid] || cfg.appid self.corpid = opts[:corpid] || cfg.corpid self.agentid = opts[:agentid] || cfg.agentid self.encrypt_mode = opts[:encrypt_mode] || cfg.encrypt_mode || corpid.present? self.encoding_aes_key = opts[:encoding_aes_key] || cfg.encoding_aes_key self.trusted_domain_fullname = opts[:trusted_domain_fullname] || cfg.trusted_domain_fullname self.oauth2_cookie_duration = opts[:oauth2_cookie_duration] || cfg.oauth2_cookie_duration.to_i.seconds self.timeout = opts[:timeout] || cfg.timeout self.skip_verify_ssl = opts.key?(:skip_verify_ssl) ? opts[:skip_verify_ssl] : cfg.skip_verify_ssl proxy_url = opts.key?(:proxy_url) ? opts[:proxy_url] : cfg.proxy_url proxy_port = opts.key?(:proxy_port) ? opts[:proxy_port] : cfg.proxy_port proxy_username = opts.key?(:proxy_username) ? opts[:proxy_username] : cfg.proxy_username proxy_password = opts.key?(:proxy_password) ? opts[:proxy_password] : cfg.proxy_password return Wechat.api if account == :default && opts.empty? access_token = opts[:access_token] || cfg.access_token jsapi_ticket = opts[:jsapi_ticket] || cfg.jsapi_ticket qcloud_env = opts[:qcloud_env] || cfg.qcloud_env qcloud_token = opts[:qcloud_token] || cfg.qcloud_token qcloud_token_lifespan = opts[:qcloud_token_lifespan] || cfg.qcloud_token_lifespan api_type = opts[:type] || cfg.type secret = corpid.present? ? opts[:corpsecret] || cfg.corpsecret : opts[:secret] || cfg.secret network_setting = Wechat::NetworkSetting.new(timeout, skip_verify_ssl, proxy_url, proxy_port, proxy_username, proxy_password) qcloud_setting = Wechat::Qcloud::Setting.new(qcloud_env, qcloud_token, qcloud_token_lifespan) get_wechat_api(api_type, corpid, appid, secret, access_token, agentid, network_setting, jsapi_ticket, qcloud_setting) end