Created
April 26, 2013 04:01
-
-
Save zhangyuan/5464970 to your computer and use it in GitHub Desktop.
Verify Wechat message signature in Rails controller.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def verify_signature? | |
| wechat_token = 'mysecret' # change it to the secret token | |
| require 'openssl' unless defined?(OpenSSL) | |
| text = %w(timestamp nonce).map {|name| params[name].to_s}.push(wechat_token).sort.join | |
| Digest::SHA1.hexdigest(text) == params[:signature] | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment