我已经为 Chrome 和 firefox 实现了推送通知。并在命令行上使用 curl 命令进行测试。
curl --header "Authorization: key=" --header "Content-Type: application/json" https://android.googleapis.com/gcm/send -d "{\"registration_ids\":[\"\"]}"
我从
reg.pushManager.subscribe({
userVisibleOnly:true
}).then(function(sub){
console.log("ENDPOINT :",sub.endpoint);
alert(sub.endpoint);
});
chrome的端点工作正常
https://android.googleapis.com/gcm/send/cQ4-FwONCH0:APA91bGjycCynoIPO-BVn0h…B9Ck_r5e3hYxcvmzamCWeWbVLDSeY18gtp-NZC3yFMVzFQauE3xQQn4vhVmfkiV3ma-cy4wIv0
来自端点的 GCM 注册 ID:
cQ4-FwONCH0:APA91bGjycCynoIPO-BVn0h…B9Ck_r5e3hYxcvmzamCWeWbVLDSeY18gtp-NZC3yFMVzFQauE3xQQn4vhVmfkiV3ma-cy4wIv0
但是来自 Firefox(nightly) 的端点从 gcm 抛出 InvalidRegistration 。端点:
"https://updates.push.services.mozilla.com/wpush/v1/gAAAAABXqswopJKVeUQEsBZl12RXsKl01wNvt5T-yqLxgzReRPRdWp7K3xJK58Tmz9YWy3op550irfD3nx-DMnqNKu8BdzvbKgjlksN2_i8VJV-oWnkO8FJwgP-0-m4W9ZVNHYseLLDJ"
GCM 的注册 ID
gAAAAABXqswopJKVeUQEsBZl12RXsKl01wNvt5T-yqLxgzReRPRdWp7K3xJK58Tmz9YWy3op550irfD3nx-DMnqNKu8BdzvbKgjlksN2_i8VJV-oWnkO8FJwgP-0-m4W9ZVNHYseLLDJ