【发布时间】:2013-09-21 15:55:26
【问题描述】:
这是我要问的新问题,因为我在 SO 上没有得到任何答案。
我正在使用 Amazon SNS Push 向我注册的设备发送推送,一切正常,我可以在我的应用程序第一次启动时注册设备,可以发送推送等。我面临的问题是,我想打开当我通过推送打开我的应用程序时的特定页面。我想用有效载荷发送一些额外的参数,但我不能这样做。
我试过这个链接:- http://docs.aws.amazon.com/sns/latest/api/API_Publish.html
我们只有一个键,即“消息”,据我所知,我们可以在其中传递有效负载。
我想传递这样的有效负载:-
{
aps = {
alert = "My Push text Msg";
};
"id" = "123",
"s" = "section"
}
或任何其他格式都可以,我只想将 2-3 个值与有效负载一起传递,以便我可以在我的应用程序中使用它们。
我用于发送推送的代码是:-
// Load the AWS SDK for PHP
if($_REQUEST)
{
$title=$_REQUEST["push_text"];
if($title!="")
{
require 'aws-sdk.phar';
// Create a new Amazon SNS client
$sns = Aws\Sns\SnsClient::factory(array(
'key' => '...',
'secret' => '...',
'region' => 'us-east-1'
));
// Get and display the platform applications
//print("List All Platform Applications:\n");
$Model1 = $sns->listPlatformApplications();
print("\n</br></br>");*/
// Get the Arn of the first application
$AppArn = $Model1['PlatformApplications'][0]['PlatformApplicationArn'];
// Get the application's endpoints
$Model2 = $sns->listEndpointsByPlatformApplication(array('PlatformApplicationArn' => $AppArn));
// Display all of the endpoints for the first application
//print("List All Endpoints for First App:\n");
foreach ($Model2['Endpoints'] as $Endpoint)
{
$EndpointArn = $Endpoint['EndpointArn'];
//print($EndpointArn . "\n");
}
//print("\n</br></br>");
// Send a message to each endpoint
//print("Send Message to all Endpoints:\n");
foreach ($Model2['Endpoints'] as $Endpoint)
{
$EndpointArn = $Endpoint['EndpointArn'];
try
{
$sns->publish(array('Message' => $title,
'TargetArn' => $EndpointArn));
//print($EndpointArn . " - Succeeded!\n");
}
catch (Exception $e)
{
//print($EndpointArn . " - Failed: " . $e->getMessage() . "!\n");
}
}
}
}
?>
任何帮助或想法将不胜感激。提前致谢。
【问题讨论】:
-
嗯,我得到了解决方案,亚马逊应该在他们的实施文档中提到它,很快我会上传答案。
-
嗨,请分享解决方案,我遇到了同样的问题 :)
-
您找到问题所在了吗?我也有同样的事情——我能发送的只是默认消息。我在不同的平台上但同样的问题 - stackoverflow.com/q/22366310/850969
-
解决方法如下,您还有什么问题吗??
-
嘿,我在哪里可以下载“aws-sdk.phar”
标签: php ios objective-c push-notification amazon