wx_miniprogram 0.1.4 → 0.1.5
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/README.md +3 -6
- data/lib/wx_miniprogram/client.rb +5 -5
- data/lib/wx_miniprogram/login.rb +5 -3
- data/lib/wx_miniprogram/open_api.rb +9 -6
- data/lib/wx_miniprogram/qrcode.rb +46 -0
- data/lib/wx_miniprogram/token.rb +17 -11
- data/lib/wx_miniprogram/url.rb +37 -0
- data/lib/wx_miniprogram/user_info.rb +6 -2
- data/lib/wx_miniprogram/util.rb +1 -1
- data/lib/wx_miniprogram/version.rb +1 -1
- metadata +3 -2
- data/.rspec +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4dfe6416efc7eca67f0ce96911661100e1e4399698ce7ba2d2253c4d2084505f
|
4
|
+
data.tar.gz: 32c49e7498321c94bf07e308aac72d229a5e564718a26a9e63a55bc5a32c3f26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37f339d883fe1a2a9addeaec9dee48841950f957b30a59c05e8de0dfe6600f27203a0de6c767363d7edb07cde839e3565b6679e7e446e5995f04bc709d16000f
|
7
|
+
data.tar.gz: 44ad9473e84a5c30a4f56f9f131fe93225613b7f8d45d9d79875253625262baab8777af2422f24feedbab26936eb462e05eee77d038af7fde9db2db2a2d6565d
|
data/README.md
CHANGED
@@ -8,7 +8,9 @@ TODO: 小程序码与小程序连接、小程序客服、消息相关、小程
|
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
11
|
+
```shell
|
11
12
|
gem install wx_miniprogram
|
13
|
+
```
|
12
14
|
|
13
15
|
## Usage
|
14
16
|
|
@@ -16,19 +18,14 @@ gem install wx_miniprogram
|
|
16
18
|
|
17
19
|
```ruby
|
18
20
|
client = WxMiniprogram::Client.new("appid", "secret")
|
19
|
-
|
20
|
-
# Token
|
21
21
|
# 获取Token
|
22
22
|
client.get_access_token!
|
23
23
|
# 获取稳定版Token
|
24
24
|
client.get_stable_access_token!
|
25
25
|
# 刷新Token
|
26
26
|
client.refresh_access_token!
|
27
|
-
|
28
|
-
# 用户信息
|
29
27
|
# 获取插件用户openpid
|
30
28
|
client.get_plugin_open_pid("openid")
|
31
|
-
|
32
29
|
# 检查加密信息
|
33
30
|
client.check_encrypted_data("encoded_str")
|
34
31
|
|
@@ -37,7 +34,7 @@ client.check_encrypted_data("encoded_str")
|
|
37
34
|
```
|
38
35
|
## Test
|
39
36
|
|
40
|
-
|
37
|
+
TODO
|
41
38
|
|
42
39
|
设置环境变量 WX_APPID 和 WX_SECRET
|
43
40
|
|
@@ -31,7 +31,7 @@ module WxMiniprogram
|
|
31
31
|
begin
|
32
32
|
send(origin_method, args)
|
33
33
|
rescue ApiError => e
|
34
|
-
puts "[debug]: #{e}" if @debug
|
34
|
+
$stderr.puts "[debug]: #{e}" if @debug
|
35
35
|
false
|
36
36
|
end
|
37
37
|
else
|
@@ -45,20 +45,20 @@ module WxMiniprogram
|
|
45
45
|
end
|
46
46
|
|
47
47
|
private
|
48
|
-
def get(path, body: nil, query: nil, need_access_token:
|
48
|
+
def get(path, body: nil, query: nil, need_access_token: true)
|
49
49
|
need_access_token && valid
|
50
50
|
resp = request(path, body: body, query: query, method: "get")
|
51
51
|
if !resp["errcode"].nil? && resp["errcode"] != 0
|
52
|
-
raise ApiError, resp
|
52
|
+
raise ApiError, resp.to_s
|
53
53
|
end
|
54
54
|
resp
|
55
55
|
end
|
56
56
|
|
57
|
-
def post(path, body: nil, query: nil, need_access_token:
|
57
|
+
def post(path, body: nil, query: nil, need_access_token: true)
|
58
58
|
need_access_token && valid
|
59
59
|
resp = request(path, body: body, query: query, method: "post")
|
60
60
|
if !resp["errcode"].nil? && resp["errcode"] != 0
|
61
|
-
raise ApiError, resp
|
61
|
+
raise ApiError, resp.to_s
|
62
62
|
end
|
63
63
|
resp
|
64
64
|
end
|
data/lib/wx_miniprogram/login.rb
CHANGED
@@ -8,7 +8,9 @@ module WxMiniprogram
|
|
8
8
|
:secret => @secret,
|
9
9
|
:js_code => js_code,
|
10
10
|
:grant_type => "authorization_code",
|
11
|
-
}
|
11
|
+
},
|
12
|
+
need_access_token: false
|
13
|
+
)
|
12
14
|
end
|
13
15
|
|
14
16
|
def check_session_key!(openid, session_key)
|
@@ -16,7 +18,7 @@ module WxMiniprogram
|
|
16
18
|
:access_token => @access_token,
|
17
19
|
:openid => openid,
|
18
20
|
:signature => hmac_sha256(session_key, ""),
|
19
|
-
:
|
21
|
+
:sig_method => "hmac_sha256"
|
20
22
|
})
|
21
23
|
end
|
22
24
|
|
@@ -26,7 +28,7 @@ module WxMiniprogram
|
|
26
28
|
}, body: {
|
27
29
|
:openid => openid,
|
28
30
|
:signature => hmac_sha256(session_key, ""),
|
29
|
-
:
|
31
|
+
:sig_method => "hmac_sha256"
|
30
32
|
})
|
31
33
|
end
|
32
34
|
|
@@ -5,24 +5,27 @@ module WxMiniprogram
|
|
5
5
|
def clear_quota!
|
6
6
|
post("cgi-bin/clear_quota",
|
7
7
|
body: {:appid => @appid},
|
8
|
-
query: {:access_token => @access_token}
|
9
|
-
)
|
8
|
+
query: {:access_token => @access_token})
|
10
9
|
end
|
11
10
|
|
12
|
-
def get_api_quota
|
11
|
+
def get_api_quota!(cgi_path)
|
13
12
|
post("cgi-bin/openapi/quota/get",
|
14
|
-
query: {:access_token => @access_token},
|
13
|
+
query: {:access_token => @access_token},
|
14
|
+
body: {:cgi_path => cgi_path}
|
15
|
+
)
|
15
16
|
end
|
16
17
|
|
17
18
|
def get_rid_info(rid)
|
18
19
|
post("cgi-bin/openapi/rid/get",
|
19
20
|
body: {:rid => rid},
|
20
|
-
query: {:access_token => @access_token}
|
21
|
+
query: {:access_token => @access_token})
|
21
22
|
end
|
22
23
|
|
23
24
|
def clear_quota_by_app_secret(appid, appsecret)
|
24
25
|
post("cgi-bin/clear_quota/v2",
|
25
|
-
body: {:appid => appid, :appsecret => appsecret}
|
26
|
+
body: {:appid => appid, :appsecret => appsecret},
|
27
|
+
need_access_token: false
|
28
|
+
)
|
26
29
|
end
|
27
30
|
end
|
28
31
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module WxMiniprogram
|
4
|
+
module QRCode
|
5
|
+
|
6
|
+
# 必填 path: 扫码进入的小程序页面路径
|
7
|
+
# 非必填 {width: number, auto_color: boolean, line_color: {r: "", g: "", b: ""}}
|
8
|
+
def get_qrcode!(path, width=nil, auto_color=false, line_color=nil)
|
9
|
+
body = {}
|
10
|
+
body[:width] = width unless width.nil?
|
11
|
+
body[:auto_color] = auto_color if auto_color
|
12
|
+
body[:line_color] = line_color unless line_color.nil?
|
13
|
+
post("wxa/getwxacode",
|
14
|
+
query: {:access_token => @access_token},
|
15
|
+
body: body
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
19
|
+
# 必填 scene
|
20
|
+
# 非必填 {page: string, check_path: boolean, env_version: string, width: number,
|
21
|
+
# auto_color: boolean, line_color: {r: string, g: string, b: string}, is_hyaline: boolean}
|
22
|
+
def get_unlimited_qrcode!(scene, path=nil, check_path=nil, env_version=nil, width=nil, auto_color=nil, line_color=nil, is_hyaline=nil)
|
23
|
+
body = {}
|
24
|
+
body[:path] = path unless path.nil?
|
25
|
+
body[:check_path] = check_path unless check_path.nil?
|
26
|
+
body[:env_version] = env_version unless env_version.nil?
|
27
|
+
body[:width] = width unless width.nil?
|
28
|
+
body[:auto_color] = auto_color unless auto_color.nil?
|
29
|
+
body[:line_color] = line_color unless line_color.nil?
|
30
|
+
body[:is_hyaline] = is_hyaline unless is_hyaline.nil?
|
31
|
+
post("wxa/getwxacodeunlimit",
|
32
|
+
query: {:access_token => @access_token},
|
33
|
+
body: body
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
def create_qrcode!(path, width=430)
|
38
|
+
post("cgi-bin/wxaapp/createwxaqrcode",
|
39
|
+
query: {:access_token => @access_token, :path => path},
|
40
|
+
body: {:width => width}
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
data/lib/wx_miniprogram/token.rb
CHANGED
@@ -3,11 +3,14 @@
|
|
3
3
|
module WxMiniprogram
|
4
4
|
module Token
|
5
5
|
def get_access_token!
|
6
|
-
resp = get("cgi-bin/token",
|
7
|
-
:
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
resp = get("cgi-bin/token",
|
7
|
+
query: {
|
8
|
+
:grant_type => "client_credential",
|
9
|
+
:appid => @appid,
|
10
|
+
:secret => @secret
|
11
|
+
},
|
12
|
+
need_access_token: false
|
13
|
+
)
|
11
14
|
unless resp["access_token"].nil?
|
12
15
|
@access_token = resp["access_token"]
|
13
16
|
@expire = resp["expires_in"] + Time.now.to_i
|
@@ -16,12 +19,15 @@ module WxMiniprogram
|
|
16
19
|
end
|
17
20
|
|
18
21
|
def get_stable_access_token!(force_refresh=false)
|
19
|
-
resp = post("cgi-bin/stable_token",
|
20
|
-
:
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
resp = post("cgi-bin/stable_token",
|
23
|
+
body: {
|
24
|
+
:grant_type => "client_credential",
|
25
|
+
:appid => @appid,
|
26
|
+
:secret => @secret,
|
27
|
+
:force_refresh => force_refresh
|
28
|
+
},
|
29
|
+
need_access_token: false
|
30
|
+
)
|
25
31
|
unless resp["access_token"].nil?
|
26
32
|
@access_token = resp["access_token"]
|
27
33
|
@expire = resp["expires_in"] + Time.now.to_i
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module WxMiniprogram
|
4
|
+
module UrlScheme
|
5
|
+
def generate_nfc_scheme!(model_id, jump_wxa={}, sn=nil)
|
6
|
+
body = {:jump_wxa => jump_wxa, :model_id => model_id}
|
7
|
+
body[:sn] = sn unless sn.nil?
|
8
|
+
post("wxa/generatenfcscheme",
|
9
|
+
query: {:access_token => @access_token},
|
10
|
+
body: body
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
def generate_scheme!(jump_wxa={}, expire_time=nil, expire_type=nil, expire_interval=nil)
|
15
|
+
body = {:jump_wxa => jump_wxa}
|
16
|
+
body[:expire_time] = expire_time unless expire_time.nil?
|
17
|
+
body[:expire_type] = expire_type unless expire_type.nil?
|
18
|
+
body[:expire_interval] = expire_interval unless expire_interval.nil?
|
19
|
+
post("wxa/generatescheme",
|
20
|
+
query: {:access_token => @access_token},
|
21
|
+
body: body
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
def query_scheme!(scheme=nil, query_type=nil)
|
26
|
+
body = {}
|
27
|
+
body[:scheme] = scheme unless scheme.nil?
|
28
|
+
body[:query_type] = query_type unless query_type.nil?
|
29
|
+
post("wxa/queryscheme",
|
30
|
+
query: {:access_token => @access_token},
|
31
|
+
body: body
|
32
|
+
)
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -19,10 +19,14 @@ module WxMiniprogram
|
|
19
19
|
})
|
20
20
|
end
|
21
21
|
|
22
|
-
def get_paid_unionid!(
|
22
|
+
def get_paid_unionid!(transaction_id=nil, mch_id=nil, out_trade_no=nil)
|
23
|
+
body = {}
|
24
|
+
body[:transaction_id] = transaction_id unless transaction_id.nil?
|
25
|
+
body[:mch_id] = mch_id unless mch_id.nil?
|
26
|
+
body[:out_trade_no] = out_trade_no unless out_trade_no.nil?
|
23
27
|
get("wxa/getpaidunionid", query: {
|
24
28
|
:access_token => @access_token
|
25
|
-
}, body:
|
29
|
+
}, body: body)
|
26
30
|
end
|
27
31
|
|
28
32
|
def get_user_encryptKey!(openid, session_key)
|
data/lib/wx_miniprogram/util.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wx_miniprogram
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ranjiayu
|
@@ -17,7 +17,6 @@ executables: []
|
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
|
-
- ".rspec"
|
21
20
|
- LICENSE.txt
|
22
21
|
- README.md
|
23
22
|
- Rakefile
|
@@ -26,7 +25,9 @@ files:
|
|
26
25
|
- lib/wx_miniprogram/client.rb
|
27
26
|
- lib/wx_miniprogram/login.rb
|
28
27
|
- lib/wx_miniprogram/open_api.rb
|
28
|
+
- lib/wx_miniprogram/qrcode.rb
|
29
29
|
- lib/wx_miniprogram/token.rb
|
30
|
+
- lib/wx_miniprogram/url.rb
|
30
31
|
- lib/wx_miniprogram/user_info.rb
|
31
32
|
- lib/wx_miniprogram/util.rb
|
32
33
|
- lib/wx_miniprogram/version.rb
|
data/.rspec
DELETED