问题
I inherited a PHP project and it's heavily integrated with AWS SDK v2. Using v3 is not an option at this time.
My question is how can I leverage SNS to send text messages to specific numbers as needed? That is, I don't want to send mass notifications to a bunch of phone numbers subscribed to a specific topic when an action occurs, I want to send a notification to a specific phone number when an action occurs.
I came across this https://stackoverflow.com/a/41268045/664881 but it appears to be using v3 of the AWS SDK. Is there an equivalent with v2 of the AWS SDK?
回答1:
I managed to make it work in PHP AWS SDK v2, but you need to add new parameter in the source code.
// update file: aws-sdk-php/src/Aws/Sdk/Resources/sns-2010-03-31.php
'Publish' => array(
'parameters' => array(
'PhoneNumber' => array( // new parameter
'type' => 'string',
'location' => 'aws.query',
),
),
),
// You just need to publish it and include the `PhoneNumber` parameter
$snsClientResult = $snsClient->publish([
'Message' => 'YOUR_MESSAGE',
'PhoneNumber' => 'PHONE_NUMBER',
'MessageStructure' => 'SMS',
'MessageAttributes' => [
'AWS.SNS.SMS.SenderID' => [
'DataType' => 'String',
'StringValue' => 'SENDER_ID',
],
'AWS.SNS.SMS.SMSType' => [
'DataType' => 'String',
'StringValue' => 'Promotional', // Transactional
]
]
]);
// Get the response
$snsClientResult['MessageId']
来源:https://stackoverflow.com/questions/43191129/use-amazon-sns-to-send-sms-messages-using-php-aws-sdk-v2