-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClientTest.php
214 lines (190 loc) · 8.05 KB
/
ClientTest.php
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<?php
/** @noinspection StaticClosureCanBeUsedInspection */
/** @noinspection PhpUnhandledExceptionInspection */
declare(strict_types=1);
/**
* Copyright (c) 2021-2024 guanguans<[email protected]>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*
* @see https://github.com/guanguans/notify
*/
namespace Guanguans\NotifyTests\WeWork;
use Guanguans\Notify\WeWork\Authenticator;
use Guanguans\Notify\WeWork\Client;
use Guanguans\Notify\WeWork\Messages\FileMessage;
use Guanguans\Notify\WeWork\Messages\ImageMessage;
use Guanguans\Notify\WeWork\Messages\MarkdownMessage;
use Guanguans\Notify\WeWork\Messages\NewsMessage;
use Guanguans\Notify\WeWork\Messages\TemplateCardMessage;
use Guanguans\Notify\WeWork\Messages\TextMessage;
use Guanguans\Notify\WeWork\Messages\UploadMediaMessage;
use Guanguans\Notify\WeWork\Messages\VoiceMessage;
beforeEach(function (): void {
$authenticator = new Authenticator('73a3d5a3-ceff-4da8-bcf3-ff5891778');
$this->client = (new Client($authenticator))->mock([
create_response('{"errcode":0,"errmsg":"ok"}'),
create_response('{"errcode":93000,"errmsg":"invalid webhook url, hint: [1708397705432012366598976], from ip: 218.72.126.124, more info at https://open.work.weixin.qq.com/devtool/query?e=93000"}'),
]);
});
it('can send upload media message', function (): void {
$uploadMediaMessage = UploadMediaMessage::make([
'media' => fixtures_path('image.png'),
'type' => 'file',
]);
expect($this->client)
->mock([
create_response('{"errcode":0,"errmsg":"ok","type":"file","media_id":"3h9Ps2X6_-HSlzxXyRJibTGRREIkBPgtZIG0dPRJFlOl5bKroWVHXaTQQV6sSPz5h","created_at":"1709387991"}'),
create_response('{"errcode":40058,"errmsg":"invalid param \'key\', hint: [1709388087101961098685339], from ip: 211.90.236.131, more info at https://open.work.weixin.qq.com/devtool/query?e=40058"}'),
])
->assertCanSendMessage($uploadMediaMessage);
})->group(__DIR__, __FILE__);
it('can send text message', function (): void {
$textMessage = TextMessage::make([
'content' => 'This is content.',
'mentioned_list' => ['wangqing', '@all'],
'mentioned_mobile_list' => ['13800001111', '@all'],
]);
expect($this->client)->assertCanSendMessage($textMessage);
})->group(__DIR__, __FILE__);
it('can send file message', function (): void {
$fileMessage = FileMessage::make()->mediaId('3NmBZNxOun8TK5zIGo18LZ3ttVeoGnWIkxcynSxlVCuiw5WcUhO-arRBMwXSGeCYw');
expect($this->client)->assertCanSendMessage($fileMessage);
})->group(__DIR__, __FILE__);
it('can send image message', function (): void {
$imageMessage = ImageMessage::make()->image(fixtures_path('image.png'));
expect($this->client)->assertCanSendMessage($imageMessage);
})->group(__DIR__, __FILE__);
it('can send markdown message', function (): void {
$markdownMessage = MarkdownMessage::make()->content("# This is title.\n>This is content.");
expect($this->client)->assertCanSendMessage($markdownMessage);
})->group(__DIR__, __FILE__);
it('can send news message', function (): void {
$newsMessage = NewsMessage::make()->addArticle([
'title' => 'This is title.',
'description' => 'This is description.',
'url' => 'https://github.com/guanguans/notify',
'picurl' => 'https://avatars.githubusercontent.com/u/22309277?v=4',
]);
expect($this->client)->assertCanSendMessage($newsMessage);
})->group(__DIR__, __FILE__);
it('can send template card of text message', function (): void {
$templateCardMessage = TemplateCardMessage::make([
'card_type' => 'text_notice',
'source' => [
'icon_url' => 'https://wework.qpic.cn/wwpic/252813_jOfDHtcISzuodLa_1629280209/0',
'desc' => '企业微信',
'desc_color' => 0,
],
'main_title' => [
'title' => '欢迎使用企业微信',
'desc' => '您的好友正在邀请您加入企业微信',
],
'emphasis_content' => [
'title' => '100',
'desc' => '数据含义',
],
'quote_area' => [
'type' => 1,
'url' => 'https://work.weixin.qq.com/?from=openApi',
'appid' => 'APPID',
'pagepath' => 'PAGEPATH',
'title' => '引用文本标题',
'quote_text' => 'Jack:企业微信真的很好用~',
],
'sub_title_text' => '下载企业微信还能抢红包!',
'horizontal_content_list' => [
$horizontalContent = [
'keyname' => '企微官网',
'value' => '点击访问',
'type' => 1,
'url' => 'https://work.weixin.qq.com/?from=openApi',
],
],
'jump_list' => [
$jump = [
'type' => 1,
'url' => 'https://work.weixin.qq.com/?from=openApi',
'title' => '企业微信官网',
],
],
'card_action' => [
'type' => 1,
'url' => 'https://work.weixin.qq.com/?from=openApi',
'appid' => 'APPID',
'pagepath' => 'PAGEPATH',
],
])
->addHorizontalContent($horizontalContent)
->addJump($jump);
expect($this->client)->assertCanSendMessage($templateCardMessage);
})->group(__DIR__, __FILE__);
it('can send template card of news message', function (): void {
$templateCardMessage = TemplateCardMessage::make([
'card_type' => 'news_notice',
'source' => [
'icon_url' => 'https://wework.qpic.cn/wwpic/252813_jOfDHtcISzuodLa_1629280209/0',
'desc' => '企业微信',
'desc_color' => 0,
],
'main_title' => [
'title' => '欢迎使用企业微信',
'desc' => '您的好友正在邀请您加入企业微信',
],
'card_image' => [
'url' => 'https://wework.qpic.cn/wwpic/354393_4zpkKXd7SrGMvfg_1629280616/0',
'aspect_ratio' => 2.25,
],
'image_text_area' => [
'type' => 1,
'url' => 'https://work.weixin.qq.com',
'title' => '欢迎使用企业微信',
'desc' => '您的好友正在邀请您加入企业微信',
'image_url' => 'https://wework.qpic.cn/wwpic/354393_4zpkKXd7SrGMvfg_1629280616/0',
],
'quote_area' => [
'type' => 1,
'url' => 'https://work.weixin.qq.com/?from=openApi',
'appid' => 'APPID',
'pagepath' => 'PAGEPATH',
'title' => '引用文本标题',
'quote_text' => 'Jack:企业微信真的很好用~Balian:超级好的一款软件!',
],
'vertical_content_list' => [
$verticalContent = [
'title' => '惊喜红包等你来拿',
'desc' => '下载企业微信还能抢红包!',
],
],
'horizontal_content_list' => [
$horizontalContent = [
'keyname' => '企微官网',
'value' => '点击访问',
'type' => 1,
'url' => 'https://work.weixin.qq.com/?from=openApi',
],
],
'jump_list' => [
$jump = [
'type' => 1,
'url' => 'https://work.weixin.qq.com/?from=openApi',
'title' => '企业微信官网',
],
],
'card_action' => [
'type' => 1,
'url' => 'https://work.weixin.qq.com/?from=openApi',
'appid' => 'APPID',
'pagepath' => 'PAGEPATH',
],
])
->addVerticalContent($verticalContent)
->addHorizontalContent($horizontalContent)
->addJump($jump);
expect($this->client)->assertCanSendMessage($templateCardMessage);
})->group(__DIR__, __FILE__);
it('can send voice message', function (): void {
$voiceMessage = VoiceMessage::make()->mediaId('3NmBZNxOun8TK5zIGo18LZ3ttVeoGnWIkxcynSxlVCuiw5WcUhO-arRBMwXSGeCYw');
expect($this->client)->assertCanSendMessage($voiceMessage);
})->group(__DIR__, __FILE__);