Php GCM实施疑虑

Php GCM实施疑虑,php,android,google-cloud-messaging,Php,Android,Google Cloud Messaging,我是GCM新手,对Android编程也比较陌生。我正在尝试实现推送通知。我的MySQL数据库中有gcm_reg_no 现在我想向这些注册ID发送推送通知。你能帮我知道下一步是什么吗?我需要在项目的Android部分添加什么吗?还是我只需要用PHP将请求发送到GCM服务器 如果您将来自设备的GCM reg ID发回服务器并存储在数据库中,那么您所要做的就是在向GCM服务器发送推送通知时将数据传递给GCM服务器 例如,下面是我用来发送推送通知的函数: //reg array here is an a

我是GCM新手,对Android编程也比较陌生。我正在尝试实现推送通知。我的MySQL数据库中有gcm_reg_no


现在我想向这些注册ID发送推送通知。你能帮我知道下一步是什么吗?我需要在项目的Android部分添加什么吗?还是我只需要用PHP将请求发送到GCM服务器

如果您将来自设备的GCM reg ID发回服务器并存储在数据库中,那么您所要做的就是在向GCM服务器发送推送通知时将数据传递给GCM服务器

例如,下面是我用来发送推送通知的函数:

//reg array here is an array of the GCM_reg_Ids I wish to send the push to
function push($regarr)
{

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

// Google API KEY, If you don't know your key just walk through the starter guide
$apiKey = "***************";

// Get all the message variables
// These are variables of data you send in the push notification which you use in the 
// Appcode to do stuff
$message = "test" ;
$data = "http://www.google.com";
$preheader = "New Notification";
$header = "test" ;

$fields = array(
              'registration_ids'  => $regarr,
              'data'              => array( "message" => $message,
                                            "preheader" => $preheader,
                                            "header" => $header,
                                            "data" => $data ),
              );

  $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);


  $json_return = json_decode($result);
  return $json_return;
}

别忘了确保你的PHP上已经启用了CURL,有很多关于示例和GCM入门的指南,快乐推送消息:D

最好的开始是官方示例。它有一个服务器部分和客户端部分。所以是的,你需要在你的Android项目中做点什么。您能详细解释一下应用程序的服务器部分将负责什么吗?