0

サーバー側でコーディングするために PHP を使用しています。

<?php

    $apiKey = "AIza......";    // my API key 

    $registrationIDs = array("APA91b............" );   // my device reg id 

     // Message to be sent
     $msg = "This is push notifications";


    // Set POST variables
    $url = 'https://android.googleapis.com/gcm/send';

     $fields = array(
            'registration_ids'  => $registrationIDs,
            'data'              => array( "message" => $msg )
            );

      $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_POSTFIELDS, json_encode( $fields ) );

// Execute post
$result = curl_exec($ch);

// Close connection
curl_close($ch);
echo $result;

  if($result == 1){
                print "\nSuccess";
        } else {
                print "\nError";
        }

 ?>

上記のスクリプトを実行したときの出力:

{"multicast_id":605543.......,"成功":1,"失敗":0,"canonical_ids":0,"結果":[{"message_id":"0:137.... ..50534%978.......ecd"}]} エラー

サーバーでメッセージセットを取得する代わりに、デバイスで「 null 」を受け取ります...

何が問題なのか教えてください....

4

0 に答える 0