douji9734
2017-10-08 14:47
浏览 34
已采纳

用于印度号码的AWS SNS SMS

I'm using AWS SDK 3.0 to send SMS via AWS SNS for indian numbers. I've ec2 instance created on AWS. Please refer the code below :

$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);

This code is sending SMS. However, the SMS are getting logged as Promotional SMS instead of Transactional. Thus getting delivered between 9am to 8pm only.

Any help is much appreciated.

图片转代码服务由CSDN问答提供 功能建议

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

  $ params = array(
'credentials'=&gt; array(
'key')  =&gt;'XXXXXX',
'秘密'=&gt;'XXXXXXX',
),
'region'=&gt;'us-west-2',//&lt;来自SNS主题区域的aws \  '版本'=&gt;'最新',
'http'=&gt; ['verify'=&gt; false] 
); 
 $ sns = new \ Aws \ Sns \ SnsClient($ params); \  n 
 $ args = array(
'FessageAttribute'=&gt; [
'AWS.SNS.SMS.SenderID'=&gt; [
'数据类型'=&gt;'字符串',
'StringValue'=  &gt;'发件人',
],
'AWS.SNS.SMS.SMSType'=&gt; [
'数据类型'=&gt;'字符串',
'StringValue'=&gt;'交易',\  n] 
],
“消息”=&gt;“测试消息”,
“电话号码”=&gt;“+ 91XXXXXX”,
'消息结构'=&gt;'字符串',
); 
  
 $ result = $ sns-&gt; publish($ args); 
   
 
 

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

非常感谢任何帮助。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • dougou8552 2017-10-08 17:02
    最佳回答

    Your programming logic is fine. There is a typo in you script.It is MessageAttributes not MessageAttribute. Due to this typo, it is ignoring the Message attributes which you are passing and taking the default message type set in your Text messaging preferences section in SNS aws console which is Promotional.

    Correct Code:

    $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',
    );
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题