美文网首页
Nodejs 实现apns推送测试

Nodejs 实现apns推送测试

作者: Faner_NG | 来源:发表于2022-03-16 18:34 被阅读0次

1、打开钥匙串找到推送证书
2、到处证书为cert.cer
3、导出私钥为key.p12
4、转换格式

$ openssl
OpenSSL> x509 -in cert.cer -inform DER -outform PEM -out cert.pem
OpenSSL> pkcs12 -in key.p12 -out key.pem -nodes

5、创建node工程文件夹,安装apn

npm install apn

6、创建推送实现文件apn.js

"use strict";

/**

Send individualised notifications

i.e. Account updates for users with one-or-more device tokens
*/

const apn = require("apn");

let users = [
  { name: "Wendy", "devices": ["2f50bc64e1434b39da31dd417b05e414477545f29893a06c3cf5235bafb5de2f", "2f50bc64e1434b39da31dd417b05e414477545f29893a06c3cf5235bafb5de2f"]},
  // { name: "John",  "devices": ["2f50bc64e1434b39da31dd417b05e414477545f29893a06c3cf5235bafb5de2f"]},
];

let service = new apn.Provider({
  cert: "cert.pem",
  key: "key.pem",
});

users.forEach( (user) => {

  let note = new apn.Notification();
  // note.alert = `Hey ${user.name}, I just sent my first Push Notification`;
  // note.type = 'activity';

//自定义json
  // note.rawPayload = {"aps":{"alert":{"title":"标题","subtitle":"子标题","body":"内容内容 进入7171房间"},"mutable-content":1},"type":"xxx","id":"7171","roomSource":"35","roomMode":"0","media":{"url":"https://ares.xxxx.com/kktv/poster/20211125/14/5888_1936279.jpg"}};
  note.rawPayload = {"aps":{"alert":{"title":"标题","subtitle":"子标题","body":"打开百度"},"mutable-content":1},"type":"activity","url":"https://www.baidu.com","media":{"url":"https://ares.xxxx.com/kktv/poster/20211125/14/5888_1936279.jpg"}};



  // The topic is usually the bundle identifier of your application.
  note.topic = "com.xxx.xxx";  

  console.log(`Sending: ${note.compile()} to ${user.devices}`);

  service.send(note, user.devices).then( result => {
      console.log("sent:", result.sent.length);
      console.log("failed:", result.failed.length);
      console.log(result.failed);
  });
});

// For one-shot notification tasks you may wish to shutdown the connection
// after everything is sent, but only call shutdown if you need your
// application to terminate.
service.shutdown();

相关文章

  • Nodejs 实现apns推送测试

    1、打开钥匙串找到推送证书2、到处证书为cert.cer3、导出私钥为key.p124、转换格式 5、创建node...

  • nodejs APNS

    node-apnnodejs + apn 推送给apns服务器的问题用NODEJS实现APNS

  • apns推送测试(node 实现 + 推送测试小工具)

    1、打开钥匙串找到推送证书2、到处证书为cert.cer3、导出私钥为key.p124、转换格式 5、创建node...

  • iOS推送记录

    APNSiOS端代码实现 APNS推送工具 推送工具: https://github.com/shaojianku...

  • APNS消息推送的实现(完整步骤)

    1. 原理及代码实现 iOS远程推送原理及实现过程 苹果远程推送通知 APNs 详解,官方,iOS | Swift...

  • iOS远程推送(Objective-C & Swift)

    iOS远程推送 APNS远程推送的流程: 1、app 注册到 APNS。2、APNS 下发 devicetoken...

  • Voip上架后无法接收通知问题

    原因:测试时,正常可以接收到Voip推送通知。上架后,无法收到推送通知。 处理:连接 APNs Server 后

  • iOS 推送参考文档

    1、ios 消息推送证书设置和整理(备忘)2、iOS 远程推送APNS从0至发布-极光推送& 真机测试篇3、iOS...

  • iOS APNS

    APNS推送机制 APNS注意事项 1、APNS免费,但需要开发者账号2、APNS不稳定,Apple对消息推送的可...

  • APNS与VoIP

    APNS 一、简述APNS APNS全称是Apple Push Notification service(苹果推送...

网友评论

      本文标题:Nodejs 实现apns推送测试

      本文链接:https://www.haomeiwen.com/subject/mlnpdrtx.html