wechat 0.6.6 → 0.6.7

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
  SHA1:
3
- metadata.gz: 38d17166a10c49de46d4e87c787b0869163e13d3
4
- data.tar.gz: 3c80f22d8adc8219c4e0b32824d2df63269a6aa6
3
+ metadata.gz: eee061e4522d5960256e017183c61f615ef94a0d
4
+ data.tar.gz: 510a350df936a6d4d9465997ba253b4ef3e78634
5
5
  SHA512:
6
- metadata.gz: bf6b9c04a09cc228db3366c6b311731404af1a2e01581c5602d96897be3a3ddb3b52d9e0c3e4013c6307bc135f3ba8db7b85ecfa3f8880f3b9a5179e8c933619
7
- data.tar.gz: d1091b3c0c44c974c42c9e88a16eadcf256d00c4108c527dc9b3969e24f22e4b7d24a559cf3f61779a09a5bbee90cdd744aa60f4d9522ee5ecb33e4239caa732
6
+ metadata.gz: f21668a1dc3cbb3fac9336e57d214a4d9d99a1814e30e1474b1a0e9d12dd47c47bc69c5f6af02c4b6bb89f09ab76ade708ebaebfb838eba4110268730ac69688
7
+ data.tar.gz: efa6851ddb7f3f948daccdc148c412f8a73e2211c123c4417ddd3e7195cdeb3030e8f046162328e3c11ded6b96cf3c5143e35d92757fe6770f530ef18ed876a4
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.6.7 (released at 12/18/2015)
4
+
5
+ * Add timeout configuration option, close #74
6
+ * New getuserinfo and oauth2_url to support getting FromUserName from web page.
7
+
3
8
  ## v0.6.6 (released at 12/15/2015)
4
9
 
5
10
  * Add jsapi_ticket support for Enterprise Account
data/README.md CHANGED
@@ -118,7 +118,8 @@ production:
118
118
  agentid: <%= ENV['WECHAT_AGENTID'] %>
119
119
  access_token: <%= ENV['WECHAT_ACCESS_TOKEN'] %>
120
120
  token: <%= ENV['WECHAT_TOKEN'] %>
121
- skip_verify_ssl: false
121
+ timeout: 30,
122
+ skip_verify_ssl: true
122
123
  encoding_aes_key: <%= ENV['WECHAT_ENCODING_AES_KEY'] %>
123
124
  jsapi_ticket: <%= ENV['WECHAT_JSAPI_TICKET'] %>
124
125
 
@@ -133,6 +134,10 @@ test:
133
134
 
134
135
  注意在Rails项目根目录下运行`wechat`命令行工具会优先使用`config/wechat.yml`中的`default`配置,如果失败则使用`~\.wechat.yml`中的配置,以便于在生产环境下管理多个微信账号应用。
135
136
 
137
+ ##### 配置微信服务器超时
138
+
139
+ 微信服务器有时请求会花很长时间,如果不配置,默认为20秒,可视情况配置。
140
+
136
141
  ##### 配置跳过SSL认证
137
142
 
