新增
This commit is contained in:
+227
@@ -0,0 +1,227 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (c) 2017-2018 THL A29 Limited, a Tencent company. All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
namespace TencentCloud\Common\Profile;
|
||||
|
||||
use TencentCloud\Common\Exception\TencentCloudSDKException;
|
||||
|
||||
/**
|
||||
* client可选参数类
|
||||
* Class ClientProfile
|
||||
* @package TencentCloud\Common\Profile
|
||||
*/
|
||||
class ClientProfile
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string hmacsha1算法
|
||||
*/
|
||||
public static $SIGN_HMAC_SHA1 = "HmacSHA1";
|
||||
|
||||
/**
|
||||
* @var string hmacsha256算法
|
||||
*/
|
||||
public static $SIGN_HMAC_SHA256 = "HmacSHA256";
|
||||
|
||||
/**
|
||||
* @var string 签名V3
|
||||
*/
|
||||
public static $SIGN_TC3_SHA256 = "TC3-HMAC-SHA256";
|
||||
|
||||
/**
|
||||
* @var string Chinese simplified
|
||||
*/
|
||||
public static $ZH_CN = "zh-CN";
|
||||
|
||||
/**
|
||||
* @var string English
|
||||
*/
|
||||
public static $EN_US = "en-US";
|
||||
|
||||
/**
|
||||
* @var boolean 开启地域容器
|
||||
*/
|
||||
public $enableRegionBreaker;
|
||||
|
||||
/**
|
||||
* @var HttpProfile http相关参数
|
||||
*/
|
||||
private $httpProfile;
|
||||
|
||||
/**
|
||||
* @var string 签名方法
|
||||
*/
|
||||
private $signMethod;
|
||||
|
||||
/**
|
||||
* @var string 忽略内容签名
|
||||
*/
|
||||
private $unsignedPayload;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
private $checkPHPVersion;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $language;
|
||||
|
||||
/**
|
||||
* @var RegionBreakerProfile 地域容灾相关参数
|
||||
*/
|
||||
private $regionBreakerProfile;
|
||||
|
||||
/**
|
||||
* ClientProfile constructor.
|
||||
* @param string $signMethod 签名算法,目前支持SHA256,SHA1
|
||||
* @param HttpProfile $httpProfile http参数类
|
||||
* @param boolean $enableRegionBreaker 开启地域容灾
|
||||
* @param RegionBreakerProfile $regionBreakerProfile 地域容灾相关参数
|
||||
*/
|
||||
public function __construct($signMethod = null, $httpProfile = null, $enableRegionBreaker = false, $regionBreakerProfile = null)
|
||||
{
|
||||
$this->signMethod = $signMethod ? $signMethod : ClientProfile::$SIGN_TC3_SHA256;
|
||||
$this->httpProfile = $httpProfile ? $httpProfile : new HttpProfile();
|
||||
$this->unsignedPayload = false;
|
||||
$this->checkPHPVersion = true;
|
||||
$this->enableRegionBreaker = $enableRegionBreaker;
|
||||
$this->regionBreakerProfile = $regionBreakerProfile;
|
||||
//$this->language = ClientProfile::$ZH_CN;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置签名算法
|
||||
* @param string $signMethod 签名方法,目前支持SHA256,SHA1, TC3
|
||||
*/
|
||||
public function setSignMethod($signMethod)
|
||||
{
|
||||
$this->signMethod = $signMethod;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置http相关参数
|
||||
* @param HttpProfile $httpProfile http相关参数
|
||||
*/
|
||||
public function setHttpProfile($httpProfile)
|
||||
{
|
||||
$this->httpProfile = $httpProfile;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取签名方法
|
||||
* @return null|string 签名方法
|
||||
*/
|
||||
public function getSignMethod()
|
||||
{
|
||||
return $this->signMethod;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置是否忽略内容签名
|
||||
* @param bool $flag true表示忽略签名
|
||||
*/
|
||||
public function setUnsignedPayload($flag)
|
||||
{
|
||||
$this->unsignedPayload = $flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取是否忽略内容签名标志位
|
||||
* @return bool
|
||||
*/
|
||||
public function getUnsignedPayload()
|
||||
{
|
||||
return $this->unsignedPayload;
|
||||
}
|
||||
|
||||
public function getCheckPHPVersion()
|
||||
{
|
||||
return $this->checkPHPVersion;
|
||||
}
|
||||
|
||||
public function setCheckPHPVersion($flag)
|
||||
{
|
||||
$this->checkPHPVersion = $flag;
|
||||
}
|
||||
|
||||
public function getLanguage()
|
||||
{
|
||||
return $this->language;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $language Valid values: zh-CN, en-US
|
||||
*/
|
||||
public function setLanguage($language)
|
||||
{
|
||||
$this->language = $language;
|
||||
}
|
||||
|
||||
public function getRegionBreakerProfile()
|
||||
{
|
||||
return $this->regionBreakerProfile;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置地域容灾相关参数
|
||||
* @param RegionBreakerProfile $regionBreakerProfile 地域容灾相关参数
|
||||
*/
|
||||
public function setRegionBreakerProfile($regionBreakerProfile)
|
||||
{
|
||||
$this->regionBreakerProfile = $regionBreakerProfile;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取http选项实例
|
||||
* @return null|HttpProfile http选项实例
|
||||
*/
|
||||
public function getHttpProfile()
|
||||
{
|
||||
return $this->httpProfile;
|
||||
}
|
||||
}
|
||||
|
||||
class RegionBreakerProfile {
|
||||
|
||||
public function __construct($masterEndpoint,
|
||||
$slaveEndpoint,
|
||||
$maxFailNum = 5,
|
||||
$maxFailPercent = 0.75,
|
||||
$windowInterval = 60*5,
|
||||
$timeout = 60,
|
||||
$maxRequests = 5) {
|
||||
if (empty($masterEndpoint) || !(substr($masterEndpoint, -20) === '.tencentcloudapi.com')) {
|
||||
throw new TencentCloudSDKException("", 'masterEndpoint must be provided and end with ".tencentcloudapi.com"');
|
||||
}
|
||||
if (empty($slaveEndpoint) || !(substr($slaveEndpoint, -20) === '.tencentcloudapi.com')) {
|
||||
throw new TencentCloudSDKException("", 'slaveEndpoint must be provided and end with ".tencentcloudapi.com"');
|
||||
}
|
||||
$this->masterEndpoint = $masterEndpoint;
|
||||
$this->slaveEndpoint = $slaveEndpoint;
|
||||
$this->maxFailNum = $maxFailNum;
|
||||
$this->maxFailPercent = $maxFailPercent;
|
||||
if ($this->maxFailPercent < 0 || $this->maxFailPercent > 1) {
|
||||
throw new TencentCloudSDKException("", "ClientError: max fail percent must be set between 0 and 1");
|
||||
}
|
||||
$this->windowInterval = $windowInterval;
|
||||
$this->timeout = $timeout;
|
||||
$this->maxRequests = $maxRequests;
|
||||
}
|
||||
}
|
||||
+215
@@ -0,0 +1,215 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (c) 2017-2018 THL A29 Limited, a Tencent company. All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
namespace TencentCloud\Common\Profile;
|
||||
|
||||
/**
|
||||
* http相关参数类
|
||||
* Class HttpProfile
|
||||
* @package TencentCloud\Common\Profile
|
||||
*/
|
||||
class HttpProfile
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string https访问
|
||||
*/
|
||||
public static $REQ_HTTPS = "https://";
|
||||
|
||||
/**
|
||||
* @var string http访问
|
||||
*/
|
||||
public static $REQ_HTTP = "http://";
|
||||
|
||||
/**
|
||||
* @var string post请求
|
||||
*/
|
||||
public static $REQ_POST = "POST";
|
||||
|
||||
/**
|
||||
* @var string get请求
|
||||
*/
|
||||
public static $REQ_GET = "GET";
|
||||
|
||||
/**
|
||||
* @var int 时间一分钟
|
||||
*/
|
||||
public static $TM_MINUTE = 60;
|
||||
|
||||
/**
|
||||
* @var string http请求方法
|
||||
*/
|
||||
private $reqMethod;
|
||||
|
||||
/**
|
||||
* @var string 请求接入点域名
|
||||
*/
|
||||
private $endpoint;
|
||||
|
||||
/**
|
||||
* @var integer 请求超时时长,单位为秒
|
||||
*/
|
||||
private $reqTimeout;
|
||||
|
||||
/**
|
||||
* @var string 请求协议
|
||||
*/
|
||||
private $protocol;
|
||||
|
||||
/**
|
||||
* @var string|array 请求代理
|
||||
*/
|
||||
private $proxy;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $rootDomain;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
private $keepAlive;
|
||||
|
||||
/**
|
||||
* HttpProfile constructor.
|
||||
* @param string $protocol 请求协议
|
||||
* @param string $endpoint 请求接入点域名(xx.[region.]tencentcloudapi.com)
|
||||
* @param string $reqMethod http请求方法,目前支持POST GET
|
||||
* @param integer $reqTimeout 请求超时时间,单位:s
|
||||
*/
|
||||
public function __construct($protocol = null, $endpoint = null, $reqMethod = null, $reqTimeout = null)
|
||||
{
|
||||
$this->reqMethod = $reqMethod ? $reqMethod : HttpProfile::$REQ_POST;
|
||||
$this->endpoint = $endpoint;
|
||||
$this->reqTimeout = $reqTimeout ? $reqTimeout : HttpProfile::$TM_MINUTE;
|
||||
$this->protocol = $protocol ? $protocol : HttpProfile::$REQ_HTTPS;
|
||||
$this->rootDomain = "tencentcloudapi.com";
|
||||
$this->keepAlive = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置http请求方法
|
||||
* @param string $reqMethod http请求方法,目前支持POST GET
|
||||
*/
|
||||
public function setReqMethod($reqMethod)
|
||||
{
|
||||
$this->reqMethod = $reqMethod;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置请求协议
|
||||
* @param string $protocol 请求协议(https:// http://)
|
||||
*/
|
||||
public function setProtocol($protocol) {
|
||||
$this->protocol = $protocol;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置请求接入点域名
|
||||
* @param string $endpoint 请求接入点域名(xx.[region.]tencentcloudapi.com)
|
||||
*/
|
||||
public function setEndpoint($endpoint)
|
||||
{
|
||||
$this->endpoint = $endpoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置请求超时时间
|
||||
* @param integer $reqTimeout 请求超时时间,单位:s
|
||||
*/
|
||||
public function setReqTimeout($reqTimeout)
|
||||
{
|
||||
$this->reqTimeout = $reqTimeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置请求代理
|
||||
* @param string|array $proxy 请求代理配置
|
||||
*/
|
||||
public function setProxy($proxy)
|
||||
{
|
||||
$this->proxy = $proxy;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取请求方法
|
||||
* @return null|string 请求方法
|
||||
*/
|
||||
public function getReqMethod()
|
||||
{
|
||||
return $this->reqMethod;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取请求协议
|
||||
* @return null|string 请求协议
|
||||
*/
|
||||
public function getProtocol()
|
||||
{
|
||||
return $this->protocol;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取请求超时时间
|
||||
* @return int 请求超时时间
|
||||
*/
|
||||
public function getReqTimeout()
|
||||
{
|
||||
return $this->reqTimeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取请求接入点域名
|
||||
* @return null|string 接入点域名
|
||||
*/
|
||||
public function getEndpoint()
|
||||
{
|
||||
return $this->endpoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取请求代理
|
||||
* @return null|string|array
|
||||
*/
|
||||
public function getProxy()
|
||||
{
|
||||
return $this->proxy;
|
||||
}
|
||||
|
||||
public function setRootDomain($domain)
|
||||
{
|
||||
$this->rootDomain = $domain;
|
||||
}
|
||||
|
||||
public function getRootDomain()
|
||||
{
|
||||
return $this->rootDomain;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param boolean $flag
|
||||
*/
|
||||
public function setKeepAlive($flag) {
|
||||
$this->keepAlive = $flag;
|
||||
}
|
||||
|
||||
public function getKeepAlive() {
|
||||
return $this->keepAlive;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user