Apple MDM - 推送通知主题

Apple MDM - Push notification topic

我正在设置 MDM 服务器并且我已经通过了所有证书生成步骤。我可以在我的 mdm 服务器上成功注册。但是当我发送唤醒推送通知时,我没有收到设备的回复。

我正在使用 Java APNS 库发送 mdm 推送通知。这是代码:

final String token = getToken("dlfkjgldfjglfl"); 
ApnsService service = APNS.newService()
                .withDelegate(listener)
                .withCert(P12_FILE_PATH, "password")
                .withProductionDestination()
                .build(); 
final String payloadString = APNS.newPayload().mdm("push_magic_token").build(); 

// Send the wake up push notification to APNS
service.push(token, payloadString);

上面的代码没有错误或异常,delegate 打印 environment:production|push notification sent|notification:Message(Id=1; Token=the_token; Payload={"mdm":"magictoken"}) 这意味着推送已成功发送到 APNS,但设备永远不会唤醒并与我的 mdm 服务器通信.

进一步阅读 Apple 文档后,它指出需要为推送通知指定主题,但库没有设置主题的方法。

来自Apple Documentation

apns-topic: The topic of the remote notification, which is typically the bundle ID for your app. The certificate you create in Member Center must include the capability for this topic. If your certificate includes multiple topics, you must specify a value for this header. If you omit this header and your APNs certificate does not specify multiple topics, the APNs server uses the certificate’s Subject as the default topic.

由此我推测 Java APNS 库正在使用该主题作为证书主题。

为了生成证书,我遵循了 this tutorial 但是生成的 vendor.p12 文件没有被 APNS 接受为我的推送通知证书(握手错误)。经过一些谷歌搜索后,我发现有些人也遇到了这个问题,他们修复了它,从从 Apple 下载的 mdm.cer 生成另一个 .p12 使用以下方法生成 MDM 证书:

openssl x509 -in mdm.cer -inform DER -out push_developer.pem -outform PEM
openssl pkcs12 -nocerts -in vendor.p12 -out vendor.pem
openssl pkcs12 -export -inkey vendor.pem -in push_developer.pem -out push_developer.p12

我用作推送通知的证书是 push_developer.p12

我不擅长证书管理,所以我迷路了。 我的问题是如何在证书中设置主题?

我设法弄清楚了这个主题是如何运作的。确实在证书里面。

因为我在 mac 上,所以我将解释如何在 mac 上获得正确的证书。

  1. 下载 Apple 生成的 MDM 证书(您应该可以从 Apple 网站上的 MDM 控制面板下载)
  2. 在您的 machine
  3. 中安装证书
  4. 打开 Keychain 并找到您在第 2 步中刚刚安装的证书。它应该类似于:APSP:slkjl34435-sdkj-sfd0-34o5uoijsdf
  5. 点击箭头,您应该会看到私钥。
  6. Select 证书。右击 select "Export 1 item"。 仅导出您的证书,而不是证书 + 私钥。
  7. 保存 .p12 文件并将其用作您的 MDM 推送通知证书。

通过这些步骤,我设法使主题生效,但我的设备仍未唤醒。我将打开一个关于设备未唤醒的新问题,因为这与主题和证书更相关(我认为设备没有唤醒是因为主题不正确)。