Class: Wechat::JSAPI::Signature

Inherits:
Object
  • Object
show all
Extended by:
Core::Common
Defined in:
lib/wechat/jsapi/signature.rb

Overview

Singature 类提供生成JS-SDK权限验证的签名的方法。如: link = ‘product-wechat.company.com/home’ ticket = // your ticket timestamp = Time.now.to_i.to_s nonce = SecureRandom.hex 8 singature = Wechat::JSAPI::Signature.create link, ticket, timestamp, nonce

Class Method Summary collapse

Class Method Details

.create(link, ticket, timestamp, nonce) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/wechat/jsapi/signature.rb', line 16

def self.create(link, ticket, timestamp, nonce)

  assert_present! :link,      link
  assert_present! :ticket,    ticket
  assert_present! :timestamp, timestamp
  assert_present! :nonce,     nonce

  Digest::SHA1.hexdigest [ "url=#{link}", "jsapi_ticket=#{ticket}", "timestamp=#{timestamp}", "noncestr=#{nonce}" ].sort.join('&')

end