wechat 0.6.10 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -20
- data/README.md +1 -0
- data/lib/wechat/api.rb +2 -2
- data/lib/wechat/api_loader.rb +2 -3
- data/lib/wechat/client.rb +15 -12
- data/lib/wechat/corp_api.rb +4 -4
- data/lib/wechat/responder.rb +3 -15
- data/lib/wechat/ticket/{public_jsapi_ticket.rb → jsapi_ticket.rb} +2 -1
- metadata +15 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7f55b06f42f4f81535e3eac7cb4030d7850758e
|
4
|
+
data.tar.gz: 5b8992563a4e96c2e084a2f371601445678a3a8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 602388ebebfda0bba1b5bc2f7cf7601cb313255acdc658902bd3bab5785c52aa23139bdd9bb503d787175012691cccebf0aa17e0637e2aa84f6e251321c43cdb
|
7
|
+
data.tar.gz: 3700915a52962394b839d77d8b3d6478cdb1df903f5d026910f9bd330755353396c5ae572e199da9f5a8e31bbfe492a0aa4f022bcbc8b7dac50d6f6b268df62f
|
data/CHANGELOG.md
CHANGED
@@ -1,27 +1,8 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
* Support Rails 3.2 again after support Rails 5.0. by @guange2015 #87
|
4
|
-
* Fetch setting from RAILS_ENV first, then fetch default. by @kikyous #85
|
5
|
-
* Warning not support on :scan with regular expression. by @kikyous #84
|
6
|
-
|
7
|
-
## v0.7.1 (released at 1/11/2016)
|
8
|
-
|
9
|
-
* Fix after using http, upload file function break. #78
|
10
|
-
* Add callback function after_wechat_response support. by @zfben #79
|
11
|
-
* Should using department_id instead of departmentid at enterprise api: user_simplelist/user_list.
|
12
|
-
|
13
3
|
## v0.7.0 (released at 1/1/2016)
|
14
4
|
|
15
|
-
* Using [http](https://github.com/httprb/http) instead of rest-client for performance reason.
|
16
|
-
|
17
|
-
## v0.6.10 (released at 1/17/2016)
|
18
|
-
|
19
|
-
* Support Rails 3.2 again after support Rails 5.0. by @guange2015 #87
|
20
|
-
* Fetch setting from RAILS_ENV first, then fetch default. by @kikyous #85
|
21
|
-
* Warning not support on :scan with regular expression. by @kikyous #84
|
22
|
-
|
23
|
-
## v0.6.9 (released at 1/6/2016)
|
24
|
-
|
5
|
+
* Using [http](https://github.com/httprb/http) instead of rest-client for performance reason.
|
25
6
|
* Fix token refresh bug on multi worker. #76
|
26
7
|
* Rewrite the token relative code to add more storage support in future.
|
27
8
|
|
data/README.md
CHANGED
data/lib/wechat/api.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'wechat/api_base'
|
2
2
|
require 'wechat/client'
|
3
3
|
require 'wechat/token/public_access_token'
|
4
|
-
require 'wechat/ticket/
|
4
|
+
require 'wechat/ticket/jsapi_ticket'
|
5
5
|
|
6
6
|
module Wechat
|
7
7
|
class Api < ApiBase
|
@@ -11,7 +11,7 @@ module Wechat
|
|
11
11
|
def initialize(appid, secret, token_file, timeout, skip_verify_ssl, jsapi_ticket_file)
|
12
12
|
@client = Client.new(API_BASE, timeout, skip_verify_ssl)
|
13
13
|
@access_token = Token::PublicAccessToken.new(@client, appid, secret, token_file)
|
14
|
-
@jsapi_ticket = Ticket::
|
14
|
+
@jsapi_ticket = Ticket::JsapiTicket.new(@client, @access_token, jsapi_ticket_file)
|
15
15
|
end
|
16
16
|
|
17
17
|
def groups
|
data/lib/wechat/api_loader.rb
CHANGED
@@ -48,10 +48,9 @@ HELP
|
|
48
48
|
rails_config_file = File.join(Dir.getwd, 'config/wechat.yml')
|
49
49
|
home_config_file = File.join(Dir.home, '.wechat.yml')
|
50
50
|
if File.exist?(rails_config_file)
|
51
|
-
|
52
|
-
config = YAML.load(ERB.new(File.read(rails_config_file)).result)[rails_env]
|
51
|
+
config = YAML.load(ERB.new(File.read(rails_config_file)).result)['default']
|
53
52
|
if config.present? && (config['appid'] || config['corpid'])
|
54
|
-
puts
|
53
|
+
puts 'Using rails project config/wechat.yml default setting...'
|
55
54
|
return config
|
56
55
|
end
|
57
56
|
end
|
data/lib/wechat/client.rb
CHANGED
@@ -1,24 +1,27 @@
|
|
1
|
-
require '
|
1
|
+
require 'http'
|
2
2
|
|
3
3
|
module Wechat
|
4
4
|
class Client
|
5
|
-
attr_reader :base, :
|
5
|
+
attr_reader :base, :ssl_context
|
6
6
|
|
7
7
|
def initialize(base, timeout, skip_verify_ssl)
|
8
8
|
@base = base
|
9
|
-
|
10
|
-
@
|
9
|
+
HTTP.timeout(:global, write: timeout, connect: timeout, read: timeout)
|
10
|
+
@ssl_context = OpenSSL::SSL::SSLContext.new
|
11
|
+
@ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE if skip_verify_ssl
|
11
12
|
end
|
12
13
|
|
13
|
-
def get(path,
|
14
|
-
request(path,
|
15
|
-
|
14
|
+
def get(path, get_header = {})
|
15
|
+
request(path, get_header) do |url, header|
|
16
|
+
params = header.delete(:params)
|
17
|
+
HTTP.headers(header).get(url, params: params, ssl_context: ssl_context)
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
19
|
-
def post(path, payload,
|
20
|
-
request(path,
|
21
|
-
|
21
|
+
def post(path, payload, post_header = {})
|
22
|
+
request(path, post_header) do |url, header|
|
23
|
+
params = header.delete(:params)
|
24
|
+
HTTP.headers(header).post(url, params: params, body: payload, ssl_context: ssl_context)
|
22
25
|
end
|
23
26
|
end
|
24
27
|
|
@@ -30,7 +33,7 @@ module Wechat
|
|
30
33
|
header.merge!(accept: :json)
|
31
34
|
response = yield(url, header)
|
32
35
|
|
33
|
-
fail "Request not OK, response
|
36
|
+
fail "Request not OK, response status #{response.status}" if response.status != 200
|
34
37
|
parse_response(response, as || :json) do |parse_as, data|
|
35
38
|
break data unless parse_as == :json && data['errcode'].present?
|
36
39
|
|
@@ -65,7 +68,7 @@ module Wechat
|
|
65
68
|
data = file
|
66
69
|
|
67
70
|
when :json
|
68
|
-
data = JSON.parse
|
71
|
+
data = JSON.parse response.body.to_s.gsub(/[\u0000-\u001f]+/, '')
|
69
72
|
else
|
70
73
|
data = response.body
|
71
74
|
end
|
data/lib/wechat/corp_api.rb
CHANGED
@@ -90,12 +90,12 @@ module Wechat
|
|
90
90
|
get 'department/list', params: { id: departmentid }
|
91
91
|
end
|
92
92
|
|
93
|
-
def user_simplelist(
|
94
|
-
get 'user/simplelist', params: {
|
93
|
+
def user_simplelist(departmentid, fetch_child = 0, status = 0)
|
94
|
+
get 'user/simplelist', params: { departmentid: departmentid, fetch_child: fetch_child, status: status }
|
95
95
|
end
|
96
96
|
|
97
|
-
def user_list(
|
98
|
-
get 'user/list', params: {
|
97
|
+
def user_list(departmentid, fetch_child = 0, status = 0)
|
98
|
+
get 'user/list', params: { departmentid: departmentid, fetch_child: fetch_child, status: status }
|
99
99
|
end
|
100
100
|
|
101
101
|
def tag_create(tagname, tagid = nil)
|
data/lib/wechat/responder.rb
CHANGED
@@ -8,7 +8,7 @@ module Wechat
|
|
8
8
|
|
9
9
|
included do
|
10
10
|
# Rails 5 remove before_filter and skip_before_filter
|
11
|
-
if
|
11
|
+
if defined?(:skip_before_action)
|
12
12
|
# Rails 5 API mode won't define verify_authenticity_token
|
13
13
|
skip_before_action :verify_authenticity_token unless defined?(:verify_authenticity_token)
|
14
14
|
before_action :verify_signature, only: [:show, :create]
|
@@ -29,13 +29,7 @@ module Wechat
|
|
29
29
|
if with.present?
|
30
30
|
fail 'Only text, event, click, view, scan and batch_job can having :with parameters' unless [:text, :event, :click, :view, :scan, :batch_job].include?(message_type)
|
31
31
|
config.merge!(with: with)
|
32
|
-
if message_type == :scan
|
33
|
-
if with.is_a?(String)
|
34
|
-
self.known_scan_key_lists = with
|
35
|
-
else
|
36
|
-
fail 'on :scan only support string in parameter with, detail see https://github.com/Eric-Guo/wechat/issues/84'
|
37
|
-
end
|
38
|
-
end
|
32
|
+
self.known_scan_key_lists = with if message_type == :scan
|
39
33
|
else
|
40
34
|
fail 'Message type click, view, scan and batch_job must specify :with parameters' if [:click, :view, :scan, :batch_job].include?(message_type)
|
41
35
|
end
|
@@ -47,8 +41,6 @@ module Wechat
|
|
47
41
|
user_defined_view_responders(with) << config
|
48
42
|
when :batch_job
|
49
43
|
user_defined_batch_job_responders(with) << config
|
50
|
-
when :scan
|
51
|
-
user_defined_scan_responders << config
|
52
44
|
when :location
|
53
45
|
user_defined_location_responders << config
|
54
46
|
else
|
@@ -72,10 +64,6 @@ module Wechat
|
|
72
64
|
@batch_job_responders[with] ||= []
|
73
65
|
end
|
74
66
|
|
75
|
-
def user_defined_scan_responders
|
76
|
-
@scan_responders ||= []
|
77
|
-
end
|
78
|
-
|
79
67
|
def user_defined_location_responders
|
80
68
|
@location_responders ||= []
|
81
69
|
end
|
@@ -100,7 +88,7 @@ module Wechat
|
|
100
88
|
elsif 'click' == message[:Event]
|
101
89
|
yield(* match_responders(responders, message[:EventKey]))
|
102
90
|
elsif known_scan_key_lists.include?(message[:EventKey])
|
103
|
-
yield(* known_scan_with_match_responders(
|
91
|
+
yield(* known_scan_with_match_responders(user_defined_responders(:scan), message))
|
104
92
|
elsif 'batch_job_result' == message[:Event]
|
105
93
|
yield(* user_defined_batch_job_responders(message[:BatchJob][:JobType]), message[:BatchJob])
|
106
94
|
elsif 'location' == message[:Event]
|
@@ -2,7 +2,8 @@ require 'wechat/ticket/jsapi_base'
|
|
2
2
|
|
3
3
|
module Wechat
|
4
4
|
module Ticket
|
5
|
-
class
|
5
|
+
class JsapiTicket < JsapiBase
|
6
|
+
# refresh jsapi ticket
|
6
7
|
def refresh
|
7
8
|
data = client.get('ticket/getticket', params: { access_token: access_token.token, type: 'jsapi' })
|
8
9
|
write_ticket_to_file(data)
|
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.
|
4
|
+
version: 0.7.0
|
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: 2016-01-
|
12
|
+
date: 2016-01-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -60,19 +60,25 @@ dependencies:
|
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
|
-
name:
|
63
|
+
name: http
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.0'
|
66
69
|
- - ">="
|
67
70
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
71
|
+
version: 1.0.1
|
69
72
|
type: :runtime
|
70
73
|
prerelease: false
|
71
74
|
version_requirements: !ruby/object:Gem::Requirement
|
72
75
|
requirements:
|
76
|
+
- - "~>"
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '1.0'
|
73
79
|
- - ">="
|
74
80
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
81
|
+
version: 1.0.1
|
76
82
|
- !ruby/object:Gem::Dependency
|
77
83
|
name: rspec-rails
|
78
84
|
requirement: !ruby/object:Gem::Requirement
|
@@ -130,7 +136,7 @@ files:
|
|
130
136
|
- lib/wechat/signature.rb
|
131
137
|
- lib/wechat/ticket/corp_jsapi_ticket.rb
|
132
138
|
- lib/wechat/ticket/jsapi_base.rb
|
133
|
-
- lib/wechat/ticket/
|
139
|
+
- lib/wechat/ticket/jsapi_ticket.rb
|
134
140
|
- lib/wechat/token/access_token_base.rb
|
135
141
|
- lib/wechat/token/corp_access_token.rb
|
136
142
|
- lib/wechat/token/public_access_token.rb
|
@@ -139,14 +145,12 @@ licenses:
|
|
139
145
|
- MIT
|
140
146
|
metadata: {}
|
141
147
|
post_install_message: |-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
1. Scan 2D barcode using new syntax `on :scan, with: 'BINDING_QR_CODE'`
|
148
|
+
*****WECHAT BREAK CHANGE*****
|
149
|
+
1. Scan 2D barcode using new syntax `on :scan, with: 'BINDING_QR_CODE' `
|
146
150
|
instead of previous `on :event, with: 'BINDING_QR_CODE' `.
|
147
151
|
2. Batch job using new syntax `on :batch_job, with: 'replace_user' `
|
148
152
|
instead of previous `on :event, with: 'replace_user' `.
|
149
|
-
|
153
|
+
*****************************
|
150
154
|
rdoc_options: []
|
151
155
|
require_paths:
|
152
156
|
- lib
|