预留在线升级功能

This commit is contained in:
2020-05-09 21:41:51 +08:00
parent fe89edd979
commit dd64af9482
4 changed files with 93 additions and 4 deletions

View File

@@ -1 +1,24 @@
APP_DEBUG = false
APP_DEBUG = false
VERSION = 4.0.2
rootuid = 1
[APP]
DEFAULT_TIMEZONE = Asia/Shanghai
[DATABASE]
TYPE = {type}
HOSTNAME = {hostname}
DATABASE = {database}
USERNAME = {username}
PASSWORD = {password}
HOSTPORT = {hostport}
CHARSET = utf8
PREFIX = {prefix}
DEBUG = false
[LANG]
default_lang = zh-cn
[JWT]
SECRET={secret}

View File

@@ -30,6 +30,18 @@ class Index extends Base {
return $this->fetch();
}
/**
* @title 系统更新
*/
public function update(){
$version = new \com\Version();
$info = $version->check();
$this->data['info'] = $info;
return $this->fetch();
}
/**
* @title 用户登录
* @return html

View File

@@ -9,6 +9,7 @@
namespace com;
use GuzzleHttp\Client;
use think\facade\Env;
/**
* @title 版本管理
@@ -16,8 +17,41 @@ use GuzzleHttp\Client;
*/
class Version{
public static function check(){
$client = new Client();
$res = $client->request('POST', 'http://www.tensent.cn/api/version/index');
public $client = "";
public $headers = "";
public function __construct(){
$this->headers = [
// 'Content-Type' => 'application/json',
// 'Authorization' => 'Bearer ' . Env::get('test.token'),
];
$this->client = new Client([
'base_uri' => 'http://www.tensent.cn/',
'timeout' => 2.0,
]);
}
public function check(){
$param = [
'client_url' => 'https://www.com',
'dd' => 'dd'
];
try {
$response = $this->client->post('api/version/index', [
'form_params' => $param,
'headers' => $this->headers,
]);
$ret = \GuzzleHttp\json_decode($response->getBody()->getContents(), true);
if($ret['code'] == 1){
$version = Env::get('version');
$data = $ret['data'];
if(version_compare($version, $data['version'], '<')){
$data['update'] = 1;
}
return $data;
}
} catch (\Exception $e) {
//throw $th;
}
}
}

View File

@@ -0,0 +1,20 @@
{extend name="admin/public/base" /}
{block name="body"}
<div class="row">
<div class="col-sm-12">
<div class="callout callout-info">
<h4>当前版本:{$version}</h4>
<h4>最新版本:{$info['version']}</h4>
{if isset($info['update']) && $info['update'] == 1}
<p>
<a href="{$info['file']}" class="btn btn-success" target="_blank">下载手动升级</a>
<button class="btn btn-success">在线升级</button>
</p>
{/if}
</div>
<div class="callout callout-success">
</div>
</div>
</div>
{/block}