1 | <?php |
||
30 | class MessageBuilder |
||
31 | { |
||
32 | /** |
||
33 | * Message target user or group. |
||
34 | * |
||
35 | * @var mixed |
||
36 | */ |
||
37 | protected $to; |
||
38 | |||
39 | /** |
||
40 | * Message type. |
||
41 | * |
||
42 | * @var string |
||
43 | */ |
||
44 | protected $msgType; |
||
45 | |||
46 | /** |
||
47 | * Message. |
||
48 | * |
||
49 | * @var mixed |
||
50 | */ |
||
51 | protected $message; |
||
52 | |||
53 | /** |
||
54 | * Message types. |
||
55 | * |
||
56 | * @var array |
||
57 | */ |
||
58 | private $msgTypes = [ |
||
59 | Broadcast::MSG_TYPE_TEXT, |
||
60 | Broadcast::MSG_TYPE_NEWS, |
||
61 | Broadcast::MSG_TYPE_IMAGE, |
||
62 | Broadcast::MSG_TYPE_VIDEO, |
||
63 | Broadcast::MSG_TYPE_VOICE, |
||
64 | Broadcast::MSG_TYPE_CARD, |
||
65 | ]; |
||
66 | |||
67 | /** |
||
68 | * Preview bys. |
||
69 | * |
||
70 | * @var array |
||
71 | */ |
||
72 | private $previewBys = [ |
||
73 | Broadcast::PREVIEW_BY_OPENID, |
||
74 | Broadcast::PREVIEW_BY_NAME, |
||
75 | ]; |
||
76 | |||
77 | /** |
||
78 | * Set message type. |
||
79 | * |
||
80 | * @param string $msgType |
||
81 | * |
||
82 | * @return MessageBuilder |
||
83 | * |
||
84 | * @throws InvalidArgumentException |
||
85 | */ |
||
86 | 5 | public function msgType($msgType) |
|
96 | |||
97 | /** |
||
98 | * Set message. |
||
99 | * |
||
100 | * @param string|array $message |
||
101 | * |
||
102 | * @return MessageBuilder |
||
103 | */ |
||
104 | 5 | public function message($message) |
|
110 | |||
111 | /** |
||
112 | * Set target user or group. |
||
113 | * |
||
114 | * @param mixed $to |
||
115 | * |
||
116 | * @return MessageBuilder |
||
117 | */ |
||
118 | 5 | public function to($to) |
|
124 | |||
125 | /** |
||
126 | * Build message. |
||
127 | * |
||
128 | * @return bool |
||
129 | * |
||
130 | * @throws RuntimeException |
||
131 | */ |
||
132 | 3 | public function build() |
|
157 | |||
158 | /** |
||
159 | * Build preview message. |
||
160 | * |
||
161 | * @param string $by |
||
162 | * |
||
163 | * @return array |
||
164 | * |
||
165 | * @throws RuntimeException |
||
166 | * @throws InvalidArgumentException |
||
167 | */ |
||
168 | 2 | public function buildPreview($by) |
|
194 | |||
195 | /** |
||
196 | * Build group. |
||
197 | * |
||
198 | * @param mixed $group |
||
199 | * |
||
200 | * @return array |
||
201 | */ |
||
202 | 2 | private function buildGroup($group) |
|
225 | |||
226 | /** |
||
227 | * Build to. |
||
228 | * |
||
229 | * @param string $to |
||
230 | * @param string $by |
||
231 | * |
||
232 | * @return array |
||
233 | */ |
||
234 | 2 | private function buildTo($to, $by) |
|
240 | |||
241 | /** |
||
242 | * Return property. |
||
243 | * |
||
244 | * @param string $property |
||
245 | * |
||
246 | * @return mixed |
||
247 | */ |
||
248 | 3 | public function __get($property) |
|
254 | } |
||
255 |