wechat 0.6.4 → 0.6.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/bin/wechat +10 -10
- data/lib/wechat.rb +2 -8
- data/lib/wechat/api_loader.rb +36 -18
- data/lib/wechat/client.rb +2 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e173474b91515c5b98160ebcf2e88c307b7a0c7
|
4
|
+
data.tar.gz: 24e1eeb02200389eb39fe1aa89a0e6dd87cfeda8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: deff7d137bfcf8e9ff9c9e5102fae2639289edb58c5a3d426d32190df1e1e860d83a9a9faec2e858cdb7258580408dd0d38824416735ea7ce22ae7fb0d0ea9fa
|
7
|
+
data.tar.gz: 88485947385312824105e5d4a1a444fb45b8ddfdb377d24283ef463d848c96e0c9dda87c1998f57dea91ca934c4fd70ff2f3f2826d1c35d9554279987842be5d
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## v0.6.5 (released at 11/24/2015)
|
4
|
+
|
5
|
+
* Handle 48001 error if token is expire/not valid, close #71
|
6
|
+
* ApiLoader will do config reading and initialize the api instead of spreading the logic.
|
7
|
+
|
3
8
|
## v0.6.4 (released at 11/16/2015)
|
4
9
|
|
5
10
|
* Command mode now display different command set based on enterprise/public account setting
|
data/bin/wechat
CHANGED
@@ -249,6 +249,16 @@ class App < Thor
|
|
249
249
|
def users
|
250
250
|
puts wechat_api.users
|
251
251
|
end
|
252
|
+
|
253
|
+
desc 'qrcode_create_scene [SCENE_ID, EXPIRE_SECONDS]', '请求临时二维码'
|
254
|
+
def qrcode_create_scene(scene_id, expire_seconds = 604800)
|
255
|
+
puts wechat_api.qrcode_create_scene(scene_id, expire_seconds)
|
256
|
+
end
|
257
|
+
|
258
|
+
desc 'qrcode_create_limit_scene [SCENE_ID_OR_STR]', '请求永久二维码'
|
259
|
+
def qrcode_create_limit_scene(scene_id_or_str)
|
260
|
+
puts wechat_api.qrcode_create_limit_scene(scene_id_or_str)
|
261
|
+
end
|
252
262
|
end
|
253
263
|
|
254
264
|
desc 'user [OPEN_ID]', '获取用户基本信息'
|
@@ -261,16 +271,6 @@ class App < Thor
|
|
261
271
|
puts wechat_api.user_update_remark(openid, remark)
|
262
272
|
end
|
263
273
|
|
264
|
-
desc 'qrcode_create_scene [SCENE_ID, EXPIRE_SECONDS]', '请求临时二维码'
|
265
|
-
def qrcode_create_scene(scene_id, expire_seconds = 604800)
|
266
|
-
puts wechat_api.qrcode_create_scene(scene_id, expire_seconds)
|
267
|
-
end
|
268
|
-
|
269
|
-
desc 'qrcode_create_limit_scene [SCENE_ID_OR_STR]', '请求永久二维码'
|
270
|
-
def qrcode_create_limit_scene(scene_id_or_str)
|
271
|
-
puts wechat_api.qrcode_create_limit_scene(scene_id_or_str)
|
272
|
-
end
|
273
|
-
|
274
274
|
desc 'menu', '当前菜单'
|
275
275
|
def menu
|
276
276
|
puts wechat_api.menu
|
data/lib/wechat.rb
CHANGED
@@ -17,17 +17,11 @@ module Wechat
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
attr_reader :config
|
21
|
-
|
22
20
|
def self.config
|
23
|
-
|
21
|
+
ApiLoader.config
|
24
22
|
end
|
25
23
|
|
26
24
|
def self.api
|
27
|
-
|
28
|
-
@api ||= CorpApi.new(config.corpid, config.corpsecret, config.access_token, config.agentid, config.skip_verify_ssl)
|
29
|
-
else
|
30
|
-
@api ||= Api.new(config.appid, config.secret, config.access_token, config.skip_verify_ssl, config.jsapi_ticket)
|
31
|
-
end
|
25
|
+
ApiLoader.api
|
32
26
|
end
|
33
27
|
end
|
data/lib/wechat/api_loader.rb
CHANGED
@@ -1,7 +1,16 @@
|
|
1
1
|
module Wechat
|
2
|
-
|
2
|
+
module ApiLoader
|
3
|
+
def self.api
|
4
|
+
c = ApiLoader.config
|
5
|
+
if c.corpid.present?
|
6
|
+
@api ||= CorpApi.new(c.corpid, c.corpsecret, c.access_token, c.agentid, c.skip_verify_ssl)
|
7
|
+
else
|
8
|
+
@api ||= Api.new(c.appid, c.secret, c.access_token, c.skip_verify_ssl, c.jsapi_ticket)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
3
12
|
def self.with(options)
|
4
|
-
c =
|
13
|
+
c = config
|
5
14
|
|
6
15
|
token_file = options[:toke_file] || c.access_token || '/var/tmp/wechat_access_token'
|
7
16
|
|
@@ -18,35 +27,44 @@ HELP
|
|
18
27
|
end
|
19
28
|
end
|
20
29
|
|
21
|
-
|
30
|
+
@config = nil
|
31
|
+
|
32
|
+
def self.config
|
33
|
+
return @config unless @config.nil?
|
34
|
+
@config ||= loading_config!
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def self.loading_config!
|
40
|
+
config ||= config_from_file || config_from_environment
|
41
|
+
|
42
|
+
if defined?(::Rails)
|
43
|
+
config[:access_token] ||= Rails.root.join('tmp/access_token').to_s
|
44
|
+
config[:jsapi_ticket] ||= Rails.root.join('tmp/jsapi_ticket').to_s
|
45
|
+
end
|
46
|
+
config.symbolize_keys!
|
47
|
+
@config = OpenStruct.new(config)
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.config_from_file
|
22
51
|
if defined?(::Rails)
|
23
52
|
config_file = Rails.root.join('config/wechat.yml')
|
24
|
-
|
53
|
+
return YAML.load(ERB.new(File.read(config_file)).result)[Rails.env] if File.exist?(config_file)
|
25
54
|
else
|
26
55
|
rails_config_file = File.join(Dir.getwd, 'config/wechat.yml')
|
27
56
|
home_config_file = File.join(Dir.home, '.wechat.yml')
|
28
|
-
|
29
57
|
if File.exist?(rails_config_file)
|
30
58
|
config = YAML.load(ERB.new(File.read(rails_config_file)).result)['default']
|
31
59
|
if config.present? && (config['appid'] || config['corpid'])
|
32
60
|
puts 'Using rails project config/wechat.yml default setting...'
|
33
|
-
|
34
|
-
config = {}
|
61
|
+
return config
|
35
62
|
end
|
36
63
|
end
|
37
|
-
|
38
|
-
|
39
|
-
config = YAML.load ERB.new(File.read(home_config_file)).result
|
64
|
+
if File.exist?(home_config_file)
|
65
|
+
return YAML.load ERB.new(File.read(home_config_file)).result
|
40
66
|
end
|
41
67
|
end
|
42
|
-
|
43
|
-
config ||= config_from_environment
|
44
|
-
if defined?(::Rails)
|
45
|
-
config[:access_token] ||= Rails.root.join('tmp/access_token').to_s
|
46
|
-
config[:jsapi_ticket] ||= Rails.root.join('tmp/jsapi_ticket').to_s
|
47
|
-
end
|
48
|
-
config.symbolize_keys!
|
49
|
-
OpenStruct.new(config)
|
50
68
|
end
|
51
69
|
|
52
70
|
def self.config_from_environment
|
data/lib/wechat/client.rb
CHANGED
@@ -45,7 +45,8 @@ module Wechat
|
|
45
45
|
# 42001: access_token超时
|
46
46
|
# 40014: 不合法的access_token
|
47
47
|
# 40001, invalid credential, access_token is invalid or not latest hint
|
48
|
-
|
48
|
+
# 48001, api unauthorized hint, for qrcode creation # 71
|
49
|
+
when 42001, 40014, 40001, 48001
|
49
50
|
fail AccessTokenExpiredError
|
50
51
|
else
|
51
52
|
fail ResponseError.new(data['errcode'], data['errmsg'])
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wechat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Skinnyworm
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-11-
|
12
|
+
date: 2015-11-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|