获取SDK

composer require alibabacloud/sdk

使用示例

<?php

use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;
use AlibabaCloud\NlpAutoml\NlpAutoml;

// Set up a global client
AlibabaCloud::accessKeyClient('foo', 'bar')
            ->regionId('cn-hangzhou')
            ->asDefaultClient();

try {

    // Access product APIs
    $request = NlpAutoml::v20191111()->getPredictResult();

    // Set options/parameters and execute request
    $result = $request->withModelId(1818) // API parameter
                      ->withContent('中华人民共和国解放军') // API parameter
                      ->client('client1') // Specify the client for send
                      ->debug(true) // Enable the debug will output detailed information
                      ->connectTimeout(0.01) // Throw an exception when Connection timeout
                      ->timeout(0.01) // Throw an exception when timeout
                      ->request(); // Execution request

} catch (ClientException $exception) {
    echo $exception->getMessage(). PHP_EOL;
} catch (ServerException $exception) {
    echo $exception->getMessage() . PHP_EOL;
    echo $exception->getErrorCode(). PHP_EOL;
    echo $exception->getRequestId(). PHP_EOL;
    echo $exception->getErrorMessage(). PHP_EOL;
}