SmsService.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 LARAVEL研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: laravel开发员 <laravel.qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Services;
  12. use App\Models\ConfigModel;
  13. /**
  14. * 手机短信管理-服务类
  15. * @author
  16. * @since 2020/11/11
  17. * Class SmsService
  18. * @package App\Services
  19. */
  20. class SmsService extends BaseService
  21. {
  22. // 静态对象
  23. protected static $instance = null;
  24. /**
  25. * 静态入口
  26. * @return static|null
  27. */
  28. public static function make()
  29. {
  30. if(!self::$instance){
  31. self::$instance = (new static());
  32. }
  33. return self::$instance;
  34. }
  35. /**
  36. * 发送手机短信
  37. * @param $email
  38. * @param string $scene 场景:默认reg-注册
  39. * @return bool
  40. */
  41. public function sendCode($mobile, $scene='reg')
  42. {
  43. return true;
  44. }
  45. /**
  46. * 验证手机短信
  47. * @param $mobile
  48. * @param $code
  49. * @param string $scene 场景:默认reg-注册
  50. * @return bool
  51. */
  52. public function check($mobile, $code, $scene='reg')
  53. {
  54. $cacheKey = "stores:codes:mobile_{$scene}:" . md5($mobile);
  55. $codeData = RedisService::get($cacheKey);
  56. $checkCode = isset($codeData['code'])? $codeData['code'] : 0;
  57. $checkMobile = isset($codeData['mobile'])? $codeData['mobile'] : '';
  58. if(empty($codeData) || empty($checkCode)){
  59. $this->error = 2010;
  60. return false;
  61. }
  62. if($checkMobile != $mobile || $checkCode != $code){
  63. $this->error = 2006;
  64. return false;
  65. }
  66. return true;
  67. }
  68. }