我正在尝试使用主题通过fcm发送消息。这是我使用的代码:
URL url = new URL("https://fcm.googleapis.com/fcm/send");
HttpURLConnection conn = (HttpURLConnection)
url.openConnection();
conn.setUseCaches(false);
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("Authorization", "key=" + apiKey);
JSONObject json = new JSONObject();
json.put("topic",codigo_chat);
JSONObject data = new JSONObject();
data.put("nick", nick_remitente);
data.put("token_socialauth_remitente", token_socialauth_remitente);
data.put("que_dijo", que_dijo);
data.put("tipo", "3"); //para el chat general
// body
json.put("data", data);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(json.toString());
wr.flush();
但是我总是得到相同的响应:
服务器返回的HTTP响应代码:400表示URL:https://fcm.googleapis.com/fcm/send
我做错了什么?