使用Amazon AWS服务PHP发送短信 [英] Sending SMS with Amazon AWS services PHP

查看:559
本文介绍了使用Amazon AWS服务PHP发送短信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在挖掘Amazon的AWS PHP-sdk的文档时遇到了麻烦.

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

基本上,我只需要向数字发送标准短信即可.我知道这是有可能的,因为Amazon允许您直接通过此屏幕通过控制台发送消息:

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:

它说明了有关使用发布"方法的一些信息,但是浏览该文档确实没有提供任何答案. #Publish文档链接

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

任何帮助或指导表示赞赏.我目前正在寻找使用SDK的 V2 的解决方案.

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

谢谢.

推荐答案

在哪里没有文档显示可与PHP一起使用.阅读Java和C#SDK之后,我编写了适用的PHP版本.

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

传递给publish方法的args现在具有新格式.固定!

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

首先安装 aws/aws-sdk-php .使用作曲家:

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

composer require aws/aws-sdk-php

使用以下方法创建一个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>";

结果必须是一个包含许多数据的数组,包括MessageId.

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

这篇关于使用Amazon AWS服务PHP发送短信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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