fastlane-plugin-wechat 0.1.0 → 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 +4 -4
- data/README.md +19 -1
- data/lib/fastlane/plugin/wechat/actions/wechat_action.rb +68 -31
- data/lib/fastlane/plugin/wechat/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86f4ebf538a861e3a2f65d087d4743949a88041791b53fa79aea8ce1e117f644
|
4
|
+
data.tar.gz: bb6e4856a74441df03937f56565948980cd846332639b767016b8fe9c51ca158
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d34a17705b6d1c2898384b5b4f847f9bdbdea7f589a884a9d79f512abef8a5c003c1782e6a8f938d0f5671b0b1b20df54ac22be24f8195d64fcf72a88541092
|
7
|
+
data.tar.gz: 78e3c736533ec10df8721da5f55485356592577eb35ee60519e1b5213bb4402e41a9b53c2f11b7875ceb32e3beae3e39e2615d5451741e4f3e9bb44c5cc8b131
|
data/README.md
CHANGED
@@ -14,7 +14,25 @@ fastlane add_plugin wechat
|
|
14
14
|
|
15
15
|
this is a wechat api wrapper
|
16
16
|
|
17
|
-
|
17
|
+
通常在各种流程结束时, 需要将结果发送出去,比如 slack … 目前因公司内部全部迁移到 企业微信,所以需要使用 企业微信 的 api 封装下,完成下面的通知 ~
|
18
|
+
|
19
|
+
### eg1
|
20
|
+
|
21
|
+

|
22
|
+
|
23
|
+
### eg2
|
24
|
+
|
25
|
+

|
26
|
+
|
27
|
+
### eg3
|
28
|
+
|
29
|
+

|
30
|
+
|
31
|
+
### eg4
|
32
|
+
|
33
|
+

