封装好的宝塔API接口类单文件版,开封即用
<?php namespace hisi; use think\Env; if(!defined('DS')) define('DS', DIRECTORY_SEPARATOR); if(!defined('ROOT_PATH')) define('ROOT_PATH',str_replace('\\','/',realpath(dirname(__FILE__).'/'))."/"); class BtApi{ private $BT_PANEL = ""; //面板地址 private $BT_KEY = ""; //接口密钥 protected $error = "未知错误"; //错误信息 //如果希望多台面板,可以在实例化对象时,将面板地址与密钥传入 public function __construct($bt_panel = null,$bt_key = null){ if($bt_panel) $this->BT_PANEL = $bt_panel; if($bt_key) $this->BT_KEY = $bt_key; } public function setBtKey($btKey) { $this->BT_KEY = $btKey; } public function setBtPanel($btPanel) { $this->BT_PANEL = $btPanel; } /** 基础信息模块开始 *******************************/ /** * 获取系统基础统计 * * @return void * @author 617 * @Description */ public function getSysTotal() { $url = $this->BT_PANEL.'/system?action=GetSystemTotal'; $ret = $this->post($url); return json_decode($ret,true); } /** * 获取磁盘分区信息 * * @param Type $var * @return void * @author 617 * @Description */ public function getDiskInfo() { $url = $this->BT_PANEL.'/system?action=GetDiskInfo'; $ret = $this->post($url); return json_decode($ret,true); } /** * 获取实时状态信息(CPU、内存、网络、负载) * * @param Type $var * @return void * @author 617 * @Description */ public function getNetWork() { $url = $this->BT_PANEL.'/system?action=GetNetWork'; $ret = $this->post($url); return json_decode($ret,true); } /** * 检查是否有安装任务 * * @param Type $var * @return void * @author 617 * @Description */ public function getTaskCount() { $url = $this->BT_PANEL.'/ajax?action=GetTaskCount'; $ret = $this->post($url); return json_decode($ret,true); } /** * 检查面板更新 * * @param Type $var * @return void * @author 617 * @Description */ public function updatePanel() { $url = $this->BT_PANEL.'/ajax?action=UpdatePanel'; $ret = $this->post($url); return json_decode($ret,true); } /** 基础信息模块结束 ********************/ /** 网站管理模块开始 ********************/ /** * 获取网站列表 * * @param array $data * p 当前分页 [可选] * limit 取回的数据行数 [必传] * type 分类标识, -1: 全部分类 0: 默认分类 [可选] * order 排序规则 使用 id 降序:id desc 使用名称升序:name desc [可选] * tojs 分页 JS 回调,若不传则构造 URI 分页连接 [可选] 示例:get_site_list * search 搜索内容 [可选] * @return void * @author 617 * @Description */ public function getWebList($data = array()) { $url = $this->BT_PANEL.'/data?action=getData&table=sites'; $verify = ['limit']; if (!$this->required($data,$verify)) return false; $ret = $this->post($url,$data); return json_decode($ret,true); } /** * 获取网站分类 * * @param array $data * @return void * @author 617 * @Description */ public function getWebTypes($data = array()) { $url = $this->BT_PANEL.'/site?action=get_site_types'; $ret = $this->post($url); return json_decode($ret,true); } /** * 获取已安装的 PHP 版本列表 * * @param array $data * @return void * @author 617 * @Description */ public function getPHPVersion() { $url = $this->BT_PANEL.'/site?action=GetPHPVersion'; $ret = $this->post($url); return json_decode($ret,true); } /** * 创建网站 * * @param array $data * webname 网站主域名和域名列表 请传 JSON [必传] 示例:{"domain":"w1.hao.com","domainlist":[],"count":0} * path 根目录 [必传] * type_id 分类标识 [必传] * version PHP 版本 请从 PHP 版本列表中选择 [必传] * port 网站端口 [必传] * ps 网站备注 [必传] * ftp 是否创建 FTP [必传] true|false * ftp_username FTP 用户名 在要创建 FTP 时必传 * ftp_password FTP 密码 在要创建 FTP 时必传 * sql 是否创建数据库[必传] true|false * codeing 数据库字符集 在要创建数据库时必传 utf8|utf8mb4|gbk|big5 * datauser 数据库用户名及名称 在要创建数据库时必传 * datapassword 数据库密码 在要创建数据库时必传 * @return void * @author 617 * @Description */ public function createWebSite($data = array()) { $url = $this->BT_PANEL.'/site?action=AddSite'; $verify = ['webname','path','type_id','version','port','ftp','sql']; if(isset($data['ftp']) && $data['ftp'] === true) $verify['ftp'] = ['ftp_username','ftp_password']; if(isset($data['sql']) && $data['sql'] === true) $verify['sql'] = ['codeing','datauser','datapassword']; if (!$this->required($data,$verify)) return false; $data['type'] = 'PHP'; $ret = $this->post($url,$data); return json_decode($ret,true); } /** * 获取网站id * * @return void * @author 617 * @Description */ public function getWebSiteId($data = array()) { $url = $this->BT_PANEL.'/data?action=getData&table=sites'; $verify = ['limit','search','type']; if (!$this->required($data,$verify)) return false; $ret = $this->post($url,$data); $ret = json_decode($ret,true); return $ret['data'][0]['id']; } /** * 删除网站 * * @param array $data * id 网站 ID [必传] * webname 网站名称 [必传] * ftp 是否删除关联 FTP ,如果不删除请不要传此参数[可选] * database 是否删除关联数据库,如果不删除请不要传此参数[可选] * path 是否删除网站根目录,如果不删除请不要传此参数[可选] * @return void * @author 617 * @Description */ public function deleteWebSite($data = array()) { $url = $this->BT_PANEL.'/site?action=DeleteSite'; $verify = ['id','webname']; if (!$this->required($data,$verify)) return false; $ret = $this->post($url,$data); return json_decode($ret,true); } /** * 停用网站 * * @param array $data * id 网站 ID [必传] * name 网站名称(主域名) [必传] * @return void * @author 617 * @Description */ public function siteStop($data = array()) { $url = $this->BT_PANEL.'/site?action=SiteStop'; $verify = ['id','name']; if (!$this->required($data,$verify)) return false; $ret = $this->post($url,$data); return json_decode($ret,true); } /** * 启用网站 * * @param array $data * id 网站 ID [必传] * name 网站名称(主域名) [必传] * @return void * @author 617 * @Description */ public function siteStart($data = array()) { $url = $this->BT_PANEL.'/site?action=SiteStart'; $verify = ['id','name']; if (!$this->required($data,$verify)) return false; $ret = $this->post($url,$data); return json_decode($ret,true); } /** * 网站到期时间 * * @param array $data * id 网站 ID [必传] * edate 到期时间 永久:0000-00-00 [必传] * @return void * @author 617 * @Description */ public function setEdate($data = array()) { $url = $this->BT_PANEL.'/site?action=SetEdate'; $verify = ['id','edate']; if (!$this->required($data,$verify)) return false; $ret = $this->post($url,$data); return json_decode($ret,true); } /** * 修改网站备注 * * @param array $data * id 网站 ID [必传] * ps 备注内容[必传] * @return void * @author 617 * @Description */ public function setPs($data = array()) { $url = $this->BT_PANEL.'/data?action=setPs&table=sites'; $verify = ['id','ps']; if (!$this->required($data,$verify)) return false; $ret = $this->post($url,$data); return json_decode($ret,true); } /** * 获取网站备份列表 * * @param array $data * p 当前分页 [可选] * limit 每页取回的数据行数 [必传] * tojs 分页 JS 回调,若不传则构造 URI 分页连接 [可选] * search 网站 ID [必传] * @return void * @author 617 * @Description */ public function getBackList($data = array()) { $url = $this->BT_PANEL.'/data?action=getData&table=backup'; $verify = ['limit','search']; if (!$this->required($data,$verify)) return false; $data['type'] = 0; $ret = $this->post($url,$data); return json_decode($ret,true); } /** * 创建网站备份 * * @param array $data * id 网站 ID [必传] * @return void * @author 617 * @Description */ public function createBack($data = array()) { $url = $this->BT_PANEL.'/site?action=ToBackup'; $verify = ['id']; if (!$this->required($data,$verify)) return false; $ret = $this->post($url,$data); return json_decode($ret,true); } /** * 删除网站备份 * * @param array $data * id 备份列表 ID [必传] * @return void * @author 617 * @Description */ public function deleteBack($data = array()) { $url = $this->BT_PANEL.'/site?action=DelBackup'; $verify = ['id']; if (!$this->required($data,$verify)) return false; $ret = $this->post($url,$data); return json_decode($ret,true); } /** * 获取网站的域名列表 * * @param array $data * search 网站 ID [必传] * @return void * @author 617 * @Description */ public function getDomainList($data = array()) { $url = $this->BT_PANEL.'/data?action=getData&table=domain'; $verify = ['search']; if (!$this->required($data,$verify)) return false; $data['list'] = true; $ret = $this->post($url,$data); return json_decode($ret,true); } /** * 添加域名 * * @param array $data * id 网站 ID [必传] * webname 网站名称 [必传] * domain 要添加的域名:端口 80 端品不必构造端口,多个域名用换行符隔开[必传] * @return void * @author 617 * @Description */ public function addDomain($data = array()) { $url = $this->BT_PANEL.'/site?action=AddDomain'; $verify = ['id','webname','domain']; if (!$this->required($data,$verify)) return false; $ret = $this->post($url,$data); return json_decode($ret,true); } /** * 删除域名 * * @param array $data * id 网站 ID [必传] * webname 网站名称 [必传] * domain 要被删除的域名 [必传] * port 该域名的端口 [必传] * @return void * @author 617 * @Description */ public function deleteDomain($data = array()) { $url = $this->BT_PANEL.'/site?action=DelDomain'; $verify = ['id','webname','domain','port']; if (!$this->required($data,$verify)) return false; $ret = $this->post($url,$data); return json_decode($ret,true); } /** * 获取网站域名绑定二级目录信息 * @param [type] $id 网站ID */ public function getDirBinding($id){ $url = $this->BT_PANEL.'/site?action=GetDirBinding'; $data['id'] = $id; $result = $this->post($url,$data); return json_decode($result,true); } /** * 设置网站域名绑定二级目录 * @param [type] $id 网站ID * @param [type] $domain 域名 * @param [type] $dirName 目录 */ public function addDirBinding($data = array()){ $url = $this->BT_PANEL.'/site?action=AddDirBinding'; $verify = ['id','domain','dirName']; if (!$this->required($data,$verify)) return false; $result = $this->post($url,$data); return json_decode($result,true); } /** * 删除网站域名绑定二级目录 * @param [type] $id 子目录ID */ public function delDirBinding($data = array()){ $url = $this->BT_PANEL.'/site?action=DelDirBinding'; $result = $this->post($url,$data); return json_decode($result,true); } /** * 获取可选的预定义伪静态列表 * * @param array $data * siteName 网站名称[必传] w2.hao.com * @return void * @author 617 * @Description */ public function getRewriteList($data = array()) { $url = $this->BT_PANEL.'/site?action=GetRewriteList'; $verify = ['siteName']; if (!$this->required($data,$verify)) return false; $ret = $this->post($url,$data); return json_decode($ret,true); } /** * 获取指定预定义伪静态规则内容(获取文件内容) * * @param array $data * path 要被获取的文件[必传] * @return void * @author 617 * @Description */ public function getFileBody($data = array()) { $url = $this->BT_PANEL.'/files?action=GetFileBody'; $verify = ['path']; if (!$this->required($data,$verify)) return false; $ret = $this->post($url,$data); return json_decode($ret,true); } /** * 保存伪静态规则内容(保存文件内容) * * @param array $data * path 要保存位置[必传] * data 规则内容 * @return void * @author 617 * @Description */ public function saveFileBody($data = array()) { $url = $this->BT_PANEL.'/files?action=SaveFileBody'; $verify = ['path','data']; if (!$this->required($data,$verify)) return false; $data['encoding'] = 'utf-8 '; $ret = $this->post($url,$data); return json_decode($ret,true); } /** * 获取网站日志 * @param [type] siteName 网站名 */ public function getSiteLogs($data = array()) { $url = $this->BT_PANEL.'/site?action=GetSiteLogs'; $verify = ['siteName']; if (!$this->required($data,$verify)) return false; $result = $this->post($url,$data); return json_decode($result,true); } /** * 获取网站盗链状态及规则信息 * @param [type] id 网站ID * @param [type] name 网站名 */ public function getSecurity($data = array()) { $url = $this->BT_PANEL.'/site?action=GetSecurity'; $verify = ['id','name']; if (!$this->required($data,$verify)) return false; $result = $this->post($url,$data); return json_decode($result,true); } /** * 设置网站盗链状态及规则信息 * @param [type] id 网站ID * @param [type] name 网站名 * @param [type] fix URL后缀 * @param [type] domains 许可域名 * @param [type] status 状态 */ public function setSecurity($data = array()) { $url = $this->BT_PANEL.'/site?action=SetSecurity'; $verify = ['id','name','fix','domains','status']; if (!$this->required($data,$verify)) return false; $result = $this->post($url,$data); return json_decode($result,true); } /** * 获取网站三项配置开关(防跨站、日志、密码访问) * @param [type] id 网站ID * @param [type] path 网站运行目录 */ public function getDirUserINI($data = array()) { $url = $this->BT_PANEL.'/site?action=GetDirUserINI'; $verify = ['id','path']; if (!$this->required($data,$verify)) return false; $result = $this->post($url,$data); return json_decode($result,true); } /** * 开启强制HTTPS * @param [type] siteName 网站域名(纯域名) */ public function httpToHttps($data = array()) { $url = $this->BT_PANEL.'/site?action=HttpToHttps'; $verify = ['siteName']; if (!$this->required($data,$verify)) return false; $result = $this->post($url,$data); return json_decode($result,true); } /** * 关闭强制HTTPS * @param [type] siteName 域名(纯域名) */ public function closeToHttps($data = array()) { $url = $this->BT_PANEL.'/site?action=CloseToHttps'; $verify = ['siteName']; if (!$this->required($data,$verify)) return false; $result = $this->post($url,$data); return json_decode($result,true); } /** * 设置SSL域名证书 * @param [type] type 类型 默认 1 * @param [type] siteName 网站名 * @param [type] key 证书key * @param [type] csr 证书PEM */ public function setSSL($data = array()) { $url = $this->BT_PANEL.'/site?action=SetSSL'; $verify = ['siteName','key','csr']; if (!$this->required($data,$verify)) return false; $data['type'] = 1; $result = $this->post($url,$data); return json_decode($result,true); } /** * 关闭SSL * @param [type] updateOf 修改状态码 * @param [type] siteName 域名(纯域名) */ public function closeSSLConf($data = array()) { $url = $this->BT_PANEL.'/site?action=CloseSSLConf'; $verify = ['siteName','updateOf']; if (!$this->required($data,$verify)) return false; $result = $this->post($url,$data); return json_decode($result,true); } /** * 获取SSL状态及证书信息 * @param [type] siteName 域名(纯域名) */ public function getSSL($data = array()) { $url = $this->BT_PANEL.'/site?action=GetSSL'; $verify = ['siteName']; if (!$this->required($data,$verify)) return false; $result = $this->post($url,$data); return json_decode($result,true); } /** * 获取网站默认文件 * @param [type] id 网站ID */ public function webGetIndex($data = array()) { $url = $this->BT_PANEL.'/site?action=GetIndex'; $verify = ['id']; if (!$this->required($data,$verify)) return false; $result = $this->post($url,$data); return json_decode($result,true); } /** * 设置网站默认文件 * @param [type] id 网站ID * @param [type] Index 内容 */ public function webSetIndex($data = array()) { $url = $this->BT_PANEL.'/site?action=SetIndex'; $verify = ['id','Index']; if (!$this->required($data,$verify)) return false; $result = $this->post($url,$data); return json_decode($result,true); } /** * 获取网站流量限制信息 * @param [type] id [description] */ public function getLimitNet($data = array()) { $url = $this->BT_PANEL.'/site?action=GetLimitNet'; $verify = ['id']; if (!$this->required($data,$verify)) return false; $result = $this->post($url,$data); return json_decode($result,true); } /** * 设置网站流量限制信息 * @param [type] id 网站ID * @param [type] perserver 并发限制 * @param [type] perip 单IP限制 * @param [type] limit_rate 流量限制 */ public function setLimitNet($data = array()) { $url = $this->BT_PANEL.'/site?action=SetLimitNet'; $verify = ['id','perserver','perip','limit_rate']; if (!$this->required($data,$verify)) return false; $result = $this->post($url,$data); return json_decode($result,true); } /** * 关闭网站流量限制 * @param [type] id 网站ID */ public function closeLimitNet($data = array()) { $url = $this->BT_PANEL.'/site?action=CloseLimitNet'; $verify = ['id']; if (!$this->required($data,$verify)) return false; $result = $this->post($url,$data); return json_decode($result,true); } /** * 获取网站301重定向信息 * @param [type] siteName 网站名 */ public function get301Status($data = array()) { $url = $this->BT_PANEL.'/site?action=Get301Status'; $verify = ['siteName']; if (!$this->required($data,$verify)) return false; $result = $this->post($url,$data); return json_decode($result,true); } /** * 设置网站301重定向信息 * @param [type] siteName 网站名 * @param [type] toDomain 目标Url * @param [type] srcDomain 来自Url * @param [type] type 类型 */ public function set301Status($data = array()) { $url = $this->BT_PANEL.'/site?action=Set301Status'; $verify = ['siteName','toDomain','srcDomain','type']; if (!$this->required($data,$verify)) return false; $result = $this->post($url,$data); return json_decode($result,true); } /** * 获取网站反代信息及状态 * @param [type] sitename [description] */ public function getProxyList($data = array()) { $url = $this->BT_PANEL.'/site?action=GetProxyList'; $verify = ['siteName']; if (!$this->required($data,$verify)) return false; $result = $this->post($url,$data); return json_decode($result,true); } /** * 添加网站反代信息 * @param [type] cache 是否缓存 * @param [type] proxyname 代理名称 * @param [type] cachetime 缓存时长 /小时 * @param [type] proxydir 代理目录 * @param [type] proxysite 反代URL * @param [type] todomain 目标域名 * @param [type] advanced 高级功能:开启代理目录 * @param [type] sitename 网站名 * @param [type] subfilter 文本替换json格式[{"sub1":"百度","sub2":"白底"},{"sub1":"","sub2":""}] * @param [type] type 开启或关闭 0关;1开 */ public function createProxy($data = array()) { $url = $this->BT_PANEL.'/site?action=CreateProxy'; $verify = ['cache','proxyname','cachetime','proxydir','proxysite','todomain','advanced','sitename','subfilter','type']; if (!$this->required($data,$verify)) return false; $result = $this->post($url,$data); return json_decode($result,true); } /** * 修改网站反代信息 * @param [type] $cache 是否缓存 * @param [type] $proxyname 代理名称 * @param [type] $cachetime 缓存时长 /小时 * @param [type] $proxydir 代理目录 * @param [type] $proxysite 反代URL * @param [type] $todomain 目标域名 * @param [type] $advanced 高级功能:开启代理目录 * @param [type] $sitename 网站名 * @param [type] $subfilter 文本替换json格式[{"sub1":"百度","sub2":"白底"},{"sub1":"","sub2":""}] * @param [type] $type 开启或关闭 0关;1开 */ public function modifyProxy($data = array()) { $url = $this->BT_PANEL.'/site?action=ModifyProxy'; $verify = ['cache','proxyname','cachetime','proxydir','proxysite','todomain','advanced','sitename','subfilter','type']; if (!$this->required($data,$verify)) return false; $result = $this->post($url,$data); return json_decode($result,true); } /** * 获取网站FTP列表 * @param string $p 当前分页 * @param string $limit 取出的数据行数 * @param string $type 分类标识 -1: 分部分类 0: 默认分类 * @param string $order 排序规则 使用 id 降序:id desc 使用名称升序:name desc * @param string $tojs 分页 JS 回调,若不传则构造 URI 分页连接 * @param string $search 搜索内容 */ public function webFtpList($data = array()) { $url = $this->BT_PANEL.'/data?action=getData&table=ftps'; $verify = ['p','limit','type','order','tojs','search']; if (!$this->required($data,$verify)) return false; $result = $this->post($url,$data); return json_decode($result,true); } /** * 修改FTP账号密码 * @param [type] id FTPID * @param [type] ftp_username 用户名 * @param [type] new_password 密码 */ public function setUserPassword($data = array()) { $url = $this->BT_PANEL.'/ftp?action=SetUserPassword'; $verify = ['id','ftp_username','new_password']; if (!$this->required($data,$verify)) return false; $result = $this->post($url,$data); return json_decode($result,true); } /** * 启用/禁用FTP * @param [type] id FTPID * @param [type] username 用户名 * @param [type] status 状态 0->关闭;1->开启 */ public function setStatus($data = array()) { $url = $this->BT_PANEL.'/ftp?action=SetStatus'; $verify = ['id','username','status']; if (!$this->required($data,$verify)) return false; $result = $this->post($url,$data); return json_decode($result,true); } /** * 获取网站SQL列表 * @param string p 当前分页 * @param string limit 取出的数据行数 * @param string type 分类标识 -1: 分部分类 0: 默认分类 * @param string order 排序规则 使用 id 降序:id desc 使用名称升序:name desc * @param string tojs 分页 JS 回调,若不传则构造 URI 分页连接 * @param string search 搜索内容 */ public function webSqlList($data = array()) { $url = $this->BT_PANEL.'/data?action=getData&table=databases'; $verify = ['limit']; if (!$this->required($data,$verify)) return false; $result = $this->post($url,$data); return json_decode($result,true); } /** * 修改SQL账号密码 * @param [type] $id SQLID * @param [type] $name 用户名 * @param [type] $password 密码 */ public function resDatabasePass($data = array()) { $url = $this->BT_PANEL.'/database?action=ResDatabasePassword'; $verify = ['id','name','password']; if (!$this->required($data,$verify)) return false; $result = $this->post($url,$data); return json_decode($result,true); } /** * 备份数据库 * @param [type] id 数据库列表ID */ public function sqlToBackup($data = array()) { $url = $this->BT_PANEL.'/database?action=ToBackup'; $verify = ['id']; if (!$this->required($data,$verify)) return false; $result = $this->post($url,$data); return json_decode($result,true); } /** * 删除数据库备份 * @param [type] id 数据库备份ID */ public function sqlDelBackup($data = array()) { $url = $this->BT_PANEL.'/database?action=DelBackup'; $verify = ['id']; if (!$this->required($data,$verify)) return false; $result = $this->post($url,$data); return json_decode($result,true); } /** 网站管理模块结束 ********************/ /** 插件相关开始 注意:必须要已安装响应的插件之后才能使用 *******/ /** * 宝塔一键部署列表 * @param string $search 搜索关键词 * @return [type] [description] */ public function deployment($data = array()) { $url = $this->BT_PANEL.'/plugin?action=a&name=deployment&s=GetList&type=0'; if($data['search']){ $url = $url.'&search='.$data['search']; } $result = $this->post($url); return json_decode($result,true); } /** * 宝塔一键部署执行 * @param [type] $dname 部署程序名 * @param [type] $site_name 部署到网站名 * @param [type] $php_version PHP版本 */ public function setupPackage($data = array()) { $url = $this->BT_PANEL.'/plugin?action=a&name=deployment&s=SetupPackage'; $verify = ['dname','site_name','php_version']; if (!$this->required($data,$verify)) return false; $result = $this->post($url,$data); return json_decode($result,true); } /** * Nginx防火墙 * */ public function getNginxWafInfo($data = array()) { $url = $this->BT_PANEL.'/plugin?action=a&name=btwaf&s=get_total_all'; $result = $this->post($url,$data); return json_decode($result,true); } /** * 开启或关闭Nginx防火墙 * */ public function setNginxWafStatus($data = array()) { $url = $this->BT_PANEL.'/plugin?action=a&name=btwaf&s=set_open'; $result = $this->post($url,$data); return json_decode($result,true); } /** * Undocumented function * * @param array $data * @return void * @Description * @author 617 <email:723875993@qq.com> */ public function getSpeed($data = array()){ $url = $this->BT_PANEL.'/plugin?action=a&name=deployment&s=GetSpeed'; $result = $this->post($url,$data); return json_decode($result,true); } /** 插件相关结束 *********************************************/ /** * 构造带有签名的关联数组 */ private function GetKeyData() { $now_time = time(); $p_data = array( 'request_token' => md5($now_time.''.md5($this->BT_KEY)), 'request_time' => $now_time ); return $p_data; } /** * 发起POST请求 * @param String $url 目标网填,带http:// * @param Array|String $data 欲提交的数据 * @return string */ private function post($url, $data = array(),$timeout = 60) { $file = ROOT_PATH . 'runtime/btcookie/'; //定义cookie保存位置 $cookie_file = $file.md5($this->BT_PANEL).'.cookie'; if(!file_exists($file)){ //检查是否有该文件夹,如果没有就创建,并给予最高权限 mkdir($file, 0777,true); } if(!file_exists($cookie_file)){ $fp = fopen($cookie_file,'w+'); fclose($fp); } // 拼接 $datas = array_merge($data,$this->GetKeyData()); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $datas); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $output = curl_exec($ch); curl_close($ch); return $output; } /** * 验证必填项 * * @param array $array 要验证的数组 一维数组! * @param array $verify 验证的值,可以是多维数组 * @return void * @author 617 * @Description */ public function required($array,$verify,&$str = array()) { foreach ($verify as $v) { if (is_array($v)) { $this->required($array,$v,$str); }else{ if (isset($array[$v])) { $array[$v] === ''?array_push($str,$v):''; }else{ array_push($str,$v); } } } if (empty($str)) return true; $this->error = implode(',',array_values(array_unique($str))).'参数不能为空!'; return false; } }