[英]no notification on device but there is notification in app -Android push notifications
There is notification in my android app.....but i cant see any notifications on my device... heres my code... 我的android应用中有通知.....但是我在设备上看不到任何通知...这是我的代码...
function androidnotify($deviceToken,$message,$app,$badge,$alerttype,$xyzid)
{
$apiKey = ".........";
$url = 'https://android.googleapis.com/gcm/send';
$regid[]=$deviceToken;
$registrationIDs = $regid;
$fields = array('registration_ids'=> $registrationIDs,
'data' => $message,
'badge'=> $badge,
'alerttype'=> $alerttype,
'xyzid' => $xyzid);
$headers = array('Authorization: key=' . $apiKey,
'Content-Type: application/json');
$ch = curl_init();
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 ) );
$result = curl_exec($ch);
}
I need notification on my device too...what should i do.... 我也需要在设备上进行通知...我该怎么办....
you can get demo of GCM from this LINK 您可以通过此链接获取GCM演示
it's working with PHP code 它正在使用PHP代码
here is a code of it 这是它的代码
$registatoin_ids must be array of device token(push tokens) $message also must be array $ registatoin_ids必须是设备令牌(推送令牌)的数组$ message也必须是数组
define("GOOGLE_API_KEY","API_KEY");
class GCM {
//put your code here
// constructor
function __construct() {
}
/**
* 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/*."\n\n".json_encode($fields);*/
}
}
To send a GCM create object of GCM CLASS 发送GCM CLASS的GCM创建对象
$gcm = new GCM();
and you can send GCM like 您可以将GCM发送给
$gcm->send_notification(DEVICE_TOKENS_AS_ARRAY, MESSAGE_AS_ARRAY);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.