-
Notifications
You must be signed in to change notification settings - Fork 182
Expand file tree
/
Copy pathCommonClient.php
More file actions
36 lines (35 loc) · 1.02 KB
/
CommonClient.php
File metadata and controls
36 lines (35 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?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;
}