发送 APN returns BadDeviceToken,DeviceToken 格式应该是什么?

Sending an APN returns BadDeviceToken, what should DeviceToken format be?

我的后端使用 Node.js 和 Express.js,使用 npm apn 包处理 APN,它使用 Apple 的新提供商身份验证令牌。 iOS 应用程序获得许可并将收到的 32 字节设备令牌发送到后端,编码为 base64 字符串。

但是当尝试使用设备令牌(编码为 ascii、utf8 或 base64)发送推送通知时,APN 服务器 returns -

{"sent":[],"failed":[{"device":"....token....","status":"400","response":{"reason":"BadDeviceToken"}}]}

发送到 APN 服务器的令牌格式应该是什么?

在互联网上搜索了几个小时后,在 APNs Provider API 扎营,在 APNs Notification API 下面有人提到 -

For the device-token parameter, specify the hexadecimal bytes of the device token for the target device.

哪个有效。设备令牌应编码为 十六进制字节 .

// Node.js snippet
let deviceToken = Buffer.from(base64Token, 'base64').toString('hex');