/php/drive/Response.php
php
<?php
//对客户端响应接口框架
class Response
{
public $code;
public $info;
public $data;
public function getRspCode()
{
return $this->code;
}
public function getRspInfo()
{
return $this->info;
}
public function getRspData()
{
return $this->data;
}
public function setRsp(& $code,& $info)
{
$this->code=$code;
$this->info=$info;
}
public function setRspData(& $code,& $info,& $data)
{
$this->code=$code;
$this->info=$info;
$this->data=$data;
}
}
?>
/php/drive/apikit.php
php
<?php
//include_once '../connector.php';
//对外请求的接口框架
trait curlassit
{
protected CurlHandle $ch;
public function setcurlhandle(CurlHandle &$curl)
{
$this->ch=&$curl;
}
public function getcurlerrormessage() //必须先设置才可以
{
return curl_error($this->ch);
}
public function getcurlhttpcode()
{
return curl_getinfo($this->ch, CURLINFO_HTTP_CODE);
}
public function getcurllasteffctiveurl()
{
return curl_getinfo($this->ch, CURLINFO_EFFECTIVE_URL);
}
//在此之前ch必须初始化
public function setgeneralheader()
{
$headerArray =array("Content-type:text/json;charset='utf-8'","Accept:application/json");
curl_setopt($this->ch,CURLOPT_HTTPHEADER,$headerArray);
curl_setopt($this->ch,CURLOPT_HTTPGET,true); //GET方法
curl_setopt($this->ch,CURLOPT_HEADER,false); //不输出HTTP头
curl_setopt($this->ch,CURLOPT_SSL_VERIFYPEER,false); //HTTPS
curl_setopt($this->ch,CURLOPT_SSL_VERIFYHOST,false);
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true) ; //true不echo 获取数据返回
curl_setopt($this->ch,CURLOPT_ENCODING,'gzip'); //gzip编码
curl_setopt($this->ch, CURLOPT_FAILONERROR, true); //默认是false
curl_setopt($this->ch, CURLOPT_TIMEOUT, 10);
}
}
class apiadapter
{
use curlassit;
protected string $data=''; //string
protected string $api=''; //原始url没有经过urlencode
public mixed $obj; //json_encode
public function getapi()
{
return $this->api;
}
public function resultdata()
{
return $this->data?$this->data:null;
}
public function datareset()
{
$this->data='';
}
public function replacezhurl(string $str)
{
$reg='/([\x81-\xfe][\x40-\xfe])/';
if(preg_match($reg,$str,$match))
{
return urlencode($str);
}
return $str;
}
}
?>
/php/drive/apifreame.php
php
<?php
//人逻辑判断的异常
trait Except
{
public $error_code;
public $error_mesg;
public function set($code,$mesg)
{
$this->error_code=$code;
$this->error_mesg=$mesg;
}
public function getErrorCode()
{
return $this->error_code;
}
public function getEroorMesg()
{
return $this->eroor_mesg;
}
}
class api
{
public $rqt_code;
public $rqt_info;
public $rqt_data;
public $usrtoken;
public function resetapi()
{
$this->rqt_code=null;
$this->rqt_data=null;
$this->usrtoken=null;
$this->rqt_info=null;
}
//request_code
public function assert_rqtcode()
{
if(!property_exists($this,'rqt_code') || $this->rqt_code==null || $this->rqt_code=='')
{
return false;
}
else
{
return true;
}
}
// request_data
public function assert_rqtdata()
{
if(!property_exists($this,'rqt_data') || $this->rqt_data==null || $this->rqt_data=='')
{
return false;
}
else
{
return true;
}
}
// request_info
public function assert_rqtinfo()
{
if(!property_exists($this,'rqt_info') || $this->rqt_info==null || $this->rqt_info=='')
{
return false;
}
else
{
return true;
}
}
// usrtoken
public function assert_usrtoken()
{
if(!property_exists($this,'usrtoken') || $this->usrtoken==null || $this->usrtoken=='')
{
return false;
}
else
{
return true;
}
}
public function assert()
{
if(!property_exists($this,'rqt_code') || !property_exists($this,'rqt_info')
|| !property_exists($this,'rqt_data') || !property_exists($this,'usrtoken'))
return false;
else
return true;
}
}
trait netlocation
{
//将部分反复使用的代码段封装到类里,减少业务层的代码和逻辑,方便检查修改
public $ipv4; //公网IPv4
public $localipv4; //局域网ipv4
public $ipv6;
public $altitude; //海拔高度
public $latitude; //纬度 #经纬度是不是强制的和必须的,存在用户不允许的情况。
public $longitude; //经度
public function resetnetlocation()
{
$this->ipv4=null;
$this->latitude=null;
$this->longitude=null;
}
public function assert_localipv4(& $obj)
{
if(!property_exists($obj,'localipv4') || $obj->localipv4==null || $obj->localipv4=='')
{
$this->localipv4=null;
return false;
}
else
{
$this->localipv4=$obj->localipv4;
return true;
}
}
public function assert_ipv6(& $obj)
{
if(!property_exists($obj,'ipv6') || $obj->ipv6==null || $obj->ipv6=='')
{
$this->ipv6=null;
return false;
}
else
{
$this->ipv6=$obj->ipv6;
return true;
}
}
// ipv4
public function assert_ipv4(& $obj)
{
if(!property_exists($obj,'ipv4') || $obj->ipv4==null || $obj->ipv4=='')
{
$this->ipv4=null;
return false;
}
else
{
$this->ipv4=$obj->ipv4;
return true;
}
}
// latitude
// longitude
public function assert_location(& $obj)
{
if(!property_exists($obj,'latitude') || $obj->latitude==null || $obj->latitude==''
|| !property_exists($obj,'longitude') || $obj->longitude==null || $obj->longitude=='')
{
$this->latitude=null;
$this->longitude=null;
return false;
}
else
{
$this->latitude=$obj->latitude;
$this->longitude=$obj->longitude;
return true;
}
}
//altitude海拔高度
public function assert_altitude(& $obj)
{
if(!property_exists($obj,'altitude') || $obj->altitude==null || $obj->altitude=='')
{
$this->altitude=null;
return false;
}
else
{
$this->altitude=$obj->altitude;
return true;
}
}
}
?>