本文为您介绍PHP调用SendMessageToGlobe发送短信到国际地区的程序样例。

注意事项

参考这个示例您需要注意以下几点:
  • regionId必须为cn-hangzhou,请勿修改。
  • product必须为Dysmsapi,请勿修改。
  • host必须为dysmsapi.aliyuncs.com,请勿修改。
  • version必须为2017-05-25,请勿修改。

编写样例程序

<?php
use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;
// Download:https://github.com/aliyun/openapi-sdk-php-client
// Usage:https://github.com/aliyun/openapi-sdk-php-client/blob/master/README-CN.md
AlibabaCloud::accessKeyClient('<accessKeyId>', '<accessSecret>')
->regionId('cn-hangzhou')
->asGlobalClient();
try {
$result = AlibabaCloud::rpcRequest()
->product('Dysmsapi')
->host('dysmsapi.aliyuncs.com')
->version('2017-05-25')
->action('SendMessageToGlobe')
->method('POST')
->options([
'query' => [
"To" => "62123****8901",
// "From" => "1234567890",
"Message" => "have a test.",
// "Type" => "OTP",
],
])
->request();
print_r($result->toArray());
} catch (ClientException $e) {
echo $e->getErrorMessage() . PHP_EOL;
} catch (ServerException $e) {
echo $e->getErrorMessage() . PHP_EOL;
}