yol_qy_weixin 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 492bc402556844ff268a6cc561decc01273d6c625cfbe3d6fead5cd990a3c543
4
- data.tar.gz: f245159f2eb8175688c586950c1ddc4e0ef20f2a1837f430ceab8898b6bf3581
3
+ metadata.gz: 16810fce99de51f9a49c445ca9e00d4c79f0fe207956e37730e49f457080103f
4
+ data.tar.gz: f9b822c1704f8736b878b5535992814f4a68e341a80d809edbca4a0a813b14b6
5
5
  SHA512:
6
- metadata.gz: '04889e7bf6966e97dd0b9bb3e5d68cd686216a8cd9878f616388f12915d3789ac1de792452b97fabd968a6673dd2364b1acb30fbd8dfe8893cbd28bbe2de80a0'
7
- data.tar.gz: e8eb257736eff86043bfe00a2a5e98fd2135d106d825dbe472eec07b9e82d0da0a4ac0a8add84cc84a72fffebe68a4de3cb7f659bff6a03bb93817c06fcee519
6
+ metadata.gz: 7ad1d2656261536b48e87c23d7e448fe3be79dda0f7c061c24d8b4570b3608cdae0e3163c374723c74561a8a36527220ca7be5490c46d1903c588a31d9a20d06
7
+ data.tar.gz: 14de072312d66e3bab849bfaed5e0dac430ca8b8101ddd0ec19840379e2b504c5876e6397f73611adb57baa506b969d1e4763ab1f223242a0097ca492b3779df
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- yol_qy_weixin (0.0.3)
4
+ yol_qy_weixin (0.0.4)
5
5
  multi_xml
6
6
  nokogiri
7
7
  roxml
data/README.md CHANGED
@@ -6,76 +6,95 @@ https://rubygems.org/gems/yol_qy_weixin
6
6
 
