1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace DingRobot\Message; |
4
|
|
|
|
5
|
|
|
use DingRobot\Message\Traits\Btn; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* ActionCard |
9
|
|
|
* |
10
|
|
|
* @method ActionCard title($title) |
11
|
|
|
* @method ActionCard text($markdownText) |
12
|
|
|
* @method ActionCard singleURL($singleUrl) |
13
|
|
|
* @method ActionCard singleTitle($singleTitle) |
14
|
|
|
* |
15
|
|
|
* @package DingRobot\Message |
16
|
|
|
*/ |
17
|
|
|
class ActionCard extends Base |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* 隐藏发消息者头像 |
21
|
|
|
* hide sender avatar |
22
|
|
|
*/ |
23
|
|
|
const AVATAR_HIDE = '1'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* 显示发消息者头像 |
27
|
|
|
* show sender avatar |
28
|
|
|
*/ |
29
|
|
|
const AVATAR_SHOW = '0'; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* 按钮横向排列 |
33
|
|
|
*/ |
34
|
|
|
const BTN_ORIENTATION_HORIZONTAL = '1'; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* 按钮竖直排列 |
38
|
|
|
*/ |
39
|
|
|
const BTN_ORIENTATION_VERTICAL = '0'; |
40
|
|
|
|
41
|
3 |
|
public function __construct($title = '') |
42
|
|
|
{ |
43
|
3 |
|
parent::__construct(); |
44
|
3 |
|
$this->title($title); |
45
|
3 |
|
$this->bodyName = 'actionCard'; |
46
|
3 |
|
} |
47
|
|
|
|
48
|
2 |
|
protected function getBody() |
49
|
|
|
{ |
50
|
2 |
|
return $this->body; |
51
|
|
|
} |
52
|
|
|
|
53
|
3 |
|
protected function bodyFields() |
54
|
|
|
{ |
55
|
|
|
return [ |
56
|
3 |
|
'title' => ['required' => true, 'type' => 'string'], |
57
|
|
|
'text' => ['required' => true, 'type' => 'string'], |
58
|
|
|
'singleURL' => ['required' => true, 'type' => 'string'], |
59
|
|
|
'singleTitle' => ['required' => true, 'type' => 'string'] |
60
|
|
|
]; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* hide sender avatar |
65
|
|
|
* 隐藏发送者头像 |
66
|
|
|
* |
67
|
|
|
* @return $this |
68
|
|
|
*/ |
69
|
2 |
|
public function hideAvatar() |
70
|
|
|
{ |
71
|
2 |
|
$this->body['hideAvatar'] = self::AVATAR_HIDE; |
72
|
|
|
|
73
|
2 |
|
return $this; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* show sender avatar |
78
|
|
|
* 显示发送者头像 |
79
|
|
|
* |
80
|
|
|
* @return $this |
81
|
|
|
*/ |
82
|
2 |
|
public function showAvatar() |
83
|
|
|
{ |
84
|
2 |
|
$this->body['hideAvatar'] = self::AVATAR_SHOW; |
85
|
|
|
|
86
|
2 |
|
return $this; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* 设置按钮横向排列 |
91
|
|
|
* set button as horizontal |
92
|
|
|
* |
93
|
|
|
* @return $this |
94
|
|
|
*/ |
95
|
2 |
|
public function btnOrientationHorizontal() |
96
|
|
|
{ |
97
|
2 |
|
$this->body['btnOrientation'] = self::BTN_ORIENTATION_HORIZONTAL; |
98
|
|
|
|
99
|
2 |
|
return $this; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* 设置按钮纵向排列 |
104
|
|
|
* set button as vertical |
105
|
|
|
* |
106
|
|
|
* @return $this |
107
|
|
|
*/ |
108
|
2 |
|
public function btnOrientationVertical() |
109
|
|
|
{ |
110
|
2 |
|
$this->body['btnOrientation'] = self::BTN_ORIENTATION_VERTICAL; |
111
|
|
|
|
112
|
2 |
|
return $this; |
113
|
|
|
} |
114
|
|
|
} |