简体   繁体   中英

Amazon SNS - aws-sdk-php

     $accessKey = 'XZA...';
     $accessSecret = 'YKW...';
     $credentials = new Aws\Credentials\Credentials($accessKey, $accessSecret);

     $sharedConfig = [
        'region'  => 'us-east-1',          
        'version' => 'latest',
        'credentials' => $credentials
    ];

     $sdk = new Aws\Sdk($sharedConfig);
     $sns = new SnsClient($sharedConfig);

     $payload = [
        'PhoneNumber' => '+999999999',   // E.164 format
        'Message' => md5(time()),
        'MessageAttributes' => [
          'DefaultSenderID' => ['DataType'=>'String','StringValue'=>'MyBrandName'],
          'DefaultSMSType' => ['DataType'=>'String','StringValue'=>'Transactional']
        ]
    ];

    try {
        $data = $sns->publish( $payload );
        $MessageId = $data->get('MessageId');
    } catch ( Exception $e ) {   }

I'm using the AWS SDK for PHP - Version 3.
The code above works well when i'm sending a single SMS message except the attribute DefaultSenderID wich is not working when i send a SMS to a mobile device.

Amazon documentation says that DefaultSenderID – A string, such as your business brand, that is displayed as the sender on the receiving device. Support for sender IDs varies by country. The sender ID can be 1 - 11 alphanumeric characters, and it must contain at least one letter.

Anyone has experienced this problem using the Amazon SNS?

For anybody still struggling with this.

If you look at the documentation here , you will find that you need to add the key AWS.SNS.SMS.SenderID to the payload's MessageAttributes .

The following should work:

$payload = [
    'PhoneNumber' => '+999999999', // E.164 format
    'Message' => md5(time()),
    'MessageAttributes' => [
        'AWS.SNS.SMS.SenderID' => [
            'DataType' => 'String',
            'StringValue' => 'YourSenderID',
        ]
    ]
];

try {
    $data = $sns->publish($payload);
    $MessageId = $data->get('MessageId');
} catch (Exception $e) { }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM