这是一个简单集成微信api的的例子,使用这个Gem:https://github.com/lanrion/weixin_rails_middleware
1. 下载这个rails4例子到本地
[url]https://github.com/caiwenhn2008/weixin_rails_middleware_example[/url]
2.运行
bundle exec bundle install
3. 启动服务器,http://localhost:3000/
rails server
4. 根据下面的例子安装,启动 localtunnelling :
[url]http://caerun.iteye.com/admin/blogs/2271660[/url]
得到这个映射的公网地址:https://gtxzozgorw.localtunnel.me
5. 在http://localhost:3000/创建用户,微信token,如下:
[img]http://dl2.iteye.com/upload/attachment/0114/5991/b7d42543-8a80-384c-93bd-e07043d6ec36.png[/img]
6.所以本地微信应用对应的公网地址:
https://gtxzozgorw.localtunnel.me/weixin/4-kov581d4uewerdtb4joj3uywbv-hhgy1i_zroabmq
Token is: 14fc9031f12fd684359c7a05
7. 登陆微信公众平台: http://mp.weixin.qq.com/debug/cgi-bin/sandboxinfo?action=showinfo&t=sandbox/index
[img]http://dl2.iteye.com/upload/attachment/0114/5993/7d4c22b8-87db-3a2d-8dce-06ace79f87b8.png[/img]
8. 用微信扫描你自己的微信公众测试号
[img]http://dl2.iteye.com/upload/attachment/0114/5995/70275f28-3a32-373b-9c41-7c3b19c0b968.png[/img]
9. 关注微信号码后可以发任何信息测试一下,得到一个相同的回复信息
10. 可以查看weixin_controller_decorator.rb如何客户化返回信息
更多请参考原作者github: https://github.com/lanrion/weixin_rails_middleware