这是我要问的新问题,因为我在 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");
}
}
}
}
?>
任何帮助或想法将不胜感激。提前致谢。