【发布时间】:2015-10-19 10:24:59
【问题描述】:
我通过 PHP 脚本发送推送通知以连接到 APNS 服务器。当我使用以下有效负载结构时,一切正常。
$body['aps'] = array(
'alert' => $message,
'badge' => $badge,
'sound' => 'default'
);
$payload = json_encode($body);
但是,我需要向“警报”元素添加更多参数,并希望添加更多自定义参数。我的做法如下,但 APNS 不接受 JSON。我在 PHP 中创建 JSON 的方法有问题吗?
$payload='{
"aps": {
"alert":{
"title": "'.$message.'",
"body":"'.$notif_desc.'"
},
"badge":"'.$badge.'",
"sound": "default"
},
"type": "notification",
"id":"'.$lastid.'",
"date:"'.$date1.'"
}';
所以基本上,我有两个疑问。第二种方法错了吗?如果是这样,请告诉我一个为 APNS 服务器创建嵌套 JSON 有效负载的有效方法。第二个问题,我需要在Payload中添加自定义的PHP变量,我想知道我在第二种方法中添加的方式是对还是错。
基本上,我需要在 PHP 中创建一个 JSON 对象,如下所示
{
"aps" : {
"alert" : {
"title" : "Game Request",
"body" : "Bob wants to play poker",
"action-loc-key" : "PLAY"
},
"badge" : 5,
},
"acme1" : "bar",
"acme2" : [ "bang", "whiz" ]
}
【问题讨论】:
标签: php json nested apple-push-notifications