|
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
|
|
|
* |
|
13
|
|
|
* @package DingRobot\Message |
|
14
|
|
|
*/ |
|
15
|
|
|
class ActionCardBtn extends Base |
|
16
|
|
|
{ |
|
17
|
|
|
use Btn; |
|
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
|
2 |
|
public function __construct($title = '') |
|
42
|
|
|
{ |
|
43
|
2 |
|
parent::__construct(); |
|
44
|
2 |
|
$this->title($title); |
|
45
|
2 |
|
$this->bodyName = 'actionCard'; |
|
46
|
2 |
|
} |
|
47
|
|
|
|
|
48
|
2 |
|
protected function getBody() |
|
49
|
|
|
{ |
|
50
|
2 |
|
if(!empty($this->btns)) { |
|
51
|
1 |
|
$this->body['btns'] = $this->btns; |
|
52
|
|
|
} else { |
|
53
|
1 |
|
throw new \InvalidArgumentException("wrong btns"); |
|
54
|
|
|
} |
|
55
|
1 |
|
return $this->body; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
2 |
|
protected function bodyFields() |
|
59
|
|
|
{ |
|
60
|
|
|
return [ |
|
61
|
2 |
|
'title' => ['required' => true, 'type' => 'string'], |
|
62
|
|
|
'text' => ['required' => true, 'type' => 'string'], |
|
63
|
|
|
]; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* hide sender avatar |
|
68
|
|
|
* 隐藏发送者头像 |
|
69
|
|
|
* |
|
70
|
|
|
* @return $this |
|
71
|
|
|
*/ |
|
72
|
1 |
|
public function hideAvatar() |
|
73
|
|
|
{ |
|
74
|
1 |
|
$this->body['hideAvatar'] = self::AVATAR_HIDE; |
|
75
|
|
|
|
|
76
|
1 |
|
return $this; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* show sender avatar |
|
81
|
|
|
* 显示发送者头像 |
|
82
|
|
|
* |
|
83
|
|
|
* @return $this |
|
84
|
|
|
*/ |
|
85
|
1 |
|
public function showAvatar() |
|
86
|
|
|
{ |
|
87
|
1 |
|
$this->body['hideAvatar'] = self::AVATAR_SHOW; |
|
88
|
|
|
|
|
89
|
1 |
|
return $this; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* 设置按钮横向排列 |
|
94
|
|
|
* set button as horizontal |
|
95
|
|
|
* |
|
96
|
|
|
* @return $this |
|
97
|
|
|
*/ |
|
98
|
1 |
|
public function btnOrientationHorizontal() |
|
99
|
|
|
{ |
|
100
|
1 |
|
$this->body['btnOrientation'] = self::BTN_ORIENTATION_HORIZONTAL; |
|
101
|
|
|
|
|
102
|
1 |
|
return $this; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* 设置按钮纵向排列 |
|
107
|
|
|
* set button as vertical |
|
108
|
|
|
* |
|
109
|
|
|
* @return $this |
|
110
|
|
|
*/ |
|
111
|
1 |
|
public function btnOrientationVertical() |
|
112
|
|
|
{ |
|
113
|
1 |
|
$this->body['btnOrientation'] = self::BTN_ORIENTATION_VERTICAL; |
|
114
|
|
|
|
|
115
|
1 |
|
return $this; |
|
116
|
|
|
} |
|
117
|
|
|
} |