【发布时间】:2021-08-05 15:35:36
【问题描述】:
我有一堆来自使用 Laravel7 的老团队的代码。我有 2 个端点:
- wd/request-otp(工作,OTP 在我的测试电子邮件中收到)
- wdreq(总是说“您的 OTP 无效!”)
所以,我查了相关代码:
resource/views/emails/otp.blade.php
<p>Your OTP:<p>
<p><h1>{{$otp}}</h1></p>
WithdrawService.php
/**
* @param $requestOTP
* @param $otpConfirmation
* @throws CustomException
*/
public function isValidOTP($requestOTP, $otpConfirmation)
{
if ($requestOTP !== (int) $otpConfirmation) {
throw new CustomException('Your OTP not valid', [$requestOTP, $otpConfirmation]);
}
}
OTP.php
/**
* Create OTP number and store in the cache
*
* @param string $prefix
* @param mixed $phone
* @return integer
*/
public function cacheTheOTP($prefix, $phone)
{
$OTP = rand(100000, 999999);
Cache::put([$this->OTPKey($prefix, $phone) => $OTP], \Carbon\Carbon::now()->addMinutes(10));
return $OTP;
}
也许 $requestOTP 总是 != $otpConfirmation (在我的电子邮件中收到,所以我可以看到它)。所以,我需要检查一下,$requestOTP 中的值是多少,与发送到我的电子邮件的 OTP 相同吗?有没有办法检查缓存记录?我应该怎么做才能解决这个问题?
【问题讨论】: