【问题标题】:Send VoIP Push notification in Cloud Functions在 Cloud Functions 中发送 VoIP 推送通知
【发布时间】:2020-09-03 00:09:33
【问题描述】:

我想从 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】:

    连接API时请尽量使用https,可以使用如下代码:

    
    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('https://api.development.push.apple.com').request(options).setEncoding('utf8').on('response', (headers, flags) => 
    { console.log(headers) 
    });
    
    

    你可以在HTTP/2 Nodejs Documentation看到前面的。

    如果有效,请告诉我。

    【讨论】:

    • 能否提供您编写之前代码所遵循的文档或教程?请尝试从选项中的 https 中删除“:”,然后重试。我将用以前的答案更新答案。谢谢
    • 请查看tutorial,因为它详细解释了如何发送 voip 推送通知。
    猜你喜欢
    • 2017-11-16
    • 1970-01-01
    • 2020-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-12
    相关资源
    最近更新 更多