代码:
<?php
namespace app\api\controller;
use app\api\controller\ba
use \Fireba
use app\api\validate\LoginValidate;
use app\common\model\UserModel;
use think\Request;
class Login extends ba
{
public function index(Request $request)
{
//验证输入是否合法
// $data=$request->param();
// $validate=new LoginValidate();
// if(!$validate->check($data)){
// return json(['code'=>0,'msg'=>$validate->getError()],400);
// }
//查询数据表
// $db=new UserModel();
// $res=$db->where('username',$data['username'])->where('password',$data['password'])->find();
// if(!$res){
// return json(['code'=>0,'msg'=>'用户名或者密码错误'],400);
// }
$key = 'api';
$pcode = array(
"iat" => time(),
"nbf" => time(),
"exp" => time()+60*60/2,//有效时间
"uid" =>122323233
);
$token =JWT::encode($pcode, $key);
return json(['code'=>1,'msg'=>'登录成功','token'=>$token]);
}
}
?>
MAD`06_DH@C$1BXCV{7GQ3X.png
( 59.59 KB 下载:7 次 )
最佳答案