【问题标题】:Use Amazon SNS to send SMS messages using PHP AWS SDK v2?使用 Amazon SNS 使用 PHP AWS SDK v2 发送 SMS 消息?
【发布时间】:2017-04-03 17:47:57
【问题描述】:

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

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

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

【问题讨论】:

  • 很遗憾,Publish 操作在 v2 中没有 PhoneNumber 参数。

标签: php amazon-web-services amazon-sns


【解决方案1】:

我设法让它在 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']

【讨论】:

  • 你救了我的命。谢谢!我有一个只能使用 v2 的 zend 项目
猜你喜欢
  • 1970-01-01
  • 2016-12-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多