123456789101112131415161718192021222324252627282930 |
- <?php
- namespace app\common\model;
- use Carbon\Carbon;
- use think\Model;
- /**
- * 短信验证码
- */
- class QiyuToken Extends Model
- {
- public static function clear(){
- return self::where('expire','<',time())->delete();
- }
- public static function getToken(){
- self::clear();
- return self::create([
- 'token'=>session_create_id(),
- 'expire'=>Carbon::now()->addSeconds(7210)->timestamp,
- ])['token'];
- }
- public static function exists($token){
- if(!$token){
- return false;
- }
- $has=self::where('token',$token)->where('expire','>',Carbon::now()->timestamp)->value('id');
- return $has>0;
- }
- }
|