备份三个PHP程序

/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;
            }
                
        }
    }

?>
相关推荐
lly2024068 小时前
PHP Error: 常见错误及其解决方法
开发语言
网安墨雨8 小时前
Python自动化一------pytes与allure结合生成测试报告
开发语言·自动化测试·软件测试·python·职场和发展·自动化
lpfasd1238 小时前
物联网后端岗位java面试题
java·物联网·php
毕设源码李师姐8 小时前
计算机毕设 java 基于 java 的图书馆借阅系统 智能图书馆借阅综合管理平台 基于 Java 的图书借阅与信息管理系统
java·开发语言·课程设计
忆~遂愿8 小时前
Runtime 上下文管理:计算实例的生命周期、延迟最小化与上下文切换优化
java·大数据·开发语言·人工智能·docker
沐知全栈开发8 小时前
PostgreSQL中的AND和OR操作符
开发语言
1尢晞19 小时前
Java学习
java·开发语言
JSON_L9 小时前
Fastadmin中使用百度翻译API
php·fastadmin·百度翻译api
毕设源码-赖学姐9 小时前
【开题答辩全过程】以 基于python的电影推荐系统为例,包含答辩的问题和答案
开发语言·python