Module: Wechat::Api::Util
- Included in:
- Client
- Defined in:
- lib/wechat/api/util.rb
Instance Method Summary collapse
- #create_qrcode(scene_str) ⇒ Object
- #create_qrcode_temp(scene_id, expire_seconds = 60_480) ⇒ Object
- #js_config(url: nil) ⇒ Object
- #js_ticket ⇒ Object
- #sign(params) ⇒ Object
Instance Method Details
#create_qrcode(scene_str) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/wechat/api/util.rb', line 21 def create_qrcode(scene_str) params = { action_name: 'QR_LIMIT_STR_SCENE', action_info: { scene: { scene_str: scene_str } } } post 'qrcode/create', params end |
#create_qrcode_temp(scene_id, expire_seconds = 60_480) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/wechat/api/util.rb', line 8 def create_qrcode_temp(scene_id, expire_seconds = 60_480) params = { action_name: 'QR_SCENE', expire_seconds: expire_seconds, action_info: { scene: { scene_id: scene_id } } } post 'qrcode/create', params end |
#js_config(url: nil) ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/wechat/api/util.rb', line 44 def js_config(url: nil) r = ticket.tap { |j| j.refresh if j.expired? }.ticket nonce = SecureRandom.hex = Time.now.to_i signature = sign(noncestr: nonce, timestamp: , jsapi_ticket: r, url: url) { appId: app_id, timestamp: , nonceStr: nonce, signature: signature }.tap { |hash| logger.debug { "js_config: #{hash}, url: #{url}" } } end |
#js_ticket ⇒ Object
34 35 36 |
# File 'lib/wechat/api/util.rb', line 34 def js_ticket get 'ticket/getticket', type: :jsapi end |
#sign(params) ⇒ Object
38 39 40 41 42 |
# File 'lib/wechat/api/util.rb', line 38 def sign(params) str = params.to_a.sort.map { |p| p.join('=') }.join('&') logger.debug { "to_sign: #{str}" } Digest::SHA1.hexdigest str end |