使用Amazon SNS通过PHP AWS开发工具包SDK v2发送SMS消息吗? [英] Use Amazon SNS to send SMS messages using PHP AWS SDK v2?

查看:64
本文介绍了使用Amazon SNS通过PHP AWS开发工具包SDK v2发送SMS消息吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我继承了一个PHP项目,该项目与AWS开发工具包v2高度集成.目前无法使用v3.

I inherited a PHP project and it's heavily integrated with AWS SDK v2. Using v3 is not an option at this time.

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

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.

我遇到了这个 https://stackoverflow.com/a/41268045/664881 ,但它似乎正在使用AWS开发工具包的第3版.第2版​​的AWS开发工具包是否具有等效功能?

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?

推荐答案

我设法使其在PHP AWS SDK v2中运行,但是您需要在源代码中添加新参数.

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

这篇关于使用Amazon SNS通过PHP AWS开发工具包SDK v2发送SMS消息吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