Skip to content

Instantly share code, notes, and snippets.

@zhangyuan
Created April 26, 2013 04:01
Show Gist options
  • Select an option

  • Save zhangyuan/5464970 to your computer and use it in GitHub Desktop.

Select an option

Save zhangyuan/5464970 to your computer and use it in GitHub Desktop.
Verify Wechat message signature in Rails controller.
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