我想从Firebase Cloud Function向我的iPhone发送VoIP推送通知,但出现错误:
TypeError [ERR_INVALID_URL]: Invalid URL: api.development.push.apple.com
我需要知道这是否是正确的方法
这是我的代码
var functions = require("firebase-functions");
const http2 = require('http2');
exports.sendVoip = functions.https.onRequest((request, response) => {
const { Storage } = require('@google-cloud/storage');
const storage = new Storage();
const cert = storage.bucket('certificate').file('voip.pem');
const key = storage.bucket('certificate').file('key.pem');
const bundleID = 'com.cvit.albyrak'
const deviceToken = '287f063372970c602cf80f889e74d0000e06649e6872c077f24fe8ce7b624b9c'
const headers = {
'apns-topic': bundleID
};
const options = {
protocol: 'https:',
method: 'POST',
hostname: 'api.development.push.apple.com',
path: '/3/device/' + deviceToken,
headers: headers,
cert: cert,
key: key,
passphrase: ""
};
const client = http2.connect('api.development.push.apple.com').request(options).setEncoding('utf8').on('response', (headers, flags) => {
console.log(headers)
});
let data = ''
req.on('data', (d) => data += d)
req.on('end', () => client.destroy())
req.end()
response.send(request.body);
});
[连接到API时请尝试使用https,您可以使用以下代码: