gpt4 book ai didi

android - OneSignal - 基于标签发送通知

转载 作者:行者123 更新时间:2023-11-29 16:53:16 26 4
gpt4 key购买 nike

我想知道我是否可以使用标签而不是 included_segments 为 OneSignal 中的特定用户发送通知 我想发送通知到特定的标签,而无需创建分割并根据他们过滤用户

$fields = array(
'app_id' => "XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX",
'included_segments' => array($segments),
'data' => array("foo" => "bar"),
'contents' => $content
);

最佳答案

在下面的示例中,如果 level>10 或 amount_spent>0 是过滤条件,其中 level 和 amount_spent 是各自标签的键。

    try {
String jsonResponse;

URL url = new URL("https://onesignal.com/api/v1/notifications");
HttpURLConnection con = (HttpURLConnection)url.openConnection();
con.setUseCaches(false);
con.setDoOutput(true);
con.setDoInput(true);

con.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
con.setRequestProperty("Authorization", "Basic NGEwMGZmMjItY2NkNy0xMWUzLTk5ZDUtMDAwYzI5NDBlNjJj");
con.setRequestMethod("POST");

String strJsonBody = "{"
+ "\"app_id\": \"5eb5a37e-b458-11e3-ac11-000c2940e62c\","
+ "\"filters\": [{\"field\": \"tag\", \"key\": \"level\", \"relation\": \">\", \"value\": \"10\"},{\"operator\": \"OR\"},{\"field\": \"amount_spent\", \"relation\": \">\",\"value\": \"0\"}],"
+ "\"data\": {\"foo\": \"bar\"},"
+ "\"contents\": {\"en\": \"English Message\"}"
+ "}";


System.out.println("strJsonBody:\n" + strJsonBody);

byte[] sendBytes = strJsonBody.getBytes("UTF-8");
con.setFixedLengthStreamingMode(sendBytes.length);

OutputStream outputStream = con.getOutputStream();
outputStream.write(sendBytes);

int httpResponse = con.getResponseCode();
System.out.println("httpResponse: " + httpResponse);

if (httpResponse >= HttpURLConnection.HTTP_OK && httpResponse < HttpURLConnection.HTTP_BAD_REQUEST) {
Scanner scanner = new Scanner(con.getInputStream(), "UTF-8");
jsonResponse = scanner.useDelimiter("\\A").hasNext() ? scanner.next() : "";
scanner.close();
}else {
Scanner scanner = new Scanner(con.getErrorStream(), "UTF-8");
jsonResponse = scanner.useDelimiter("\\A").hasNext() ? scanner.next() : "";
scanner.close();
}
System.out.println("jsonResponse:\n" + jsonResponse);

} catch(Throwable t) {
t.printStackTrace();
}

取自:Source .从提到的来源搜索基于过滤器/标签发送 - 创建通知

关于android - OneSignal - 基于标签发送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45735124/

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