Android设备在使用RESTAPI从PHP发送数据时未收到通知?

Android设备在使用RESTAPI从PHP发送数据时未收到通知?,php,android,google-cloud-messaging,Php,Android,Google Cloud Messaging,我收到了设备的GCM注册令牌,但当我从PHP使用RESTAPI发送消息时,它显示成功,但没有在设备上接收消息。php代码 确保您的API密钥正确,并且您的服务器IP被证书列为受信任的。有时,WiFi连接的设备在一段时间后对GCM没有响应。尝试重新启动设备。它应该开始接收您发送的所有消息 此外,在此检查您是否错误地使用了android:permission=“com.google.android.gcm.c2dm.permission.SEND”,而不是android:permission=“co

我收到了设备的GCM注册令牌,但当我从PHP使用RESTAPI发送消息时,它显示成功,但没有在设备上接收消息。php代码


确保您的API密钥正确,并且您的服务器IP被证书列为受信任的。有时,WiFi连接的设备在一段时间后对GCM没有响应。尝试重新启动设备。它应该开始接收您发送的所有消息

此外,在此检查您是否错误地使用了
android:permission=“com.google.android.gcm.c2dm.permission.SEND”
,而不是
android:permission=“com.google.android.c2dm.permission.SEND”


希望这有帮助

谢谢@abielita,权限是正确的。解析消息时出现问题。所以没有问题,应用程序正在接收消息。
<?php 
 $data = array( 'message' => 'Hello World! First Message from PHP' );
 $ids = 'device registration token';
 // Send a GCM push
 sendGoogleCloudMessage(  $data, $ids );

function sendGoogleCloudMessage( $data, $ids )
{
// Insert real GCM API key from Google APIs Console
// https://code.google.com/apis/console/        
$apiKey = 'API Key'; //(server API Key)
// Define URL to GCM endpoint
$url = 'https://gcm-http.googleapis.com/gcm/send';
// Set GCM post variables (device IDs and push payload)     
$post = array(
                'to'  => $ids,
                'data'              => $data,
                );

// Set CURL request headers (authentication and type)       
$headers = array( 
                    'Authorization: key=' . $apiKey,
                    'Content-Type: application/json'
                );

// Initialize curl handle       
$ch = curl_init();

// Set URL to GCM endpoint      
curl_setopt( $ch, CURLOPT_URL, $url );

// Set request method to POST       
curl_setopt( $ch, CURLOPT_POST, true );

// Set our custom headers       
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );

// Get the response back as string instead of printing it       
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );

// Set JSON post data
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $post ) );

// Actually send the push   
$result = curl_exec( $ch );

// Error handling
if ( curl_errno( $ch ) )
{
    echo 'GCM error: ' . curl_error( $ch );
}

// Close curl handle
curl_close( $ch );

// Debug GCM response       
echo $result;
print_r($result);
}
?>
{"multicast_id":8550022549195779350,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1459795352923689%21f96bfff9fd7ecd"}]}