
*.tencentcloudapi.com,产品的调用地址有一定区别,例如,云服务器的调用地址为cvm.tencentcloudapi.com。具体调用地址可参考对应产品的 API 文档。curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
composer config -g repos.packagist composer https://mirrors.tencent.com/composer/
C:\\Users\\···>目录下,则在指定的位置打开命令窗口,并执行以下命令:composer require tencentcloud/tencentcloud-sdk-php
require '/path/to/vendor/autoload.php';
composer require tencentcloud/产品名,例如composer require tencentcloud/cvm。<?phprequire_once '/path/to/vendor/autoload.php';use TencentCloud\\Cvm\\V20170312\\Models\\DescribeInstancesRequest;use TencentCloud\\Common\\Exception\\TencentCloudSDKException;use TencentCloud\\Common\\Credential;try {$cred = new Credential("secretId", "secretKey");$client = new CvmClient($cred, "ap-guangzhou");$req = new DescribeInstancesRequest();$resp = $client->DescribeInstances($req);print_r($resp->toJsonString());}catch(TencentCloudSDKException $e) {echo $e;}
<?phprequire_once '/path/to/vendor/autoload.php';// 导入对应产品模块的clientuse TencentCloud\\Cvm\\V20170312\\CvmClient;// 导入要请求接口对应的Request类use TencentCloud\\Cvm\\V20170312\\Models\\DescribeInstancesRequest;use TencentCloud\\Cvm\\V20170312\\Models\\Filter;use TencentCloud\\Common\\Exception\\TencentCloudSDKException;use TencentCloud\\Common\\Credential;// 导入可选配置类use TencentCloud\\Common\\Profile\\ClientProfile;use TencentCloud\\Common\\Profile\\HttpProfile;try {// 实例化一个证书对象,入参需要传入腾讯云账户secretId,secretKey$cred = new Credential("secretId", "secretKey");// 实例化一个http选项,可选的,没有特殊需求可以跳过$httpProfile = new HttpProfile();// 配置代理// $httpProfile->setProxy("https://ip:port");$httpProfile->setReqMethod("GET"); // post请求(默认为post请求)$httpProfile->setReqTimeout(30); // 请求超时时间,单位为秒(默认60秒)$httpProfile->setEndpoint("cvm.ap-shanghai.tencentcloudapi.com"); // 指定接入地域域名(默认就近接入)// 实例化一个client选项,可选的,没有特殊需求可以跳过$clientProfile = new ClientProfile();$clientProfile->setSignMethod("TC3-HMAC-SHA256"); // 指定签名算法(默认为HmacSHA256)$clientProfile->setHttpProfile($httpProfile);// 实例化要请求产品(以cvm为例)的client对象,clientProfile是可选的$client = new CvmClient($cred, "ap-shanghai", $clientProfile);// 实例化一个cvm实例信息查询请求对象,每个接口都会对应一个request对象。$req = new DescribeInstancesRequest();// 填充请求参数,这里request对象的成员变量即对应接口的入参// 你可以通过官网接口文档或跳转到request对象的定义处查看请求参数的定义$respFilter = new Filter(); // 创建Filter对象, 以zone的维度来查询cvm实例$respFilter->Name = "zone";$respFilter->Values = ["ap-shanghai-1", "ap-shanghai-2"];$req->Filters = [$respFilter]; // Filters 是成员为Filter对象的列表// 通过client对象调用DescribeInstances方法发起请求。注意请求方法名与请求对象是对应的// 返回的resp是一个DescribeInstancesResponse类的实例,与请求对象对应$resp = $client->DescribeInstances($req);// 输出json格式的字符串回包print_r($resp->toJsonString());// 也可以取出单个值。// 你可以通过官网接口文档或跳转到response对象的定义处查看返回字段的定义print_r($resp->TotalCount);}catch(TencentCloudSDKException $e) {echo $e;}
https_proxy,否则可能无法正常调用,抛出连接超时的异常。 或者使用 GuzzleHttp 代理配置:$cred = new Credential("secretId", "secretKey");$httpProfile = new HttpProfile();$httpProfile->setProxy('https://ip:port');$clientProfile = new ClientProfile();$clientProfile->setHttpProfile($httpProfile);$client = new OcrClient($cred, 'ap-beijing', $this->clientProfile);
cURL error 60: See http://curl.haxx.se/libcurl/c/libcurl-errors.html,请尝试按以下步骤解决:cacert.pem,将其保存到 PHP 安装路径下。php.ini文件,删除curl.cainfo配置项前的分号注释符(;),值设置为保存的证书文件cacert.pem的绝对路径。cURL error 0: The cURL request was retried 3 times and did not succeed. The most likely reason for the failure is that cURL was unable to rewind the body of the request and subsequent retries resulted in the same error. Turn on the debug option to see what went wrong. See https://bugs.php.net/bug.php?id=47204 for more information. (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)php -r "echo sys_get_temp_dir();",打印系统默认临时目录绝对路径,然后在php.ini配置sys_temp_dir为这个值,尝试是否能解决。git clone命令才能拿到 vendor 目录的情况,对一些不熟悉 github 的用户造成了困扰。从3.0.188版本开始,我们暂时移除了源码安装,必须使用 composer 安装 SDK 和依赖的包。文档反馈