《PHP-Cache實現短信驗證碼驗證》

/**
     * 檢測手機短信驗證碼
     */
    protected function checkRegSms($mobile, $code = false)
    {
        if (!$mobile) return false;
        if ($code === false) {   //判斷60秒以內是否重複發送
            if (!Cache::has('sms_' . $mobile)) return true;
            if (Cache::get('sms_' . $mobile)['times'] > time()) {
                return false;
            } else {
                return true;
            }
        } else {  //判斷驗證碼是否輸入正確
            if (!Cache::has('sms_' . $mobile)) return false;
            if (Cache::get('sms_' . $mobile)['code'] == $code) {
                return true;
            } else {
                return false;
            }
        }
    }

    /**
     * 設置手機短息驗證碼緩存
     */
    protected function setRegSmsCache($data_cache)
    {
        Cache::set('sms_'. $data_cache['mobile'], $data_cache, 300);
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章