-1

「$registrationIDs = array( "reg id1","re​​g id2");」を取得する方法を教えてください。次のコードに記載されています。これは、PHP を使用した GCM (Google Cloud Messaging) に投稿されています。

<?php
           // Replace with real server API key from Google APIs  
            $apiKey = "your api key";    

              // Replace with real client registration IDs
           $registrationIDs = array( "reg id1","reg id2");

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

         // 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);
       ?>
4

1 に答える 1

0

アプリが RegID を受信したら、アプリが RegID を通信するために使用できる Web ページを作成する必要があります。RegID が格納されるある種のサーバー側ストレージ (データベース、ファイル) を導入する必要があります。

ビジネスによっては、いくつかの追加パラメーターを受け入れたい場合があります。POST フォームは、それらに適した場所です。

次に、アプリで RegID を取得したら、HTTP 要求を実行して RegID を渡します。注意:HttpClientメインスレッドから呼び出さないでください。を使用するAsyncTaskか、新しい をスピンしThreadます。

于 2012-10-01T18:46:10.710 に答える