Chrome扩展程序未收到Firebase云消息

时间:2017-01-13 16:22:46

标签: google-chrome firebase google-chrome-extension google-cloud-messaging

我真的很奇怪。昨天atfernoon我意识到我的Chrome扩展程序没有收到我服务器发送的Firebase Cloud Messages。我尝试创建一个新的Chrome扩展程序,其中只包含GCM API和带有邮件发件人的简单服务器页面,但它仍无效。

突然它再次开始工作,我收到了那段时间发送的所有消息!我认为这是一个服务器问题,好吧。今天早上它工作得很好。但是,下午,它停了下来!我不知道该怎么做,我几个月来一直在使用Chrome扩展程序与GCM API,而以前从未发生过。

我的扩展名:

的manifest.json

{
  "name": "__MSG_myextension__",
  "version": "1.3",
  "icons": {
    "128": "images/my-icon.png"
  },
  "permissions": [
    "background",
    "gcm",
    "storage"
  ],
  "background": {
    "scripts": ["background.js"]
  },
  "manifest_version": 2,
  "default_locale" : "en"
}

background.js(是的,我是从here复制的)

function registerCallback(registrationId) {   
   console.log(registrationId);   
   if (chrome.runtime.lastError) {
    console.log(chrome.runtime.lastError);
    return;   
   }
}

var senderIds = ["MY-SENDER-ID"]; 
chrome.gcm.register(senderIds, registerCallback);

chrome.gcm.onMessage.addListener(function(message) {    
  console.log(message);  
});

我的服务器:

$registration_id = '...'; 
$key = '...'; 
$message = '{"collapse_key":"'.time().'","data":{"message":"hello world"},"priority":"high","registration_ids":["'.$registration_id.'"]}';

$headers = array(
        'Content-Type: application/json; charset=UTF-8',
        'Authorization:key=' . $key );

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, "https://fcm.googleapis.com/fcm/send");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); 
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8'); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $message);

$result = curl_exec($ch);
var_dump($result);

由于我的卷曲,我总是成功。 我很确定我正在将消息发送到正确的注册ID。 有人可以帮助我吗?

0 个答案:

没有答案
相关问题