【发布时间】:2021-11-17 18:16:20
【问题描述】:
设置
我已经下载了aws.zip file for AWS V3 SDK for PHP 并将其解压缩到我的项目文件夹中,并将它的自动加载器连接到我的自动加载器中。我还完成了创建 AWS 账户的所有步骤,以及设置 SNS,包括获取要使用的电话号码。所有示例工作都在完整性检查中显示。
有一个你应该知道的黑暗角落。您需要在~/.aws/ 目录中创建一个credentials 文件。如果您在 php-fpm 上下文中使用它,则该主目录可能是您的 /var/www/ 目录,因此您应该将您的凭据文件放在 /var/www/.aws/ 下。
更多关于配置文件的信息可以在这里找到...AWS Command Line Interface - Configuration and credential file settings。
健全性检查
遵循AWS SNS Documentation - Publish to a Text Message (SMS Message) 中的示例。
Test-AWS-SNS.php
require 'vendor/autoload.php';
use Aws\Sns\SnsClient;
use Aws\Exception\AwsException;
$SnSclient = new SnsClient([
'profile' => 'default',
'region' => 'us-east-1',
'version' => '2010-03-31'
]);
$message = 'This message is sent from a Amazon SNS code sample.';
$phone = '+1AAALLL####';
try {
$result = $SnSclient->publish([
'Message' => $message,
'PhoneNumber' => $phone,
]);
var_dump($result);
} catch (AwsException $e) {
// output error message if fails
error_log($e->getMessage());
}
(注意:+1AAALLL#### 实际上指向我的手机号码,但我显然不会把它放在这里。)
问题
问题在于,没有关于如何从我在 AWS 的 SNS 长代码列表中拥有的号码之一发送短信的文档。它总是来自列表中的第一个电话号码,我找不到任何关于如何将号码更改为另一个号码的文档。这里的一些帮助会很棒。
先前的研究
显然,我浏览过文档并搜索过 Stack Overflow。 This one is pretty close, as it sets a SenderID。他们的文档 mentions how to do it as an optional number 9 next to the sender ID from above 但我确实知道这是可能的,因为他们在 Oct 23, 2020 - Amazon SNS now supports selecting the origination number when sending SMS messages 上添加了该功能——他们只是没有放置任何代码示例。
帮助我欧比旺克诺比,你是我唯一的希望。
【问题讨论】:
标签: php amazon-web-services amazon-sns