Class: XiWechatCorp::Callback::Response
- Inherits:
-
Object
- Object
- XiWechatCorp::Callback::Response
- Defined in:
- lib/xi_wechat_corp/callback/response.rb
Constant Summary collapse
- TEMPLATE =
'<xml><Encrypt>%s</Encrypt><MsgSignature>%s</MsgSignature><TimeStamp>%d</TimeStamp><Nonce>%d</Nonce></xml>'
- NONCE_UPPER =
1 << 32
Instance Method Summary collapse
- #assign(xml) ⇒ Object
-
#initialize(cryptor, signer, xml = nil) ⇒ Response
constructor
A new instance of Response.
- #to_s ⇒ Object (also: #to_xml)
Constructor Details
#initialize(cryptor, signer, xml = nil) ⇒ Response
Returns a new instance of Response.
9 10 11 12 13 |
# File 'lib/xi_wechat_corp/callback/response.rb', line 9 def initialize(cryptor, signer, xml = nil) @cryptor = cryptor @signer = signer assign(xml) end |
Instance Method Details
#assign(xml) ⇒ Object
15 16 17 |
# File 'lib/xi_wechat_corp/callback/response.rb', line 15 def assign(xml) @encrypt = xml ? @cryptor.encrypt(xml) : nil end |
#to_s ⇒ Object Also known as: to_xml
19 20 21 22 23 24 25 |
# File 'lib/xi_wechat_corp/callback/response.rb', line 19 def to_s return '' if @encrypt.nil? = Time.now.to_i nonce = SecureRandom.random_number(NONCE_UPPER) signature = @signer.sign(@encrypt, , nonce) sprintf(TEMPLATE, @encrypt, signature, , nonce) end |