1 | <?php |
||
10 | class Sms |
||
11 | { |
||
12 | private $auth; |
||
13 | private $baseURL; |
||
14 | |||
15 | public function __construct(Auth $auth) |
||
21 | |||
22 | /** |
||
23 | * 创建签名 |
||
24 | * |
||
25 | * @param string $signature 签名 |
||
26 | * @param string $source 签名来源,申请签名时必须指定签名来源 |
||
27 | * @param string $pics 签名对应的资质证明图片进行 base64 编码格式转换后的字符串,可选 |
||
28 | * @return array |
||
29 | * |
||
30 | * @link https://developer.qiniu.com/sms/api/5844/sms-api-create-signature |
||
31 | */ |
||
32 | public function createSignature($signature, $source, $pics = null) |
||
43 | |||
44 | /** |
||
45 | * 编辑签名 |
||
46 | * |
||
47 | * @param string $id 签名 ID |
||
48 | * @param string $signature 签名 |
||
49 | * @param string $source 签名来源 |
||
50 | * @param string $pics 签名对应的资质证明图片进行 base64 编码格式转换后的字符串,可选 |
||
51 | * @return array |
||
52 | * @link https://developer.qiniu.com/sms/api/5890/sms-api-edit-signature |
||
53 | */ |
||
54 | public function updateSignature($id, $signature, $source, $pics = null) |
||
65 | |||
66 | /** |
||
67 | * 列出签名 |
||
68 | * |
||
69 | * @param string $audit_status 审核状态:"passed"(通过), "rejected"(未通过), "reviewing"(审核中) |
||
70 | * @param int $page 页码。默认为 1 |
||
71 | * @param int $page_size 分页大小。默认为 20 |
||
72 | * @return array |
||
73 | * @link https://developer.qiniu.com/sms/api/5889/sms-api-query-signature |
||
74 | */ |
||
75 | public function querySignature($audit_status = null, $page = 1, $page_size = 20) |
||
87 | |||
88 | /** |
||
89 | * 查询单个签名 |
||
90 | * |
||
91 | * @param string $signature_id |
||
92 | * @return array |
||
93 | * @link https://developer.qiniu.com/sms/api/5970/query-a-single-signature |
||
94 | */ |
||
95 | public function checkSingleSignature($signature_id) |
||
105 | |||
106 | /** |
||
107 | * 删除签名 |
||
108 | * |
||
109 | * @param string $signature_id 签名 ID |
||
110 | * @return array |
||
111 | * @link https://developer.qiniu.com/sms/api/5891/sms-api-delete-signature |
||
112 | */ |
||
113 | public function deleteSignature($signature_id) |
||
118 | |||
119 | /** |
||
120 | * 创建模板 |
||
121 | * |
||
122 | * @param string $name 模板名称 |
||
123 | * @param string $template 模板内容 可设置自定义变量,发送短信时候使用,参考:${code} |
||
124 | * @param string $type notification:通知类,verification:验证码,marketing:营销类,voice:语音类 |
||
125 | * @param string $description 申请理由简述 |
||
126 | * @param string $signature_id 已经审核通过的签名 |
||
127 | * @return array array |
||
128 | * @link https://developer.qiniu.com/sms/api/5893/sms-api-create-template |
||
129 | */ |
||
130 | public function createTemplate( |
||
147 | |||
148 | /** |
||
149 | * 列出模板 |
||
150 | * |
||
151 | * @param string $audit_status 审核状态:passed (通过), rejected (未通过), reviewing (审核中) |
||
152 | * @param int $page 页码。默认为 1 |
||
153 | * @param int $page_size 分页大小。默认为 20 |
||
154 | * @return array |
||
155 | * @link https://developer.qiniu.com/sms/api/5894/sms-api-query-template |
||
156 | */ |
||
157 | public function queryTemplate($audit_status = null, $page = 1, $page_size = 20) |
||
169 | |||
170 | /** |
||
171 | * 查询单个模版 |
||
172 | * |
||
173 | * @param string $template_id 模版ID |
||
174 | * @return array |
||
175 | * @link https://developer.qiniu.com/sms/api/5969/query-a-single-template |
||
176 | */ |
||
177 | public function querySingleTemplate($template_id) |
||
187 | |||
188 | /** |
||
189 | * 编辑模板 |
||
190 | * |
||
191 | * @param string $id 模板 ID |
||
192 | * @param string $name 模板名称 |
||
193 | * @param string $template 模板内容 |
||
194 | * @param string $description 申请理由简述 |
||
195 | * @param string $signature_id 已经审核通过的签名 ID |
||
196 | * @return array |
||
197 | * @link https://developer.qiniu.com/sms/api/5895/sms-api-edit-template |
||
198 | */ |
||
199 | public function updateTemplate( |
||
214 | |||
215 | /** |
||
216 | * 删除模板 |
||
217 | * |
||
218 | * @param string $template_id 模板 ID |
||
219 | * @return array |
||
220 | * @link https://developer.qiniu.com/sms/api/5896/sms-api-delete-template |
||
221 | */ |
||
222 | public function deleteTemplate($template_id) |
||
227 | |||
228 | /** |
||
229 | * 发送短信 |
||
230 | * |
||
231 | * @param string $template_id 模板 ID |
||
232 | * @param string[] $mobiles 手机号 |
||
233 | * @param string $parameters 自定义模板变量,变量设置在创建模板时,参数template指定 |
||
234 | * @return array |
||
235 | * @link https://developer.qiniu.com/sms/api/5897/sms-api-send-message |
||
236 | */ |
||
237 | public function sendMessage($template_id, $mobiles, $parameters = null) |
||
248 | |||
249 | /** |
||
250 | * 查询发送记录 |
||
251 | * |
||
252 | * @param string $job_id 发送任务返回的 id |
||
253 | * @param string $message_id 单条短信发送接口返回的 id |
||
254 | * @param string $mobile 接收短信的手机号码 |
||
255 | * @param string $status sending: 发送中,success: 发送成功,failed: 发送失败,waiting: 等待发送 |
||
256 | * @param string $template_id 模版 id |
||
257 | * @param string $type marketing:营销,notification:通知,verification:验证码,voice:语音 |
||
258 | * @param string $start 开始时间,timestamp,例如: 1563280448 |
||
259 | * @param int $end 结束时间,timestamp,例如: 1563280471 |
||
260 | * @param int $page 页码,默认为 1 |
||
261 | * @param int $page_size 每页返回的数据条数,默认20,最大200 |
||
262 | * @return array |
||
263 | * @link https://developer.qiniu.com/sms/api/5852/query-send-sms |
||
264 | */ |
||
265 | public function querySendSms( |
||
292 | |||
293 | |||
294 | public function imgToBase64($img_file) |
||
327 | |||
328 | private function get($url, $contentType = 'application/x-www-form-urlencoded') |
||
338 | |||
339 | private function delete($url, $contentType = 'application/json') |
||
349 | |||
350 | private function post($url, $body, $contentType = 'application/json') |
||
363 | |||
364 | private function PUT($url, $body, $contentType = 'application/json') |
||
375 | } |
||
376 |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.