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日

悬赏问题

  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波