Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
430 views
in Technique[技术] by (71.8m points)

android - PHP GCM error message MismatchSenderId

I am facing the problem with GCM push notification. I am getting the following error.

{
  "multicast_id":4630467710672911593,
  "success":0,
  "failure":1,
  "canonical_ids":0,
  "results":[{
      "error":"MismatchSenderId"
  }]
}

Following is the code. Any help would be really appreciated. Thanks in Advance.

public function gcmPush() 
{
    $regId = "APA91bHFcgOssQZEqtdUk3EC1ojwC5-LVG3NPV2bMqKyC9rPymR6StmAbz-N7Ss8fnvruZhWWNrR3lmBqpjQItlu00AKHPbltBclUJF-EfC5qG4CF2xiuYYC0NCf8u5rbiYFk8ARhIT4lY2AEPWzGpl1OtTvQEC0gA"; 
    $registatoin_ids = array($regId); 
    $message = array("msg" => 12345); 

    $this->send_notification($registatoin_ids, $message);
}

public function send_notification($registatoin_ids, $message) 
{
  // Set POST variables
  $url = 'https://android.googleapis.com/gcm/send';         
  define('GOOGLE_API_KEY', 'AIzaSyBavsIgQKo1Nf9wKZ5o_fGvE_6MI52LFR0');
  $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;
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...