wechat-gate 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +10 -6
- data/RELEASE.md +2 -0
- data/bin/refresh_token_and_ticket +1 -1
- data/lib/wechat_gate/config.rb +9 -9
- data/lib/wechat_gate/controller.rb +1 -1
- data/lib/wechat_gate/message.rb +1 -1
- data/lib/wechat_gate/oauth.rb +4 -4
- data/lib/wechat_gate/send_message.rb +2 -2
- data/lib/wechat_gate/tokens/access_token.rb +1 -1
- data/lib/wechat_gate/tokens/base.rb +2 -2
- data/lib/wechat_gate/version.rb +1 -1
- data/wechat-gate.gemspec +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca58efe7130862ff001bf9c8f1ae6e2fc20862f3
|
4
|
+
data.tar.gz: 588aeee145bb71ff8e552ede1538dac430100cc5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 862464a34266eb84ff53bd07c40f19f3ec67f5ed39c10fd005292a8bbcdbb5b442b2eb8140200734f95dacf3fa2123b826cebade52c00db749a18e72cb37ca7a
|
7
|
+
data.tar.gz: 228643ff98b0d2157c2b53c3b2b380cb536d8d4c1e77cea45e622310f42a3670b5485e2700dd908a1f37b931fda509c59a61940bfbed57f33c1e5207d0d64c7e
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -76,9 +76,11 @@ app_name:
|
|
76
76
|
oauth2_redirect_uri: <%= ENV['WECHAT_APP_NAME_OAUTH2_REDIRECT_URI'] %>
|
77
77
|
```
|
78
78
|
|
79
|
-
然后在ApplicationController
|
79
|
+
然后在ApplicationController中指定当前要读取的公众号名称:
|
80
80
|
|
81
|
+
```
|
81
82
|
self.wechat_gate_app_name = 'eggman'
|
83
|
+
```
|
82
84
|
|
83
85
|
## 后端调用
|
84
86
|
|
@@ -105,21 +107,23 @@ wechat_gate_config.menu_create(MENU_HASH) # 创建菜单
|
|
105
107
|
wechat_gate_config.generate_js_request_params(REFERER_URL) # 返回JS-SDK的验证参数,供前端JS-SDK使用
|
106
108
|
```
|
107
109
|
|
108
|
-
|
110
|
+
当然你也可以手工来初始化配置,甚至指定配置文件的路径:
|
109
111
|
|
110
112
|
```
|
111
|
-
config.
|
112
|
-
config.refresh_jsapi_ticket
|
113
|
+
config = WechatGate::Config.new('eggman', '/path/to/what/ever/you/want.yml')
|
113
114
|
```
|
114
115
|
|
115
|
-
|
116
|
+
access_token和JS_SDK中ticket都有过期时间和刷新次数限制,这里已经考虑了,你可以不用管,如果你想手工刷新,可以这样:
|
116
117
|
|
117
118
|
```
|
118
|
-
config
|
119
|
+
config.refresh_access_token
|
120
|
+
config.refresh_jsapi_ticket
|
119
121
|
```
|
120
122
|
|
121
123
|
**配置文件支持erb**
|
122
124
|
|
125
|
+
> 更多接口和文档请直接看源码,写的很详细
|
126
|
+
|
123
127
|
## JS-SDK
|
124
128
|
|
125
129
|
```ruby
|
data/RELEASE.md
ADDED
@@ -5,7 +5,7 @@ require "wechat-gate"
|
|
5
5
|
|
6
6
|
# usage:
|
7
7
|
# output_type: "/file/to/write/js/variable" | ruby | js
|
8
|
-
# refresh_token_and_ticket
|
8
|
+
# refresh_token_and_ticket app_name page_url output_type
|
9
9
|
#
|
10
10
|
|
11
11
|
WechatGate::Config.new(ARGV[0]) do |config|
|
data/lib/wechat_gate/config.rb
CHANGED
@@ -15,8 +15,8 @@ require 'wechat_gate/controller'
|
|
15
15
|
module WechatGate
|
16
16
|
class Config
|
17
17
|
|
18
|
-
attr_reader :
|
19
|
-
attr_reader :
|
18
|
+
attr_reader :app_name
|
19
|
+
attr_reader :config
|
20
20
|
attr_reader :output_type
|
21
21
|
|
22
22
|
include WechatGate::Tokens::AccessToken
|
@@ -29,7 +29,7 @@ module WechatGate
|
|
29
29
|
include WechatGate::Message
|
30
30
|
include WechatGate::SendMessage
|
31
31
|
|
32
|
-
def initialize
|
32
|
+
def initialize app_name, config_file = nil
|
33
33
|
unless config_file
|
34
34
|
if defined?(Rails)
|
35
35
|
config_file = "#{Rails.root}/config/wechat.yml"
|
@@ -43,17 +43,17 @@ module WechatGate
|
|
43
43
|
|
44
44
|
config_text = ERB.new(File.read(config_file)).result
|
45
45
|
configs = YAML.load(config_text)
|
46
|
-
unless configs[
|
47
|
-
raise Exception::ConfigException, "no configuration found for app: #{
|
46
|
+
unless configs[app_name]
|
47
|
+
raise Exception::ConfigException, "no configuration found for app: #{app_name}!"
|
48
48
|
end
|
49
49
|
|
50
|
-
@
|
51
|
-
configs[
|
50
|
+
@config = if defined?(Rails)
|
51
|
+
configs[app_name][Rails.env] || configs[app_name]
|
52
52
|
else
|
53
|
-
configs[
|
53
|
+
configs[app_name]
|
54
54
|
end
|
55
55
|
|
56
|
-
@
|
56
|
+
@app_name = app_name
|
57
57
|
|
58
58
|
yield(self) if block_given?
|
59
59
|
end
|
data/lib/wechat_gate/message.rb
CHANGED
@@ -39,7 +39,7 @@ module WechatGate
|
|
39
39
|
%Q{
|
40
40
|
<xml>
|
41
41
|
<ToUserName><![CDATA[#{to}]]></ToUserName>
|
42
|
-
<FromUserName><![CDATA[#{self.
|
42
|
+
<FromUserName><![CDATA[#{self.config['wechat_id']}]]></FromUserName>
|
43
43
|
<CreateTime>#{Time.now.to_i}</CreateTime>
|
44
44
|
<MsgType><![CDATA[#{type}]]></MsgType>
|
45
45
|
#{content}
|
data/lib/wechat_gate/oauth.rb
CHANGED
@@ -21,11 +21,11 @@ module WechatGate
|
|
21
21
|
def oauth2_entrance_url(ops = {})
|
22
22
|
ops = {
|
23
23
|
state: 'empty', # 自定义参数值
|
24
|
-
redirect_uri: self.
|
24
|
+
redirect_uri: self.config["oauth2_redirect_uri"],
|
25
25
|
scope: 'snsapi_base' # snsapi_base | snsapi_userinfo
|
26
26
|
}.merge(ops)
|
27
27
|
|
28
|
-
"https://open.weixin.qq.com/connect/oauth2/authorize?appid=#{self.
|
28
|
+
"https://open.weixin.qq.com/connect/oauth2/authorize?appid=#{self.config['app_id']}&redirect_uri=#{CGI.escape(ops[:redirect_uri])}&response_type=code&scope=#{ops[:scope]}&state=#{ops[:state]}#wechat_redirect"
|
29
29
|
end
|
30
30
|
|
31
31
|
# TODO
|
@@ -46,7 +46,7 @@ module WechatGate
|
|
46
46
|
# 此时这里的access_token意义就不大了,这里的access_token和Tokens::AccessToken的token是完全不一样的。
|
47
47
|
#
|
48
48
|
def oauth2_access_token(code)
|
49
|
-
WechatGate::Request.send("https://api.weixin.qq.com/sns/oauth2/access_token?appid=#{self.
|
49
|
+
WechatGate::Request.send("https://api.weixin.qq.com/sns/oauth2/access_token?appid=#{self.config['app_id']}&secret=#{self.config['app_secret']}&code=#{code}&grant_type=authorization_code")
|
50
50
|
end
|
51
51
|
|
52
52
|
# access_token拥有较短的有效期,当access_token超时后,可以使用refresh_token进行刷新,
|
@@ -67,7 +67,7 @@ module WechatGate
|
|
67
67
|
# "scope":"SCOPE"
|
68
68
|
# }
|
69
69
|
def oauth2_refresh_access_token(refresh_token)
|
70
|
-
WechatGate::Request.send("https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=#{self.
|
70
|
+
WechatGate::Request.send("https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=#{self.config['app_id']}&grant_type=refresh_token&refresh_token=#{refresh_token}")
|
71
71
|
end
|
72
72
|
|
73
73
|
# 获取用户信息
|
@@ -112,8 +112,8 @@ module WechatGate
|
|
112
112
|
url: "https://mp.weixin.qq.com/cgi-bin/login?lang=zh_CN",
|
113
113
|
verify_ssl: false,
|
114
114
|
payload: {
|
115
|
-
username: self.
|
116
|
-
pwd: Digest::MD5.hexdigest(self.
|
115
|
+
username: self.config['wechat_login_username'],
|
116
|
+
pwd: Digest::MD5.hexdigest(self.config['wechat_login_password']),
|
117
117
|
imgcode: "",
|
118
118
|
f: "json"
|
119
119
|
}.to_query,
|
@@ -15,7 +15,7 @@ module WechatGate
|
|
15
15
|
|
16
16
|
class Get < WechatGate::Tokens::Base
|
17
17
|
def url
|
18
|
-
"https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=#{@config.
|
18
|
+
"https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=#{@config.config['app_id']}&secret=#{@config.config['app_secret']}"
|
19
19
|
end
|
20
20
|
|
21
21
|
def save response
|
@@ -41,8 +41,8 @@ module WechatGate
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def saved_file
|
44
|
-
# File.expand_path("../../../../data/APP-#{@config.
|
45
|
-
"/tmp/APP-#{@config.
|
44
|
+
# File.expand_path("../../../../data/APP-#{@config.app_name}-#{self.class.name}", __FILE__)
|
45
|
+
"/tmp/APP-#{@config.app_name}-#{self.class.name}-#{@config.config['app_id']}"
|
46
46
|
end
|
47
47
|
|
48
48
|
def is_expired?
|
data/lib/wechat_gate/version.rb
CHANGED
data/wechat-gate.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Lei Lee"]
|
10
10
|
spec.email = ["mytake6@gmail.com"]
|
11
11
|
|
12
|
-
spec.summary = %q{
|
12
|
+
spec.summary = %q{隔壁家老李的微信开发Ruby Gem}
|
13
13
|
spec.description = %q{接口简单易用,实在是微信开发必备之好Gem}
|
14
14
|
spec.homepage = "https://github.com/eggmantv/wechat_gate"
|
15
15
|
spec.license = "MIT"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wechat-gate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lei Lee
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -79,6 +79,7 @@ files:
|
|
79
79
|
- Gemfile.lock
|
80
80
|
- LICENSE.txt
|
81
81
|
- README.md
|
82
|
+
- RELEASE.md
|
82
83
|
- Rakefile
|
83
84
|
- bin/console
|
84
85
|
- bin/refresh_token_and_ticket
|
@@ -124,5 +125,5 @@ rubyforge_project:
|
|
124
125
|
rubygems_version: 2.5.1
|
125
126
|
signing_key:
|
126
127
|
specification_version: 4
|
127
|
-
summary:
|
128
|
+
summary: 隔壁家老李的微信开发Ruby Gem
|
128
129
|
test_files: []
|