| Conditions | 6 |
| Paths | 7 |
| Total Lines | 37 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 42 |
| Changes | 0 | ||
| 1 | <?php |
||
| 22 | public static function verify($credentials = []) |
||
| 23 | { |
||
| 24 | $credentials['appkey'] = config('services.mobsms.key'); |
||
| 25 | |||
| 26 | try { |
||
| 27 | $response = (new HttpClient([ |
||
| 28 | 'connect_timeout' => 5, |
||
| 29 | 'timeout' => 20, |
||
| 30 | ])) |
||
| 31 | ->post('https://webapi.sms.mob.com/sms/verify', [ |
||
| 32 | 'form_params' => $credentials, |
||
| 33 | ]) |
||
| 34 | ->getBody(); |
||
| 35 | |||
| 36 | $response = json_decode($response, true); |
||
| 37 | } catch (Exception $e) { |
||
| 38 | throw new ActionFailureException('短信网关请求失败'); |
||
| 39 | } |
||
| 40 | |||
| 41 | if (! is_array($response)) { |
||
| 42 | throw new ActionFailureException('短信网关数据异常[sms]'); |
||
| 43 | } |
||
| 44 | |||
| 45 | $status = (int) array_get($response, 'status', -1); |
||
| 46 | |||
| 47 | if (200 === $status) { |
||
| 48 | return; |
||
| 49 | } |
||
| 50 | |||
| 51 | if (457 === $status) { |
||
| 52 | throw new InvalidInputException('请填写正确的手机号', 10); |
||
| 53 | } elseif (467 === $status) { |
||
| 54 | throw new InvalidInputException('请求验证码过于频繁,请稍后再试'); |
||
| 55 | } else { |
||
| 56 | throw new InvalidInputException("验证码无效,请重新获取 [{$status}]"); |
||
| 57 | } |
||
| 58 | } |
||
| 59 | } |
||
| 60 |