繁体   English   中英

在Android中测试gcm推送通知

[英]testing gcm push notification in android

我为GCM使用了mark nutter phonegap插件 ,并且成功从服务器获取了注册ID

这是我使用的PHP脚本

  <?php
           // Replace with real server API key from Google APIs  
            $apiKey = "AIzaSyC7wzEjjMaOGLYp8_w3USftv_3lI-qCdZ4";    

              // Replace with real client registration IDs
           $registrationIDs = array( "APA91bFt3slFE96jaB5qnoD5gR0TCwsxe5StEGyrECR0umYviG0cfG1JNnFxYqP1ERr1RoWc38rsuWjRUx5SZ7cgUNG9-mQ4mSsY8_XQLquft5DLnqWcLCEB2wtQpfA6EAp5OQmOWzpUZU5bohfG4sfLWNUco7XxXg");

          // Message to be sent
         $message = "hi SOurabh";

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

       $fields = array(
       'registration_ids' => $registrationIDs,
         'data' => array( "message" => $message ),
        );
     $headers = array(
      'Authorization: key=' . $apiKey,
     '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 );
        //curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $fields ) );

         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     //     curl_setopt($ch, CURLOPT_POST, true);
       //     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode( $fields ));

            // Execute post
         $result = curl_exec($ch);

        // Close connection
           curl_close($ch);
         echo $result;
          //print_r($result);
           //var_dump($result);
       ?>

我不太了解我用来测试通知的php

当我运行这个时,我得到以下消息

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

知道为什么我会得到这个吗? 或任何其他方式来测试应用程序?

您在项目中使用的项目ID是否与Google控制台上显示的ID匹配?

https : //code.google.com/apis/console/#project :?????

API密钥是否在Google GCM页面上的“服务器应用程序”下? 您的手机还必须具有有效的注册Google帐户才能接收通知。

我开始使用您的php-script调试我的应用程序上的推送通知。 我第一次收到相同的错误。 Android客户端应用程序SENDER_ID值更新为Google API控制台应用程序Project ID解决了该问题-消息已成功发送。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM