<?php
error_reporting(0);
abstract class Controller {
protected $registry;
public function __construct($registry)
{
//设计思路理念
$this->registry = $registry;
$_SERVER['REQUEST_URI'];
$str = http_build_query($_REQUEST);
$_SERVER['REMOTE_ADDR'];
}
public function __get($key) {}
public function __set($key, $value) {}
public function exit( $json ) {
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
/*
* 检测必填参数*/
public function must_params($data) {
$return = true;
foreach($data as $val) {
if(empty($this->request->post[$val])) { //必填参数不能为空
$return = false;
break;
}
}
return $return;
}
/*
* 需要登录的构造函数*/
public function _construct($data) {
foreach($data as $val) {
if(empty($this->request->post[$val])) { //必填参数不能为空
return array('code'=>0,'message'=>'参数错误!');
break;
}
}
//验证token checkExpire()) //token有效期
//token 是否正确
}
/*
* 输出返回数据*/
public function return_output($data,$type = 'JSON') {
/*$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($data));*/
if(empty($type)) $type = 'JSON';
if(strtoupper($type)=='JSON') {
// 返回JSON数据格式到客户端 包含状态信息
// header('Content-Type:text/html; charset=utf-8');
header('Content-Type: application/json');
exit(json_encode($data));
}elseif(strtoupper($type)=='XML'){
// 返回xml格式数据
header('Content-Type:text/xml; charset=utf-8');
exit(xml_encode($data));
}elseif(strtoupper($type)=='EVAL'){
// 返回可执行的js脚本
header('Content-Type:text/html; charset=utf-8');
exit($data);
}else{
// TODO 增加其它格式
}
}
//获取距离
//在线时间
$online_time = formatOnlineTime($rVal['heartbeat']);
$rVal = array_merge($rVal,$online_time);
//当前位置数据
//获取距离
//当前位置
//距离
//经度
//维度
//地址
//直播ID
unset($rVal['heartbeat']);
/*
* 获取两点距离
* */
C设计思路理念
最新推荐文章于 2022-01-14 18:17:54 发布