7
7
  [![Gem Version](https://badge.fury.io/rb/yol_qy_weixin.svg)](http://badge.fury.io/rb/yol_qy_weixin)
8
8
 
9
- **企业号对应多个管理组,请前往 `设置` => `权限管理` 任意创建一个管理组,在管理组最下角即可获取 CorpID Secret**
10
-
11
9
  **有问题请及时提issue**
12
10
 
13
11
  ```ruby
14
- gem "qy_wechat_api", git: "https://github.com/lanrion/qy_wechat_api.git"
12
+ gem "yol_qy_weixin", git: "https://github.com/luojie2019/yol_qy_weixin.git"
15
13
  ```
16
14
 
17
15
  # 配置
18
16
 
19
- ## jsticket、suite_token存储方案
20
- 如果你是在Rails框架下,默认情况下直接使用Rails.cache,如果你想独立cache,请配置如下:
17
+ ## 安装依赖Installation
18
+
19
+ Add this line to your application's Gemfile:
20
+
21
21
  ```ruby
22
- QyWechatApi.configure do |config|
23
- config.cache_store = YourCustomCacheStore
24
- end
22
+ gem 'yol_qy_weixin'
25
23
  ```
26
- cache_store按照Rails.cache的接口实现,强烈建议使用ActiveSupport::Cache
24
+ ## 配置 corpid secret
27
25
 
28
- ## 日志配置
29
- 如果你是在Rails框架下,默认情况下直接使用Rails.logger,如果你想独立cache,请配置如下:
30
26
  ```ruby
31
- QyWechatApi.configure do |config|
32
- config.logger = YourCustomLogger
33
- end
34
- ```
35
- logger按照Rails.logger的接口实现,强烈建议使用ActiveSupport::Logger
27
+ # 目录
36
28
 
37
- ## Token 存储方案(TODO: 待重构直接使用cache_store)
29
+ file: your_project/config/qy_weixin.yml
38
30
 
39
- ### 对象存储
40
- 如果你是单个企业号,建议使用这个方案,无需任何配置即可使用。
31
+ .your_project/
32
+ ├── app
33
+ ├── bin
34
+ ├── config
35
+ │ ├── redis.yml
36
+ │ ├── database.yml
37
+ │ ├── qy_weixin.yml
38
+ ```
41
39
 
42
- ### Redis 存储
43
- ```ruby
44
- redis = Redis.new(host: "127.0.0.1", port: "6379")
40
+ ```yml
41
+ defaults: &defaults
42
+ corpid: '1**'
43
+ secret: '2**'
45
44
 
46
- namespace = "qy_wechat_api:redis_storage"
45
+ development: &development
46
+ <<: *defaults
47
47
 
48
- # cleanup keys in the current namespace when restart server everytime.
49
- exist_keys = redis.keys("#{namespace}:*")
50
- exist_keys.each{|key|redis.del(key)}
48
+ test:
49
+ <<: *defaults
51
50
 
52
- redis_with_ns = Redis::Namespace.new("#{namespace}", redis: redis)
51
+ production:
52
+ corpid: <%= ENV.fetch('QY_WEIXIN_CORPID') { '1**'' } %>
53
+ secret: <%= ENV.fetch('QY_WEIXIN_SECRET') { '2**'' } %>
54
+ ```
53
55
 
54
- QyWechatApi.configure do |config|
55
- config.redis = redis_with_ns
56
- end
56
+ ## 读取配置
57
+ ```ruby
58
+ # 读取qy_weixin.yml配置
59
+ qy_weixin_config = YAML::load(ERB.new(File.read("#{Rails.root}/config/qy_weixin.yml")).result)[Rails.env]
57
60
  ```
61
+ 如果你是在Rails框架下,也可以使用Settingslogic读取yml配置:
62
+ ```ruby
63
+ # 引用gem
64
+ gem 'settingslogic', '2.0.9'
65
+
66
+ # your_project/app/settings/weixin_setting.rb
67
+ class WeixinSetting < Settingslogic
68
+ source "#{Rails.root}/config/weixin.yml"
69
+ namespace Rails.env
70
+ end
58
71
 
59
- # API基本用法
72
+ corpid = WeixinSetting.corpid
73
+ corp_secret = WeixinSetting.secret
74
+ ```
60
75
 
61
- 请务必结合:http://qydev.weixin.qq.com/wiki/index.php 理解以下API参数使用。
76
+ **说明:redis配置请参考官方文档https://github.com/redis/redis-rb/blob/master/README.md**
62
77
 
63
- ## 初始化
78
+ ## 实例对象
64
79
 
65
80
  ```ruby
66
- group_client = QyWechatApi::Client.new(corpid, corpsecret)
81
+ # 目录 file: your_project/config/initializers/qy_weixin.rb
67
82
 
68
- # 为了确保用户输入的corpid, corpsecret是准确的,请务必执行:
69
- group_client.is_valid?
83
+ QyWexinClient = YolQyWeixin::Client.new(
84
+ corpid: qy_weixin_config["corpid"],
85
+ secret: qy_weixin_config["secret"],
86
+ redis: RedisClient
87
+ )
70
88
  ```
71
89
 
72
- 如果需要使用通过第三方应用 **获取企业号access_token** API 获取的 access_token
73
- 做如下处理:
90
+
91
+ # 基本用法
92
+
93
+ 如果需要获取的 access_token
74
94
 
75
95
  ```ruby
76
- options = {access_token: "access_token"}
77
- # redis_key 也可定制
78
- group_client = QyWechatApi::Client.new(corpid, corpsecret, options)
96
+ access_token = QyWexinClient.get_access_token
97
+ # 对应企业微信官方文档:https://work.weixin.qq.com/api/doc/90000/90135/91039
79
98
  ```
80
99
 
81
100
  ## 部门
@@ -17,4 +17,4 @@ module YolQyWeixin
17
17
  @redis = options[:redis] || YolQyWeixin.configuration.redis
18
18
  end
19
19
  end
20
- end
20
+ end
@@ -18,26 +18,22 @@ module YolQyWeixin
18
18
  end
19
19
 
20
20
  def get_access_token
21
- # access_token = redis.find("access_token_#{appid}")
22
-
23
- # if access_token.nil?
24
- # access_token_res = get_token(corpid, secret)
25
-
26
- # # TODO:
27
- # access_token = JSON.parse(access_token_res)["access_token"] rescue nil
28
-
29
- # if access_token.nil?
30
- # raise Exception.new("Weixin access token authorize false, appid: #{appid},
31
- # appsecret: #{appsecret}, access_token_res: #{access_token_res.to_s}")
32
- # else
33
- # redis.save("access_token_#{appid}", access_token)
34
- # redis.expire("access_token_#{appid}", 7200)
35
- # end
36
- # end
37
-
38
- # access_token
39
- access_token_res = get_token(corpid, secret)
40
- access_token = access_token_res["access_token"] rescue nil
21
+ if redis.nil?
22
+ access_token_res = get_token(corpid, secret)
23
+ access_token = access_token_res["access_token"] rescue nil
24
+ else
25
+ access_token = redis.get("qywx_access_token")
26
+ if access_token.nil?
27
+ access_token_res = get_token(corpid, secret)
28
+ access_token = access_token_res["access_token"] rescue nil
29
+ if access_token.nil?
30
+ raise Exception.new("QyWeixin access token authorize false, corpid: #{corpid}")
31
+ else
32
+ redis.set("qywx_access_token", access_token)
33
+ redis.expire("qywx_access_token", 7200)
34
+ end
35
+ end
36
+ end
41
37
  access_token
42
38
  end
43
39
 
@@ -1,12 +1,20 @@
1
1
  module YolQyWeixin
2
2
  module Connection
3
3
  module User
4
+ def get_user_id(code)
5
+ http_get(user_info_url(open_id))
6
+ end
7
+
4
8
  def get_user_info(open_id)
5
9
  http_get(user_info_url(open_id))
6
10
  end
7
11
 
8
12
  private
9
13
 
14
+ def user_id_url(code)
15
+ "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?access_token=#{get_access_token}&code=#{code}"
16
+ end
17
+
10
18
  def user_info_url(open_id)
11
19
  "https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token=#{get_access_token}&userid=#{open_id}"
12
20
  end
@@ -1,3 +1,3 @@
1
1
  module YolQyWeixin
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -6,8 +6,8 @@ require 'yol_qy_weixin/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "yol_qy_weixin"
8
8
  spec.version = YolQyWeixin::VERSION
9
- spec.authors = ["cjl"]
10
- spec.email = ["chenjialiang@yeezon.com"]
9
+ spec.authors = ["luojie2019"]
10
+ spec.email = ["luojie@yolanda.hk"]
11
11
  spec.summary = %q{Shop middleware for Weixin.}
12
12
  spec.description = ""
13
13
  spec.homepage = ""
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yol_qy_weixin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
- - cjl
7
+ - luojie2019
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-10 00:00:00.000000000 Z
11
+ date: 2021-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -82,7 +82,7 @@ dependencies:
82
82
  version: '0'
83
83
  description: ''
84
84
  email:
85
- - chenjialiang@yeezon.com
85
+ - luojie@yolanda.hk
86
86
  executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []