Initial commit
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
namespace Home\Controller;
|
||||
use Think\Controller;
|
||||
|
||||
class BaseController extends Controller
|
||||
{
|
||||
private $loginStatus=1;//1为登录正常,0为登录异常
|
||||
public $user_id;
|
||||
public $openid;
|
||||
function _initialize() {
|
||||
//api接口相关设置
|
||||
C("SHOW_PAGE_TRACE",false);//强制关闭调试器
|
||||
header("Access-Control-Allow-Origin:*");//允许ajax远程跨域
|
||||
header('Access-Control-Allow-Headers:x-requested-with,content-type,user_id,openid');
|
||||
}
|
||||
public function __construct(){
|
||||
parent::__construct();
|
||||
//校验用户登录信息
|
||||
$this->checkLogin();
|
||||
}
|
||||
function checkLogin(){
|
||||
$this->user_id=$_SERVER['HTTP_USER_ID'];
|
||||
if(!$this->user_id){
|
||||
$loginStatus = 0;
|
||||
}
|
||||
$this->openid = $_SERVER['HTTP_OPENID'];
|
||||
if(!$this->openid){
|
||||
$loginStatus = 0;
|
||||
}
|
||||
header('loginStatus:'.$this->loginStatus);
|
||||
//error方法一定要放到header下而,否则客户端无法收到header中的loginStatus,newToken字段
|
||||
if(!$this->loginStatus ){
|
||||
$this->error('未登录');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user