fastlane-plugin-wechat 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4f7163ab8d591543852bcfbe325094bc8776806c66df86a37f500ad268af79fd
4
- data.tar.gz: d0b1b754b06eea5d0ca9588207748f020dcf782fdb5c782315a869825d3c1d7f
3
+ metadata.gz: 86f4ebf538a861e3a2f65d087d4743949a88041791b53fa79aea8ce1e117f644
4
+ data.tar.gz: bb6e4856a74441df03937f56565948980cd846332639b767016b8fe9c51ca158
5
5
  SHA512:
6
- metadata.gz: 80ed4ef10565f18c51689c305353760f8aec686bc0b475d2a39bd2e61990a3c2ab396cfe9afd37717d8ed3194daee268cdd4125e490dc8f81f4f420785c7ad09
7
- data.tar.gz: 3124e1beade42d0ee9b6dfc8ec06447afa604c5958a1096885a5704666ffb6835529040500be26b5019ab9da4ff2b14bff5b25ac8f3106f189ae9f3ac3422aca
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
- **Note to author:** Add a more detailed description about this plugin here. If your plugin contains multiple actions, make sure to mention them here.
17
+ 通常在各种流程结束时, 需要将结果发送出去,比如 slack 目前因公司内部全部迁移到 企业微信,所以需要使用 企业微信 api 封装下,完成下面的通知 ~
18
+
19
+ ### eg1
20
+
21
+ ![](images/Snip20190803_31.png)
22
+
23
+ ### eg2
24
+
25
+ ![](images/Snip20190808_1.png)
26
+
27
+ ### eg3
28
+
29
+ ![](images/Snip20190808_2.png)
30
+
31
+ ### eg4
32
+
33
+ ![](images/Snip20190808_5.png)
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
- access_token = params[:access_token]
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
- msgtype = params[:msgtype]
18
- text = params[:text]
19
- articles = params[:articles]
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
- # UI.success(body)
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: :access_token,
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: false
201
+ optional: true
165
202
  ),
166
203
  FastlaneCore::ConfigItem.new(
167
204
  key: :text,
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module Wechat
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
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.1.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-07-31 00:00:00.000000000 Z
11
+ date: 2019-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry