Module: MpWeixin::ServerHelper
- Defined in:
- lib/mp_weixin/server_helper.rb
Instance Method Summary collapse
-
#generate_signature(token, timestamp, nonce) ⇒ String
generate a signature string through sha1 encrypt token, timestamp, nonce .
-
#reply_image_message(attributes = {}, &block) ⇒ Object
initialize an ImageReplyMessage.
-
#reply_music_message(attributes = {}, &block) ⇒ Object
initialize an MusicReplyMessage.
-
#reply_news_message(attributes = {}, &block) ⇒ Object
initialize an NewsReplyMessage.
-
#reply_text_message(attributes = {}) ⇒ Object
initialize an TextReplyMessage.
-
#reply_video_message(attributes = {}, &block) ⇒ Object
initialize an VideoReplyMessage.
-
#reply_voice_message(attributes = {}, &block) ⇒ Object
initialize an VoiceReplyMessage.
-
#valid_signature?(signature, timestamp, nonce) ⇒ Boolean
Whether or not the signature is eql with local_signature.
Instance Method Details
#generate_signature(token, timestamp, nonce) ⇒ String
generate a signature string through sha1 encrypt token, timestamp, nonce .
17 18 19 20 |
# File 'lib/mp_weixin/server_helper.rb', line 17 def generate_signature(token, , nonce) signature_content = [token.to_s, .to_s, nonce.to_s].sort.join("") Digest::SHA1.hexdigest(signature_content) end |
#reply_image_message(attributes = {}, &block) ⇒ Object
initialize an ImageReplyMessage
46 47 48 49 50 51 |
# File 'lib/mp_weixin/server_helper.rb', line 46 def (attributes = {}, &block) = MpWeixin::ImageReplyMessage.new(attributes) block.call() if block_given? end |
#reply_music_message(attributes = {}, &block) ⇒ Object
initialize an MusicReplyMessage
76 77 78 79 80 81 |
# File 'lib/mp_weixin/server_helper.rb', line 76 def (attributes = {}, &block) = MpWeixin::MusicReplyMessage.new(attributes) block.call() if block_given? end |
#reply_news_message(attributes = {}, &block) ⇒ Object
initialize an NewsReplyMessage
86 87 88 89 90 91 92 |
# File 'lib/mp_weixin/server_helper.rb', line 86 def (attributes = {}, &block) = MpWeixin::NewsReplyMessage.new(attributes) block.call() if block_given? end |
#reply_text_message(attributes = {}) ⇒ Object
initialize an TextReplyMessage
39 40 41 |
# File 'lib/mp_weixin/server_helper.rb', line 39 def (attributes = {}) MpWeixin::TextReplyMessage.new(attributes) end |
#reply_video_message(attributes = {}, &block) ⇒ Object
initialize an VideoReplyMessage
66 67 68 69 70 71 |
# File 'lib/mp_weixin/server_helper.rb', line 66 def (attributes = {}, &block) = MpWeixin::VideoReplyMessage.new(attributes) block.call() if block_given? end |
#reply_voice_message(attributes = {}, &block) ⇒ Object
initialize an VoiceReplyMessage
56 57 58 59 60 61 |
# File 'lib/mp_weixin/server_helper.rb', line 56 def (attributes = {}, &block) = MpWeixin::VoiceReplyMessage.new(attributes) block.call() if block_given? end |
#valid_signature?(signature, timestamp, nonce) ⇒ Boolean
Whether or not the signature is eql with local_signature
29 30 31 32 33 34 |
# File 'lib/mp_weixin/server_helper.rb', line 29 def valid_signature?(signature, , nonce) token = Config.token local_signature = generate_signature(token,,nonce) local_signature.eql? signature end |