2 Star 9 Fork 0

13165796312 / 宝塔api

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
api.php 5.12 KB
一键复制 编辑 原始数据 按行查看 历史
13165796312 提交于 2022-01-17 09:03 . 首次提交api文件
<?php
/*
* 无想一刀:827712674@qq.com
* gitee: https://gitee.com/Jane_kang
*以下api通过互联网收集整理以及本人补充
*收集不易请各位小哥哥点个小红心
*问题反馈以及建议请联系我的邮箱
*/
class bt_api {
private $BT_KEY = "1wE0oE1IDU0qkV9uUMK3yhQPecpADbK1"; //接口密钥
private $BT_PANEL = "http://127.0.0.1:8888";
//如果希望多台面板,可以在实例化对象时,将面板地址与密钥传入
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;
}
/**
* 无想一刀:827712674@qq.com
* gitee: https://gitee.com/Jane_kang
* 不需要携带参数的api 详见config.php
*/
public function All($config){
$url = $this->BT_PANEL.$config;
$p_data = $this->GetKeyData();
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 无想一刀:827712674@qq.com
* gitee: https://gitee.com/Jane_kang
* 通过api添加邮局账号
* $email 邮箱账号
* $nickname 昵称
* is_admin:普通用户&管理员(没啥差别) quota:可用空5 GB注意5后面的空格一定要有
* password 首位一定要大写按需 固定内容或传参
*/
public function EmailAdd($email,$nickname){
$url = $this->BT_PANEL.'/plugin?action=a&name=mail_sys&s=add_mailbox';
$p_data = $this->GetKeyData();
$p_data['username'] = $email;
$p_data['password'] = 'Qq123321';
$p_data['full_name'] = $nickname;
$p_data['quota'] = '5 GB';
$p_data['is_admin'] = '0' ;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/*
* 无想一刀:827712674@qq.com
* gitee: https://gitee.com/Jane_kang
* 宝塔邮局发送邮件
* $mail_from 发件地址
* $mail_to 收件地址
* $subject:邮件标题 $conten:邮件正文
*/
public function Emaifa($mail_from,$mail_to,$subject,$conten){
$url = $this->BT_PANEL.'/plugin?action=a&name=mail_sys&s=send_mail';
$p_data = $this->GetKeyData();
$p_data['smtp_server'] = 'localhost';
$p_data['mail_from'] = $mail_from;
$p_data['mail_to'] = $mail_to;
$p_data['subject'] = $subject;
$p_data['content'] = $conten;
$p_data['subtype'] = 'html';
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data ;
}
/*
* 无想一刀:827712674@qq.com
* gitee: https://gitee.com/Jane_kang
* 通过api安装&卸载软件
* @version 版本号
* @sName 软件名称
* 安装参数:install_plugin 卸载参数:uninstall_plugin
*/
public function install($data){
$url = $this->BT_PANEL.'/plugin?action='.$data['parameter'];
$p_data = $this->GetKeyData();
$p_data['sName'] = $data['sName'];
$p_data['version'] = $data['version'];
$p_data['type'] = 1;
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/*
* 无想一刀:827712674@qq.com
* gitee: https://gitee.com/Jane_kang
* 注释请查看/demo/WebAddSite.php
*/
public function WebAddSite($data) {
$url = $this->BT_PANEL.'/site?action=AddSite';
$p_data = $this->GetKeyData();
$p_data['webname']= $data['webname'];
$p_data['type']= $data['type'];
$p_data['port']= $data['port'];
$p_data['ps']= $data['ps'];
$p_data['path']= $data['path'];
$p_data['type_id']= $data['ype_id'];
$p_data['version']= $data['version'];
$p_data['ftp']= $data['ftp'];
$p_data['sql']= $data['sql'];
$p_data['codeing']= $data['codeing'];
$result = $this->HttpPostCookie($url,$p_data);
$data = json_decode($result,true);
return $data;
}
/**
* 构造带有签名的关联数组
*/
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 HttpPostCookie($url, $data,$timeout = 60)
{
//定义cookie保存位置
$cookie_file='./'.md5($this->BT_PANEL).'.cookie';
if(!file_exists($cookie_file)){
$fp = fopen($cookie_file,'w+');
fclose($fp);
}
$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, $data);
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;
}
}
?>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/Jane_kang/pagoda-api.git
git@gitee.com:Jane_kang/pagoda-api.git
Jane_kang
pagoda-api
宝塔api
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891