1 | <?php |
||
31 | class Notice extends AbstractAPI |
||
32 | { |
||
33 | /** |
||
34 | * Default color. |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | protected $defaultColor = '#173177'; |
||
39 | |||
40 | /** |
||
41 | * Attributes. |
||
42 | * |
||
43 | * @var array |
||
44 | */ |
||
45 | protected $message = [ |
||
46 | 'touser' => '', |
||
47 | 'template_id' => '', |
||
48 | 'url' => '', |
||
49 | 'data' => [], |
||
50 | ]; |
||
51 | |||
52 | /** |
||
53 | * Required attributes. |
||
54 | * |
||
55 | * @var array |
||
56 | */ |
||
57 | protected $required = ['touser', 'template_id']; |
||
58 | |||
59 | /** |
||
60 | * Message backup. |
||
61 | * |
||
62 | * @var array |
||
63 | */ |
||
64 | protected $messageBackup; |
||
65 | |||
66 | const API_SEND_NOTICE = 'https://api.weixin.qq.com/cgi-bin/message/template/send'; |
||
67 | const API_SET_INDUSTRY = 'https://api.weixin.qq.com/cgi-bin/template/api_set_industry'; |
||
68 | const API_ADD_TEMPLATE = 'https://api.weixin.qq.com/cgi-bin/template/api_add_template'; |
||
69 | const API_GET_INDUSTRY = 'https://api.weixin.qq.com/cgi-bin/template/get_industry'; |
||
70 | const API_GET_ALL_PRIVATE_TEMPLATE = 'https://api.weixin.qq.com/cgi-bin/template/get_all_private_template'; |
||
71 | const API_DEL_PRIVATE_TEMPLATE = 'https://api.weixin.qq.com/cgi-bin/template/del_private_template'; |
||
72 | |||
73 | /** |
||
74 | * Notice constructor. |
||
75 | * |
||
76 | * @param \EasyWeChat\Core\AccessToken $accessToken |
||
77 | */ |
||
78 | 7 | public function __construct(AccessToken $accessToken) |
|
79 | { |
||
80 | 7 | parent::__construct($accessToken); |
|
81 | |||
82 | 7 | $this->messageBackup = $this->message; |
|
83 | 7 | } |
|
84 | |||
85 | /** |
||
86 | * Set default color. |
||
87 | * |
||
88 | * @param string $color example: #0f0f0f |
||
89 | * |
||
90 | * @return $this |
||
91 | */ |
||
92 | public function defaultColor($color) |
||
93 | { |
||
94 | $this->defaultColor = $color; |
||
95 | |||
96 | return $this; |
||
97 | } |
||
98 | |||
99 | /** |
||
100 | * Set industry. |
||
101 | * |
||
102 | * @param int $industryOne |
||
103 | * @param int $industryTwo |
||
104 | * |
||
105 | * @return \EasyWeChat\Support\Collection |
||
106 | */ |
||
107 | 1 | public function setIndustry($industryOne, $industryTwo) |
|
116 | |||
117 | /** |
||
118 | * Get industry. |
||
119 | * |
||
120 | * @return \EasyWeChat\Support\Collection |
||
121 | */ |
||
122 | 1 | public function getIndustry() |
|
126 | |||
127 | /** |
||
128 | * Add a template and get template ID. |
||
129 | * |
||
130 | * @param string $shortId |
||
131 | * |
||
132 | * @return \EasyWeChat\Support\Collection |
||
133 | */ |
||
134 | 1 | public function addTemplate($shortId) |
|
140 | |||
141 | /** |
||
142 | * Get private templates. |
||
143 | * |
||
144 | * @return \EasyWeChat\Support\Collection |
||
145 | */ |
||
146 | 1 | public function getPrivateTemplates() |
|
150 | |||
151 | /** |
||
152 | * Delete private template. |
||
153 | * |
||
154 | * @param string $templateId |
||
155 | * |
||
156 | * @return \EasyWeChat\Support\Collection |
||
157 | */ |
||
158 | 1 | public function deletePrivateTemplate($templateId) |
|
164 | |||
165 | /** |
||
166 | * Send a notice message. |
||
167 | * |
||
168 | * @param $data |
||
169 | * |
||
170 | * @return \EasyWeChat\Support\Collection |
||
171 | * |
||
172 | * @throws \EasyWeChat\Core\Exceptions\InvalidArgumentException |
||
173 | */ |
||
174 | 2 | public function send($data = []) |
|
192 | |||
193 | /** |
||
194 | * Magic access.. |
||
195 | * |
||
196 | * @param string $method |
||
197 | * @param array $args |
||
198 | * |
||
199 | * @return Notice |
||
200 | */ |
||
201 | 2 | public function __call($method, $args) |
|
231 | |||
232 | /** |
||
233 | * Format template data. |
||
234 | * |
||
235 | * @param array $data |
||
236 | * |
||
237 | * @return array |
||
238 | */ |
||
239 | 2 | protected function formatData($data) |
|
270 | } |
||
271 |