namespace app\api\controller;
use think\Request;
class Api extends \think\Controller
{
public function __construct(Request $request)
{
if ($request->Controller() !== 'Api') {
$token = isset($request->post(false)['token'])?$request->post(false)['token']:'';
// 实例化Redis
$redis = new \Redis();
$redis -> connect('localhost',6379);
$redis -> auth('8G66336951a.');
if (!$redis -> get($token)) {
$data = [ 'info' => '信息为空', "status"=> 1 ];
echo json_encode($data);
exit;
}
}
}
/**
* 通过传入账号密码交换token
* @param string $user 账号
* @param string $password 密码
* @return string token
*/
<