138
143
  Wechat服务器有报道曾出现[RestClient::SSLCertificateNotVerified](http://qydev.weixin.qq.com/qa/index.php?qa=11037)错误,此时可以选择关闭SSL验证。`skip_verify_ssl: true`
@@ -191,6 +196,7 @@ Wechat commands:
191
196
  wechat menu # 当前菜单
192
197
  wechat menu_create [MENU_YAML_PATH] # 创建菜单
193
198
  wechat menu_delete # 删除菜单
199
+ wechat oauth2_url [REDIRECT_URI] # 生成OAuth2.0验证URL
194
200
  wechat qrcode_create_limit_scene [SCENE_ID_OR_STR] # 请求永久二维码
195
201
  wechat qrcode_create_scene [SCENE_ID, EXPIRE_SECONDS] # 请求临时二维码
196
202
  wechat qrcode_download [TICKET, QR_CODE_PIC_PATH] # 通过ticket下载二维码
@@ -236,6 +242,7 @@ Wechat commands:
236
242
  wechat menu_create [MENU_YAML_PATH] # 创建菜单
237
243
  wechat menu_delete # 删除菜单
238
244
  wechat message_send [OPENID, TEXT_MESSAGE] # 发送文字消息
245
+ wechat oauth2_url [REDIRECT_URI] # 生成OAuth2.0验证URL
239
246
  wechat qrcode_download [TICKET, QR_CODE_PIC_PATH] # 通过ticket下载二维码
240
247
  wechat tag [TAG_ID] # 获取标签成员
241
248
  wechat tag_add_department [TAG_ID, PARTY_IDS] # 增加标签部门
data/bin/wechat CHANGED
@@ -13,6 +13,7 @@ require 'active_support/json'
13
13
  require 'fileutils'
14
14
  require 'yaml'
15
15
  require 'wechat/api_loader'
16
+ require 'cgi'
16
17
 
17
18
  class App < Thor
18
19
  package_name 'Wechat'
@@ -284,6 +285,12 @@ class App < Thor
284
285
  puts wechat_api.user(open_id)
285
286
  end
286
287
 
288
+ desc 'oauth2_url [REDIRECT_URI]', '生成OAuth2.0验证URL'
289
+ def oauth2_url(redirect_uri)
290
+ appid = Wechat.config.corpid || Wechat.config.appid
291
+ puts oauth2_url(redirect_uri, appid)
292
+ end
293
+
287
294
  desc 'user_update_remark [OPEN_ID, REMARK]', '设置备注名'
288
295
  def user_update_remark(openid, remark)
289
296
  puts wechat_api.user_update_remark(openid, remark)
@@ -6,6 +6,7 @@ module ActionController
6
6
  self.corpid = opts[:corpid] || Wechat.config.corpid
7
7
  self.agentid = opts[:agentid] || Wechat.config.agentid
8
8
  self.encrypt_mode = opts[:encrypt_mode] || Wechat.config.encrypt_mode || corpid.present?
9
+ self.timeout = opts[:timeout] || 20
9
10
  self.skip_verify_ssl = opts[:skip_verify_ssl]
10
11
  self.token = opts[:token] || Wechat.config.token
11
12
  self.encoding_aes_key = opts[:encoding_aes_key] || Wechat.config.encoding_aes_key
@@ -14,9 +15,9 @@ module ActionController
14
15
  self.wechat = Wechat.api
15
16
  else
16
17
  if corpid.present?
17
- self.wechat = Wechat::CorpApi.new(corpid, opts[:corpsecret], opts[:access_token], agentid, skip_verify_ssl, opts[:jsapi_ticket])
18
+ self.wechat = Wechat::CorpApi.new(corpid, opts[:corpsecret], opts[:access_token], agentid, timeout, skip_verify_ssl, opts[:jsapi_ticket])
18
19
  else
19
- self.wechat = Wechat::Api.new(opts[:appid], opts[:secret], opts[:access_token], skip_verify_ssl, opts[:jsapi_ticket])
20
+ self.wechat = Wechat::Api.new(opts[:appid], opts[:secret], opts[:access_token], timeout, skip_verify_ssl, opts[:jsapi_ticket])
20
21
  end
21
22
  end
22
23
  end
@@ -19,6 +19,8 @@ production:
19
19
  # appid: <%= ENV['WECHAT_APPID'] %>
20
20
  # secret: <%= ENV['WECHAT_APP_SECRET'] %>
21
21
  token: <%%= ENV['WECHAT_TOKEN'] %>
22
+ timeout: 30,
23
+ skip_verify_ssl: true
22
24
  access_token: <%%= ENV['WECHAT_ACCESS_TOKEN'] %>
23
25
  encrypt_mode: false # if true must fill encoding_aes_key
24
26
  encoding_aes_key: <%%= ENV['WECHAT_ENCODING_AES_KEY'] %>
@@ -8,8 +8,8 @@ module Wechat
8
8
  API_BASE = 'https://api.weixin.qq.com/cgi-bin/'
9
9
  OAUTH2_BASE = 'https://api.weixin.qq.com/sns/oauth2/'
10
10
 
11
- def initialize(appid, secret, token_file, skip_verify_ssl, jsapi_ticket_file)
12
- @client = Client.new(API_BASE, skip_verify_ssl)
11
+ def initialize(appid, secret, token_file, timeout, skip_verify_ssl, jsapi_ticket_file)
12
+ @client = Client.new(API_BASE, timeout, skip_verify_ssl)
13
13
  @access_token = AccessToken.new(@client, appid, secret, token_file)
14
14
  @jsapi_ticket = JsapiTicket.new(@client, @access_token, jsapi_ticket_file)
15
15
  end
@@ -7,9 +7,9 @@ module Wechat
7
7
  js_token_file = options[:js_token_file] || c.jsapi_ticket || '/var/tmp/wechat_jsapi_ticket'
8
8
 
9
9
  if c.appid && c.secret && token_file.present?
10
- Wechat::Api.new(c.appid, c.secret, token_file, c.skip_verify_ssl, js_token_file)
10
+ Wechat::Api.new(c.appid, c.secret, token_file, c.timeout, c.skip_verify_ssl, js_token_file)
11
11
  elsif c.corpid && c.corpsecret && token_file.present?
12
- Wechat::CorpApi.new(c.corpid, c.corpsecret, token_file, c.agentid, c.skip_verify_ssl, js_token_file)
12
+ Wechat::CorpApi.new(c.corpid, c.corpsecret, token_file, c.agentid, c.timeout, c.skip_verify_ssl, js_token_file)
13
13
  else
14
14
  puts <<-HELP
15
15
  Need create ~/.wechat.yml with wechat appid and secret
@@ -35,6 +35,7 @@ HELP
35
35
  config[:access_token] ||= Rails.root.join('tmp/access_token').to_s
36
36
  config[:jsapi_ticket] ||= Rails.root.join('tmp/jsapi_ticket').to_s
37
37
  end
38
+ config[:timeout] ||= 20
38
39
  config.symbolize_keys!
39
40
  @config = OpenStruct.new(config)
40
41
  end
@@ -68,6 +69,7 @@ HELP
68
69
  token: ENV['WECHAT_TOKEN'],
69
70
  access_token: ENV['WECHAT_ACCESS_TOKEN'],
70
71
  encrypt_mode: ENV['WECHAT_ENCRYPT_MODE'],
72
+ timeout: ENV['WECHAT_TIMEOUT'],
71
73
  skip_verify_ssl: ENV['WECHAT_SKIP_VERIFY_SSL'],
72
74
  encoding_aes_key: ENV['WECHAT_ENCODING_AES_KEY'],
73
75
  jsapi_ticket: ENV['WECHAT_JSAPI_TICKET'] }
