class SimpleWechat::JsApi
Public Instance Methods
connection()
click to toggle source
# File lib/simple_wechat/jsapi.rb, line 44 def connection @connection ||= begin conn = Faraday.new do |faraday| faraday.adapter Faraday.default_adapter end end end
get_config(jsapi_ticket, url, appid, api_list, options = {})
click to toggle source
# File lib/simple_wechat/jsapi.rb, line 32 def get_config(jsapi_ticket, url, appid, api_list, options = {}) timestamp = (options[:timestamp] || Time.now).to_i noncestr = options[:noncestr] || SecureRandom.hex(10) signature = sign(jsapi_ticket, noncestr, timestamp, url) { appId: appid, timestamp: timestamp, signature: signature, jsApiList: api_list } end
get_ticket(access_token)
click to toggle source
# File lib/simple_wechat/jsapi.rb, line 14 def get_ticket(access_token) response = connection.get("https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=#{access_token}&type=jsapi") Ticket.new MultiJson.load(response.body) end
sign(jsapi_ticket, noncestr, timestamp, url)
click to toggle source
# File lib/simple_wechat/jsapi.rb, line 19 def sign(jsapi_ticket, noncestr, timestamp, url) params = { noncestr: noncestr, timestamp: timestamp, jsapi_ticket: jsapi_ticket, url: url } text = params.keys.sort.map {|key| "#{key}=#{params[key]}"}.join('&') Digest::SHA1.hexdigest(text) end