Module: WeChat::Messaging::Responder
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/we_chat/messaging/responder.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/we_chat/messaging/responder.rb', line 19 def create = WeChat::Messaging::Message.new(params[:xml] || post_data) response = self.class.create_response() if response.nil? Rails.logger.debug 'response is null' render nothing: true, status: 200, content_type: 'text/html' else render xml: response.source.to_xml(root: 'xml') end end |
#post_data ⇒ Object
36 37 38 39 |
# File 'lib/we_chat/messaging/responder.rb', line 36 def post_data data = Hash.from_xml(request.raw_post) HashWithIndifferentAccess. data.fetch('xml', {}) end |
#show ⇒ Object
15 16 17 |
# File 'lib/we_chat/messaging/responder.rb', line 15 def show render :text => params[:echostr] end |
#verify_signature ⇒ Object
30 31 32 33 34 |
# File 'lib/we_chat/messaging/responder.rb', line 30 def verify_signature array = [WeChat.wechat_token, params[:timestamp], params[:nonce]].compact.collect(&:to_s).sort Rails.logger.debug Digest::SHA1.hexdigest(array.join) render :text => "Forbidden", :status => 403 if params[:signature] != Digest::SHA1.hexdigest(array.join) end |