php宝塔api接口

<?php

namespace xm;

use ba\Exception;

class BaoTa
{
    private string $api_url;
    private string $api_key;

    /**
     * @param string $api_url Api接口地址
     * @param string $api_key Api秘钥
     * @throws Exception
     */
    public function __construct(string $api_url, string $api_key)
    {
        if (empty($api_url) || empty($api_key)) {
            throw new Exception('api_url or Api key is empty');
        }
        $this->api_url = $api_url;
        $this->api_key = $api_key;
    }

    /**
     * 获取服务器配置
     * @return mixed
     * @throws Exception
     
     * Date: 2024/7/24上午11:06
     */
    public function getConfig(): mixed
    {
        $url = $this->api_url . config("bt.GetConfig");
        $p_data = $this->GetKeyData();
        $result = $this->httpPostCookie($url, $p_data);
        return json_decode($result, true);
    }

    /**
     * 获取系统基础统计
     * @return mixed
     * @throws Exception
     
     * Date: 2024/7/24上午11:06
     */
    public function getSystemTotal(): mixed
    {
        $url = $this->api_url . config("bt.GetSystemTotal");
        $p_data = $this->GetKeyData();
        $result = $this->httpPostCookie($url, $p_data);
        return json_decode($result, true);
    }

    /**
     * 获取磁盘分区信息
     * @return mixed
     * @throws Exception
     
     * Date: 2024/7/24上午11:10
     */
    public function getDiskInfo(): mixed
    {
        $url = $this->api_url . config("bt.GetDiskInfo");
        $p_data = $this->GetKeyData();
        $result = $this->httpPostCookie($url, $p_data);
        return json_decode($result, true);
    }

    /**
     * 获取实时状态信息(CPU、内存、网络、负载)
     * @return mixed
     * @throws Exception
     
     * Date: 2024/7/24上午11:11
     */
    public function getNetWork(): mixed
    {
        $url = $this->api_url . config("bt.GetNetWork");
        $p_data = $this->GetKeyData();
        $result = $this->httpPostCookie($url, $p_data);

        return json_decode($result, true);
    }

    /**
     * 获取网站列表
     * @param int|string $page 当前分页
     * @param int|string $limit 取出的数据行数
     * @param int|string $type 分类标识 -1: 分部分类 0: 默认分类
     * @param string $order 排序规则 使用 id 降序:id desc 使用名称升序:name desc
     * @param string $tojs 分页 JS 回调,若不传则构造 URI 分页连接
     * @param string $search 搜索内容
     * @return mixed
     * @throws Exception
     
     * Date: 2024/7/24上午11:15
     */
    public function webSites(string $search = '', int|string $page = 1, int|string $limit = 15, int|string $type = -1, string $order = 'id desc', string $tojs = ''): mixed
    {
        $url = $this->api_url . config("bt.Websites");
        $p_data = $this->GetKeyData();
        $p_data['p'] = $page;
        $p_data['limit'] = $limit;
        $p_data['type'] = $type;
        $p_data['order'] = $order;
        $p_data['tojs'] = $tojs;
        $p_data['search'] = $search;
        $result = $this->httpPostCookie($url, $p_data);
        return json_decode($result, true);
    }

    /**
     * 网站域名列表
     * @param int|string $search 搜索内容
     * @param string $table 表
     * @param string $list 列表
     * @return mixed
     * @throws Exception Author: Lxy
     * Date: 2024/7/24上午11:20
     */
    public function siteDomains(int|string $search, string $table, string $list = 'True'): mixed
    {
        $url = $this->api_url . config("bt.Websitess");
        $p_data = $this->GetKeyData();
        $p_data['table'] = $table;
        $p_data['list'] = $list;
        $p_data['search'] = $search;
        $result = $this->httpPostCookie($url, $p_data);
        return json_decode($result, true);
    }

