我已经按照“t”的每个示例进行操作,并且无法让 Azure 通知中心返回除以下 401 消息之外的任何内容:“MalformedToken:授权 header 中包含的凭据不是 WRAP 格式。”
我尝试了命名空间访问键和通知中心键,但没有成功。我按照这里的例子:https://msdn.microsoft.com/en-us/library/azure/dn495630.aspx并且一直无法让它发挥作用。我更改了所有帐户特定设置,例如命名空间、通知中心名称和授权 key 。
var registrationXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<entry xmlns=\"http://www.w3.org/2005/Atom\">" +
"<content type=\"application/xml\">" +
"<GcmTemplateRegistrationDescription xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://schemas.microsoft.com/netservices/2010/10/servicebus/connect\">" +
"<GcmRegistrationId>" + {GCMRegID} + "</GcmRegistrationId> " +
"<BodyTemplate><![CDATA[ {\"data\": { \"message\": \"$(msg)\" } }]]></BodyTemplate>" +
"</GcmTemplateRegistrationDescription>" +
"</content>" +
"</entry>";
$.ajax(
{
type: "POST",
url: "https://{myNamespace}.servicebus.windows.net/{myHubName}/registrations/?api-version=2015-01",
headers: { 'Authorization': '{myAccessKey}', 'Content-Type': 'application/atom+xml;type=entry;charset=utf-8', 'x-ms-version': '2015-01' },
data: registrationXML,
dataType: "xml",
contentType: "text/xml",
success: function (data) {
debugger;
},
error: function (xhr, ajaxOptions, thrownError) {
debugger;
}
});
最佳答案
{myAccessKey} 的值应类似于:
SharedAccessSignature sig=<signature-string>&se=<expiry>&skn=<keyName>&sr=<URL-encoded-resourceURI>
构建签名的文档位于 https://msdn.microsoft.com/en-us/library/azure/dn170477.aspx
关于azure - 在 Azure 通知中心注册设备时不断获得未经授权的情况,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31174499/