php调用阿里云的短信服务

  • composer require alibabacloud/client

  • 在安装完成后,您可以使用OpenAPI Explorer来生成相关API的Demo并应用在您的项目中。

  • 代码示例如下

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;
}

你可能感兴趣的:(php调用阿里云的短信服务)