Notification Service – v4.x 示例
发送移动推送通知
注册应用通知服务
Notification Service 为安装在相应移动设备上的应用提供推送通知功能。移动应用必须在 FCM (Android 或 iOS)/APNS (iOS) 注册才能接收推送通知。
应用可以选择 iOS (沙箱和生产环境)或 Android 配置。注册移动应用允许开发者在 Notification Service 中为应用提供必要的推送通知提供者凭证。租户在 Notification Service 中对每个应用仅需进行一次注册。
fcmServerKey
是FCM用于发送推送通知的应用的唯一服务器ID。
下面给出了通过这个端点注册 iOS 应用时提供 APNS 相关配置的说明。
在 APNS 为 iOS 应用提供的 PEM 文件上执行以下命令。 这将提供 apnsSslCertificate
和一个加密的 APNS 应用私钥到 keys_out
文本文件。
openssl pkcs12 -in MyRootCA.p12 -out keys_out.txt
执行以下命令从上一步生成的文本文件中提取 apnsAppPrivateKey
。例如, keys_out.txt
到 private.txt
。
openssl rsa -in keys_out.txt -out private.txt
apnsSslCertificate
和 apnsAppPrivateKey
一起用于 Notification Service 中的应用注册。
应用使用以下端点注册:
POST /mobileApps
Andriod 移动应用请求示例:
{
"name": "Voith_Service_App",
"type": "android",
"android": {
"fcmServerKey": "serverKey"
}
}
iOS 移动应用请求示例:
{
"name": "Voith_Service_App",
"type": "ios",
"ios": {
"bundleId": "com.your-company.app-name",
"apnsSslCertificate": "ssl certificate in string format",
"apnsAppPrivateKey": "private key in string format",
"production": false
}
}
或
{
"name": "Voith_Service_App",
"type": "ios",
"ios": {
"fcmServerKey": "serverKey"
}
}
响应示例:
{
"id": "59f92744-7bbc-4540-8b78-ee9976befc1a",
"type": "ios",
"name": "Voith_Service_App",
"android": {
"fcmServerKey": "serverKey"
},
"ios": {
"fcmServerKey": "serverKey",
"bundleId": "com.your-company.app-name",
"apnsSslCertificate": "ssl certificate in string format",
"apnsAppPrivateKey": "private key in string format",
"production": false
}
}
生成的ID mobileAppId
被进一步引用以触发通知。
对于已注册的应用,也可以执行以下操作:
- 为租户获取所有已注册的应用
- 更新已注册的移动应用
- 从 Notification Service 中删除已注册的移动应用
更多信息,请参见 Notification Service API 规范.
注册移动设备实例
对于上述创建的移动应用实体,移动设备应在 Notification Service 中注册。 应用程序开发者可以通过移动应用来完成。开发人员可以提供一个选项来选择在用户设备上接收通知的首选语言。 这些端点根据移动应用启用的指导访问。 关于移动应用启用更多信息,请参见在MindSphere中开发移动应用.
在 Developer Cockpit 中注册移动应用, 在"授权管理"中选择 mdsp:core:nose.mobileappuser
角色以访问移动设备 API。
移动安装实例使用以下端点注册:
POST /mobileApps/{id}/instances
请求示例:
{
"deviceModel": "iPhone X",
"deviceOS": "iOS 10",
"language": "de",
"pushNotificationToken": "7abcd558f29d0c1f048083e2134ad8ea4b3d87d8ae9c038b43c132706ff445f0"
}
响应示例:
{
"id": "59f92744-7bbc-4540-8b78-ee9976befc1a",
"deviceModel": "iPhone X",
"deviceOS": "iOS 10",
"language": "de",
"pushNotificationToken": "7abcd558f29d0c1f048083e2134ad8ea4b3d87d8ae9c038b43c132706ff445f0"
}
生成的 appInstanceIds
ID 将被用于触发通知。
对于已注册的移动设备实例,还可以执行以下操作。
- 显示指定移动应用的所有注册移动应用实例
- 编辑指定移动应用实例注册
- 删除指定移动应用实例注册
更多信息,请参见 Notification Service API 规范.
触发通知
要触发准备好的通知给指定的用户或设备,请使用以下端点:
POST/multicastPushNotificationJobs
以下示例请求使用以上步骤创建的 mobileAppId
和 appInstanceIds
。 这里 mobileAppId
是相应移动应用 ID, recipients
包含需要发送推送通知的设备中已登录应用用户的移动实例或电子邮件地址。
消息可以用多种语言发送,默认语言为英语(en)。 设备将以其首选语言接收消息,否则将以默认语言(en)接收消息。
请求示例:
{
"mobileAppId": "59f92744-7bbc-4540-8b78-ee9976befc1a",
"recipients": {
"appInstanceIds": [
"59f92744-7bbc-4540-8b78-ee9976befc1a"
],
"userEmailAddresses": [
"joe.smith@siemens.com"
]
},
"message": {
"title": "{ \"en\": \"Siemens Mindsphere October 2019\", \"de\": \"Siemens MindSphere Oktober 2019\"}",
"text": "{ \"en\": \"Hi there, Welcome to MindSphere!\", \"de\": \"Hallo, Willkommen bei MindSphere!\"}"
}
}
响应示例:
{
"id": "59f92744-7bbc-4540-8b78-ee9976befc1a",
"status": "queued",
"startTime": "2017-07-21T17:32:28.000Z"
}
还有问题?
除非另行声明,该网站内容遵循MindSphere开发许可协议.