gpt4 book ai didi

api - OneSignal - 创建分段

转载 作者:行者123 更新时间:2023-12-04 20:31:18 30 4
gpt4 key购买 nike

我想在 oneSignal 中创建 Segments 而不必访问仪表板,所以我想知道他们是否有一个 API 用于或任何
和我一起做的其他方式

最佳答案

目前 OneSignal 没有任何用于创建段的 api,但如果您想向特定组发送通知,您可以使用标签。

是的,您可以向特定标签发送通知,标签可以用作段的替代。
如果您想向分割 A 发送通知,请将该用户的标签设置为 {user:A}
并且可以使用这个 php 请求发送通知。

$fields = array(
'app_id' => YOUR_ONE_SIGNAL_APP_ID,
//'included_segments' => array('plant_a'),
'filters' => array(array("field" => "tag", "key" => "user", "relation" => "=", "value" => "A")),
'data' => array("foo" => "bar"),
'contents' => $content
);

您的完整代码将类似于
<?PHP
function sendMessage(){
$content = array(
"en" => 'English Message'
);

$fields = array(
'app_id' => YOUR_ONE_SIGNAL_APP_ID,
'filters' => array(array("field" => "tag", "key" => "user", "relation" => "=", "value" => "A")),
'data' => array("foo" => "bar"),
'contents' => $content
);

$fields = json_encode($fields);
print("\nJSON sent:\n");
print($fields);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://onesignal.com/api/v1/notifications");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8',
'Authorization: Basic REST_API_KEY'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

$response = curl_exec($ch);
curl_close($ch);

return $response;
}

$response = sendMessage();
$return["allresponses"] = $response;
$return = json_encode( $return);

print("\n\nJSON received:\n");
print($return);
print("\n");
?>

关于api - OneSignal - 创建分段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45728036/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com