[英]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.