【问题标题】:How to send push notification from web to iOS and android device using AWS SNS in Laravel 5.1?如何在 Laravel 5.1 中使用 AWS SNS 从 Web 向 iOS 和 android 设备发送推送通知?
【发布时间】:2016-06-02 10:36:44
【问题描述】:

我的代码是这样的,

$sns = App::make('aws')->createClient('sns');

    $data = json_encode([
        'APNS' => ['apns' => [
                'alert' => $message
            ]
        ]
    ]);

    Log::info($data);

    $sns->publish(array(
        'Message' => $data,
        'TargetArn' => "arn:aws:sns:us-west-2:360542326270:endpoint/APNS_SANDBOX/Testtest/20a75cd1-da25-3331-8126-4db497cbdd5e"
    ));

我收到如下错误:

[Aws\Sns\Exception\SnsException]                                                                                                                                                        

在“https://sns.us-east-1.amazonaws.com”上执行“发布”时出错; AWS HTTP 错误:客户端错误:POST https://sns.us-east-1.amazonaws.com 导致 400 Bad Request 响应:

  <Type>Sender</Type>                                                                                                                                                                 
  <Code>InvalidPara (truncated...)                                                                                                                                                    

InvalidParameter(客户端):无效参数:TargetArn 原因:找不到指定目标 arn 的端点 -

  <Type>Sender</Type>                                                                                                                                                                 
  <Code>InvalidParameter</Code>                                                                                                                                                       
  <Message>Invalid parameter: TargetArn Reason: No endpoint found for the target arn specified</Message>                                                                              

<RequestId>18937e90-5453-5e30-bf89-315a59c3f2af</RequestId>                                                                                                                           

[GuzzleHttp\Exception\ClientException]
客户端错误:POST https://sns.us-east-1.amazonaws.com 导致 400 Bad Request 响应:

  <Type>Sender</Type>                                                                             
  <Code>InvalidPara (truncated...) 

谁能帮我找到解决办法?提前谢谢..

【问题讨论】:

    标签: php amazon-web-services laravel-5.1


    【解决方案1】:

    查看this forum post。基本上,问题源于您的主题/目标 arn 适用于 us-west-2。但默认情况下,您的 SNS 客户端指向 us-east-1。您需要在 snsClient 上调用setRegion

    这就是帖子所说的:

    snsClient.setRegion(Region.getRegion(Regions.US_WEST_2));
    

    您可能需要翻译成您正在使用的 PHP laravel 特定客户端。

    【讨论】:

      【解决方案2】:

      我已通过以下链接在 config/aws.php 文件中使用我的 AWS 账户密钥和秘密更新了配置文件 https://github.com/aws/aws-sdk-php-laravel。这样,它就起作用了。以前,我在 .env 文件中进行了更新。现在,它运行良好。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-22
        相关资源
        最近更新 更多