-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathto_webchat.m
More file actions
43 lines (40 loc) · 1.4 KB
/
to_webchat.m
File metadata and controls
43 lines (40 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
%% 发消息到企业微信
% 将指定字符串发送到企业微信群的群机器人。
% curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=9a5d8dc2-7623-468d-b438-563e6e7920bb' \
% -H 'Content-Type: application/json' \
% -d '
% {
% "msgtype": "text",
% "text": {
% "content": "hello world"
% }
% }'
%% 方案一:Web Access using Data Import and Export API
% https://curlconverter.com/matlab
% 下面为将curl命令转换生成的matlab代码。
params = {'key' '9a5d8dc2-7623-468d-b438-563e6e7920bb'};
baseURI = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send';
uri = [baseURI '?' char(join(join(params, '='), '&'))];
body = struct(...
'msgtype', 'text',...
'text', struct(...
'content', 'hello webchat'...
)...
);
options = weboptions('MediaType', 'application/json');
response = webwrite(uri, body, options);
%% 方案二:HTTP Interface
% import matlab.net.*
% import matlab.net.http.*
% import matlab.net.http.io.*
%
% params = {'key' '9a5d8dc2-7623-468d-b438-563e6e7920bb'};
% header = HeaderField('Content-Type', 'application/json');
% uri = URI('https://qyapi.weixin.qq.com/cgi-bin/webhook/send', QueryParameter(params'));
% body = JSONProvider(struct(...
% 'msgtype', 'text',...
% 'text', struct(...
% 'content', 'hello world'...
% )...
% ));
% response = RequestMessage('post', header, body).send(uri.EncodedURI);