在云功能中发送VoIP推送通知

问题描述 投票:0回答:1

我想从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);

});
ios firebase google-cloud-functions google-cloud-storage voip
1个回答
0
投票

[连接到API时请尝试使用https,您可以使用以下代码:

© www.soinside.com 2019 - 2024. All rights reserved.