Class: Magpie::Snake
Class Method Summary (collapse)
Instance Method Summary (collapse)
- - (Object) alipay_index
- - (Object) call(env)
- - (Object) chinabank_index
-
- (Snake) initialize(app, &block)
constructor
A new instance of Snake.
- - (Object) order_pay
- - (Object) reg(target, state)
- - (Object) route(method, target, states)
- - (Object) tenpay_index
- - (Object) tongue(target, contents = { })
Methods included from Utils
#build_xml, #dig, #get_notify_res, #get_query, #get_xml_body, #hash_to_xml, #log_errors, #log_notify, #post_query, #send_notify, #send_req_to, #start_http
Constructor Details
- (Snake) initialize(app, &block)
A new instance of Snake
13 14 15 16 |
# File 'lib/middles/snake.rb', line 13 def initialize(app, &block) @app = app @block = block end |
Class Method Details
+ (Object) reg(snake, target, state)
9 10 11 |
# File 'lib/middles/snake.rb', line 9 def self.reg(snake, target, state) proc{ instance_method("#{target}_#{state}").bind(snake).call} end |
Instance Method Details
- (Object) alipay_index
56 57 58 59 60 |
# File 'lib/middles/snake.rb', line 56 def alipay_index @am = AlipayModel.new(@req.params) @title = "支付宝-收银台" render_success_or_fail end |
- (Object) call(env)
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/middles/snake.rb', line 18 def call(env) state, header, body = @app.call(env) @block.call(self) @req = Rack::Request.new(env) @urls[@req.request_method].each { |path, lamb| if @req.path_info =~ Regexp.new("^#{path}$") body = lamb.call break end } [state, header, body] rescue Exception => e Magpie.logger.info(e.inspect + ":\n" + e.backtrace[0..8].join("\n")) [500, header, "500, 请查看日志,了解异常原因"] end |
- (Object) chinabank_index
62 63 64 65 66 |
# File 'lib/middles/snake.rb', line 62 def chinabank_index @am = ChinabankModel.new(@req.params) @title = "网银在线-收银台" render_success_or_fail end |
- (Object) order_pay
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/middles/snake.rb', line 74 def order_pay return "支付失败, 缺少足够的参数" if @req.params.blank? case @req.params["notify_kind"] when "alipay", "chinabank" notify_res = send_notify("POST", @req.params["notify_url"], query_to_hash(@req.params["notify"])) method = "POST" when "tenpay" notify_res = send_notify("GET", @req.params["notify_url"], @req.params["notify"]) method = "GET" end log_notify(method, @req.params["notify_url"], query_to_hash(@req.params["notify"]), notify_res) notify_res end |
- (Object) reg(target, state)
42 43 44 |
# File 'lib/middles/snake.rb', line 42 def reg(target, state) self.class.reg(self, target, state) end |
- (Object) route(method, target, states)
46 47 48 49 50 51 52 53 54 |
# File 'lib/middles/snake.rb', line 46 def route(method, target, states) routes = states.inject({ }){ |h, state| url_path = "/#{target}/#{state}" h[url_path] = reg(target, state) h["/#{target}"] = reg(target, state) if state.to_s == "index" h } @urls[method.to_s.upcase].merge!(routes) end |
- (Object) tenpay_index
68 69 70 71 72 |
# File 'lib/middles/snake.rb', line 68 def tenpay_index @am = TenpayModel.new(@req.params) @title = "财付通-收银台" render_success_or_fail end |
- (Object) tongue(target, contents = { })
34 35 36 37 38 39 40 |
# File 'lib/middles/snake.rb', line 34 def tongue(target, contents = { }) @urls ||= { "GET" => { }, "POST" => { }} states = [contents[:states]].flatten.compact route("GET", target, states) actions = [contents[:actions]].flatten.compact route("POST", target, actions) end |