php APNS JSON PAYLOAD - 更多参数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5954882/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
APNS JSON PAYLOAD - more arguments
提问by sebastian
I need to add some arguments to a json payload for APNS service. How can i do this? this is the documentation of apple: http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ApplePushService/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW1
我需要为 APNS 服务的 json 负载添加一些参数。我怎样才能做到这一点?这是苹果的文档:http: //developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ApplePushService/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW1
When i try to send a message with close and view buttons, i need to add two more arguments that my mobile application needs. Any idea?
当我尝试发送带有关闭和查看按钮的消息时,我需要添加我的移动应用程序需要的另外两个参数。任何的想法?
回答by lostInTransit
Not sure if you got the answer yet. But this is what the documentation mentions
不确定你是否得到了答案。但这是文档中提到的
Providers can specify custom payload values outside the Apple-reserved aps namespace. Custom values must use the JSON structured and primitive types: dictionary (object), array, string, number, and Boolean.
提供商可以在 Apple 保留的 aps 命名空间之外指定自定义负载值。自定义值必须使用 JSON 结构化和原始类型:字典(对象)、数组、字符串、数字和布尔值。
So in order to add custom values to your payload, just add them as key-value pairs in your payload. Something like this
因此,为了向您的负载添加自定义值,只需将它们作为键值对添加到您的负载中。像这样的东西
{
"aps":{
"alert":"Your Message",
"sound":"push1.wav"
},
"custom_key1":"value1",
"custom_key2":"value2"
}
Here custom_key1
and custom_key2
are your custom keys and value1
and value2
are their values.
这里custom_key1
和custom_key2
是您的自定义键,value1
和value2
是它们的值。
回答by amol-c
In case someone is still wondering :
如果有人仍然想知道:
$body = (array('aps' => array('alert' => $message,'sound' => $sound_file_wav), "some_key" => "custom_id"));
$payload = json_encode($body);
回答by raju_kr
I use the following in PHP
我在 PHP 中使用以下内容
$title = 'My Test Message';
$sound = 'doorbell.caf';
$msgpayload=json_encode(array('aps' => array('alert' => $title,'sound' => $sound,)));
$response = $sns->publish(array(
'TopicArn' => $TopicArn,
'MessageStructure' => 'json',
'Message' => json_encode(array(
'default' => $title,
'APNS_SANDBOX' => $msgpayload
))
));