使用 Amazon SNS 通过 PHP AWS SDK v2 发送 SMS 消息



我继承了一个PHP项目,它与AWS SDK v2高度集成。目前无法使用 v3。

我的问题是如何利用SNS根据需要向特定号码发送短信?也就是说,我不想在操作发生时向订阅特定主题的一堆电话号码发送大量通知,我想在操作发生时向特定电话号码发送通知。

我遇到了这个 https://stackoverflow.com/a/41268045/664881 但它似乎使用的是 AWS 开发工具包的 v3。是否有与 AWS 开发工具包 v2 等效的版本?

我设法让它在 PHP AWS SDK v2 中工作,但您需要在源代码中添加新参数。

// 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']

最新更新