SmsModel::CheckCaptcha PHP Method

CheckCaptcha() public method

校验验证码是否正确
Author: Medz Seven ([email protected])
public CheckCaptcha ( float $phone, integer $code ) : boolean
$phone float 手机号码
$code integer 验证码
return boolean
    public function CheckCaptcha($phone, $code)
    {
        $data = $this->where('`phone` = ' . floatval($phone) . ' AND `message` = \'\' AND `code` != 0 AND `time` > ' . (time() - 1800))->field('code')->order('`time` DESC')->getField('code');
        $code = intval($code);
        /* # 判断验证码是否为空 */
        if (!$code) {
            $this->setMessage('验证码不能为空');
            return false;
            /* # 判断是否有发送记录数据 */
        } elseif (!$data) {
            $this->setMessage('没有发送记录');
            return false;
            /* # 判断是否匹配 */
        } elseif ($data != $code) {
            $this->setMessage('验证码不正确');
            return false;
        }
        return true;
    }