11
This commit is contained in:
@ -31,9 +31,11 @@ class AuthService
|
||||
|
||||
function getUserInfoByToken($sToken)
|
||||
{
|
||||
|
||||
if (empty($sToken)) return null;
|
||||
$sUidInfo = Redis::get(RedisConst::TOKEN_UID . $sToken);
|
||||
if (empty($sUidInfo)) return null;
|
||||
|
||||
return unserialize($sUidInfo);
|
||||
}
|
||||
|
||||
@ -43,7 +45,14 @@ class AuthService
|
||||
'uid' => $iUid,
|
||||
'device' => $sDevice,
|
||||
]);
|
||||
return Redis::set(RedisConst::TOKEN_UID . $sToken, $sUidInfo, RedisConst::COMMON_EXP_TIME);
|
||||
// 临时用predis
|
||||
return Redis::command('set', [
|
||||
RedisConst::TOKEN_UID . $sToken,
|
||||
$sUidInfo,
|
||||
'ex',
|
||||
RedisConst::COMMON_EXP_TIME,
|
||||
]);
|
||||
//return Redis::set(RedisConst::TOKEN_UID . $sToken, $sUidInfo, RedisConst::COMMON_EXP_TIME);
|
||||
}
|
||||
|
||||
function delUserInfoToToken($sToken)
|
||||
@ -78,7 +87,11 @@ class AuthService
|
||||
'exp_time' => Carbon::parse(time() + RedisConst::COMMON_EXP_TIME)->toDateTimeString(),
|
||||
];
|
||||
$sTokenList = serialize($aTokenInfoList);
|
||||
return Redis::set(RedisConst::UID_TOKENS . $iUid, $sTokenList);
|
||||
// 临时用predis
|
||||
return Redis::command('set', [
|
||||
RedisConst::UID_TOKENS . $iUid, $sTokenList
|
||||
]);
|
||||
// return Redis::set(RedisConst::UID_TOKENS . $iUid, $sTokenList);
|
||||
}
|
||||
|
||||
function delTokenByUidInfo($iUid, $sToken)
|
||||
@ -88,7 +101,11 @@ class AuthService
|
||||
if (!isset($aTokenInfoList[$sToken])) return false;
|
||||
unset($aTokenInfoList[$sToken]);
|
||||
$sTokenList = serialize($aTokenInfoList);
|
||||
return Redis::set(RedisConst::UID_TOKENS . $iUid, $sTokenList);
|
||||
// 临时用predis
|
||||
return Redis::command('set', [
|
||||
RedisConst::UID_TOKENS . $iUid, $sTokenList
|
||||
]);
|
||||
//return Redis::set(RedisConst::UID_TOKENS . $iUid, $sTokenList);
|
||||
}
|
||||
|
||||
function getTokenFromReq(\Illuminate\Http\Request $request = null)
|
||||
|
||||
@ -67,7 +67,9 @@ class VrCodeService
|
||||
*/
|
||||
public function setIType($iType): void
|
||||
{
|
||||
if (!in_array($iType, VrCode::TOPIC)) throw new AppException('invalid sms type');
|
||||
if (!in_array($iType, VrCode::TOPIC)) {
|
||||
throw new AppException('invalid sms type');
|
||||
}
|
||||
$this->iType = $iType;
|
||||
}
|
||||
|
||||
@ -93,7 +95,7 @@ class VrCodeService
|
||||
{
|
||||
$this->sKey = $this->genKey();
|
||||
$this->sCode = $this->genCode();
|
||||
if (!$this->sendSmsToPhone()) throw new AppException('send sms failed');
|
||||
//没有先注释 if (!$this->sendSmsToPhone()) throw new AppException('send sms failed');
|
||||
$this->setCodeToCache();
|
||||
}
|
||||
|
||||
@ -102,7 +104,8 @@ class VrCodeService
|
||||
*/
|
||||
function genKey(): false|string
|
||||
{
|
||||
if (!in_array($this->iType, VrCode::TOPIC_PREFIX)) throw new AppException('invalid sms type');
|
||||
var_dump($this->iType);
|
||||
if (!in_array($this->iType, VrCode::TOPIC)) throw new AppException('invalid sms type');
|
||||
if ($this->iType == VrCode::TOPIC_REGISTER) {
|
||||
return VrCode::TOPIC_PREFIX[VrCode::TOPIC_REGISTER] . md5($this->sPhoneArea . $this->sPhone);
|
||||
} else {
|
||||
@ -117,7 +120,10 @@ class VrCodeService
|
||||
|
||||
function setCodeToCache()
|
||||
{
|
||||
return Redis::set($this->sKey, $this->sCode, VrCode::REDIS_CACHE_EXPIRE);
|
||||
var_dump($this->sCode);
|
||||
//临时用predis
|
||||
return Redis::command('set', [$this->sKey, $this->sCode, 'ex', VrCode::REDIS_CACHE_EXPIRE]);
|
||||
//return Redis::set($this->sKey, $this->sCode, VrCode::REDIS_CACHE_EXPIRE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -134,7 +140,9 @@ class VrCodeService
|
||||
if ($sReqCode === '000000') return true;
|
||||
}
|
||||
$sCode = $this->getCodeFromCache();
|
||||
if (empty($sCode)) return false;
|
||||
var_dump($sCode);
|
||||
var_dump($sReqCode);
|
||||
if (empty($sReqCode)) return false;
|
||||
if ($sCode != $sReqCode) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user