|
34
|
+
|
35
|
+
如果你也需要,参考下面目前支持的 消息类型.
|
18
36
|
|
19
37
|
## Example
|
20
38
|
|
@@ -4,35 +4,89 @@ require_relative '../helper/wechat_helper'
|
|
4
4
|
module Fastlane
|
5
5
|
module Actions
|
6
6
|
class WechatAction < Action
|
7
|
+
require 'net/http'
|
7
8
|
require 'net/https'
|
8
9
|
require 'json'
|
9
10
|
|
10
11
|
def self.run(params)
|
11
|
-
|
12
|
+
if params[:webhook]
|
13
|
+
send_with_webhook(params)
|
14
|
+
else
|
15
|
+
send_with_token(params)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.send_with_webhook(params = {})
|
20
|
+
msgtype = params[:msgtype]
|
21
|
+
text = params[:text]
|
22
|
+
|
23
|
+
url = URI(params[:webhook])
|
24
|
+
http = Net::HTTP.new(url.host, url.port)
|
25
|
+
http.use_ssl = true if url.scheme == 'https'
|
26
|
+
|
27
|
+
request = Net::HTTP::Post.new(url)
|
28
|
+
request["Content-Type"] = 'application/json'
|
29
|
+
request.body = http_body(params)
|
30
|
+
|
31
|
+
puts http.request(request).body
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.send_with_token(params = {})
|
12
35
|
access_token_url = params[:access_token_url]
|
13
36
|
agentid = params[:agentid]
|
14
37
|
secret = params[:secret]
|
15
|
-
recievers = params[:recievers]
|
16
38
|
send_message_url = params[:send_message_url]
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
unless access_token
|
22
|
-
access_token = request_access_token(access_token_url, agentid, secret)
|
23
|
-
UI.important "[WechatAction] request access_token: #{access_token}"
|
24
|
-
end
|
39
|
+
|
40
|
+
access_token = request_access_token(access_token_url, agentid, secret)
|
41
|
+
UI.important "[WechatAction] request access_token: #{access_token}"
|
25
42
|
|
26
43
|
msg_uri = URI(send_message_url)
|
44
|
+
http = Net::HTTP.new(msg_uri.host, msg_uri.port)
|
45
|
+
http.use_ssl = true if msg_uri.scheme == 'https'
|
46
|
+
|
27
47
|
headers = {
|
28
48
|
'token' => access_token,
|
29
49
|
'agentid' => agentid,
|
30
50
|
'Content-Type' => 'application/json'
|
31
51
|
}
|
52
|
+
|
53
|
+
request = Net::HTTP::Post.new(msg_uri, headers)
|
54
|
+
request.body = http_body(params)
|
55
|
+
puts http.request(request).body
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.request_access_token(url, agentid, secret)
|
59
|
+
token_uri = URI(url)
|
60
|
+
|
61
|
+
http = Net::HTTP.new(token_uri.host, token_uri.port)
|
62
|
+
http.use_ssl = true if token_uri.scheme == 'https'
|
63
|
+
|
64
|
+
request = Net::HTTP::Get.new(token_uri)
|
65
|
+
request['agentid'] = agentid.to_s
|
66
|
+
request['secret'] = secret.to_s
|
67
|
+
|
68
|
+
# resp = Net::HTTP.start(token_uri.hostname, token_uri.port) do |http|
|
69
|
+
# http.request(request)
|
70
|
+
# end
|
71
|
+
# JSON.parse(resp.body)["access_token"]
|
72
|
+
|
73
|
+
resp = http.request(request)
|
74
|
+
JSON.parse(resp.body)["access_token"]
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.http_body(params = {})
|
78
|
+
recievers = params[:recievers]
|
79
|
+
msgtype = params[:msgtype]
|
80
|
+
text = params[:text]
|
81
|
+
articles = params[:articles]
|
82
|
+
|
32
83
|
body = {}
|
33
|
-
body['touser'] = recievers.join('|')
|
34
84
|
body['msgtype'] = msgtype
|
35
85
|
|
86
|
+
unless params[:webhook]
|
87
|
+
body['touser'] = recievers.join('|')
|
88
|
+
end
|
89
|
+
|
36
90
|
# 1、文本类型
|
37
91
|
# {
|
38
92
|
# "msgtype": "text",
|
@@ -64,7 +118,6 @@ module Fastlane
|
|
64
118
|
}
|
65
119
|
end
|
66
120
|
|
67
|
-
|
68
121
|
# 3、图片类型
|
69
122
|
# {
|
70
123
|
# "msgtype": "image",
|
@@ -99,23 +152,7 @@ module Fastlane
|
|
99
152
|
}
|
100
153
|
end
|
101
154
|
|
102
|
-
|
103
|
-
req = Net::HTTP::Post.new(msg_uri, headers)
|
104
|
-
req.body = body.to_json
|
105
|
-
Net::HTTP.new(msg_uri.host, msg_uri.port).start do |http|
|
106
|
-
http.request(req)
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
def self.request_access_token(url, agentid, secret)
|
111
|
-
token_uri = URI(url)
|
112
|
-
req = Net::HTTP::Get.new(token_uri)
|
113
|
-
req['agentid'] = agentid.to_s
|
114
|
-
req['secret'] = secret.to_s
|
115
|
-
res = Net::HTTP.start(token_uri.hostname, token_uri.port) do |http|
|
116
|
-
http.request(req)
|
117
|
-
end
|
118
|
-
JSON.parse(res.body)["access_token"]
|
155
|
+
body.to_json
|
119
156
|
end
|
120
157
|
|
121
158
|
def self.description
|
@@ -133,7 +170,7 @@ module Fastlane
|
|
133
170
|
def self.available_options
|
134
171
|
[
|
135
172
|
FastlaneCore::ConfigItem.new(
|
136
|
-
key: :
|
173
|
+
key: :webhook,
|
137
174
|
description: "wechat access token",
|
138
175
|
type: String,
|
139
176
|
optional: true,
|
@@ -161,7 +198,7 @@ module Fastlane
|
|
161
198
|
key: :recievers,
|
162
199
|
description: "how many man to receive this message",
|
163
200
|
type: Array,
|
164
|
-
optional:
|
201
|
+
optional: true
|
165
202
|
),
|
166
203
|
FastlaneCore::ConfigItem.new(
|
167
204
|
key: :text,
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fastlane-plugin-wechat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- xiongzenghui
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-09-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|