QiyuToken.php 692 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. namespace app\common\model;
  3. use Carbon\Carbon;
  4. use think\Model;
  5. /**
  6. * 短信验证码
  7. */
  8. class QiyuToken Extends Model
  9. {
  10. public static function clear(){
  11. return self::where('expire','<',time())->delete();
  12. }
  13. public static function getToken(){
  14. self::clear();
  15. return self::create([
  16. 'token'=>session_create_id(),
  17. 'expire'=>Carbon::now()->addSeconds(7210)->timestamp,
  18. ])['token'];
  19. }
  20. public static function exists($token){
  21. if(!$token){
  22. return false;
  23. }
  24. $has=self::where('token',$token)->where('expire','>',Carbon::now()->timestamp)->value('id');
  25. return $has>0;
  26. }
  27. }