1

GCM 用のmark nutter phonegap プラグインを使用し、サーバーから登録 ID を正常に取得しました

ここに私が使用するphpスクリプトがあります

  <?php
           // Replace with real server API key from Google APIs  
            $apiKey = "AIzaSyC7wzEjjMaOGLYp8_w3USftv_3lI-qCdZ4";    

              // Replace with real client registration IDs
           $registrationIDs = array( "APA91bFt3slFE96jaB5qnoD5gR0TCwsxe5StEGyrECR0umYviG0cfG1JNnFxYqP1ERr1RoWc38rsuWjRUx5SZ7cgUNG9-mQ4mSsY8_XQLquft5DLnqWcLCEB2wtQpfA6EAp5OQmOWzpUZU5bohfG4sfLWNUco7XxXg");

          // Message to be sent
         $message = "hi SOurabh";

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

         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     //     curl_setopt($ch, CURLOPT_POST, true);
       //     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;
          //print_r($result);
           //var_dump($result);
       ?>

私は通知をテストするためだけにこれを使用したPHPについてあまり知りません

これを実行すると、次のメッセージが表示されます

{"multicast_id":9187695352946100598,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"MismatchSenderId"}]}

なぜ私はこれを得るのですか?またはアプリをテストする他の方法はありますか?

4

2 に答える 2

1

プロジェクトで使用したプロジェクトIDは、Googleコンソールに表示されているものと一致していますか?

https ://code.google.com/apis/console/#project:?????

APIキーはGoogleGCMページの「サーバーアプリ」に属しますか?通知を受信するには、携帯電話にも有効な登録済みのGoogleアカウントが必要です。

于 2012-10-19T07:16:06.377 に答える