WokerTask/vendor/tencentcloud/tencentcloud-sdk-php/examples/common/CommonClient.php

37 lines
1.0 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
require_once __DIR__.'/../../vendor/autoload.php';
use TencentCloud\Common\CommonClient;
use TencentCloud\Common\Exception\TencentCloudSDKException;
use TencentCloud\Common\Credential;
try {
$cred = new Credential(
getenv("TENCENTCLOUD_SECRET_ID"),
getenv("TENCENTCLOUD_SECRET_KEY")
);
// 和各产品 Client 相比CommonClient 需要先指定产品名和版本号
$client = new CommonClient("cvm", "2017-03-12", $cred, "ap-guangzhou");
$headers = array();
$body = [
"Filters" => [
[
"Name" => "zone",
"Values" => ["ap-guangzhou-1", "ap-guangzhou-2"]
]
]
];
// 返回的是 array 对象,如请求失败则抛出异常
$resp = $client->callJson(
// 接口名
"DescribeInstances",
// 请求体,目前必须为 array 对象
$body,
// 请求头,可留空
//$headers,
);
echo $resp["TotalCount"].PHP_EOL;
}
catch(TencentCloudSDKException $e) {
echo $e;
}