用于印度号码的 AWS SNS SMS

AWS SNS SMS for Indian Numbers

我正在使用 AWS SDK 3.0 通过 AWS SNS 为印度号码发送短信。我在 AWS 上创建了 ec2 实例。 请参考以下代码:

$params = array(
        'credentials' => array(
            'key' => 'XXXXXX',
            'secret' => 'XXXXXXX',
        ),
        'region' => 'us-west-2', // < your aws from SNS Topic region
        'version' => 'latest',
         'http' => [ 'verify' => false ]
    );
    $sns = new \Aws\Sns\SnsClient($params);

    $args = array(
        'MessageAttribute' => [
            'AWS.SNS.SMS.SenderID' => [
                'DataType'    => 'String',
                'StringValue' => 'Sender',
            ],
            'AWS.SNS.SMS.SMSType'  => [
                'DataType'    => 'String',
                'StringValue' => 'Transactional',
            ]
        ],
        "Message" => "Test Message",
        "PhoneNumber" => "+91XXXXXX",
        'MessageStructure' => 'string',
    );

    $result = $sns->publish($args);

此代码正在发送短信。但是,SMS 被记录为促销 SMS 而不是事务性 SMS。因此只能在上午 9 点到晚上 8 点之间送货。

非常感谢任何帮助。

你的编程逻辑没问题。你有一个错字 script.It 是 MessageAttributes 而不是 MessageAttribute。由于这个拼写错误,它忽略了您传递的消息属性,并在 SNS aws 控制台的 Text messaging preferences 部分中设置 default message type,即 Promotional.

正确代码:

$args = array(
    'MessageAttributes' => [
        'AWS.SNS.SMS.SenderID' => [
            'DataType'    => 'String',
            'StringValue' => 'Sender',
        ],
        'AWS.SNS.SMS.SMSType'  => [
            'DataType'    => 'String',
            'StringValue' => 'Transactional',
        ]
    ],
    "Message" => "Test Message",
    "PhoneNumber" => "+91XXXXXX",
    'MessageStructure' => 'string',
);