我正在尝试使用AWS SDK通过我的PHP站点发送短信。我使用Sending SMS with Amazon AWS services PHP的代码。
require $_SERVER['DOCUMENT_ROOT'] . '/inc/aws/aws-autoloader.php';
error_reporting(E_ALL);
ini_set("display_errors", 1);
$params = array(
'credentials' => array(
'key' => 'abc',
'secret' => 'abc',
),
'region' => 'eu-west-1', // < your aws from SNS Topic region
'version' => 'latest'
);
$sns = new \Aws\Sns\SnsClient($params);
$args = array(
"SenderID" => "TestSender",
"SMSType" => "Transactional",
"Message" => "Sending SMS with PHP",
"PhoneNumber" => "+87654321"
);
$result = $sns->publish($args);
echo "<pre>";
var_dump($result);
echo "</pre>";
这不起作用。我已经测试了很多不同的SenderID,所有消息都是从NOTICE收到的。但是,当我从AWS控制台发送消息时,将使用正确的SenderID接收消息。所以我认为我的代码是错误的。
我找到了解决方案。以这种方式设置args。有用!
$args = array(
'MessageAttributes' => [
'AWS.SNS.SMS.SenderID' => [
'DataType' => 'String',
'StringValue' => 'YourSenderName'
]
],
"SMSType" => "Transactional",
"PhoneNumber" => "+87654321",
"Message" => "Hello World!"
);