简体   繁体   English

如何在Laravel 5.1中使用AWS SNS将推送通知从Web发送到iOS和android设备?

[英]How to send push notification from web to iOS and android device using AWS SNS in Laravel 5.1?

I have coded like, 我编码像

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

I'am getting the error as below: 我收到如下错误:

[Aws\Sns\Exception\SnsException]                                                                                                                                                        

Error executing "Publish" on " https://sns.us-east-1.amazonaws.com "; 在“ https://sns.us-east-1.amazonaws.com ”上执行“发布”时出错; AWS HTTP error: Client error: POST https://sns.us-east-1.amazonaws.com resulted in a 400 Bad Request response: AWS HTTP错误:客户端错误: POST https://sns.us-east-1.amazonaws.com导致400 Bad Request响应:

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

InvalidParameter (client): Invalid parameter: TargetArn Reason: No endpoint found for the target arn specified - 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] [GuzzleHttp \\异常\\ ClientException]
Client error: POST https://sns.us-east-1.amazonaws.com resulted in a 400 Bad Request response: 客户端错误: POST https://sns.us-east-1.amazonaws.com导致400 Bad Request响应:

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

Can anyone help me to find the solution? 谁能帮助我找到解决方案? Thanks in advance.. 提前致谢..

Check out this forum post . 查看此论坛帖子 Basically, the issue stems from the fact that your Topic/Target arn is for us-west-2 . 基本上,问题源于您的Topic / Target arn适用于us-west-2 But by default your SNS client is pointing to us-east-1 . 但是默认情况下,您的SNS客户端指向us-east-1 You need to call setRegion on snsClient. 您需要在setRegion上调用setRegion。

This is how the post says to do it: 帖子说的是这样的:

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

You'll probably have to translate into the PHP laravel specific client you are using. 您可能必须将其转换为所使用的PHP laravel特定客户端。

I have updated the config file with my AWS account Key and secret in the config/aws.php file by following the link https://github.com/aws/aws-sdk-php-laravel . 我已通过以下链接https://github.com/aws/aws-sdk-php-laravel使用AWS账户Key和secret在config / aws.php文件中更新了配置文件。 By this, it gets worked. 这样,它就可以工作了。 Previously, I have updated in my .env file. 以前,我已经在.env文件中进行了更新。 Now, it works well. 现在,它运作良好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将推送通知从 Firebase 发送到 iOS 设备上的 web 应用程序? - How to send push notification from Firebase to web app on iOS device? 如何在Laravel中使用Kreait / Firebase云消息向多个设备发送发送推送通知 - How to send send push notification to multiple device using kreait/firebase cloud message in laravel 使用APNS和使用PHP的DataService向iOS设备发送推送通知 - Send Push notification to IOS Device using APNS and DataService using PHP AWS SNS推送通知澄清 - AWS SNS push notification clarification 如何使用php向Android发送推送通知 - How to send push notification by using php to android 如何在较新版本的 ios 中使用 php 从服务器在 ios 中发送推送通知,而不使用 pem 文件 - how to send push notification in ios from server using php in newer version of ios, without using pem file 如何通过Amazon SNS推送通知在有效负载中发送额外参数 - How to send Extra parameters in payload via Amazon SNS Push Notification Android使用GCM和PHP将通知从设备发送到其他设备 - Android send notification from device to other device using GCM and PHP 使用laravel-push-notification将推送通知发送到Android - Send push notification to Android, with laravel-push-notification 如何从 PHP 网站向 iOS 和 Android 发送推送通知? - How can I send push notification from PHP website to iOS and Android?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM