Class: Wechat::Callback::MessageSignature

Inherits:
Object
  • Object
show all
Extended by:
Wechat::Core::Common
Defined in:
lib/wechat/callback/message_signature.rb

Overview

Message Signature 是消息签名类。

Class Method Summary collapse

Class Method Details

.create(encoded_message, token, timestamp, nonce) ⇒ Object

消息加解密 技术方案mp.weixin.qq.com/wiki/6/90f7259c0d0739bbb41d9f4c4c8e59a2.html

为了验证消息体的合法性,公众平台新增消息体签名,开发者可用以验证消息体的真实性,并对验证通过的消息体进行解密msg_signature = sha1(sort(token、timestamp、nonce, encoded_message))

encoded_message 前文描述密文消息体token 公众平台上,开发者设置的 token timestamp URL上原有参数,时间戳nonce URL上原有参数,随机数



19
20
21
22
23
24
25
26
27
28
# File 'lib/wechat/callback/message_signature.rb', line 19

def self.create(encoded_message, token, timestamp, nonce)

  assert_present! :encoded_message, encoded_message
  assert_present! :token,           token
  assert_present! :timestamp,       timestamp
  assert_present! :nonce,           nonce

  Digest::SHA1.hexdigest [ token, timestamp, nonce, encoded_message ].sort.join

end