123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <?php
- require_once __DIR__.'/../../../vendor/autoload.php';
-
- use TencentCloud\Cvm\V20170312\CvmClient;
-
- 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 {
-
-
- $cred = new Credential(getenv("TENCENTCLOUD_SECRET_ID"), getenv("TENCENTCLOUD_SECRET_KEY"));
-
-
- $httpProfile = new HttpProfile();
- $httpProfile->setReqMethod("GET");
- $httpProfile->setReqTimeout(30);
- $httpProfile->setEndpoint("cvm.ap-shanghai.tencentcloudapi.com");
-
-
-
-
- $clientProfile = new ClientProfile();
- $clientProfile->setSignMethod("TC3-HMAC-SHA256");
- $clientProfile->setHttpProfile($httpProfile);
-
-
- $client = new CvmClient($cred, "ap-shanghai", $clientProfile);
-
-
- $req = new DescribeInstancesRequest();
-
-
-
- $respFilter = new Filter();
- $respFilter->Name = "zone";
- $respFilter->Values = ["ap-shanghai-1", "ap-shanghai-2"];
- $req->Filters = [$respFilter];
-
-
- $params = [
- "Filters" => [
- [
- "Name" => "zone",
- "Values" => ["ap-shanghai-1", "ap-shanghai-2"]
- ]
- ]
- ];
- $req->fromJsonString(json_encode($params));
-
-
-
- $resp = $client->DescribeInstances($req);
-
-
- print_r($resp->toJsonString());
-
-
-
- print_r($resp->TotalCount);
- }
- catch(TencentCloudSDKException $e) {
- echo $e;
- }
|