【问题标题】:AWS SNS SMS for Indian Numbers适用于印度号码的 AWS SNS SMS
【发布时间】:2023-04-03 00:32:01
【问题描述】:

我正在使用 AWS SDK 3.0 通过 AWS SNS 为印度号码发送 SMS。我在 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);

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

非常感谢任何帮助。

【问题讨论】:

    标签: php amazon-web-services amazon-ec2 aws-sdk amazon-sns


    【解决方案1】:

    您的编程逻辑很好。您的脚本中有错字。它是 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',
    );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-04-11
      • 1970-01-01
      • 1970-01-01
      • 2021-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多