php fcm 서버

조회수 2112회

php로 fcm 서버를 만들고 있는 학생입니다. message status를 출력하니 success":6,"failure":0,"canonical_ids":0 와 같이 출력이 되며 success가 떴음에도 불구하고 token이 등록된 기기로 알림이 가지 않습니다. 코드는 아래와 같고 token 값은 제대로 입력 되었습니다. 무엇이 문제인가요?

<?php
        function send_notification ($tokens, $message)
        {
            $url = 'https://fcm.googleapis.com/fcm/send';
            $fields = array(
                 'registration_ids' => $tokens,
                 'data' => $message
                );
            $headers = array(
                'Authorization:key = 여기엔 서버 api key값을 넣었어요',
                'Content-Type: application/json'
                );
           $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_POST, true);
         curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
         curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
         $result = curl_exec($ch);
         if ($result === FALSE) {
             die('Curl failed: ' . curl_error($ch));
         }
         curl_close($ch);
         return $result;
        }

        $conn = mysqli_connect("localhost","db user명","비밀번호","db명");
        $sql = " Select Token From users";
        $result = mysqli_query($conn,$sql);
        $tokens = array();
        if(mysqli_num_rows($result) > 0 ){
            while ($row = mysqli_fetch_assoc($result)) {
                $tokens[] = $row["Token"];
          echo $row["Token"];
          echo "<br>";

            }
        }
        mysqli_close($conn);
        $message = array("message" => " FCM PUSH NOTIFICATION TEST MESSAGE");
        $message_status = send_notification($tokens, $message);
        echo $message_status;
      if  (in_array  ('curl', get_loaded_extensions())) {
        echo "cURL is installed on this server";
      }
      else {
        echo "cURL is not installed on this server";
      }
     ?>
  • (•́ ✖ •̀)
    알 수 없는 사용자

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)