Module: WxExt::Api::Js

Extended by:
Js
Included in:
Js
Defined in:
lib/wx_ext/api/js.rb

Overview

User api of weixin.

Author:

  • FuShengYang

Instance Method Summary collapse

Instance Method Details

#get_jsapi_config(access_token, url, app_id, jsapi_ticket) ⇒ Hash

Get js api config hash.

Parameters:

  • access_token (Enumerable<String>)
  • url (Enumerable<String>)
  • app_id (Enumerable<String>)

Returns:

  • (Hash)

    Json based hash.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/wx_ext/api/js.rb', line 30

def get_jsapi_config(access_token, url, app_id, jsapi_ticket)
  timestamp = set_timestamp
  noncestr = set_noncestr
  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,
    jsapi_ticket: jsapi_ticket,
    url: url,
    str: str
  }
end

#get_jsapi_ticket(access_token) ⇒ Hash

Get js api ticket.

Parameters:

  • access_token (Enumerable<String>)

Returns:

  • (Hash)

    Json based hash.



19
20
21
22
# File 'lib/wx_ext/api/js.rb', line 19

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