module WechatPublic::Responder

Public Instance Methods

get_uid(params) click to toggle source
if response.respond_to? :to_xml
  render xml: response.to_xml
else
  render :nothing => true, :status => 200, :content_type => 'text/html'
end

end

# File lib/wechat/responder.rb, line 97
def get_uid params
  request = WechatPublic::Message.from_hash(params[:xml] || post_xml)
  response = self.class.responder_for(request) do |responder, *args|
    responder ||= self.class.responders(:login).first

    next if responder.nil?
    next request.reply.text responder[:respond] if (responder[:respond])
    next responder[:proc].call(*args.unshift(request)) if (responder[:proc])
  end
  {
    request: request,
    response: response
  }
end

Private Instance Methods

post_xml() click to toggle source
# File lib/wechat/responder.rb, line 119
def post_xml
  data = Hash.from_xml(request.raw_post)
  HashWithIndifferentAccess.new_from_hash_copying_default data.fetch('xml', {})
end
verify_signature() click to toggle source
# File lib/wechat/responder.rb, line 113
def verify_signature
  array = [self.class.token, params[:timestamp], params[:nonce]].compact.collect(&:to_s).sort
  render :text => "Forbidden", :status => 403 if params[:signature] != Digest::SHA1.hexdigest(array.join)
end