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