From c4aac313b488dd20c1c282fc8877044e086df22f Mon Sep 17 00:00:00 2001 From: vkill Date: Sat, 29 Dec 2018 09:57:01 +0800 Subject: [PATCH] Update README.md --- README.md | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index da16e9e..8535c2e 100644 --- a/README.md +++ b/README.md @@ -197,7 +197,7 @@ r = WxPay::Service.generate_js_pay_req params #### Notify Process -A simple example of processing notify. +A simple example of processing notify for Rails Action Controller. ```ruby # config/routes.rb @@ -219,6 +219,39 @@ def notify end ``` +A simple example of processing notify for Grape v1.2.2 . + +```ruby +# Gemfile +gem 'multi_xml' + +# config/routes.rb +mount Wechat::Api => '/notify' + +# app/api/wechat/api.rb +module Wechat + class Api < Grape::API + content_type :xml, 'text/xml' + format :xml + formatter :xml, lambda { |object, env| object.to_xml(root: 'xml', dasherize: false) } + + post "" do + result = params["xml"] + if WxPay::Sign.verify?(result) + # find your order and process the post-paid logic. + + status 200 + {return_code: "SUCCESS"} + else + status 200 + {return_code: "FAIL", return_msg: "签名失败"} + end + end + end +end +``` + + ### Integrate with QRCode(二维码) Wechat payment integrating with QRCode is a recommended process flow which will bring users comfortable experience. It is recommended to generate QRCode using `rqrcode` and `rqrcode_png`. -- libgit2 0.21.0