| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- // +----------------------------------------------------------------------
- // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
- // +----------------------------------------------------------------------
- // | 版权所有 2017~2021 LARAVEL研发中心
- // +----------------------------------------------------------------------
- // | 官方网站: http://www.laravel.cn
- // +----------------------------------------------------------------------
- // | Author: laravel开发员 <laravel.qq.com>
- // +----------------------------------------------------------------------
- namespace App\Services;
- /**
- * 谷歌验证码管理-服务类
- * Class GoogleCodeService
- * @package App\Services
- */
- class GoogleCodeService extends BaseService
- {
- // 静态对象
- protected static $instance = null;
- /**
- * 初始化配置
- * @return bool
- */
- public function __construct()
- {
- $this->config = ConfigService::make()->getConfigByGroup(2);
- if (empty($this->config)) {
- return false;
- }
- }
- /**
- * 静态入口
- * @return static|null
- */
- public static function make()
- {
- if (!self::$instance) {
- self::$instance = (new static());
- }
- return self::$instance;
- }
- public function getQrcode($userId)
- {
- }
- /**
- * 发送谷歌验证码
- * @param $userId
- * @param string $scene 场景:默认reg-注册
- * @return bool
- */
- public function sendCode($userId, $scene = 'reg')
- {
- try {
- $cacheKey = "stores:codes:google_{$scene}:{$userId}";
- } catch (\Exception $exception) {
- $this->error = $exception->getMessage();
- return false;
- }
- }
- /**
- * 验证手机短信
- * @param $mobile
- * @param $code
- * @param string $scene 场景:默认reg-注册
- * @return bool
- */
- public function check($mobile, $code, $scene = 'reg')
- {
- $cacheKey = "stores:codes:sms_{$scene}:". substr($mobile, -3, 3) . '_' . md5($mobile);
- $codeData = RedisService::get($cacheKey);
- $checkCode = isset($codeData['code']) ? $codeData['code'] : 0;
- $checkMobile = isset($codeData['mobile']) ? $codeData['mobile'] : '';
- if (empty($codeData) || empty($checkCode)) {
- $this->error = 2010;
- return false;
- }
- if ($checkMobile != $mobile || $checkCode != $code) {
- $this->error = 2006;
- return false;
- }
- return true;
- }
- }
|