0

그래서이 질문은 Jersey을 사용하여 보았습니다. 하지만 여전히 내 서버에서 주제 구독 사용자에게 간단한 푸시 알림을 보내는 방법을 파악하지 못했습니다. 을 기반으로 구축하려고하므로 내 요청에 무엇이 잘못되었는지 이해하지 못합니다.Firebase가 서버 알림을 전송합니다.

public class OverSLANotifier { 

    public static void main(String[] args) throws Exception, FirebaseException { 
     String rawData = "{\"to\": \"/topics/sla\",\"data\": {\"message\": \"This is test push notification!\",}}"; 
     String encodedData = URLEncoder.encode(rawData, "UTF-8"); 

     URL u = new URL("https://fcm.googleapis.com/fcm/send"); 
     HttpURLConnection conn = (HttpURLConnection) u.openConnection(); 
     conn.setDoOutput(true); 
     conn.setRequestMethod("POST"); 
     conn.setRequestProperty("Authorization", "key=AI<redacted>VGB6YwPWrinoz1YFBgdKv4Pgm8s"); 
     conn.setRequestProperty("Content-Type", "application/json"); 
     OutputStream os = conn.getOutputStream(); 
     os.write(encodedData.getBytes()); 
     System.out.println(""+ conn.getResponseCode() + "-->>"+conn.getResponseMessage()); 
    } 

내 클라이언트는 properly set 내가 콘솔에서 보내는 경우받을 수 있습니다.

응답은 항상 :

401 - >> 무단

답변

1

당신이있는 거 JSON은 잘못된 것 같다

{\"to\": \"/topics/sla\",\"data\": {\"message\": \"This is test push notification!\",}} 

또한

{\"to\": \"/topics/sla\",\"data\": {\"message\": \"This is test push notification!\"}} 

대 docu를 확인하십시오. 조언 :

메시지를 보내는 데 사용 된 보낸 사람 계정을 인증 할 수 없습니다. 가능한 원인은 다음과 같습니다

  • 인증 헤더가 없거나 HTTP 요청에 잘못된 구문.
  • 잘못된 프로젝트 번호가 키로 전송되었습니다.
  • 키는 유효하지만 FCM 서비스가 비활성화되어 있습니다.
  • 서버 키 IP에 허용 된 이 아닌 서버에서 발생한 요청입니다.

Source

PS : 그 문서의 무효 알면 here 찾을 수)

관련 문제