wechat-utils 0.1.4 → 0.2.0
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 +5 -5
- data/lib/wechat/utils.rb +13 -13
- data/lib/wechat/utils/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7aab203d0deeca0b338677d09c3f016b14c84a8ec7a6586c06590fe6ad0f863e
|
4
|
+
data.tar.gz: 55fdf426f53e85bfbaab90a523656ba7939823482d261f2e758078e378675441
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4973714a1ae14d2a41c45d0fd34abe7c2416f3cdb93ac9ea369160492c1f245a205a0ec5fd8e94a215336f2049846f1b2d3f26d36881fb458f29e5259e42965
|
7
|
+
data.tar.gz: 11b171dcef4a4799fd897b22cfc41ac268721cf9902f4998f70d136bc2a01145780ee36750d58bdaf5ef7c3d60fae1145063c3fcb268ecc563fb455f83551882
|
data/lib/wechat/utils.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'json'
|
1
2
|
require 'rest-client'
|
2
3
|
require 'wechat/utils/version'
|
3
4
|
require 'securerandom'
|
@@ -27,42 +28,41 @@ module Wechat
|
|
27
28
|
"https://api.weixin.qq.com/sns/oauth2/access_token?#{hash_to_query query_parts}"
|
28
29
|
end
|
29
30
|
|
30
|
-
def fetch_openid_and_access_token app_id, app_secret, code
|
31
|
+
def fetch_openid_and_access_token app_id, app_secret, code, request_opts: {}
|
31
32
|
url = create_oauth_url_for_openid app_id, app_secret, code
|
32
|
-
response = get_request url
|
33
|
+
response = get_request url, request_opts
|
33
34
|
return response['openid'], response['access_token'], response
|
34
35
|
end
|
35
36
|
|
36
37
|
# access_token is get from oauth
|
37
|
-
def fetch_oauth_user_info access_token, openid
|
38
|
-
get_request "https://api.weixin.qq.com/sns/userinfo?access_token=#{access_token}&openid=#{openid}&lang=zh_CN"
|
38
|
+
def fetch_oauth_user_info access_token, openid, request_opts: {}
|
39
|
+
get_request "https://api.weixin.qq.com/sns/userinfo?access_token=#{access_token}&openid=#{openid}&lang=zh_CN", request_opts
|
39
40
|
end
|
40
41
|
|
41
42
|
# access_token is the global token
|
42
|
-
def fetch_user_info access_token, openid
|
43
|
-
get_request "https://api.weixin.qq.com/cgi-bin/user/info?access_token=#{access_token}&openid=#{openid}&lang=zh_CN"
|
43
|
+
def fetch_user_info access_token, openid, request_opts: {}
|
44
|
+
get_request "https://api.weixin.qq.com/cgi-bin/user/info?access_token=#{access_token}&openid=#{openid}&lang=zh_CN", request_opts
|
44
45
|
end
|
45
46
|
|
46
|
-
def get_request url
|
47
|
+
def get_request url, extra_opts
|
47
48
|
request_opts = {
|
48
49
|
:url => url,
|
49
50
|
:verify_ssl => false,
|
50
51
|
:ssl_version => 'TLSv1',
|
51
52
|
:method => 'GET',
|
52
53
|
:headers => false,
|
53
|
-
:open_timeout => 30,
|
54
54
|
:timeout => 30
|
55
|
-
}
|
55
|
+
}.merge(extra_opts)
|
56
56
|
JSON.parse RestClient::Request.execute(request_opts).body
|
57
57
|
end
|
58
58
|
|
59
|
-
def fetch_jsapi_ticket access_token
|
60
|
-
response = get_request "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=#{access_token}&type=jsapi"
|
59
|
+
def fetch_jsapi_ticket access_token, request_opts: {}
|
60
|
+
response = get_request "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=#{access_token}&type=jsapi", request_opts
|
61
61
|
return response['ticket'], response
|
62
62
|
end
|
63
63
|
|
64
|
-
def fetch_global_access_token appid, secret
|
65
|
-
response = get_request "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=#{appid}&secret=#{secret}"
|
64
|
+
def fetch_global_access_token appid, secret, request_opts: {}
|
65
|
+
response = get_request "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=#{appid}&secret=#{secret}", request_opts
|
66
66
|
return response['access_token'], response
|
67
67
|
end
|
68
68
|
|
data/lib/wechat/utils/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wechat-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oscar Jiang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -119,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
119
|
version: '0'
|
120
120
|
requirements: []
|
121
121
|
rubyforge_project:
|
122
|
-
rubygems_version: 2.
|
122
|
+
rubygems_version: 2.7.7
|
123
123
|
signing_key:
|
124
124
|
specification_version: 4
|
125
125
|
summary: wechat api for remote calls
|