1 | <?php |
||
9 | class Sms |
||
10 | { |
||
11 | private $auth; |
||
12 | private $baseURL; |
||
13 | |||
14 | public function __construct(Auth $auth) |
||
20 | |||
21 | /* |
||
22 | * 创建签名 |
||
23 | * signature: string 类型,必填,【长度限制8个字符内】超过长度会报错 |
||
24 | * source: string 类型,必填,申请签名时必须指定签名来源。取值范围为: |
||
25 | nterprises_and_institutions 企事业单位的全称或简称 |
||
26 | website 工信部备案网站的全称或简称 |
||
27 | app APP应用的全称或简称 |
||
28 | public_number_or_small_program 公众号或小程序的全称或简称 |
||
29 | store_name 电商平台店铺名的全称或简称 |
||
30 | trade_name 商标名的全称或简称, |
||
31 | * pics: 本地的图片路径 string 类型,可选 |
||
32 | *@return: 类型array { |
||
33 | "signature_id": <signature_id> |
||
34 | } |
||
35 | */ |
||
36 | public function createSignature(string $signature, string $source, string $pics = null) |
||
48 | |||
49 | /* |
||
50 | * 编辑签名 |
||
51 | * id 签名id : string 类型,必填, |
||
52 | * signature: string 类型,必填, |
||
53 | * source: string 类型,必填,申请签名时必须指定签名来源。取值范围为: |
||
54 | enterprises_and_institutions 企事业单位的全称或简称 |
||
55 | website 工信部备案网站的全称或简称 |
||
56 | app APP应用的全称或简称 |
||
57 | public_number_or_small_program 公众号或小程序的全称或简称 |
||
58 | store_name 电商平台店铺名的全称或简称 |
||
59 | trade_name 商标名的全称或简称, |
||
60 | * pics: 本地的图片路径 string 类型,可选, |
||
61 | * @return: 类型array { |
||
62 | "signature": string |
||
63 | } |
||
64 | */ |
||
65 | public function updateSignature(string $id, string $signature, string $source, string $pics = null) |
||
77 | |||
78 | /* |
||
79 | * 查询签名 |
||
80 | * audit_status: 审核状态 string 类型,可选, |
||
81 | 取值范围为: "passed"(通过), "rejected"(未通过), "reviewing"(审核中) |
||
82 | * page:页码 int 类型, |
||
83 | * page_size: 分页大小 int 类型,可选, 默认为20 |
||
84 | *@return: 类型array { |
||
85 | "items": [{ |
||
86 | "id": string, |
||
87 | "signature": string, |
||
88 | "source": string, |
||
89 | "audit_status": string, |
||
90 | "reject_reason": string, |
||
91 | "created_at": int64, |
||
92 | "updated_at": int64 |
||
93 | }...], |
||
94 | "total": int, |
||
95 | "page": int, |
||
96 | "page_size": int, |
||
97 | } |
||
98 | */ |
||
99 | public function checkSignature(string $audit_status = null, int $page = 1, int $page_size = 20) |
||
112 | |||
113 | |||
114 | /* |
||
115 | * 删除签名 |
||
116 | * id 签名id string 类型,必填, |
||
117 | * @retrun : 请求成功 HTTP 状态码为 200 |
||
118 | */ |
||
119 | public function deleteSignature(string $id) |
||
125 | |||
126 | |||
127 | |||
128 | |||
129 | /* |
||
130 | * 创建模板 |
||
131 | * name : 模板名称 string 类型 ,必填 |
||
132 | * template: 模板内容 string 类型,必填 |
||
133 | * type: 模板类型 string 类型,必填, |
||
134 | 取值范围为: notification (通知类短信), verification (验证码短信), marketing (营销类短信) |
||
135 | * description: 申请理由简述 string 类型,必填 |
||
136 | * signature_id: 已经审核通过的签名 string 类型,必填 |
||
137 | * @return: 类型 array { |
||
138 | "template_id": string |
||
139 | } |
||
140 | */ |
||
141 | public function createTemplate( |
||
159 | |||
160 | /* |
||
161 | * 查询模板 |
||
162 | * audit_status: 审核状态 string 类型 ,可选, |
||
163 | 取值范围为: passed (通过), rejected (未通过), reviewing (审核中) |
||
164 | * page: 页码 int 类型,可选,默认为 1 |
||
165 | * page_size: 分页大小 int 类型,可选,默认为 20 |
||
166 | * @return: 类型array{ |
||
167 | "items": [{ |
||
168 | "id": string, |
||
169 | "name": string, |
||
170 | "template": string, |
||
171 | "audit_status": string, |
||
172 | "reject_reason": string, |
||
173 | "type": string, |
||
174 | "signature_id": string, // 模版绑定的签名ID |
||
175 | "signature_text": string, // 模版绑定的签名内容 |
||
176 | "created_at": int64, |
||
177 | "updated_at": int64 |
||
178 | }...], |
||
179 | "total": int, |
||
180 | "page": int, |
||
181 | "page_size": int |
||
182 | } |
||
183 | */ |
||
184 | public function queryTemplate(string $audit_status = null, int $page = 1, int $page_size = 20) |
||
197 | |||
198 | /* |
||
199 | * 编辑模板 |
||
200 | * id :模板id |
||
201 | * name : 模板名称 string 类型 ,必填 |
||
202 | * template: 模板内容 string 类型,必填 |
||
203 | * description: 申请理由简述 string 类型,必填 |
||
204 | * signature_id: 已经审核通过的签名 string 类型,必填 |
||
205 | * @retrun : 请求成功 HTTP 状态码为 200 |
||
206 | */ |
||
207 | public function updateTemplate( |
||
223 | |||
224 | /* |
||
225 | * 删除模板 |
||
226 | * id :模板id string 类型,必填, |
||
227 | * @retrun : 请求成功 HTTP 状态码为 200 |
||
228 | */ |
||
229 | public function deleteTemplate(string $id) |
||
235 | |||
236 | /* |
||
237 | * 发送短信 |
||
238 | * 编辑模板 |
||
239 | * template_id :模板id string类型,必填 |
||
240 | * mobiles : 手机号数组 []string 类型 ,必填 |
||
241 | * parameters: 模板内容 map[string]string 类型,可选 |
||
242 | * @return: 类型json { |
||
243 | "job_id": string |
||
244 | } |
||
245 | */ |
||
246 | public function sendMessage(string $template_id, array $mobiles, array $parameters = null) |
||
258 | |||
259 | public function imgToBase64(string $img_file) |
||
292 | |||
293 | private function get($url, $cType = null) |
||
303 | |||
304 | private function delete($url, $contentType = 'application/json') |
||
314 | |||
315 | private function post($url, $body, $contentType = 'application/json') |
||
337 | } |
||
338 |
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.