发布推送
This commit is contained in:
@ -7,6 +7,7 @@ use App\Const\VrCode;
|
||||
use App\Exceptions\AppException;
|
||||
use App\Tools\Tools;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Env;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
|
||||
class VrCodeService
|
||||
@ -18,47 +19,47 @@ class VrCodeService
|
||||
public $iType = null;
|
||||
public $iUid = null;
|
||||
|
||||
public function getSKey(): null
|
||||
public function getSKey()
|
||||
{
|
||||
return $this->sKey;
|
||||
}
|
||||
|
||||
public function setSKey(null $sKey): void
|
||||
public function setSKey($sKey): void
|
||||
{
|
||||
$this->sKey = $sKey;
|
||||
}
|
||||
|
||||
public function getsCode(): null
|
||||
public function getsCode()
|
||||
{
|
||||
return $this->sCode;
|
||||
}
|
||||
|
||||
public function setsCode(null $sCode): void
|
||||
public function setsCode($sCode): void
|
||||
{
|
||||
$this->sCode = $sCode;
|
||||
}
|
||||
|
||||
public function getSPhoneArea(): null
|
||||
public function getSPhoneArea()
|
||||
{
|
||||
return $this->sPhoneArea;
|
||||
}
|
||||
|
||||
public function setSPhoneArea(null $sPhoneArea): void
|
||||
public function setSPhoneArea($sPhoneArea): void
|
||||
{
|
||||
$this->sPhoneArea = $sPhoneArea;
|
||||
}
|
||||
|
||||
public function getSPhone(): null
|
||||
public function getSPhone()
|
||||
{
|
||||
return $this->sPhone;
|
||||
}
|
||||
|
||||
public function setSPhone(null $sPhone): void
|
||||
public function setSPhone($sPhone): void
|
||||
{
|
||||
$this->sPhone = $sPhone;
|
||||
}
|
||||
|
||||
public function getIType(): null
|
||||
public function getIType()
|
||||
{
|
||||
return $this->iType;
|
||||
}
|
||||
@ -66,25 +67,25 @@ class VrCodeService
|
||||
/**
|
||||
* @throws AppException
|
||||
*/
|
||||
public function setIType(null $iType): void
|
||||
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;
|
||||
}
|
||||
|
||||
public function getIUid(): null
|
||||
public function getIUid()
|
||||
{
|
||||
return $this->iUid;
|
||||
}
|
||||
|
||||
public function setIUid(null $iUid): void
|
||||
public function setIUid($iUid): void
|
||||
{
|
||||
$this->iUid = $iUid;
|
||||
}
|
||||
|
||||
function sendSmsToPhone(): bool
|
||||
{
|
||||
return true;
|
||||
return (new SmsService())->sendSmsCode($this->sPhoneArea.$this->sPhone, $this->sCode);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -94,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();
|
||||
}
|
||||
|
||||
@ -103,10 +104,10 @@ class VrCodeService
|
||||
*/
|
||||
function genKey(): false|string
|
||||
{
|
||||
if(!in_array($this->iType,VrCode::TOPIC_PREFIX)) throw new AppException('invalid sms type');
|
||||
if($this->iType == VrCode::TOPIC_REGISTER) {
|
||||
if (!in_array($this->iType, VrCode::TOPIC_PREFIX)) 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 {
|
||||
} else {
|
||||
return VrCode::TOPIC_PREFIX[VrCode::TOPIC_REGISTER] . $this->iUid;
|
||||
}
|
||||
}
|
||||
@ -118,7 +119,7 @@ class VrCodeService
|
||||
|
||||
function setCodeToCache()
|
||||
{
|
||||
return Redis::set($this->sKey,$this->sCode,VrCode::REDIS_CACHE_EXPIRE);
|
||||
return Redis::set($this->sKey, $this->sCode, VrCode::REDIS_CACHE_EXPIRE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -131,9 +132,12 @@ class VrCodeService
|
||||
|
||||
function checkCode($sReqCode): bool
|
||||
{
|
||||
if(Env::get('APP_DEBUG') == true){
|
||||
if ($sReqCode === '000000') return true;
|
||||
}
|
||||
$sCode = $this->getCodeFromCache();
|
||||
if(empty($sCode)) return false;
|
||||
if($sCode != $sReqCode) return false;
|
||||
if (empty($sCode)) return false;
|
||||
if ($sCode != $sReqCode) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user