[英]push notification is not received by device through gcm google api and php server
I have followed this tutorial , and I managed to register the application in the cgm server with device but I canno't receive push notification from server to device I tested on genymotion emulator and real device but always no notification received on device I don't know the error and the don't knwo how can I fix this issue 我已经按照本教程进行了操作 ,并设法在具有设备的cgm服务器中注册了应用程序,但是我无法从服务器发送到在genymotion模拟器和真实设备上测试的设备到设备的推送通知,但始终没有在设备上收到通知,但我没有知道错误并且不知道如何解决此问题
Here is the method which send push notification: 这是发送推送通知的方法:
/**
* Sending Push Notification
*/
public function send_notification($registatoin_ids, $message) {
// include config
include_once './config.php';
// Set POST variables
$url = 'https://android.googleapis.com/gcm/send';
$fields = array(
'registration_ids' => $registatoin_ids,
'data' => $message,
);
$headers = array(
'Authorization: key=' . GOOGLE_API_KEY,
'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);
// Disabling SSL Certificate support temporarly
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
// Execute post
$result = curl_exec($ch);
if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
}
// Close connection
curl_close($ch);
echo $result;
}
I have set the api key and project id and all is done. 我已经设置了api密钥和项目ID,一切都完成了。
Try this: 尝试这个:
$apiKey = "your api key goes here (use browser api)";
$headers = array("Content-Type:" . "application/json", "Authorization:" . "key=" . $apiKey);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.