我正试图使用OneSignal服务的api向具有特定标签的用户发送推送通知,如下所示:https://www.onesignal.com/
我似乎无法正确格式化数组。以下是我所拥有或想要的,但它不起作用:
"tags" => array[{"key": "NotifyLive", "relation": "=", "value": "true"}],
因此,我想将目标用户的标签"NotifyLive"设置为"true"。
我相信这是可以做到的,因为它在这里的文档中显示了这一点。向下滚动到标记:对象数组示例。我就是不知道如何对这一行进行编码。
以下是我随通知发送的字段:
$fields = array(
"app_id" => "example",
"android_sound" => "$num",
"big_picture" => "http://website.com/mypic.jpg",
"tags" => array[{"key": "NotifyLive", "relation": "=", "value": "true"}],// Doesn't work!
"data" => array("autoplay" => "true"),
"contents" => $content,
"headings" => $heading
);
错误:收到的JSON:{"allresponses":"{''"errors''":[''"标记必须是一个数组。例如,[{''''"key''''":''''"gender''''",''''"relationship''''":''''"=''''",''''"value''''":''"male''"}]''"]}"}
该团队得到了惊人的支持,但我现在正在编码,所以我需要在工作时间之外得到答案。感谢您的真知灼见。
找到了答案。数组必须以以下格式写入:
// This Array format worked
$daTags = array(
array("key" => "NotifySound", "relation" => "=", "value" => "true"),
);
$fields = array(
"app_id" => "exampleID",
"android_sound" => "$num",
"big_picture" => "http://wesite.com/mypic.jpg",
"tags" => $daTags,
"data" => array("autoplay" => "true"),
"contents" => $content,
"headings" => $heading
);
由于tags
字段被弃用,您应该使用filters
字段通过标记来定位用户
$filters = array(
array("field" => "tag", "key" => "NotifySound", "relation" => "=", "value" => "true"),
);
$fields = array(
"app_id" => "exampleID",
"android_sound" => "sound",
"big_picture" => "http://wesite.com/mypic.jpg",
"filters" => $filters,
"data" => array("autoplay" => "true"),
"contents" => $content,
"headings" => $heading
);