$phone, 'code' => mt_rand(100000,999999), 'status' => 0, 'add_time' => $curTime, 'end_time' => $curTime + 10*60 ]; $ret = Db::name('sms_record')->insert($data); return $ret?$data['code']:false; } // 验证手机验证码 public function checkCode($phone,$code){ $info = Db::name('sms_record') ->where('phone',$phone) ->where('code',$code) ->find(); if(!$info){ return false; } if($info['status'] != 0 || $info['end_time'] < time()){ return false; } Db::name('sms_record')->where('id',$info['id'])->setField('status',1); return true; } }