Conditions | 9 |
Paths | 9 |
Total Lines | 34 |
Code Lines | 22 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 90 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
21 | public static function verify($credentials = []) |
||
22 | { |
||
23 | $response = (new HttpClient('https://webapi.sms.mob.com/')) |
||
24 | ->formParams(array_merge($credentials, ['appkey' => config('services.mobsms.key')])) |
||
25 | ->fetchJson('/sms/verify', 'POST'); |
||
26 | |||
27 | if (! is_array($response)) { |
||
28 | throw new ActionFailureException('短信网关请求失败'); |
||
29 | } |
||
30 | |||
31 | $status = (int) array_get($response, 'status', -1); |
||
32 | |||
33 | switch ($status) { |
||
34 | case 200: |
||
35 | return; |
||
36 | |||
37 | case 405: |
||
38 | case 406: |
||
39 | case 474: |
||
40 | throw new ActionFailureException('Server Error #'.$status); |
||
41 | |||
42 | case 457: |
||
43 | throw new InvalidInputException('请填写正确的手机号', 10); |
||
44 | |||
45 | case 466: |
||
46 | throw new InvalidInputException('验证码不能为空'); |
||
47 | |||
48 | case 467: |
||
49 | throw new InvalidInputException('请求验证码过于频繁,请稍后再试'); |
||
50 | |||
51 | default: |
||
52 | throw new InvalidInputException('验证码无效,请重新获取'); |
||
53 | } |
||
54 | } |
||
55 | } |
||
56 |