Commit 13ebb290 by lanrion

updated README.md

parent 676c8751
# WeixinAuthorize # WeixinAuthorize
Support using [Redis](http://redis.io) to store `access_token`
## Installation ## Installation
Add this line to your application's Gemfile: Add this line to your application's Gemfile:
...@@ -27,37 +29,38 @@ Or install it yourself as: ...@@ -27,37 +29,38 @@ Or install it yourself as:
$client ||= WeixinAuthorize::Client.new(ENV["APPID"], ENV["APPSECRET"]) $client ||= WeixinAuthorize::Client.new(ENV["APPID"], ENV["APPSECRET"])
``` ```
If you use [Redis](http://redis.io) to store your access_token, you can also specify the `key`: ## Option: use [Redis](http://redis.io) to store your access_token (Recommend)
```ruby
$client ||= WeixinAuthorize::Client.new(ENV["APPID"], ENV["APPSECRET"], "your_store_key")
```
## Configure to use Redis to store your access_token (Recommend) **If you don't use Redis, it will send a request to get a new access_token everytime!**
* Create file in: `config/initializers/weixin_authorize.rb` * Create file in: `config/initializers/weixin_authorize.rb`
```ruby ```ruby
# don't forget change namespace
namespace = "app_name_weixin:weixin_authorize"
redis = Redis.new(:host => "127.0.0.1", :port => "6379", :db => 15)
# cleanup keys in the current namespace when restart server everytime.
exist_keys = redis.keys("#{namespace}:*")
exist_keys.each{|key|redis.del(key)}
# Give a special namespace as prefix for Redis key, when your have more than one project used weixin_authorize, this config will make them work fine.
redis = Redis::Namespace.new("#{namespace}", :redis => redis)
require "redis" WeixinAuthorize.configure do |config|
require "redis-namespace" config.redis = redis
require "weixin_authorize" end
# don't forget change namespace ```
namespace = "your_app_name_weixin:weixin_authorize"
redis = Redis.new(:host => "127.0.0.1",:port => "6379", :db => 15)
# Delete the current namespace keys when restart everytime. * You can also specify the `key`, but it is optionly.
exist_keys = redis.keys("#{namespace}:*")
exist_keys.each{|key|redis.del(key)}
# Give a special namespace as prefix for Redis key, when your have more than one project used weixin_authorize, this config will make them work fine. ```ruby
redis = Redis::Namespace.new("#{namespace}", :redis => redis)
WeixinAuthorize.configure do |config| $client ||= WeixinAuthorize::Client.new(ENV["APPID"], ENV["APPSECRET"], "your_store_key")
config.redis = redis ```
end **Note: ** `your_store_key` should be unique for every account!
```
### 获取用户管理信息 ### 获取用户管理信息
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment