如何将Azure通知REST API与Google云消息一起使用



我们正在使用Unity 3d实现一个应用程序,我们正在使用Azure推送通知REST API。但是,关于如何成功发送和接收消息,还有几个问题。

为了进行测试,我们正在为chrome使用Advanced Rest客户端扩展。我们可以使用本机模板创建注册(检查https://msdn.microsoft.com/en-us/library/azure/dn223265.aspx)

<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
<content type="application/xml">
<GcmRegistrationDescription xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
<Tags></Tags>
<GcmRegistrationId>Some Id from somewhere</GcmRegistrationId> 
</GcmRegistrationDescription>
</content>
</entry>

到目前为止,我们发送的请求带有空标签,我们不确定GcmRegistration应该是什么,奇怪的是,无论我们发送什么,我们都会得到有效的响应。

<entry a:etag="W/"1"">
<id>https://cloudservicechat-ns.servicebus.windows.net/cloudservicechat/registrations/8760279628548469956-1956153846630646542-1?api-version=2015-01</id>
<title type="text">8760279628548469956-1956153846630646542-1</title>
<published>2016-06-01T15:15:16Z</published>
<updated>2016-06-01T15:15:16Z</updated>
<link rel="self" href="https://cloudservicechat-ns.servicebus.windows.net/cloudservicechat/registrations/8760279628548469956-1956153846630646542-1?api-version=2015-01" />
<content type="application/xml">
<GcmRegistrationDescription>
<ETag>1</ETag>
<ExpirationTime>2016-08-30T15:15:16.215Z</ExpirationTime>
<RegistrationId>8760279628548469956-1956153846630646542-1</RegistrationId>
<GcmRegistrationId>Some Id from somewhere</GcmRegistrationId>
</GcmRegistrationDescription>
</content>
</entry>

现在我们正在尝试发送通知(https://msdn.microsoft.com/en-us/library/azure/dn223273.aspx)但我们不确定在使用GCM时使用azure的正确有效载荷根据GCM中的文件有效载荷将类似于

{
"to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
"notification" : {
"body" : "great match!",
"title" : "Portugal vs. Denmark",
"icon" : "myicon"
}
}

然而,无论我们做什么,我们总是会收到未经授权的回复。

还尝试使用模板使用注册,但我们不确定应该添加什么(检查https://msdn.microsoft.com/en-us/library/azure/dn223265.aspx)

所以问题是*我们可以从哪里获取GcmRegistrationId?*我们应该如何替换{BodyTemplate}格式*使用Azure测试发送使用的有效通知负载是什么

感谢的帮助

根据本文档,您需要在MyHandler类中添加参数gcmRegistrationId来覆盖onRegistered方法,该方法将您的设备注册到移动服务通知中心。示例:

@Override
public void onRegistered(Context context,  final String gcmRegistrationId) {
super.onRegistered(context, gcmRegistrationId);
new AsyncTask<Void, Void, Void>() {
protected Void doInBackground(Void... params) {
try {
ToDoActivity.mClient.getPush().register(gcmRegistrationId, null);
return null;
}
catch(Exception e) { 
// handle error             
}
return null;            
}
}.execute();
}

您可以在本文档中阅读有关如何使用模板跨平台向所有设备发送与平台无关的通知,以及向每个设备个性化广播通知的步骤。

发送推送通知的标准方式是为要发送的每个通知向平台通知服务(WNS、APNS)发送特定的有效载荷。例如,要向APNS发送警报,有效载荷是以下形式的Json对象:

{"aps": {"alert" : "Hello!" }}

您可以检查这些相关线程:

  • 添加Google GCM Api Key Azure通知中心错误
  • NotificationHubUnauthorizedException:未经授权在Azure上注册NotificationHub

相关内容

最新更新