Skip to content

Commit

Permalink
- 优化接口返回数据
Browse files Browse the repository at this point in the history
  • Loading branch information
dtapps committed Apr 5, 2020
1 parent 2c3a61f commit ed7a1bc
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 40 deletions.
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
],
"homepage": "https://www.liguangchun.cn",
"require": {
"php": ">=7.0"
"php": ">=7.0",
"ext-json": "*",
"ext-curl": "*"
},
"autoload": {
"psr-4": {
Expand Down
26 changes: 25 additions & 1 deletion src/Base.php → src/BaseBt.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,24 @@

namespace LiGuAngChUn\Bt;

class Base
class BaseBt
{
/**
* 定义当前版本
*/
const VERSION = '1.0.1';

/**
* 配置
* @var
*/
public $config;

/**
* Base constructor.
* @param array $options
* @throws BtException
*/
public function __construct(array $options)
{
if (empty($options['key'])) throw new BtException('请检查配置 接口密钥:[key],示例:x0m1NM1yumUVTyzLrpoJ4tgbVAZFzWVj');
Expand Down Expand Up @@ -63,4 +73,18 @@ private function GetKeyData()
'request_time' => $now_time
);
}

/**
* 获取总数
* @param string $str
* @return false|int|string
*/
protected function getCountData(string $str)
{
$start = strpos($str, "");
$end = strpos($str, "条数据");
$count = substr($str, $start + 3, $end - $start - 3);
if (empty($count)) return 0;
return $count;
}
}
10 changes: 6 additions & 4 deletions src/Control.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,19 @@
* Class Control
* @package LiGuAngChUn\Bt
*/
class Control extends Base
class Control extends BaseBt
{
/**
* 获取监控信息
* @param string $type 类型 GetCpuIo = CPU信息/内存 GetDiskIo = 磁盘IO GetNetWorkIo = 网络IO
* @param string $start_time 开始时间
* @param string $end_time 结束时间
* @param int $start_time 开始时间
* @param int $end_time 结束时间
* @return mixed
*/
public function getInfo($type = 'GetCpuIo', $start_time = '1584547201', $end_time = '1584547904')
public function getInfo($type = 'GetCpuIo', $start_time = 0, $end_time = 0)
{
if (empty($start_time)) $start_time = strtotime(date('Y-m-d'));
if (empty($end_time)) $end_time = time();
$url = "/ajax?action={$type}&start={$start_time}&end={$end_time}";
//请求面板接口
$result = $this->HttpPostCookie($url, []);
Expand Down
8 changes: 6 additions & 2 deletions src/CronTab.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Class CronTab
* @package LiGuAngChUn\Bt
*/
class CronTab extends Base
class CronTab extends BaseBt
{
/**
* 获取网站列表
Expand All @@ -24,6 +24,10 @@ public function getDataList()
//请求面板接口
$result = $this->HttpPostCookie($url, $p_data);
//解析JSON数据
return json_decode($result, true);
$data = json_decode($result, true);
return [
'data' => $data['data'],
'orderOpt' => $data['orderOpt']
];
}
}
19 changes: 13 additions & 6 deletions src/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,31 @@
* Class Database
* @package LiGuAngChUn\Bt
*/
class Database extends Base
class Database extends BaseBt
{
/**
* 获取数据库列表
* @param int $page
* @param int $limit
* @param string $search
* @return mixed
*/
public function getList()
public function getList($page = 1, $limit = 15, $search = '')
{
$url = '/data?action=getData';
$p_data['tojs'] = 'database.get_list';
$p_data['table'] = 'databases';
$p_data['limit'] = 15;
$p_data['p'] = 1;
$p_data['search'] = '';
$p_data['limit'] = $limit;
$p_data['p'] = $page;
$p_data['search'] = $search;
$p_data['order'] = 'id desc';
//请求面板接口
$result = $this->HttpPostCookie($url, $p_data);
//解析JSON数据
return json_decode($result, true);
$data = json_decode($result, true);
return [
'data' => $data['data'],
'count' => $this->getCountData($data['page'])
];
}
}
2 changes: 1 addition & 1 deletion src/Files.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Class Files
* @package LiGuAngChUn\Bt
*/
class Files extends Base
class Files extends BaseBt
{

}
36 changes: 27 additions & 9 deletions src/Firewall.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,55 @@
* Class firewall
* @package LiGuAngChUn\Bt
*/
class Firewall extends Base
class Firewall extends BaseBt
{
/**
* 获取防火墙
* @param int $page
* @param int $limit
* @return mixed
*/
public function getList()
public function getList($page = 1, $limit = 10)
{
$url = '/data?action=getData';
$p_data['table'] = 'logs';
$p_data['limit'] = 10;
$p_data['tojs'] = 'firewall.get_list';
$p_data['table'] = 'firewall';
$p_data['limit'] = $limit;
$p_data['p'] = $page;
$p_data['search'] = '';
$p_data['order'] = 'id desc';
//请求面板接口
$result = $this->HttpPostCookie($url, $p_data);
//解析JSON数据
return json_decode($result, true);
$data = json_decode($result, true);
return [
'data' => $data['data'],
'count' => $this->getCountData($data['page'])
];
}

/**
* 获取面板日志
* @param int $page
* @param int $limit
* @return mixed
*/
public function getLog()
public function getLog($page = 1, $limit = 10)
{
$url = '/data?action=getData';
$p_data['table'] = 'logs';
$p_data['limit'] = 10;
$p_data['tojs'] = 'firewall.get_log_list';
$p_data['table'] = 'logs';
$p_data['limit'] = $limit;
$p_data['p'] = $page;
$p_data['search'] = '';
$p_data['order'] = 'id desc';
//请求面板接口
$result = $this->HttpPostCookie($url, $p_data);
//解析JSON数据
return json_decode($result, true);
$data = json_decode($result, true);
return [
'data' => $data['data'],
'count' => $this->getCountData($data['page'])
];
}
}
2 changes: 1 addition & 1 deletion src/Ftp.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Class Ftp
* @package LiGuAngChUn\Bt
*/
class Ftp extends Base
class Ftp extends BaseBt
{

}
2 changes: 1 addition & 1 deletion src/Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Class Setup
* @package LiGuAngChUn\Bt
*/
class Setup extends Base
class Setup extends BaseBt
{
/**
* 获取消息通道
Expand Down
22 changes: 15 additions & 7 deletions src/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,34 @@
* Class Site
* @package LiGuAngChUn\Bt
*/
class Site extends Base
class Site extends BaseBt
{
/**
* 获取网站列表
* @param int $page
* @param int $limit
* @param string $search
* @param int $type
* @return mixed
*/
public function getList()
public function getList($page = 1, $limit = 15, $search = '', $type = -1)
{
$url = '/data?action=getData';
$p_data['tojs'] = 'site.get_list';
$p_data['table'] = 'site';
$p_data['limit'] = 15;
$p_data['p'] = 1;
$p_data['search'] = '';
$p_data['limit'] = $limit;
$p_data['p'] = $page;
$p_data['search'] = $search;
$p_data['order'] = 'id desc';
$p_data['type'] = -1;
$p_data['type'] = $type;
//请求面板接口
$result = $this->HttpPostCookie($url, $p_data);
//解析JSON数据
return json_decode($result, true);
$data = json_decode($result, true);
return [
'data' => $data['data'],
'count' => $this->getCountData($data['page'])
];
}

/**
Expand Down
20 changes: 14 additions & 6 deletions src/Soft.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,24 @@
* Class Soft
* @package LiGuAngChUn\Bt
*/
class Soft extends Base
class Soft extends BaseBt
{
public function getList()
/**
* 获取软件列表
* @param int $page
* @param int $type
* @param int $force
* @param string $query
* @return mixed
*/
public function getList($page = 1, $type = 0, $force = 0, $query = '')
{
$url = '/plugin?action=get_soft_list';
$p_data['p'] = 0;
$p_data['type'] = 0;
$p_data['p'] = $page;
$p_data['type'] = $type;
$p_data['tojs'] = 'soft.get_list';
$p_data['force'] = 0;// 是否更新列表 1=是 0=否
$p_data['query'] = ''; // 搜索
$p_data['force'] = $force;// 是否更新列表 1=是 0=否
$p_data['query'] = $query; // 搜索
//请求面板接口
$result = $this->HttpPostCookie($url, $p_data);
//解析JSON数据
Expand Down
2 changes: 1 addition & 1 deletion src/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Class System
* @package LiGuAngChUn\Bt
*/
class System extends Base
class System extends BaseBt
{
/**
* 获取硬盘信息
Expand Down

0 comments on commit ed7a1bc

Please sign in to comment.