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