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

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

问题描述

我在浏览 Amazon 的 AWS PHP-sdk 文档时遇到问题.

基本上,我只需要向一个号码发送标准文本消息.我知道这是可能的,因为亚马逊允许您通过此屏幕直接通过控制台发送消息:

它说明了有关使用发布"方法的一些内容,但查看该文档确实没有提供任何答案.#发布文档链接

感谢任何帮助或指导.我目前正在寻找使用 sdk 的 V2 的解决方案.

提前致谢.

解决方案

没有文档显示它可以与 PHP 一起使用.阅读 Java 和 C# sdk 我编写了有效的 PHP 版本.

18 年 12 月 20 日更新

传递给 publish 方法的参数现在有了新的格式.固定!

如何使用 PHP 通过 AWS 发送短信

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

composer 需要 aws/aws-sdk-php

创建一个php文件:

require './vendor/autoload.php';错误报告(E_ALL);ini_set("display_errors", 1);$params = 数组('凭据' =>大批('键' =>'YOUR_KEY_HERE','秘密' =>'YOUR_SECRET_HERE',),'地区' =>'us-east-1',//<您来自 SNS 主题区域的 aws'版本' =>'最新的');$sns = new AwsSnsSnsClient($params);$args = 数组(消息属性"=>['AWS.SNS.SMS.SenderID' =>['数据类型' =>'细绳','字符串值' =>您的SENDER_ID"],'AWS.SNS.SMS.SMSType' =>['数据类型' =>'细绳','字符串值' =>'交易']],消息"=>"Hello World!访问 www.tiagogouvea.com.br!",电话号码" =>FULL_PHONE_NUMBER");$result = $sns->publish($args);echo "

";var_dump($result);echo "</pre>";

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

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:

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.

解决方案

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 AwsSnsSnsClient($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.

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

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