// +---------------------------------------------------------------------- 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; } }