|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
if (!function_exists('d_make_btn')) { |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* 生成 button 辅助函数 |
|
7
|
|
|
* |
|
8
|
|
|
* @param string $title 按钮文案 |
|
9
|
|
|
* @param string $actionURL 按钮跳转地址 |
|
10
|
|
|
* |
|
11
|
|
|
* @return array |
|
12
|
|
|
*/ |
|
13
|
|
|
function d_make_btn($title, $actionURL) |
|
14
|
|
|
{ |
|
15
|
3 |
|
if (!is_string($title) || !is_string($actionURL)) { |
|
16
|
1 |
|
throw new \InvalidArgumentException('wrong btn params'); |
|
17
|
|
|
} |
|
18
|
3 |
|
return compact('title', 'actionURL'); |
|
19
|
|
|
} |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
if (!function_exists('d_make_link')) { |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* 生成 link 辅助函数 |
|
26
|
|
|
* |
|
27
|
|
|
* @param string $title 链接标题 |
|
28
|
|
|
* @param string $messageURL 跳转链接 |
|
29
|
|
|
* @param string $picURL 图片地址 |
|
30
|
|
|
* |
|
31
|
|
|
* @return array |
|
32
|
|
|
*/ |
|
33
|
|
|
function d_make_link($title, $messageURL, $picURL) |
|
34
|
|
|
{ |
|
35
|
2 |
|
if (!is_string($title) || !is_string($messageURL) || !is_string($picURL)) { |
|
36
|
1 |
|
throw new \InvalidArgumentException('wrong link params'); |
|
37
|
|
|
} |
|
38
|
2 |
|
return compact('title', 'messageURL', 'picURL'); |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
if (!function_exists('d_action_card')) { |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* 快速生成 action card 辅助函数 |
|
46
|
|
|
* |
|
47
|
|
|
* @param string $title 标题 |
|
48
|
|
|
* @param string $text markdown 格式摘要 |
|
49
|
|
|
* @param string $singleTitle 单个按钮文案 |
|
50
|
|
|
* @param string $singleURL 按钮跳转地址 |
|
51
|
|
|
* |
|
52
|
|
|
* @return \DingRobot\Message\ActionCard |
|
53
|
|
|
*/ |
|
54
|
|
|
function d_action_card($title, $text, $singleTitle, $singleURL) |
|
55
|
|
|
{ |
|
56
|
1 |
|
return \DingRobot\Ding::actionCard($title)->text($text)->singleTitle($singleTitle) |
|
57
|
1 |
|
->singleURL($singleURL); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
if (!function_exists('d_action_card_btn')) { |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* 快速生成 action_card_btn 辅助函数 |
|
65
|
|
|
* |
|
66
|
|
|
* @param string $title 标题 |
|
67
|
|
|
* @param string $text markdown 格式摘要 |
|
68
|
|
|
* @param array $btns 按钮 |
|
69
|
|
|
* |
|
70
|
|
|
* @return \DingRobot\Message\ActionCardBtn |
|
71
|
|
|
*/ |
|
72
|
|
|
function d_action_card_btn($title, $text, array $btns) |
|
73
|
|
|
{ |
|
74
|
1 |
|
return \DingRobot\Ding::actionCardBtn($title)->text($text)->btns($btns); |
|
|
|
|
|
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
if (!function_exists('d_feed_card')) { |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* 快速生成 action card 辅助函数 |
|
82
|
|
|
* |
|
83
|
|
|
* @param array $links 链接 |
|
84
|
|
|
* |
|
85
|
|
|
* @return \DingRobot\Message\FeedCard |
|
86
|
|
|
*/ |
|
87
|
|
|
function d_feed_card(array $links) |
|
88
|
|
|
{ |
|
89
|
1 |
|
return \DingRobot\Ding::feedCard($links); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
if (!function_exists('d_link')) { |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* 快速生成 Link 辅助函数 |
|
97
|
|
|
* |
|
98
|
|
|
* @param string $title 标题 |
|
99
|
|
|
* @param string $text markdown 格式摘要 |
|
100
|
|
|
* @param string $messageUrl 点击消息跳转的URL |
|
101
|
|
|
* @param string|null $picUrl 图片地址 |
|
102
|
|
|
* |
|
103
|
|
|
* @return \DingRobot\Message\Link |
|
104
|
|
|
*/ |
|
105
|
|
|
function d_link($title, $text, $messageUrl, $picUrl = '') |
|
106
|
|
|
{ |
|
107
|
1 |
|
return \DingRobot\Ding::link($title)->text($text)->messageUrl($messageUrl)->picUrl($picUrl); |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
if (!function_exists('d_markdown')) { |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* 快速生成 Markdown 辅助函数 |
|
115
|
|
|
* |
|
116
|
|
|
* @param string $title 标题 |
|
117
|
|
|
* @param string $text markdown 格式摘要 |
|
118
|
|
|
* |
|
119
|
|
|
* @return \DingRobot\Message\Markdown |
|
120
|
|
|
*/ |
|
121
|
|
|
function d_markdown($title, $text) |
|
122
|
|
|
{ |
|
123
|
1 |
|
return \DingRobot\Ding::markdown($title)->text($text); |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
if (!function_exists('d_text')) { |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* 快速生成 Text 辅助函数 |
|
131
|
|
|
* |
|
132
|
|
|
* @param string $content 内容 |
|
133
|
|
|
* |
|
134
|
|
|
* @return \DingRobot\Message\Text |
|
135
|
|
|
*/ |
|
136
|
|
|
function d_text($content) |
|
137
|
|
|
{ |
|
138
|
2 |
|
return \DingRobot\Ding::text($content); |
|
139
|
|
|
} |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
if (!function_exists('d_web_hook')) { |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* 设置 或者 获取 web hook 地址 |
|
146
|
|
|
* |
|
147
|
|
|
* @param string|null $web_hook_val web hook 地址 |
|
148
|
|
|
* |
|
149
|
|
|
* @return mixed |
|
150
|
|
|
*/ |
|
151
|
|
|
function d_web_hook($web_hook_val = null) |
|
152
|
|
|
{ |
|
153
|
1 |
|
static $web_hook; |
|
154
|
|
|
|
|
155
|
1 |
|
if ($web_hook_val) { |
|
156
|
1 |
|
$web_hook = $web_hook_val; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
1 |
|
return $web_hook; |
|
160
|
|
|
} |
|
161
|
|
|
} |