预留在线升级功能
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user