郭靖丶 2014-01-16 06:54 采纳率: 0%
浏览 2624

node-apn推送消息时513错误是什么意思?

var  apn=require("apn")

var token = '60c3b0b7 b6c464f0 e86bf6f0 ac1fc3d3 26701bae fae89183 4c2d80d9 51811965'; //长度为64的设备Token

var options = { "gateway": "gateway.sandbox.push.apple.com"
,"cert": "./pro_mic_cer.pem",
    "key": "./pro_mic_key.pem"
},
apnConnection = new apn.Connection(options),
device = new apn.Device(token),
note = new apn.Notification();

note.expiry = Math.floor(Date.now() / 1000) + 3600; // Expires 1 hour from now.
note.badge = 3;
note.sound = "ping.aiff";
note.alert = "\uD83D\uDCE7 \u2709 You have a new message";
note.payload = {'messageFrom': 'Caroline'};

apnConnection.pushNotification(note, device);

apnConnection.on('connected',function() {
console.log("Connected");
});
apnConnection.on('transmitted',function(notification, device) {
console.log("Notificationtransmitted to:" + device.token.toString('hex'));
});
apnConnection.on('transmissionError',function(errCode, notification, device) {
console.error("Notificationcaused error: " + errCode + " for device ",     device,notification);
});
apnConnection.on('timeout',function () {
console.log("ConnectionTimeout");
});
apnConnection.on('disconnected',function() {
console.log("Disconnectedfrom APNS");
});
apnConnection.on('socketError',console.error);

然后会报错:
Notificationcaused error: 513 for device { token: f0 e8 6b f6 f0 ac 1f c3 d3 26 70 1b ae fa e8 91 83 4c 2d 80 d9 51 81 19 65> } {
encoding: 'utf8',
payload:
{ messageFrom: 'Caroline',
aps:
{ badge: 3,
sound: 'ping.aiff',
alert: '� ✉ You have a new message' } },
expiry: 1389887110,
identifier: 0,
priority: 10,
retryLimit: -1,
device: undefined,
alert: '� ✉ You have a new message',
badge: 3,
sound: 'ping.aiff',
newsstandAvailable: undefined,
contentAvailable: undefined,
mdm: undefined,
compiled: true,
truncateAtWordEnd: false,
urlArgs: undefined,
compiledPayload: '{"messageFrom":"Caroline","aps":{"badge":3,"sound":"ping.ai
f","alert":"� ✉ You have a new message"}}' }

展开全部

  • 写回答

1条回答 默认 最新

  • 你知我知皆知 2024-08-01 09:25
    关注

    以下回答参考 皆我百晓生券券喵儿 等免费微信小程序相关内容作答,并由本人整理回复。

    在Node.js中使用APN(Apple Push Notification Service)发送通知时可能会遇到513错误。这通常意味着客户端没有正确地将数据包传递给服务器。

    513是APN服务器上处理请求的一个常见错误码。它表示客户端无法完成HTTP POST请求。

    要解决这个问题,请确保以下几点:

    1. 确保你的apn.Connection对象已经成功创建并连接到APN服务器。
    2. 检查你是否尝试了正确的URL和端口来连接到APN服务器。例如:
      var apnConnection = new apn.Connection({
          gateway: 'https://gateway.sandbox.push.apple.com',
          cert: './pro_mic_cer.pem',
          key: './pro_mic_key.pem'
      });
      
    3. 检查你的options.gateway字段是否正确设置为https://gateway.sandbox.push.apple.com
    4. 确保你的token变量包含正确的设备令牌,并且它的长度等于64字节。
    5. 如果以上步骤都检查过并且仍然出现513错误,可能是因为你的客户端或服务器端正在接收超时请求。你可以添加一个等待时间来避免这种情况:
      apnConnection.on('transmissionError', function (errCode, notification, device) {
          console.error("TransmissionError: " + errCode + " for device " + device + " and notification " + JSON.stringify(notification));
          setTimeout(function () {
              // 重试或修改请求设置
          }, 1000); // 设置1秒后再次尝试
      });
      

    如果问题依然存在,请提供更详细的错误信息或者具体的环境配置,以便进行进一步的帮助。

    评论
    编辑
    预览

    报告相同问题?

    手机看
    程序员都在用的中文IT技术交流社区

    程序员都在用的中文IT技术交流社区

    专业的中文 IT 技术社区,与千万技术人共成长

    专业的中文 IT 技术社区,与千万技术人共成长

    关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

    关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

    客服 返回
    顶部