Files
OMS/app/ome/lib/saas/manager.php
2026-01-04 19:08:31 +08:00

133 lines
3.6 KiB
PHP

<?php
/**
* Copyright 2012-2026 ShopeX (https://www.shopex.cn)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
class ome_saas_manager extends ome_saas_request {
/*api请求host地址*/
const HOST = 'http://api.saas.taoex.com/';
/*api请求host地址的具体路径*/
const INFO_API = 'api.php';
/*api请求方法名*/
const INFO_METHOD = 'host.getinfo_byservername';
private $info = null;
/**
* __construct
* @param mixed $site site
* @return mixed 返回值
*/
public function __construct(ome_saas_site &$site) {
$this->site = $site;
}
/**
* @获取服务到期的剩余天数
* @access public
* @param void
* @return int
*/
public function getValidityDate() {
$this->initInfo();
$tmp_days = $this->site->getCycleEnd();
if($tmp_days<= 0){
return false;
}
$end = strtotime($tmp_days);
$days = $end - time();
$days = ceil($days/86400);
return $days;
}
/**
* @获取服务基本信息
* @access public
* @param void
* @return int
*/
public function getInfo() {
$this->initInfo();
return $this->site->getInfo();
}
/**
* @具体根据应用访问域名获取主机资源信息的方法
* @access public
* @param void
* @return void
*/
public function initInfo() {
if($this->info !== null) {
return $this->info;
}
$sysParams ['app_key'] = $this->site->getKey();
$sysParams ['format'] = $this->site->getFormat();
$sysParams ['method'] = self::INFO_METHOD;
$sysParams ['server_name'] = $this->site->getDomain();
$sysParams ['sign'] = $this->generateSign ($sysParams);
$requestUrl = self::HOST . self::INFO_API . "?";
foreach ( $sysParams as $sysParamKey => $sysParamValue ) {
$requestUrl .= "$sysParamKey=" . urlencode ( $sysParamValue ) . "&";
}
$requestUrl = substr ( $requestUrl, 0, - 1 );
try {
$resp = $this->curl ( $requestUrl );
} catch ( Exception $e ) {
return false;
}
$respWellFormed = false;
if ("json" == $this->site->getFormat()) {
$respObject = json_decode ( $resp );
if (null !== $respObject) {
$respWellFormed = true;
foreach ( $respObject as $propKey => $propValue ) {
$respObject = $propValue;
}
}
} else if ("xml" == $this->site->getFormat()) {
$respObject = @simplexml_load_string ( $resp );
if (false !== $respObject) {
$respWellFormed = true;
}
}
if (false === $respWellFormed) {
return false;
}
$this->info = $respObject;
$fc = 'ome_saas_format_'. $this->site->getFormat();
$format = new $fc($respObject);
$this->site->setInfo($format);
return $respObject;
}
}