weixin_js_sdk 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +11 -3
- data/lib/weixin_js_sdk/access_token.rb +13 -10
- data/lib/weixin_js_sdk/errors.rb +1 -1
- data/lib/weixin_js_sdk/signature.rb +1 -3
- data/lib/weixin_js_sdk/ticket.rb +13 -9
- data/lib/weixin_js_sdk/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec9759260f854f08d5fc61c89030156e39216add
|
4
|
+
data.tar.gz: 7531d01eb33b517e15754fc90747b474596ee447
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e47835f4c5e060ba8b292a00438bb07ff8a4b12cd0214b46b85858cbc10c40c8000c392ab300ece5a4d9aa00e659076a453cfb69eb5effb4e642bb972ef39146
|
7
|
+
data.tar.gz: 9748612a4ba156f49715fd446df638d308ffd74540fb8f912971218cb33b6ca15f2877bb5ae5fd7e99f1de250b670d00d98648ddf4d69fa2153086c3a0e4d787
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -30,22 +30,30 @@ Or install it yourself as:
|
|
30
30
|
access_token = WeixinJsSDK::AccessToken.new(
|
31
31
|
app_id: ENV['WEIXIN_APP_ID'],
|
32
32
|
app_secret: ENV['WEIXIN_APP_SECRET']
|
33
|
-
)
|
33
|
+
)
|
34
|
+
#=> #<WeixinJsSDK::AccessToken:0x007ff9c488a111>
|
35
|
+
access_token.token
|
34
36
|
#=> xxx
|
37
|
+
access_token.expires_in
|
38
|
+
#=> 7200
|
35
39
|
```
|
36
40
|
|
37
41
|
* Fetch Ticket
|
38
42
|
|
39
43
|
```ruby
|
40
|
-
ticket = WeixinJsSDK::Ticket.new(access_token: access_token)
|
44
|
+
ticket = WeixinJsSDK::Ticket.new(access_token: access_token.token)
|
45
|
+
#=> #<WeixinJsSDK::Ticket:0x007fe62d133c68>
|
46
|
+
ticket.token
|
41
47
|
#=> xxx
|
48
|
+
ticket.expires_in
|
49
|
+
#=> 7200
|
42
50
|
```
|
43
51
|
|
44
52
|
* Generate Signature
|
45
53
|
|
46
54
|
```ruby
|
47
55
|
signature = WeixinJsSDK::Signature.new(
|
48
|
-
ticket: ticket,
|
56
|
+
ticket: ticket.token,
|
49
57
|
nonce_str: 'Wm3WZYTPz0wzccnW',
|
50
58
|
timestamp: '1414587457',
|
51
59
|
url: 'http://mp.weixin.qq.com'
|
@@ -2,23 +2,26 @@ module WeixinJsSDK
|
|
2
2
|
class AccessToken
|
3
3
|
URI_TEMPLATE = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%{app_id}&secret=%{app_secret}'.freeze
|
4
4
|
|
5
|
-
|
6
|
-
@app_id = app_id
|
7
|
-
@app_secret = app_secret
|
8
|
-
end
|
5
|
+
attr_reader :token, :expires_in
|
9
6
|
|
10
|
-
def
|
7
|
+
def initialize(app_id: '', app_secret: '')
|
11
8
|
url = URI_TEMPLATE % {
|
12
|
-
app_id:
|
13
|
-
app_secret:
|
9
|
+
app_id: app_id,
|
10
|
+
app_secret: app_secret
|
14
11
|
}
|
15
12
|
|
16
13
|
json = Util.get_json(url)
|
17
14
|
|
18
|
-
|
19
|
-
expires_in = json['expires_in']
|
15
|
+
@token = json['access_token']
|
16
|
+
@expires_in = json['expires_in']
|
17
|
+
end
|
20
18
|
|
21
|
-
|
19
|
+
# <b>DEPRECATED:</b> Please use <tt>token</tt> instead.
|
20
|
+
def fetch
|
21
|
+
warn "[DEPRECATION] `fetch` is deprecated. Please use `token` instead."
|
22
|
+
token
|
22
23
|
end
|
24
|
+
|
25
|
+
alias_method :access_token, :token
|
23
26
|
end
|
24
27
|
end
|
data/lib/weixin_js_sdk/errors.rb
CHANGED
@@ -5,7 +5,7 @@ module WeixinJsSDK
|
|
5
5
|
class InvalidRequest < Standard
|
6
6
|
DOC_URI = 'http://mp.weixin.qq.com/wiki/17/fa4e1434e57290788bde25603fa2fcbd.html'.freeze
|
7
7
|
|
8
|
-
def initialize(error_code
|
8
|
+
def initialize(error_code: '', message: '')
|
9
9
|
@error_code = error_code
|
10
10
|
@message = message
|
11
11
|
end
|
@@ -4,7 +4,7 @@ module WeixinJsSDK
|
|
4
4
|
class Signature
|
5
5
|
TEMPLATE = 'jsapi_ticket=%{jsapi_ticket}&noncestr=%{nonce_str}×tamp=%{timestamp}&url=%{url}'.freeze
|
6
6
|
|
7
|
-
def initialize(ticket
|
7
|
+
def initialize(ticket: '', nonce_str: '', timestamp: '', url: '')
|
8
8
|
@ticket = ticket
|
9
9
|
@nonce_str = nonce_str
|
10
10
|
@timestamp = timestamp
|
@@ -19,8 +19,6 @@ module WeixinJsSDK
|
|
19
19
|
url: @url
|
20
20
|
}
|
21
21
|
|
22
|
-
puts str
|
23
|
-
|
24
22
|
Digest::SHA1.hexdigest(str)
|
25
23
|
end
|
26
24
|
end
|
data/lib/weixin_js_sdk/ticket.rb
CHANGED
@@ -2,21 +2,25 @@ module WeixinJsSDK
|
|
2
2
|
class Ticket
|
3
3
|
URI_TEMPLATE = 'https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=%{access_token}&type=jsapi'.freeze
|
4
4
|
|
5
|
-
|
6
|
-
@access_token = access_token
|
7
|
-
end
|
5
|
+
attr_reader :token, :expires_in
|
8
6
|
|
9
|
-
def
|
7
|
+
def initialize(access_token: '')
|
10
8
|
url = URI_TEMPLATE % {
|
11
|
-
access_token:
|
9
|
+
access_token: access_token
|
12
10
|
}
|
13
11
|
|
14
|
-
json = Util.get_json(url)
|
12
|
+
json = Util.get_json(url) rescue {}
|
15
13
|
|
16
|
-
|
17
|
-
expires_in = json['expires_in']
|
14
|
+
@token = json['ticket']
|
15
|
+
@expires_in = json['expires_in']
|
16
|
+
end
|
18
17
|
|
19
|
-
|
18
|
+
# <b>DEPRECATED:</b> Please use <tt>token</tt> instead.
|
19
|
+
def fetch
|
20
|
+
warn "[DEPRECATION] `fetch` is deprecated. Please use `token` instead."
|
21
|
+
token
|
20
22
|
end
|
23
|
+
|
24
|
+
alias_method :ticket, :token
|
21
25
|
end
|
22
26
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: weixin_js_sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jun Lin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -107,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
107
|
version: '0'
|
108
108
|
requirements: []
|
109
109
|
rubyforge_project:
|
110
|
-
rubygems_version: 2.
|
110
|
+
rubygems_version: 2.4.5
|
111
111
|
signing_key:
|
112
112
|
specification_version: 4
|
113
113
|
summary: A Weixin JS-SDK toolkit.
|