first commit

This commit is contained in:
Your Name
2026-01-19 14:19:22 +08:00
commit fe2d9c1868
4777 changed files with 665503 additions and 0 deletions

201
vendor/tencentcloud/common/LICENSE vendored Normal file
View File

@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
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.

19
vendor/tencentcloud/common/README.MD vendored Normal file
View File

@@ -0,0 +1,19 @@
# 简介
欢迎使用腾讯云开发者工具套件SDK3.0SDK3.0是云 API3.0 平台的配套工具。目前已经支持cvm、vpc、cbs等产品后续所有的云服务产品都会接入进来。新版SDK实现了统一化具有各个语言版本的SDK使用方法相同接口调用方式相同统一的错误码和返回包格式这些优点。
为方便 PHP 开发者调试和接入腾讯云产品 API这里向您介绍适用于 PHP 的腾讯云开发工具包,并提供首次使用开发工具包的简单示例。让您快速获取腾讯云 PHP SDK 并开始调用。
# 依赖环境
1. PHP 5.6.0 版本及以上
2. 从腾讯云控制台 开通相应产品
3. 获取 SecretID、SecretKey 以及调用地址endpointendpoint 一般形式为*.tencentcloudapi.com如CVM 的调用地址为 cvm.tencentcloudapi.com具体参考各产品说明。
# 获取安装
## 通过 Composer 安装
通过 Composer 获取安装是使用 PHP SDK 的推荐方法Composer 是 PHP 的依赖管理工具,支持您项目所需的依赖项,并将其安装到项目中。关于 Composer 详细可参考 Composer 官网 。
1. 安装Composer
windows环境请访问[Composer官网](https://getcomposer.org/download/)下载安装包安装。
unix环境在命令行中执行以下命令安装。
> curl -sS https://getcomposer.org/installer | php
> sudo mv composer.phar /usr/local/bin/composer
2. 建议中国大陆地区的用户设置腾讯云镜像源:`composer config -g repos.packagist composer https://mirrors.tencent.com/composer/`
3. 执行命令 `composer require tencentcloud/common` 添加依赖。

View File

@@ -0,0 +1,24 @@
{
"name": "tencentcloud/common",
"description": "TencentCloudApi php sdk",
"type": "library",
"homepage": "https://github.com/tencentcloud-sdk-php/common",
"license": "Apache-2.0",
"authors": [
{
"name": "tencentcloudapi",
"email": "tencentcloudapi@tencent.com",
"homepage": "https://cloud.tencent.com/document/sdk/PHP",
"role": "Developer"
}
],
"require": {
"php": ">=5.6.0",
"guzzlehttp/guzzle": "^6.3||^7.0"
},
"autoload": {
"psr-4": {
"TencentCloud\\": "./src/TencentCloud"
}
}
}

View File

@@ -0,0 +1,593 @@
<?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;
use \ReflectionClass;
use TencentCloud\Common\Http\HttpConnection;
use TencentCloud\Common\Profile\ClientProfile;
use TencentCloud\Common\Profile\HttpProfile;
use TencentCloud\Common\Profile\RegionBreakerProfile;
use TencentCloud\Common\CircuitBreaker;
use TencentCloud\Common\Exception\TencentCloudSDKException;
/**
* 抽象api类禁止client引用
* @package TencentCloud\Common
*/
abstract class AbstractClient
{
/**
* @var string SDK版本
*/
public static $SDK_VERSION = "SDK_PHP_3.0.990";
/**
* @var integer http响应码200
*/
public static $HTTP_RSP_OK = 200;
private $PHP_VERSION_MINIMUM = "5.6.0";
/**
* @var Credential 认证类实例,保存认证相关字段
*/
private $credential;
/**
* @var ClientProfile 会话配置信息类
*/
private $profile;
private $regionBreakerProfile;
private $circuitBreaker;
/**
* @var string 产品地域
*/
private $region;
/**
* @var string 请求路径
*/
private $path;
/**
* @var string sdk版本号
*/
private $sdkVersion;
/**
* @var string api版本号
*/
private $apiVersion;
/**
* @var HttpConnection
*/
private $httpConn;
/**
* 基础client类
* @param string $endpoint Deprecated, we use service+rootdomain instead
* @param string $version api版本
* @param Credential $credential 认证信息实例
* @param string $region 产品地域
* @param ClientProfile $profile
*/
function __construct($endpoint, $version, $credential, $region, $profile=null)
{
$this->path = "/";
$this->credential = $credential;
$this->region = $region;
if ($profile) {
$this->profile = $profile;
} else {
$this->profile = new ClientProfile();
}
$this->getRefreshedEndpoint();
$this->sdkVersion = AbstractClient::$SDK_VERSION;
$this->apiVersion = $version;
if ($this->profile->enableRegionBreaker) {
if (is_null($this->profile->getRegionBreakerProfile())) {
throw new TencentCloudSDKException("ClientError", "RegionBreakerProfile have not been set yet.");
}
$this->circuitBreaker = new CircuitBreaker($this->profile->getRegionBreakerProfile());
}
if (version_compare(phpversion(), $this->PHP_VERSION_MINIMUM, '<') && $profile->getCheckPHPVersion()) {
throw new TencentCloudSDKException("ClientError", "PHP version must >= ".$this->PHP_VERSION_MINIMUM.", your current is ".phpversion());
}
$this->httpConn = $this->createConnect();
}
/**
* 设置产品地域
* @param string $region 地域
*/
public function setRegion($region)
{
$this->region = $region;
}
/**
* 获取产品地域
* @return string
*/
public function getRegion()
{
return $this->region;
}
/**
* 设置认证信息实例
* @param Credential $credential 认证信息实例
*/
public function setCredential($credential)
{
$this->credential = $credential;
}
/**
* 返回认证信息实例
* @return Credential
*/
public function getCredential()
{
return $this->credential;
}
/**
* 设置配置实例
* @param ClientProfile $profile 配置实例
*/
public function setClientProfile($profile)
{
$this->profile = $profile;
}
/**
* 返回配置实例
* @return ClientProfile
*/
public function getClientProfile()
{
return $this->profile;
}
/**
* @param string $action 方法名
* @param array $request 参数列表
* @return mixed
* @throws TencentCloudSDKException
*/
public function __call($action, $request)
{
if ($this->profile->enableRegionBreaker) {
return $this->doRequestWithOptionsOnRegionBreaker($action, $request[0], array());
}
else {
return $this->doRequestWithOptions($action, $request[0], array());
}
}
/**
* @param string $action
* @param array $headers
* @param string $body json content
* @return mixed
* @throws TencentCloudSDKException
*/
public function callJson($action, $body, $headers=null) {
try {
$responseData = null;
$options = array(
"IsCommonJson" => true,
);
if ($this->profile->getHttpProfile()->getReqMethod() == HttpProfile::$REQ_GET) {
throw new TencentCloudSDKException("ClientError", "Common client call doesn't support GET method");
}
if ($this->profile->getSignMethod() != ClientProfile::$SIGN_TC3_SHA256) {
throw new TencentCloudSDKException("ClientError", "Common client call must use TC3-HMAC-SHA256");
}
$responseData = $this->doRequestWithTC3($action, $body, $options, $headers, null);
if ($responseData->getStatusCode() !== AbstractClient::$HTTP_RSP_OK) {
throw new TencentCloudSDKException($responseData->getReasonPhrase(), $responseData->getBody());
}
$resp = json_decode($responseData->getBody(), true)["Response"];
if (array_key_exists("Error", $resp)) {
throw new TencentCloudSDKException($resp["Error"]["Code"], $resp["Error"]["Message"], $resp["RequestId"]);
}
return $resp;
} catch (\Exception $e) {
if (!($e instanceof TencentCloudSDKException)) {
throw new TencentCloudSDKException("", $e->getMessage());
} else {
throw $e;
}
}
}
/**
* @param string $action 方法名
* @param array $headers 自定义headers
* @param string $body content
* @return mixed
* @throws TencentCloudSDKException
*/
public function call_octet_stream($action, $headers, $body) {
try {
$responseData = null;
$options = array(
"IsOctetStream" => true,
);
switch ($this->profile->getSignMethod()) {
case ClientProfile::$SIGN_TC3_SHA256:
$responseData = $this->doRequestWithTC3($action, Null, $options, $headers, $body);
break;
default:
throw new TencentCloudSDKException("ClientError", "Invalid sign method");
break;
}
if ($responseData->getStatusCode() !== AbstractClient::$HTTP_RSP_OK) {
throw new TencentCloudSDKException($responseData->getReasonPhrase(), $responseData->getBody());
}
$tmpResp = json_decode($responseData->getBody(), true)["Response"];
if (array_key_exists("Error", $tmpResp)) {
throw new TencentCloudSDKException($tmpResp["Error"]["Code"], $tmpResp["Error"]["Message"], $tmpResp["RequestId"]);
}
return $this->returnResponse($action, $tmpResp);
} catch (\Exception $e) {
if (!($e instanceof TencentCloudSDKException)) {
throw new TencentCloudSDKException("", $e->getMessage());
} else {
throw $e;
}
}
}
protected function doRequestWithOptions($action, $request, $options)
{
try {
$responseData = null;
$serializeRequest = $request->serialize();
$method = $this->getPrivateMethod($request, "arrayMerge");
$serializeRequest = $method->invoke($request, $serializeRequest);
switch ($this->profile->getSignMethod()) {
case ClientProfile::$SIGN_HMAC_SHA1:
case ClientProfile::$SIGN_HMAC_SHA256:
$responseData = $this->doRequest($action, $serializeRequest);
break;
case ClientProfile::$SIGN_TC3_SHA256:
$responseData = $this->doRequestWithTC3($action, $request, $options, array(), "");
break;
default:
throw new TencentCloudSDKException("ClientError", "Invalid sign method");
break;
}
if ($responseData->getStatusCode() !== AbstractClient::$HTTP_RSP_OK) {
throw new TencentCloudSDKException($responseData->getReasonPhrase(), $responseData->getBody());
}
$tmpResp = json_decode($responseData->getBody(), true)["Response"];
if (array_key_exists("Error", $tmpResp)) {
throw new TencentCloudSDKException($tmpResp["Error"]["Code"], $tmpResp["Error"]["Message"], $tmpResp["RequestId"]);
}
return $this->returnResponse($action, $tmpResp);
} catch (\Exception $e) {
if (!($e instanceof TencentCloudSDKException)) {
throw new TencentCloudSDKException("", $e->getMessage());
} else {
throw $e;
}
}
}
protected function doRequestWithOptionsOnRegionBreaker($action, $request, $options)
{
try {
$endpoint = $this->profile->getRegionBreakerProfile()->masterEndpoint;
list($generation, $need_break) = $this->circuitBreaker->beforeRequests();
if ($need_break) {
$endpoint = $this->profile->getRegionBreakerProfile()->slaveEndpoint;
}
$this->profile->getHttpProfile()->setEndpoint($endpoint);
$responseData = null;
$serializeRequest = $request->serialize();
$method = $this->getPrivateMethod($request, "arrayMerge");
$serializeRequest = $method->invoke($request, $serializeRequest);
switch ($this->profile->getSignMethod()) {
case ClientProfile::$SIGN_HMAC_SHA1:
case ClientProfile::$SIGN_HMAC_SHA256:
$responseData = $this->doRequest($action, $serializeRequest);
break;
case ClientProfile::$SIGN_TC3_SHA256:
$responseData = $this->doRequestWithTC3($action, $request, $options, array(), "");
break;
default:
throw new TencentCloudSDKException("ClientError", "Invalid sign method");
break;
}
if ($responseData->getStatusCode() !== AbstractClient::$HTTP_RSP_OK) {
throw new TencentCloudSDKException($responseData->getReasonPhrase(), $responseData->getBody());
}
$tmpResp = json_decode($responseData->getBody(), true)["Response"];
if (array_key_exists("Error", $tmpResp)) {
$this->circuitBreaker->afterRequests($generation, True);
throw new TencentCloudSDKException($tmpResp["Error"]["Code"], $tmpResp["Error"]["Message"], $tmpResp["RequestId"]);
}
$this->circuitBreaker->afterRequests($generation, True);
return $this->returnResponse($action, $tmpResp);
} catch (\Exception $e) {
$this->circuitBreaker->afterRequests($generation, False);
if (!($e instanceof TencentCloudSDKException)) {
throw new TencentCloudSDKException("", $e->getMessage());
} else {
throw $e;
}
}
}
private function doRequest($action, $request)
{
switch ($this->profile->getHttpProfile()->getReqMethod()) {
case HttpProfile::$REQ_GET:
return $this->getRequest($action, $request);
break;
case HttpProfile::$REQ_POST:
return $this->postRequest($action, $request);
break;
default:
throw new TencentCloudSDKException("", "Method only support (GET, POST)");
break;
}
}
private function doRequestWithTC3($action, $request, $options, $headers, $payload)
{
$endpoint = $this->getRefreshedEndpoint();
$headers["Host"] = $endpoint;
$headers["X-TC-Action"] = ucfirst($action);
$headers["X-TC-RequestClient"] = $this->sdkVersion;
$headers["X-TC-Timestamp"] = time();
$headers["X-TC-Version"] = $this->apiVersion;
if ($this->region) {
$headers["X-TC-Region"] = $this->region;
}
if ($this->credential->getToken()) {
$headers["X-TC-Token"] = $this->credential->getToken();
}
$language = $this->profile->getLanguage();
if ($language) {
$headers["X-TC-Language"] = $language;
}
$canonicalUri = $this->path;
$reqmethod = $this->profile->getHttpProfile()->getReqMethod();
if (HttpProfile::$REQ_GET == $reqmethod) {
$headers["Content-Type"] = "application/x-www-form-urlencoded";
$rs = $request->serialize();
$am = $this->getPrivateMethod($request, "arrayMerge");
$rsam = $am->invoke($request, $rs);
$canonicalQueryString = http_build_query($rsam);
$payload = "";
}
if (HttpProfile::$REQ_POST == $reqmethod) {
if (isset($options["IsMultipart"]) && $options["IsMultipart"] === true) {
$boundary = uniqid();
$headers["Content-Type"] = "multipart/form-data; boundary=" . $boundary;
$canonicalQueryString = "";
$payload = $this->getMultipartPayload($request, $boundary, $options);
} else if (isset($options["IsOctetStream"]) && $options["IsOctetStream"] === true) {
$headers["Content-Type"] = "application/octet-stream";
$canonicalQueryString = "";
} else if (isset($options["IsCommonJson"]) && $options["IsCommonJson"] === true) {
$headers["Content-Type"] = "application/json";
$canonicalQueryString = "";
$payload = json_encode($request);
} else {
$headers["Content-Type"] = "application/json";
$canonicalQueryString = "";
$payload = $request->toJsonString();
}
}
if ($this->profile->getUnsignedPayload() == true) {
$headers["X-TC-Content-SHA256"] = "UNSIGNED-PAYLOAD";
$payloadHash = hash("SHA256", "UNSIGNED-PAYLOAD");
} else {
$payloadHash = hash("SHA256", $payload);
}
$canonicalHeaders = "content-type:".$headers["Content-Type"]."\n".
"host:".$headers["Host"]."\n";
$signedHeaders = "content-type;host";
$canonicalRequest = $reqmethod."\n".
$canonicalUri."\n".
$canonicalQueryString."\n".
$canonicalHeaders."\n".
$signedHeaders."\n".
$payloadHash;
$algo = "TC3-HMAC-SHA256";
// date_default_timezone_set('UTC');
// $date = date("Y-m-d", $headers["X-TC-Timestamp"]);
$date = gmdate("Y-m-d", $headers["X-TC-Timestamp"]);
$service = explode(".", $endpoint)[0];
$credentialScope = $date."/".$service."/tc3_request";
$hashedCanonicalRequest = hash("SHA256", $canonicalRequest);
$str2sign = $algo."\n".
$headers["X-TC-Timestamp"]."\n".
$credentialScope."\n".
$hashedCanonicalRequest;
$skey = $this->credential->getSecretKey();
$signature = Sign::signTC3($skey, $date, $service, $str2sign);
$sid = $this->credential->getSecretId();
$auth = $algo.
" Credential=".$sid."/".$credentialScope.
", SignedHeaders=content-type;host, Signature=".$signature;
$headers["Authorization"] = $auth;
if (HttpProfile::$REQ_GET == $reqmethod) {
$connect = $this->getConnect();
return $connect->getRequest($this->path, $canonicalQueryString, $headers);
} else {
$connect = $this->getConnect();
return $connect->postRequestRaw($this->path, $headers, $payload);
}
}
private function getMultipartPayload($request, $boundary, $options)
{
$body = "";
$params = $request->serialize();
foreach ($params as $key => $value) {
$body .= "--".$boundary."\r\n";
$body .= "Content-Disposition: form-data; name=\"".$key;
if (in_array($key, $options["BinaryParams"])) {
$body .= "\"; filename=\"".$key;
}
$body .= "\"\r\n";
if (is_array($value)) {
$value = json_encode($value);
$body .= "Content-Type: application/json\r\n";
}
$body .= "\r\n".$value."\r\n";
}
if ($body != "") {
$body .= "--".$boundary."--\r\n";
}
return $body;
}
/**
* @throws TencentCloudSDKException
*/
private function getRequest($action, $request)
{
$query = $this->formatRequestData($action, $request, httpProfile::$REQ_GET);
$connect = $this->getConnect();
return $connect->getRequest($this->path, $query, []);
}
/**
* @throws TencentCloudSDKException
*/
private function postRequest($action, $request)
{
$body = $this->formatRequestData($action, $request, httpProfile::$REQ_POST);
$connect = $this->getConnect();
return $connect->postRequest($this->path, [], $body);
}
/**
* @throws TencentCloudSDKException
*/
private function formatRequestData($action, $request, $reqMethod)
{
$param = $request;
$param["Action"] = ucfirst($action);
$param["RequestClient"] = $this->sdkVersion;
$param["Nonce"] = rand();
$param["Timestamp"] = time();
$param["Version"] = $this->apiVersion;
if ($this->credential->getSecretId()) {
$param["SecretId"] = $this->credential->getSecretId();
}
if ($this->region) {
$param["Region"] = $this->region;
}
if ($this->credential->getToken()) {
$param["Token"] = $this->credential->getToken();
}
if ($this->profile->getSignMethod()) {
$param["SignatureMethod"] = $this->profile->getSignMethod();
}
$language = $this->profile->getLanguage();
if ($language) {
$param["Language"] = $language;
}
$signStr = $this->formatSignString($this->getRefreshedEndpoint(), $this->path, $param, $reqMethod);
$param["Signature"] = Sign::sign($this->credential->getSecretKey(), $signStr, $this->profile->getSignMethod());
return $param;
}
private function createConnect()
{
$prot = $this->profile->getHttpProfile()->getProtocol();
return new HttpConnection($prot.$this->getRefreshedEndpoint(), $this->profile);
}
private function getConnect() {
$keepAlive = $this->profile->getHttpProfile()->getKeepAlive();
if (true === $keepAlive) {
return $this->httpConn;
} else {
return $this->createConnect();
}
}
private function formatSignString($host, $uri, $param, $requestMethod)
{
$tmpParam = [];
ksort($param);
foreach ($param as $key => $value) {
array_push($tmpParam, $key . "=" . $value);
}
$strParam = join ("&", $tmpParam);
$signStr = strtoupper($requestMethod) . $host . $uri ."?".$strParam;
return $signStr;
}
private function getPrivateMethod($obj, $methodName) {
$objReflectClass = new ReflectionClass(get_class($obj));
$method = $objReflectClass->getMethod($methodName);
$method->setAccessible(true);
return $method;
}
/**
* User might call httpProfile.SetEndpoint after client is initialized,
* so everytime we get the enpoint we need to check it.
* Or we must find a way to disable such usage.
*/
private function getRefreshedEndpoint() {
$this->endpoint = $this->profile->getHttpProfile()->getEndpoint();
if ($this->endpoint === null) {
$this->endpoint = $this->service.".".$this->profile->getHttpProfile()->getRootDomain();
}
return $this->endpoint;
}
}

View File

@@ -0,0 +1,129 @@
<?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;
use \ReflectionClass;
/**
* 抽象model类禁止client引用
* @package TencentCloud\Common
*/
abstract class AbstractModel
{
/**
* 内部实现,用户禁止调用
*/
public function serialize()
{
$ret = $this->objSerialize($this);
return $ret;
}
private function objSerialize($obj) {
$memberRet = [];
$ref = new ReflectionClass(get_class($obj));
$memberList = $ref->getProperties();
foreach ($memberList as $x => $member)
{
$name = ucfirst($member->getName());
$member->setAccessible(true);
$value = $member->getValue($obj);
if ($value === null) {
continue;
}
if ($value instanceof AbstractModel) {
$memberRet[$name] = $this->objSerialize($value);
} else if (is_array($value)) {
$memberRet[$name] = $this->arraySerialize($value);
} else {
$memberRet[$name] = $value;
}
}
return $memberRet;
}
private function arraySerialize($memberList) {
$memberRet = [];
foreach ($memberList as $name => $value)
{
if ($value === null) {
continue;
}
if ($value instanceof AbstractModel) {
$memberRet[$name] = $this->objSerialize($value);
} elseif (is_array($value)) {
$memberRet[$name] = $this->arraySerialize($value);
}else {
$memberRet[$name] = $value;
}
}
return $memberRet;
}
private function arrayMerge($array, $prepend = null)
{
$results = array();
foreach ($array as $key => $value) {
if (is_array($value)) {
$results = array_merge($results, static::arrayMerge($value, $prepend.$key.'.'));
}
else {
if (is_bool($value)) {
$results[$prepend.$key] = json_encode($value);
} else {
$results[$prepend.$key] = $value;
}
}
}
return $results;
}
abstract public function deserialize($param);
/**
* @param string $jsonString json格式的字符串
*/
public function fromJsonString($jsonString)
{
$arr = json_decode($jsonString, true);
$this->deserialize($arr);
}
public function toJsonString()
{
$r = $this->serialize();
// it is an object rather than an array
if (empty($r)) {
return "{}";
}
return json_encode($r, JSON_UNESCAPED_UNICODE);
}
public function __call($member, $param)
{
$act = substr($member,0,3);
$attr = substr($member,3);
if ($act === "get") {
return $this->$attr;
} else if ($act === "set") {
$this->$attr = $param[0];
}
}
}

View File

@@ -0,0 +1,155 @@
<?php
namespace TencentCloud\Common;
define("STATE_CLOSED", 0);
define("STATE_HALF_OPEN", 1);
define("STATE_OPEN", 2);
class Counter
{
public $failures = 0;
public $total = 0;
public $consecutiveSuccesses = 0;
public $consecutiveFailures = 0;
public function onSuccess()
{
$this->total++;
$this->consecutiveSuccesses++;
$this->consecutiveFailures = 0;
}
public function onFailure()
{
$this->total++;
$this->failures++;
$this->consecutiveFailures++;
$this->consecutiveSuccesses = 0;
}
public function clear()
{
$this->failures = 0;
$this->total = 0;
$this->consecutiveSuccesses = 0;
$this->consecutiveFailures = 0;
}
public function getFailureRate()
{
if ($this->total == 0) {
return 0.0;
}
return floatval($this->failures) / $this->total;
}
}
class CircuitBreaker
{
public $breakerSetting;
public $counter;
public $state;
public $expiry;
public $generation;
public function __construct($breakerSetting)
{
$this->breakerSetting = $breakerSetting;
$this->counter = new Counter();
$this->state = STATE_CLOSED;
$this->expiry = time() + $breakerSetting->windowInterval;
$this->generation = 0;
}
public function readyToOpen()
{
return ($this->counter->failures >= $this->breakerSetting->maxFailNum &&
$this->counter->getFailureRate() >= $this->breakerSetting->maxFailPercent) ||
$this->counter->consecutiveFailures >= 5;
}
public function currentState($now)
{
if ($this->state == STATE_CLOSED) {
if ($this->expiry <= $now) {
$this->toNewGeneration($now);
}
} elseif ($this->state == STATE_OPEN) {
if ($this->expiry <= $now) {
$this->switchState(STATE_HALF_OPEN, $now);
}
}
return array($this->state, $this->generation);
}
public function switchState($newState, $now)
{
if ($this->state == $newState) {
return;
}
$this->state = $newState;
$this->toNewGeneration($now);
}
public function toNewGeneration($now)
{
$this->generation = ($this->generation + 1) % 10;
$this->counter->clear();
if ($this->state == STATE_CLOSED) {
$this->expiry = $now + $this->breakerSetting->windowInterval;
} elseif ($this->state == STATE_OPEN) {
$this->expiry = $now + $this->breakerSetting->timeout;
} else { // STATE_HALF_OPEN
$this->expiry = time();
}
}
public function beforeRequests()
{
$now = time();
list($state, $generation) = $this->currentState($now);
if ($state == STATE_OPEN) {
return array($generation, true);
}
return array($generation, false);
}
public function afterRequests($before, $success)
{
$now = time();
list($state, $generation) = $this->currentState($now);
if ($generation != $before) {
return;
}
if ($success) {
$this->onSuccess($state, $now);
} else {
$this->onFailure($state, $now);
}
}
public function onSuccess($state, $now)
{
if ($state == STATE_CLOSED) {
$this->counter->onSuccess();
} elseif ($state == STATE_HALF_OPEN) {
$this->counter->onSuccess();
if ($this->counter->total - $this->counter->failures >= $this->breakerSetting->maxRequests) {
$this->switchState(STATE_CLOSED, $now);
}
}
}
public function onFailure($state, $now)
{
if ($state == STATE_CLOSED) {
$this->counter->onFailure();
if ($this->readyToOpen()) {
$this->switchState(STATE_OPEN, $now);
}
} elseif ($state == STATE_HALF_OPEN) {
$this->counter->onFailure();
$this->switchState(STATE_OPEN, $now);
}
}
}

View File

@@ -0,0 +1,45 @@
<?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;
use TencentCloud\Common\AbstractClient;
use TencentCloud\Common\Profile\ClientProfile;
use TencentCloud\Common\Credential;
class CommonClient extends AbstractClient
{
protected $endpoint;
protected $service;
protected $version;
/**
* @param string $service
* @param string $version
* @param Credential $credential
* @param string $region
* @param ClientProfile|null $profile
* @throws TencentCloudSDKException
*/
function __construct($service, $version, $credential, $region, $profile=null)
{
$this->service = $service;
$this->version = $version;
$this->endpoint = $service.".tencentcloudapi.com";
parent::__construct($this->endpoint, $version, $credential, $region, $profile);
}
}

View File

@@ -0,0 +1,107 @@
<?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;
/**
* 证书类,保存认证相关参数
* @package TencentCloud\Common
*/
class Credential
{
/**
* @var string secretId
*/
private $secretId;
/**
* @var string secretKey
*/
private $secretKey;
/**
* @var string token
*/
private $token;
/**
* Credential constructor.
* @param string $secretId secretId
* @param string $secretKey secretKey
* @param string $token token
*/
public function __construct($secretId, $secretKey, $token = null)
{
$this->secretId = $secretId;
$this->secretKey = $secretKey;
$this->token = $token;
}
/**
* 设置secretId
* @param string $secretId secretId
*/
public function setSecretId($secretId)
{
$this->secretId = $secretId;
}
/**
* 设置secretKey
* @param string $secretKey secretKey
*/
public function setSecretKey($secretKey)
{
$this->secretKey = $secretKey;
}
/**
* @param string $token 要设置的token
*/
public function setToken($token)
{
$this->token = $token;
}
/**
* 获取secretId
* @return string secretId
*/
public function getSecretId()
{
return $this->secretId;
}
/**
* 获取secretKey
* @return string secretKey
*/
public function getSecretKey()
{
return $this->secretKey;
}
/**
* 获取token
* @return null|string token
*/
public function getToken()
{
return $this->token;
}
}

View File

@@ -0,0 +1,77 @@
<?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\Exception;
/**
* sdk异常类
* @package TencentCloud\Common\Exception
*/
class TencentCloudSDKException extends \Exception
{
/**
* @var string 请求id
*/
private $requestId;
private $errorCode;
/**
* TencentCloudSDKException constructor.
* @param string $code 异常错误码
* @param string $message 异常信息
* @param string $requestId 请求ID
*/
public function __construct($code = "", $message = "", $requestId = "")
{
parent::__construct($message, 0);
$this->errorCode = $code;
$this->requestId = $requestId;
}
/**
* 返回请求id
* @return string
*/
public function getRequestId()
{
return $this->requestId;
}
/**
* 返回错误码
* @return string
*/
public function getErrorCode()
{
return $this->errorCode;
}
/**
* 格式化输出异常码异常信息请求id
* @return string
*/
public function __toString()
{
return "[".__CLASS__."]"." code:".$this->errorCode.
" message:".$this->getMessage().
" requestId:".$this->requestId;
}
}

View File

@@ -0,0 +1,85 @@
<?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\Http;
use GuzzleHttp\Client;
/**
* http连接类
* @package TencentCloud\Common\http
*/
class HttpConnection
{
private $client;
private $profile;
function __construct($url, $profile)
{
$this->client = new Client(["base_uri" => $url]);
$this->profile = $profile;
}
private function getOptions()
{
$options = ["allow_redirects" => false];
$options["timeout"] = $this->profile->getHttpProfile()->getReqTimeout();
$options["proxy"] = $this->profile->getHttpProfile()->getProxy();
return $options;
}
public function getRequest($uri = '', $query = [], $headers = [])
{
$options = $this->getOptions();
if ($query) {
$options["query"] = $query;
}
if ($headers) {
$options["headers"] = $headers;
}
return $this->client->get($uri, $options);
}
public function postRequest($uri = '', $headers = [], $body = '')
{
$options = $this->getOptions();
if ($headers) {
$options["headers"] = $headers;
}
if ($body) {
$options["form_params"] = $body;
}
return $this->client->post($uri, $options);
}
public function postRequestRaw($uri = '', $headers = [], $body = '')
{
$options = $this->getOptions();
if ($headers) {
$options["headers"] = $headers;
}
if ($body) {
$options["body"] = $body;
}
return $this->client->post($uri, $options);
}
}

View File

@@ -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 签名算法目前支持SHA256SHA1
* @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 签名方法目前支持SHA256SHA1, 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;
}
}

View File

@@ -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;
}
}

View File

@@ -0,0 +1,49 @@
<?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;
use TencentCloud\Common\Exception\TencentCloudSDKException;
/**
* 签名类禁止client引用
* @package TencentCloud\Common
* @throws TencentCloudSDKException
*/
class Sign
{
/**
* @throws TencentCloudSDKException
*/
public static function sign($secretKey, $signStr, $signMethod)
{
$signMethodMap = ["HmacSHA1" => "SHA1", "HmacSHA256" => "SHA256"];
if (!array_key_exists($signMethod, $signMethodMap)) {
throw new TencentCloudSDKException("signMethod invalid", "signMethod only support (HmacSHA1, HmacSHA256)");
}
$signature = base64_encode(hash_hmac($signMethodMap[$signMethod], $signStr, $secretKey, true));
return $signature;
}
public static function signTC3($skey, $date, $service, $str2sign)
{
$dateKey = hash_hmac("SHA256", $date, "TC3".$skey, true);
$serviceKey = hash_hmac("SHA256", $service, $dateKey, true);
$reqKey = hash_hmac("SHA256", "tc3_request", $serviceKey, true);
return hash_hmac("SHA256", $str2sign, $reqKey);
}
}