我的应用程序没有收到任何来自GCM的消息 [英] my app doesn't receive any messages from GCM

查看:155
本文介绍了我的应用程序没有收到任何来自GCM的消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序不会收到来自gcm的任何消息我创建的发件人页面和接收类,我只想在通知栏上显示它

GCM.php

p>

 <?php 

class GSM {

function _construct(){



public function send_notification($ registration_ids,$ message){

include_once'./config.php';


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

$ fileds = array(
'registration_ids'=> $ registration_ids,
'message'=> $ message,

);
$ headers = array(
'Authorization:key ='。GOOGLE_API_KEY,
'Content-Type:application / json'
);
$ ch = curl_init();

curl_setopt($ ch,CURLOPT_URL,$ url);
curl_setopt($ ch,CURLOPT_HTTPHEADER,$ headers);
curl_setopt($ ch,CURLOPT_RETURNTRANSFER,true);

curl_setopt($ ch,CURLOPT_SSL_VERIFYPEER,false);

curl_setopt($ ch,CURLOPT_POSTFIELDS,json_encode($ fields));

$ result = curl_exec($ ch);
if($ result === false){

die('Cutl failed:'。curl_error($ ch));
}
curl_close($ ch);
echo $ result;
}
}



?>

index.php

 <!DOCTYPE html> 
< html>
< head>
< title>< / title>
< meta http-equiv =Content-Typecontent =text / html; charset = UTF-8>
< script src =http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js>< / script>
< script type =text / javascript>
$(document).ready(function(){

});
函数sendPushNotification(id){
var data = $('form#'+ id).serialize();
$('form#'+ id).unbind('submit');
$ .ajax({
url:send_message.php,
类型:'GET',
data:data,
beforeSend:function(){
$ b $,
成功:function(data,textStatus,xhr){
$('。txt_message')。val();
},
error:function(xhr,textStatus,errorThrown){
$ b $}
});
返回false;
}
< / script>
< style type =text / css>
.container {
width:950px;
margin:0 auto;
padding:0;
}
h1 {
font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;
font-size:24px;
颜色:#777;

}
div.clear {
clear:both;
}
ul.devices {
margin:0;
padding:0;
}
ul.devices li {
float:right;
list-style:none;
border:1px solid #dedede;
padding:10px;
margin:0 15px 25px 0;
border-radius:3px;
-webkit-box-shadow:0 1px 5px rgba(0,0,0,0.35);
-moz-box-shadow:0 1px 5px rgba(0,0,0,0.35);
box-shadow:0 1px 5px rgba(0,0,0,0.35);
font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;
颜色:#555;
}
ul.devices li label,ul.devices li span {
font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;
font-size:12px;
font-style:normal;
font-variant:normal;
font-weight:bold;
颜色:#393939;
display:block;
float:right;
}
ul.devices li label {
height:25px;
width:50px;
}
ul.devices li textarea {
float:right;
resize:none; (#0096FF)到(#005DFF)的背景:-webkit-gradient(线性,0%0%,0%100%)。
}
ul.devices li .send_btn {
background: );
background:-webkit-linear-gradient(0%0%,0%100%,从(#0096FF)到(#005DFF));
background:-moz-linear-gradient(center top,#0096FF,#005DFF);
背景:线性渐变(#0096FF,#005DFF);
text-shadow:0 1px 0 rgba(0,0,0,0.3);
border-radius:3px;
颜色:#fff;
}
< / style>
< style>

< / style>
< / head>
< body>
<?php
include_once'db_functions.php';
$ db = new DB_Functions();
$ users = $ db-> getAllUsers();
if($ users!= false)
$ no_of_users = mysql_num_rows($ users);
else
$ no_of_users = 0;
?>


< div class =containeralign =right>

< h1><?php echo $ no_of_users; ?> :عددالأجهزةالمسجلة< / h1>
< hr />

< ul class =devices>
<?php
if($ no_of_users> 0){
?>
<?php
while($ row = mysql_fetch_array($ users)){
?>

< li>
< form id =<?php echo $ row [id]?> name =method =postonsubmit =return sendPushNotification)'
<?php echo $ row [id]?>')>

< label dir =rtl>显示:< / label> < span><?php echo $ row [name]?>< / span>
< div class =clear>< / div>
< label dir =rtl>存款:< / label> < span><?php echo $ row [email]?>< / span>
< div class =clear>< / div>
< div class =send_container>