mini_program 0.7.0 → 0.11.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 +4 -4
- data/README.md +3 -3
- data/lib/mini_program/client.rb +8 -8
- data/lib/mini_program/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33eb5ef599719b87fa6f41511075a9a63583aa0a09b7889cf198fff54b23ad9d
|
4
|
+
data.tar.gz: 5c7384b8a9b7f8b87476e3a4f9664a2011106eadbb02e4727ae3ee5a40074396
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5926356805f658544866838ac1f5222aeb463fe97d35d8fd2c1bfec31f9238f5089b530c8e8b594e4328c1ff527372aa24d4116878f792ad180e6323dd6cd638
|
7
|
+
data.tar.gz: 3d6a4b3e3250b1639c53c211854c41616d24959f830816e70a2d097db58d7eef8b0323d9e1cd6bab48ac9819cb3f11886c984d7810cfc712570c1fdac50f37a5
|
data/README.md
CHANGED
@@ -32,7 +32,7 @@ mp = MiniProgram::Client.new
|
|
32
32
|
# code 是在小程序端调用 wx.login 拿到的
|
33
33
|
result = mp.login(code)
|
34
34
|
if result.success?
|
35
|
-
|
35
|
+
openid = result.data[:openid]
|
36
36
|
session_key = result.data[:session_key]
|
37
37
|
end
|
38
38
|
```
|
@@ -83,12 +83,12 @@ msg = MiniProgram::Msg.new(:progress, {
|
|
83
83
|
detail: "测试已完成"
|
84
84
|
})
|
85
85
|
|
86
|
-
# send_to 的参数可以是 openid(字符串),或者是带有
|
86
|
+
# send_to 的参数可以是 openid(字符串),或者是带有 openid 方法的对象,返回 MiniProgram::ServiceResult
|
87
87
|
result = msg.send_to("ogT7J5YddGnll-ippRvJq62Nv5W0")
|
88
88
|
|
89
89
|
# or
|
90
90
|
user = User.first
|
91
|
-
user.
|
91
|
+
user.openid # => ogT7J5YddGnll-ippRvJq62Nv5W0
|
92
92
|
result = msg.send_to(user)
|
93
93
|
|
94
94
|
if result.success?
|
data/lib/mini_program/client.rb
CHANGED
@@ -52,7 +52,7 @@ module MiniProgram
|
|
52
52
|
|
53
53
|
result = JSON.parse(response)
|
54
54
|
|
55
|
-
if result["errcode"].to_s != "0"
|
55
|
+
if result["errcode"] && result["errcode"].to_s != "0"
|
56
56
|
logger.error <<~ERROR
|
57
57
|
Get access token failed.
|
58
58
|
api: #{api}
|
@@ -94,11 +94,11 @@ module MiniProgram
|
|
94
94
|
|
95
95
|
# 发送订阅消息
|
96
96
|
# @param [MiniProgram::Msg] msg
|
97
|
-
# @param [String] to 用户的
|
97
|
+
# @param [String] to 用户的openid
|
98
98
|
def send_msg(msg, to: )
|
99
|
-
|
99
|
+
openid = to.try(:openid) || to
|
100
100
|
|
101
|
-
payload = msg.as_json.merge!(touser:
|
101
|
+
payload = msg.as_json.merge!(touser: openid)
|
102
102
|
|
103
103
|
# 获取 access_token
|
104
104
|
get_token_result = get_access_token
|
@@ -123,7 +123,7 @@ module MiniProgram
|
|
123
123
|
# 现在小程序的模板消息功能关闭了,就只剩下发送模板消息到公众号这个功能了
|
124
124
|
#
|
125
125
|
def send_uniform_msg(msg, to: )
|
126
|
-
|
126
|
+
openid = to.try(:openid) || to
|
127
127
|
|
128
128
|
payload = msg.as_json
|
129
129
|
|
@@ -134,7 +134,7 @@ module MiniProgram
|
|
134
134
|
|
135
135
|
api = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/uniform_send?access_token=#{get_token_result["access_token"]}"
|
136
136
|
result = post(api, {
|
137
|
-
touser:
|
137
|
+
touser: openid,
|
138
138
|
mp_template_msg: payload
|
139
139
|
})
|
140
140
|
|
@@ -152,7 +152,7 @@ module MiniProgram
|
|
152
152
|
login_result = login(code)
|
153
153
|
return login_result if login_result.failure?
|
154
154
|
|
155
|
-
|
155
|
+
openid = login_result.data[:openid]
|
156
156
|
session_key = login_result.data[:session_key]
|
157
157
|
|
158
158
|
data = decrypt_phone_data(encrypted_data, iv, session_key)
|
@@ -162,7 +162,7 @@ module MiniProgram
|
|
162
162
|
MiniProgram::ServiceResult.new(
|
163
163
|
success: true,
|
164
164
|
data: {
|
165
|
-
|
165
|
+
openid: openid,
|
166
166
|
phone_num: phone_num
|
167
167
|
})
|
168
168
|
end
|
data/lib/mini_program/version.rb
CHANGED