将用户存储在OneSignal中时,为什么预订的字段显示“无推送令牌”?

时间:2019-05-29 09:43:08

标签: spring-boot onesignal

我正在使用Spring Boot创建一个Rest API,并将其配置为与OneSignal一起使用。 我设法在数据库中检索并存储了players_id。

之后,我创建了一个端点,该端点检索这些ID并在发送消息时向它们发送通知。 This is how it looks in OneSignal

响应代码为:

strJsonBody:
{"app_id": "b27c8471-e134-4991-b722- 
e4498273c5f4","include_external_user_ids": ["0c25334c-302e-4022-b494- 
a11ea6f43318", "d3349289-b406-480e-8093-d410e7aacc2d"],"data": {"foo": 
"bar"},"contents": {"en": "com.chatapp.model.Message@2d379c31"}}
httpResponse: 200
jsonResponse:
{"id":"","recipients":0,"errors":["All included players are not 
subscribed"]}

所以我不知道如何存储该令牌或该怎么办?

这是用于注册用户设备的代码:

public String registerDevice() {
       try {
           String jsonResponse;
           URL url = new URL(playersUrl);
           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 " + appKey);//REST API
           con.setRequestMethod("POST");

           String strJsonBody = "{"
                   + "\"app_id\": \"" + appId + "\","
                   + "\"device_type\": \"" + 5 + "\""
                   + "}";

           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);

           jsonResponse = mountResponseRequest(con, httpResponse);
           System.out.println("jsonResponse:\n" + jsonResponse);

           JSONObject jsonObject = new JSONObject(jsonResponse);
           String id = jsonObject.getString("id");

           return id;
       } catch (Throwable t) {
           t.printStackTrace();
           return null;
       }
   }

0 个答案:

没有答案