Class: WeixinJsSDK::Signature

Inherits:
Object
  • Object
show all
Defined in:
lib/weixin_js_sdk/signature.rb

Constant Summary collapse

TEMPLATE =
'jsapi_ticket=%{jsapi_ticket}&noncestr=%{nonce_str}&timestamp=%{timestamp}&url=%{url}'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(ticket: '', nonce_str: '', timestamp: '', url: '') ⇒ Signature

Returns a new instance of Signature.



7
8
9
10
11
12
# File 'lib/weixin_js_sdk/signature.rb', line 7

def initialize(ticket: '', nonce_str: '', timestamp: '', url: '')
  @ticket = ticket
  @nonce_str = nonce_str
  @timestamp = timestamp
  @url = url
end

Instance Method Details

#signObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/weixin_js_sdk/signature.rb', line 14

def sign
  str = TEMPLATE % {
    jsapi_ticket: @ticket,
    nonce_str: @nonce_str,
    timestamp: @timestamp,
    url: @url
  }

  Digest::SHA1.hexdigest(str)
end