我正在尝试学习使用AWS SNS服务从我的Web应用程序发送短信。 我目前正在本地服务器上操作。
$params = array(
'credentials' => array(
'key' => 'iam_key',
'secret' => 'iam_secret',
),
'region' => 'ap-south-1', // < your aws from SNS Topic region
'version' => 'latest',
'http' => ['verify'=>false]
);
$sns = \Aws\Sns\SnsClient::factory($params);
$msgattributes = [
'AWS.SNS.SMS.SenderID' => [
'DataType' => 'String',
'StringValue' => 'Klassroom',
],
'AWS.SNS.SMS.SMSType' => [
'DataType' => 'String',
'StringValue' => 'Transactional',
]
];
$payload = array(
'Message' => "HK test",
"PhoneNumber" => "1234567890",
'MessageAttributes' => $msgattributes
);
$result = $sns->publish($payload);
我想直接向手机号发送短信。这段代码出现了以下错误:
致命错误:未捕获异常 'Aws\Sns\Exception\SnsException',消息为'在"https://sns.ap-south-1.amazonaws.com"上执行“发布”时出错;AWS HTTP错误:客户端错误:
POST https://sns.ap-south-1.amazonaws.com
导致400 Bad Request
响应: 发送者InvalidParameter(已截断...)
无效参数(客户端):无效参数:PhoneNumber 原因:+1234567890不适用于发布到 - 发送者InvalidParameter
无效参数:PhoneNumber原因:+1234567890不适用于发布到13e181c2-a20f-5e77-9c8e-d38c55c50266 异常'GuzzleHttp\Exception\ClientException',消息为'客户端错误:POST https://sns.ap-south-1.amazonaws.com
导致400 Bad Request
我不知道为什么会出现这个错误...