PhoneService.php 799 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. namespace App\Services\Auth;
  3. use App\Facades\ChuanglanSmsFacade;
  4. use App\Services\Service;
  5. use Illuminate\Support\Facades\Cache;
  6. class PhoneService extends Service
  7. {
  8. /**
  9. * 发送短信验证码
  10. * @param string $phone
  11. * @return bool
  12. */
  13. public function sendVerifyCode(string $phone)
  14. {
  15. $code = rand(1000, 9999);
  16. $result = ChuanglanSmsFacade::sendSMS($phone, "【无邪科技】您的短信验证码为:{$code},若非本人操作请忽略。");
  17. if (isset($result['code']) && $result['code'] == '0') {
  18. Cache::put("smsverifycode:{$phone}", $code, 1);
  19. return true;
  20. }
  21. app('sentry')->captureMessage("验证码发送异常日志", array(), array('extra' => $result));
  22. return false;
  23. }
  24. }