-
composer require alibabacloud/client
-
在安装完成后,您可以使用OpenAPI Explorer来生成相关API的Demo并应用在您的项目中。
-
代码示例如下
<?php
// 引入自动加载
require __DIR__ . '/vendor/autoload.php';
use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;
$accessKeyId='*********';
$accessSecret='*********************';
// APP传过来的accesstoken
$AccessToken='****************************************************';
AlibabaCloud::accessKeyClient($accessKeyId, $accessSecret)
->regionId('cn-hangzhou')
->asDefaultClient();
try {
$result = AlibabaCloud::rpc()
->product('Dypnsapi')
->scheme('https') // 设置协议头 https | http
->version('2017-05-25')
->action('GetMobile')
->method('POST')
->host('dypnsapi.aliyuncs.com')
->options([
'query' => [
'RegionId' => "cn-hangzhou",
'AccessToken' => $accessToken,
'PhoneNumbers' => $phone,
'SignName' => $config['SignName'],
'TemplateCode' => $config['TemplateCode'],
'TemplateParam' => json_encode($param)
],
])
->request();
print_r($result->toArray());
} catch (ClientException $e) {
echo $e->getErrorMessage() . PHP_EOL;
} catch (ServerException $e) {
echo $e->getErrorMessage() . PHP_EOL;
}
网友评论