@@ -2,30 +2,23 @@ require 'rest_client'
2
2
 
3
3
  module Wechat
4
4
  class Client
5
- attr_reader :base, :verify_ssl
5
+ attr_reader :base, :timeout, :verify_ssl
6
6
 
7
- def initialize(base, skip_verify_ssl)
7
+ def initialize(base, timeout, skip_verify_ssl)
8
8
  @base = base
9
- @verify_ssl = !skip_verify_ssl
9
+ @timeout = timeout
10
+ @verify_ssl = skip_verify_ssl ? OpenSSL::SSL::VERIFY_NONE : OpenSSL::SSL::VERIFY_PEER
10
11
  end
11
12
 
12
13
  def get(path, header = {})
13
14
  request(path, header) do |url, header|
14
- if verify_ssl
15
- RestClient.get(url, header)
16
- else
17
- RestClient::Request.execute(url: url, method: :get, headers: header, verify_ssl: OpenSSL::SSL::VERIFY_NONE)
18
- end
15
+ RestClient::Request.execute(method: :get, url: url, headers: header, timeout: timeout, verify_ssl: verify_ssl)
19
16
  end
20
17
  end
21
18
 
22
19
  def post(path, payload, header = {})
23
20
  request(path, header) do |url, header|
24
- if verify_ssl
25
- RestClient.post(url, payload, header)
26
- else
27
- RestClient::Request.execute(url: url, method: :post, payload: payload, headers: header, verify_ssl: OpenSSL::SSL::VERIFY_NONE)
28
- end
21
+ RestClient::Request.execute(method: :post, url: url, payload: payload, headers: header, timeout: timeout, verify_ssl: verify_ssl)
29
22
  end
30
23
  end
31
24
 
@@ -2,6 +2,7 @@ require 'wechat/api_base'
2
2
  require 'wechat/client'
3
3
  require 'wechat/access_token'
4
4
  require 'wechat/corp_jsapi_ticket'
5
+ require 'cgi'
5
6
 
6
7
  module Wechat
7
8
  class CorpAccessToken < AccessToken
@@ -18,8 +19,8 @@ module Wechat
18
19
 
19
20
  API_BASE = 'https://qyapi.weixin.qq.com/cgi-bin/'
20
21
 
21
- def initialize(appid, secret, token_file, agentid, skip_verify_ssl, jsapi_ticket_file)
22
- @client = Client.new(API_BASE, skip_verify_ssl)
22
+ def initialize(appid, secret, token_file, agentid, timeout, skip_verify_ssl, jsapi_ticket_file)
23
+ @client = Client.new(API_BASE, timeout, skip_verify_ssl)
23
24
  @access_token = CorpAccessToken.new(@client, appid, secret, token_file)
24
25
  @agentid = agentid
25
26
  @jsapi_ticket = CorpJsapiTicket.new(@client, @access_token, jsapi_ticket_file)
@@ -37,6 +38,15 @@ module Wechat
37
38
  get 'user/get', params: { userid: userid }
38
39
  end
39
40
 
41
+ def getuserinfo(code)
42
+ get 'user/getuserinfo', params: { code: code }
43
+ end
44
+
45
+ def oauth2_url(redirect_uri, appid)
46
+ redirect_uri = CGI.escape(redirect_uri)
47
+ "https://open.weixin.qq.com/connect/oauth2/authorize?appid=#{appid}&redirect_uri=#{redirect_uri}&response_type=code&scope=snsapi_base#wechat_redirect"
48
+ end
49
+
40
50
  def convert_to_openid(userid)
41
51
  post 'user/convert_to_openid', JSON.generate(userid: userid, agentid: agentid)
42
52
  end
@@ -12,7 +12,7 @@ module Wechat
12
12
  end
13
13
 
14
14
  module ClassMethods
15
- attr_accessor :wechat, :token, :corpid, :agentid, :encrypt_mode, :skip_verify_ssl, :encoding_aes_key
15
+ attr_accessor :wechat, :token, :corpid, :agentid, :encrypt_mode, :timeout, :skip_verify_ssl, :encoding_aes_key
16
16
 
17
17
  def on(message_type, with: nil, respond: nil, &block)
18
18
  fail 'Unknow message type' unless [:text, :image, :voice, :video, :link, :event, :click, :view, :scan, :batch_job, :location, :fallback].include?(message_type)
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.6
4
+ version: 0.6.7
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-12-15 00:00:00.000000000 Z
12
+ date: 2015-12-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport