This commit is contained in:
pomjay
2025-06-25 09:35:09 +08:00
parent 81a95f47a0
commit 7e3eba92e2
16 changed files with 154 additions and 44 deletions

View File

@ -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;
}