-1

谁能告诉我如何获得“$registrationIDs = array("reg id1","re​​g id2");",在下面的代码中提到,发布在这里GCM with PHP (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 进行通信。您必须引入某种服务器端存储(数据库、文件)来存储 RegID。

根据您的业务,您可能希望接受一些附加参数。POST 表格对那些人来说是个好地方。

然后在应用程序中,一旦您获得 RegID,就执行 HTTP 请求,同时传递 RegID。注意事项:不要HttpClient从主线程调用。使用一个AsyncTask,或旋转一个新的Thread

于 2012-10-01T18:46:10.710 回答