gpt4 book ai didi

ios - 如何从 Node js 发送 voip 推送通知?我可以从 curl 发送 voip 推送,但不能从 Node 发送

转载 作者:行者123 更新时间:2023-12-04 11:55:43 27 4
gpt4 key购买 nike

我正在使用 voip 推送通知制作 ios 应用程序。
我想从 Node js 发送 voip 推送通知,但不是很好。

我阅读了本教程 CallKit iOS Swift Tutorial for VoIP Apps (Super Easy)我使用 voip push 制作了 ios 应用程序。
我可以从 curl 命令发送 voip push。

curl -v -d '{"aps":{"alert":"hello"}}' --http2 --cert chara.pem:passphase https://api.push.apple.com/3/device/ede0d5e78f771d5916345aa48bd098e86aeab40b5e7d985fb9c74586d1a5a681
node index.js
const http2 = require('http2');
const fs = require('fs');

exports.handler = async (event) => {

const bundleID = 'com.swiswiswift.CharacterAlarm'
const deviceToken = 'ede0d5e78f771d5916345aa48bd098e86aeab40b5e7d985fb9c74586d1a5a681'

const headers = {
'apns-topic': bundleID
};

const options = {
protocol: 'https:',
method: 'POST',
hostname: 'api.push.apple.com',
path: '/3/device/' + deviceToken,
headers: headers,
cert: fs.readFileSync('chara.pem'),
passphrase: "passphrase"
};

const client = http2.connect('api.push.apple.com')
const req = client.request(options)
req.setEncoding('utf8')

req.on('response', (headers, flags) => {
console.log(headers)
});

let data = ''
req.on('data', (d) => data += d)
req.on('end', () => client.destroy())
req.end()
}

exports.handler('local-test')

[Object: null prototype] {
':status': 405,
'apns-id': 'xxxxxxx-xxxx-xxxx-xxx-xxxxxxxx' }

最佳答案

var apn = require("apn");

var deviceToken = "device token";

var service = new apn.Provider({
cert: '.path to /cert.pem', key:'pat to ./key.pem'
});

var note = new apn.Notification();


note.expiry = Math.floor(Date.now() / 1000) + 60; // Expires 1 minute from now.
note.badge = 3;
note.sound = "ping.aiff";
note.alert = " You have a new message";
note.payload = {'messageFrom': 'Rahul test apn'};
note.topic = "(Bundle_id).voip";
note.priority = 10;
note.pushType = "alert";

service.send(note, deviceToken).then( (err,result) => {
if(err) return console.log(JSON.stringify(err));
return console.log(JSON.stringify(result))
});
这是 apn voip push 的工作代码
也引用这个
https://alexanderpaterson.com/posts/send-ios-push-notifications-with-a-node-backend

关于ios - 如何从 Node js 发送 voip 推送通知?我可以从 curl 发送 voip 推送,但不能从 Node 发送,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58152554/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com