Module: YolQyWeixin::Connection::Base
- Included in:
- YolQyWeixin::Client
- Defined in:
- lib/yol_qy_weixin/connections/base.rb
Instance Method Summary collapse
Instance Method Details
#get_access_token ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/yol_qy_weixin/connections/base.rb', line 20 def get_access_token if redis.nil? access_token_res = get_token(corpid, secret) access_token = access_token_res["access_token"] rescue nil else access_token = redis.get("qywx_access_token") if access_token.nil? access_token_res = get_token(corpid, secret) access_token = access_token_res["access_token"] rescue nil if access_token.nil? raise Exception.new("QyWeixin access token authorize false, corpid: #{corpid}") else redis.set("qywx_access_token", access_token) redis.expire("qywx_access_token", 7200) end end end access_token end |
#http_get(url) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/yol_qy_weixin/connections/base.rb', line 12 def http_get(url) uri = URI(url) req = Net::HTTP.new(uri.host, uri.port) req.use_ssl = true res = req.get("#{uri.path}?#{uri.query}") handle_res(res) end |
#http_post(url, params) ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/yol_qy_weixin/connections/base.rb', line 4 def http_post(url, params) uri = URI(url) req = Net::HTTP.new(uri.host, uri.port) req.use_ssl = true res = req.post("#{uri.path}?#{uri.query}", params.to_json) handle_res(res) end |