Sha256: 8a09a6ba1bc5690dc173fd3d968c0923429010379f26ff30d9831524d173a02e

Contents?: true

Size: 971 Bytes

Versions: 3

Compression:

Stored size: 971 Bytes

Contents

require 'sinatra'
require 'nokogiri'
require 'digest/sha1'

set(:access_token) { |token_proc|
  condition do
    token = token_proc.call
    return true if token.nil? || token.empty?
    origin_signature_strings = [token, params[:timestamp], params[:nonce]]
    signature = Digest::SHA1.hexdigest origin_signature_strings.sort!.join
    signature.eql? params[:signature]
  end
}

token_proc = proc {
  WeiBackend::MessageDispatcher.token
}

get '/weixin', :access_token => token_proc do
  params[:echostr]
end

post '/weixin', :access_token => token_proc do
  request.body.rewind
  weixin_params = WeiBackend::Utils.parse_params request.body.read
  handler = WeiBackend::MessageDispatcher.new
  results = handler.on weixin_params[:MsgType], weixin_params

  haml results[:format].to_sym, :views => File.dirname(__FILE__)+'/wei-templates', :locals => results[:model]
end

helpers do
  def cdata content
    "<![CDATA[#{content}]]>"
  end
end

extend WeiBackend::Delegator

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
wei-backend-0.1.4 lib/wei-backend/main.rb
wei-backend-0.1.2 lib/wei-backend/main.rb
wei-backend-0.1.1 lib/wei-backend/main.rb