duanpo2813 2016-08-03 19:42
浏览 488

使用Amazon AWS服务PHP发送SMS

I'm having trouble digging through the documentation for Amazon's AWS PHP-sdk.

Basically, I just need to send a standard text message to a number. I know it is possible because amazon allows you to send messages through the console directly via this screen:

Amazon Console SMS

It says something about using the "publish" method, but looking through that documentation really didn't provide any answers. #Publish documentation link

Any help or guidance is appreciated. I am currently looking for a solution that uses V2 of the sdk.

Thanks in advance.

  • 写回答

5条回答 默认 最新

  • duanbo1659 2016-12-21 16:58
    关注

    No where have a doc showing it to use with PHP. Reading the Java and C# sdk I wrote the PHP version that works.

    Updated on dec 20 '18

    The args passed to publish method now have a new format. Fixed!

    How to send a SMS over AWS using PHP

    First install aws/aws-sdk-php. Using composer:

    composer require aws/aws-sdk-php

    Create a php file with:

    require './vendor/autoload.php';
    error_reporting(E_ALL);
    ini_set("display_errors", 1);
    
    $params = array(
        'credentials' => array(
            'key' => 'YOUR_KEY_HERE',
            'secret' => 'YOUR_SECRET_HERE',
        ),
        'region' => 'us-east-1', // < your aws from SNS Topic region
        'version' => 'latest'
    );
    $sns = new \Aws\Sns\SnsClient($params);
    
    $args = array(
        "MessageAttributes" => [
                    'AWS.SNS.SMS.SenderID' => [
                        'DataType' => 'String',
                        'StringValue' => 'YOUR_SENDER_ID'
                    ],
                    'AWS.SNS.SMS.SMSType' => [
                        'DataType' => 'String',
                        'StringValue' => 'Transactional'
                    ]
                ],
        "Message" => "Hello World! Visit www.tiagogouvea.com.br!",
        "PhoneNumber" => "FULL_PHONE_NUMBER"
    );
    
    
    $result = $sns->publish($args);
    echo "<pre>";
    var_dump($result);
    echo "</pre>";
    

    The result must have one array with many data, including MessageId.

    评论

报告相同问题?

问题事件

  • 专家修改了标签 8月18日

悬赏问题

  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。
  • ¥15 livecharts wpf piechart 属性
  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题