【问题标题】:Android Push Notification not sendingAndroid推送通知未发送
【发布时间】:2016-03-29 12:53:33
【问题描述】:

我正在尝试使用cakephp 发送推送通知,但未发送推送通知。 现在一天 GCM id 看起来不同了,谷歌在推送通知过程中改变了一些东西,例如(fRAvDRuNUU8:APA91bHvSGxi4AVPx2wGTFWb7OyAPPvXoIAcT)。 每次我得到一个下面的 json 时,都会给:

 {
       "multicast_id": 5873180458565135923,
       "success": 0,
       "failure": 1,
       "canonical_ids": 0,
       "results": [
         {
           "error": "NotRegistered"
         }
     ]
 }

我尝试了很多来自互联网的代码,但每次都得到相同的结果。 我正在使用的代码可以完美地处理许多其他应用程序。 以下是我的代码:

`    public function sendMessageAndroid($registatoin_ids, $message){
     $url = 'https://android.googleapis.com/gcm/send';
     $apiKey = "AIzaSyBf5vaONLbMyGdDoOEeC_MTTh9x1G4Qm-4";
     $fields = array(
        'registration_ids' => $registatoin_ids,//here my gcm id come in //array form array($device_id)
        'data' => $message,//this is my message //$send_message['m']=array('msg'=>$message,'type'=>'chat');
    );  
    $headers = array(
        'Authorization: key=' . $apiKey,
        'Content-Type: application/json'
    );   
    $ch = curl_init();      
    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_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
    $result = curl_exec($ch);
    if ($result === FALSE) {
        //die('Curl failed: ' . curl_error($ch));
    }        
   curl_close($ch);
   return $result;
}`

我尝试了一切,但没有运气。请帮忙。

【问题讨论】:

  • 你想说什么。我不懂。请详细解释。
  • 你的意思是“现在一天 GCM id 看起来不同是谷歌在推送通知过程中改变了一些东西,例如(fRAvDRuNUU8:APA91bHvSGxi4AVPx2wGTFWb7OyAPPvXoIAcT)”请改进你的写作,因为不清楚你在问什么.
  • 我认为在 kitkat 版本之后推送通知不会发送/接收。它们不会在棒棒糖和棉花糖上发送。
  • @Alessandro Cuttin:上面的代码我在很多应用程序中使用过,它运行良好,但在我当前的应用程序中,即使在某些允许我们发送在线推送通知的在线网站上也无法运行,例如:apns-gcm.bryantan.info也不发送推送通知总是返回以下 json: { "multicast_id": 5873180458565135923, "success": 0, "failure": 1, "canonical_ids": 0, "results": [ { "error": "NotRegistered" } ] }

标签: php android curl push-notification


【解决方案1】:

是的,我的问题现在已经解决了。我的代码没有错误。这是我的移动开发人员的错误。每当你得到下面这样的响应时

` { 
       "multicast_id": 5873180458565135923, 
       "success": 0, 
       "failure": 1, 
       "canonical_ids": 0,
       "results": [ { "error": "NotRegistered" } 

` 这是android代码中的明显错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多