    /**
     * 获取重定向列表
     * @param string $siteName 网站名
     * @return mixed
     * @throws Exception
     
     * Date: 2024/7/24下午1:42
     */
    public function GetRedirectList(string $siteName): mixed
    {
        $url = $this->api_url . config("bt.GetRedirectList");
        $p_data = $this->GetKeyData();
        $p_data['sitename'] = $siteName;
        $result = $this->httpPostCookie($url, $p_data);
        return json_decode($result, true);
    }

    /**
     * 添加重定向
     * @param int $type 重定向类型
     * * @param int $holdPath 保留URL参数
     * * @param string $domainorPath 重定向类型
     * * @param int $redirectType 重定向方式
     * * @param string $redirectPath
     * * @param string $toUrl 目标url
     * * @param string $redirectDomain 重定向域名
     * * @param string $siteName 网站名
     * @return mixed
     * @throws Exception
     
     * Date: 2024/7/24下午12:04
     */
    public function createRedirect(int $type = 1, int $holdPath = 1, string $domainorPath = 'domain', int $redirectType = 301, string $redirectPath = '', string $toUrl = '', string $redirectDomain = '', string $siteName = ''): mixed
    {
        $url = $this->api_url . config("bt.CreateRedirect");
        $p_data = $this->GetKeyData();
        $p_data['type'] = $type;
        $p_data['holdpath'] = $holdPath;
        $p_data['domainorpath'] = $domainorPath;
        $p_data['redirecttype'] = $redirectType;
        $p_data['redirectpath'] = $redirectPath;
        $p_data['tourl'] = $toUrl;
        $p_data['redirectdomain'] = $redirectDomain;
        $p_data['redirectname'] = time();
        $p_data['sitename'] = $siteName;
        $result = $this->httpPostCookie($url, $p_data);
        return json_decode($result, true);
    }

    /**
     * 修改重定向
     * @param int $type 重定向类型
     * @param int $holdPath 保留URL参数
     * @param string $domainorPath 重定向类型
     * @param int $redirectType 重定向方式
     * @param string $redirectPath
     * @param string $toUrl 目标url
     * @param string $redirectDomain 重定向域名
     * @param string $siteName 网站名
     * @return mixed
     * @throws Exception
     
     * Date: 2024/7/24下午12:04
     */
    public function modifyRedirect(int $type = 1, int $holdPath = 1, string $domainorPath = 'domain', int $redirectType = 301, string $redirectPath = '', string $toUrl = '', string $redirectDomain = '', string $siteName = ''): mixed
    {
        $url = $this->api_url . config("bt.ModifyRedirect");
        $p_data = $this->GetKeyData();
        $p_data['type'] = $type;
        $p_data['holdpath'] = $holdPath;
        $p_data['domainorpath'] = $domainorPath;
        $p_data['redirecttype'] = $redirectType;
        $p_data['redirectpath'] = $redirectPath;
        $p_data['tourl'] = $toUrl;
        $p_data['redirectdomain'] = $redirectDomain;
        $p_data['redirectname'] = time();
        $p_data['sitename'] = $siteName;
        $result = $this->httpPostCookie($url, $p_data);
        return json_decode($result, true);
    }

    /**
     * 重定向删除
     * @param string $siteName 网站名
     * @param string $redirectName 重定向名
     * @return mixed
     * @throws Exception
     
     * Date: 2024/7/24下午1:38
     */
    public function deleteRedirect(string $siteName, string $redirectName): mixed
    {
        $url = $this->api_url . config("bt.DeleteRedirect");
        $p_data = $this->GetKeyData();
        $p_data['sitename'] = $siteName;
        $p_data['redirectname'] = $redirectName;
        $result = $this->httpPostCookie($url, $p_data);
        return json_decode($result, true);
    }

    /**
     * 获取已安装的 PHP 版本列表
     * @return mixed
     * @throws Exception
     
     * Date: 2024/7/24下午1:45
     */
    public function getPhpVersion(): mixed
    {
        $url = $this->api_url . config("bt.GetPHPVersion");
        $p_data = $this->GetKeyData();
        $result = $this->httpPostCookie($url, $p_data);
        return json_decode($result, true);
    }

    /**
     * 获取指定网站运行的PHP版本
     * @param string $siteName 网站名
     * @return mixed
     * @throws Exception Author: Lxy
     * Date: 2024/7/24下午1:48
     */
    public function getSitePhpVersion(string $siteName): mixed
    {
        $url = $this->api_url . config("bt.GetSitePHPVersion");
        $p_data = $this->GetKeyData();
        $p_data['siteName'] = $siteName;
        $result = $this->httpPostCookie($url, $p_data);
        return json_decode($result, true);
    }

    /**
     * 修改指定网站的PHP版本
     * @param string $siteName
     * @param int $phpVersion
     * @return mixed
     * @throws Exception Author: Lxy
     * Date: 2024/7/24下午1:51
     */
    public function setPhpVersion(string $siteName, int $phpVersion): mixed
    {
        $url = $this->api_url . config("bt.SetPHPVersion");
        $p_data = $this->GetKeyData();
        $p_data['siteName'] = $siteName;
        $p_data['version'] = $phpVersion;
        $result = $this->httpPostCookie($url, $p_data);
        return json_decode($result, true);
    }

    /**
     * 新增网站
     * @param array $data POST数据
     * @return mixed
     * @throws Exception Author: Lxy
     * Date: 2024/7/24下午2:00
     */
    public function addSite(array $data = []): mixed
    {
        $url = $this->api_url . config("bt.WebAddSite");
        $p_data = $this->GetKeyData();
        $p_data['webname'] = $data['webname'];//网站域名 json格式
        $p_data['path'] = $data['path'];//网站路径
        $p_data['type_id'] = $data['type_id'];//网站分类ID
        $p_data['type'] = $data['type'];//网站类型
        $p_data['version'] = $data['version'];//PHP版本
        $p_data['port'] = $data['port'];//网站端口
        $p_data['ps'] = $data['ps'];//网站备注
        $p_data['ftp'] = $data['ftp'];//网站是否开通FTP
        if (isset($data['ftp']) && $data['ftp'] !== false) {
            $p_data['ftp_username'] = $data['ftp_username'];//FTP用户名
            $p_data['ftp_password'] = $data['ftp_password'];//FTP密码
        }
        $p_data['sql'] = $data['sql'];//网站是否开通数据库 MySQL、SQLServer
        $p_data['codeing'] = $data['codeing'];//数据库编码类型 utf8|utf8mb4|gbk|big5
        if (isset($data['sql']) && $data['sql'] !== false) {
            $p_data['datauser'] = $data['datauser'];//数据库账号
            $p_data['datapassword'] = $data['datapassword'];//数据库密码
        }
        $p_data['check_dir'] = $data['check_dir'];
        $result = $this->httpPostCookie($url, $p_data);
        return json_decode($result, true);
    }

    /**
     * 删除网站
     * @param int $id 网站ID
     * @param string $webName 网站名称
     * @param int $ftp 是否删除关联FTP
     * @param int $database 是否删除关联数据库
     * @param int $path 是否删除关联网站根目录
     * @return mixed
     * @throws Exception
     
     * Date: 2024/7/24下午2:12
     */
    public function deleteSite(int $id, string $webName, int $ftp = 1, int $database = 1, int $path = 1): mixed
    {
        $url = $this->api_url . config("bt.WebDeleteSite");
        $p_data = $this->GetKeyData();
        $p_data['id'] = $id;
        $p_data['webname'] = $webName;
        $p_data['ftp'] = $ftp;
        $p_data['database'] = $database;
        $p_data['path'] = $path;
        $result = $this->httpPostCookie($url, $p_data);
        return json_decode($result, true);
    }

    /**
     * 停用站点
     * @param int $id 网站ID
     * @param string $name 网站名称
     * @return mixed
     * @throws Exception
     
     * Date: 2024/7/24下午2:13
     */
    public function siteStop(int $id, string $name): mixed
    {
        $url = $this->api_url . c
  • 13
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值