Class: Wechat::Callback::Signature
- Inherits:
-
Object
- Object
- Wechat::Callback::Signature
- Extended by:
- Wechat::Core::Common
- Defined in:
- lib/wechat/callback/signature.rb
Overview
Singature 用于生成参数签名。
Class Method Summary collapse
Class Method Details
.create(token, timestamp, nonce, *args) ⇒ Object
token 可由开发者在开发者中心配置项任意填写 timestamp 时间戳 nonce 随机数
加密/校验流程如下:
-
将token、timestamp、nonce三个参数进行字典序排序
-
将三个参数字符串拼接成一个字符串进行sha1加密
-
开发者获得加密后的字符串可与signature对比,标识该请求来源于微信
21 22 23 24 25 26 27 28 29 |
# File 'lib/wechat/callback/signature.rb', line 21 def self.create(token, , nonce, *args) assert_present! :token, token assert_present! :timestamp, assert_present! :nonce, nonce Digest::SHA1.hexdigest [ token, nonce, , *args ].sort.join end |