我试图用变量进行json调用,但由于调用没有注册引号而一直出错。
以下语法使通知推送正确发送:
'include_player_ids' => array('00000000-6fee-11e4-8ec9-000000000000')
此方法导致失败的地方:
$playerID = '00000000-6fee-11e4-8ec9-000000000000';
...
'include_player_ids' => array($playerID)
作为api的原因需要数组项周围的引号,但我在php上并不太好,并且无法弄清楚如何在它周围添加它们因为这种方法不起作用对我来说:
'include_player_ids' => array(' . $playerID . '),
好(工作)输出:
"include_player_ids":["00000000-6fee-11e4-8ec9-000000000000"]
错误(非工作)输出:
"include_player_ids":[00000000-6fee-11e4-8ec9-000000000000]
答案 0 :(得分:0)
以json(标题设置为"Content-Type" => "application/json"
)发送POST请求应该有效:
$fields = (object) [
'app_id' => $this->appId,
'include_player_ids' => $playerIds,
'template_id' => '374e7074-f07d-4743-ad90-5598967e4494', // `daily generic`
];
json_encode($fields);