在PHP中使用GCM向iOS发送远程推送通知时InternalServerError的结果

前端之家收集整理的这篇文章主要介绍了在PHP中使用GCM向iOS发送远程推送通知时InternalServerError的结果前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我尝试在我的应用程序中为iOS实施Google Cloud Messaging(GCM).我尝试了pod GcmExample Xcode Project上提供的代码并编写了一个 PHP脚本,它将通过 PHP cURL发送请求.

我的PHP代码如下:

  1. gcmPush(
  2. "kU6GAbdQEg0:APA91bGSF42WITzubJ9lwQ2qUqL4ETtZfQEOthazc4tP1CRhxx8tKSRChwgtFK37-kt7RjG2P_Ncj2bDOONpPVsYkjxCNi3NDhMNWSkJ7pnlR83jdbMJfOKlD1CPXCgAvZjbwpzdeiTa","This is only a test from GCM for iOS.","PHP test"
  3. );
  4.  
  5. function gcmPush($GCM_regID,$message,$title) {
  6.  
  7. $GOOGLE_API_KEY = "AIzaSyAd8pw7_J8i-FPswnhUMkFCDHtufSCFFTc";
  8. $url = 'https://android.googleapis.com/gcm/send';
  9.  
  10. $fields = array(
  11. 'to' => $GCM_regID,'notification' => array(
  12. 'sound' => 'default','badge' => '1','body' => $message,'title' => $title
  13. )
  14. );
  15.  
  16. $headers = array(
  17. 'Authorization: key=' . $GOOGLE_API_KEY,'Content-Type: application/json'
  18. );
  19.  
  20. $ch = curl_init();
  21. curl_setopt($ch,CURLOPT_URL,$url);
  22. curl_setopt($ch,CURLOPT_POST,true);
  23. curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
  24. curl_setopt($ch,CURLOPT_POSTFIELDS,json_encode($fields));
  25.  
  26. $result = curl_exec($ch);
  27. echo "\r\n";
  28. if ($result === FALSE) {
  29. die('Failed: ' . curl_error($ch) . "\r\n");
  30. } else {
  31.  
  32. echo "Success\r\n";
  33. }
  34.  
  35. curl_close($ch);
  36. }

请求成功,但Google GCM服务器的结果包含以下内容

{"multicast_id":6164898138439370127,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InternalServerError"}]}

Google API密钥有什么问题吗?
我尝试使用此脚本将远程通知发送到GcmExample.xcworkspace并且它有效.
我想知道如何解决这个问题.

如果您在GCM for iOS中遇到此错误消息{“error”:“InternalServerError”},请确保您在Google Developer Console中上传了正确的P12证书.并确保为签名证书正确设置了配置文件,并按如下所示进行以下设置:

>发展:

@{kGGLInstanceIDRegisterAPNSOption:deviceToken,kGGLInstanceIDAPNSServerTypeSandBoxOption:@YES};

>生产/分销:

@{kGGLInstanceIDRegisterAPNSOption:deviceToken,kGGLInstanceIDAPNSServerTypeSandBoxOption:@NO};

猜你在找的PHP相关文章