안드로이드 gcm 관련 php 통신.

|

대강

할건 없고. 오픈소스 프로젝트의 프로젝트대로 소스 복붙하고

자기 자신의 regid 알아낸다음에 아래에 입력해주고

노티피케이션이 실행되는지만 하면 됨.


상용화될 게임에는 regid 등록해주는 부분에서 각 DB 에 regid 등록해주고

아래 php 구문을 DB에 접속해서 DB의 regid 를 모두 호출해주는 식으로 수정해주면 될거같음.

일단 확실히 되는 php 구문임..


   <?php
        // Replace with real server API key from Google APIs        
        // 서버api Key 입력

        $apiKey = "";
      
        // Replace with real client registration IDs
        // 각 핸드폰 기계의 registraitionID 입력.

        $registrationIDs = array(
        " ",

  " ",

        );
      
        // Message to be sent

        // 입력하고 싶은 메시지 입력
        $message = "Test Notificación PHP";
      
        // Set POST variables
        $url = 'https://android.googleapis.com/gcm/send';
      
        $fields = array(
            'registration_ids' => $registrationIDs,
            'data' => array( "message" => $message ),
        );
      
        $headers = array(
            'Authorization: key=' . $apiKey,
            'Content-Type: application/json'
        );
      
        // Open connection
        $ch = curl_init();
      
        // Set the url, number of POST vars, POST data
        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_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode( $fields ));
      
        // Execute post
        $result = curl_exec($ch);      
        // Close connection
        curl_close($ch);
        echo $result;
    ?>

Trackback 0 And Comment 0
prev | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | ··· | 15 | next