Module: WxExt::Api::Js

Defined in:
lib/wx_ext/api/js.rb

Overview

微信扩展接口, 模拟登陆微信公众平台

Class Method Summary collapse

Class Method Details

.get_jsapi_config(access_token, url, app_id) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/wx_ext/api/js.rb', line 19

def get_jsapi_config(access_token, url, app_id)
  config_hash = {}
  jsapi_ticket_hash = get_jsapi_ticket(access_token)
  timestamp = set_timestamp
  noncestr = set_noncestr
  if jsapi_ticket_hash['errcode'] == 0
    jsapi_ticket = jsapi_ticket_hash['ticket']
    str = "jsapi_ticket=#{jsapi_ticket}&noncestr=#{noncestr}&timestamp=#{timestamp}&url=#{url}"
    signature = Digest::SHA1.hexdigest(str)
    config_hash = {
      app_id: app_id,
      timestamp: timestamp,
      noncestr: noncestr,
      signature: signature
    }
  end
  config_hash
end

.get_jsapi_ticket(access_token) ⇒ Object



14
15
16
17
# File 'lib/wx_ext/api/js.rb', line 14

def get_jsapi_ticket(access_token)
  url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=#{access_token}&type=jsapi"
  Helper.http_get(url, { accept: :json })
end