I am working on a webservice for android appliction's chat system, where I am using GCM(google cloud messaging). But always I am getting invalid registration response by GCM. I know this can cause by formatting of the registration ID that I pass to the server, but I am sure it matches the registration ID the phone receives in the chat system.
Here is my code(where I amsending reciever phone number gcm registarion id):
if (isset($_POST["regId"]) && isset($_POST["message"]) && isset($_POST['acceptor_no'])) {
include_once './config.php';
//include_once './db_connect.php';
$con = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
// selecting database
mysql_select_db(DB_DATABASE);
$regId = $_POST["regId"];
$accepterPhone=$_POST['acceptor_no'];
$message = $_POST["message"];
$arr=array();
$selectDeviceId=mysql_query("select gcm_regid from gcm_users where phone='".$accepterPhone."'");
$selectDeviceIdRow=mysql_fetch_array($selectDeviceId);
$accepterDeviceId=$selectDeviceIdRow['gcm_regid'];
include_once './GCM.php';
$gcm = new GCM();
$registatoin_ids = array($accepterDeviceId);
$message = array("price" => $message);
$result = $gcm->send_notification($registatoin_ids, $message);
//$arr['response'] = array('msg'=>$message,'status'=>true,'phone'=>$accepterPhone,'deviceId'=>$regId,'accepterDeviceId'=>$accepterDeviceId);
//echo json_encode($arr);
if(isset($result))
{
$abc=json_encode($result);
echo $abc;
}else
{
//echo json_encode($result);
$msg="Does not Exists";
$arr['response'] = array('msg'=>$msg,'status'=>false);
$abc=json_encode($arr);
echo json_encode($arr);
}
}else
{
$msg="No data Available";
$arr['response'] = array('msg' => $msg ,'status'=>false);
$abc=json_encode($arr);
echo json_encode($arr);
}
But I am always getting "Does not Exist" response if I print json response in this condition then it says "invalid registration".
Please suggest me how to solve this type of error in GCM response.
Thanks
It is possible that you copied the apid from UrbanAirship? If so, look at my answer in https://stackoverflow.com/a/27071675/679049
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.