无法使用Node.js后端在Azure通知中心上注册设备

时间:2018-04-26 14:47:51

标签: cordova push-notification azure-mobile-services azure-notificationhub

我正在尝试使用Azure Mobile Services Node.js后端使用以下代码注册设备:



var notificationHubService = azure.createNotificationHubService('<HubName>', '<Endpoint>');
var payload = {
    alert: 'Hello!'
};

function insert(item, user, request) {
    notificationHubService.createRegistrationId(function (error, registrationId, response) {
        if (!error) {
            notificationHubService.apns.createOrUpdateNativeRegistration(registrationId, item.Token, [item.id], function (error, response) {

                if (!error) {
                    console.log('Inside : createOrUpdateNativeRegistration' + response);
                    notificationHubService.apns.send(null, payload, function (error) {
                        if (!error) {
                            // notification sent

                            console.log('Success: Inside the notification send call to Hub.');

                        }
                    });

                }
                else {

                    console.log('Error in registering the device with Hub for Token: ' + item.Token + '>> ' + error);
                }

            });

        }
        else {
            console.log('Error in generating the registration Id' + error);
        }

    });
    request.execute();   
 }
&#13;
&#13;
&#13;

但我一直收到以下错误:

编辑:此行导致错误:

&#13;
&#13;
notificationHubService.apns.createOrUpdateNativeRegistration
&#13;
&#13;
&#13;

&#13;
&#13;
 Error: 400 - One or more characters in device token is not a hexadecimal 
&#13;
&#13;
&#13;

令牌是使用客户端上的https://github.com/Telerik-Verified-Plugins/PushNotification cordova插件生成的,这会产生以下令牌:

&#13;
&#13;
APA91bGiwjCSslyOjqIP4Cerf5LJFkDYAyVHpT0GdIEQ81z9LJMGkUAV0ScgL9ioOqL38ZFTuFHwQRP389OAOPcOGxp2MZHBbYR6BlL70xIW8jHU1ZsJIdtUoww1mCx4cWqmZzjErZDz
&#13;
&#13;
&#13;

我还尝试使用客户端上的https://github.com/phonegap/phonegap-plugin-push cordova插件生成令牌,这会产生以下令牌:

&#13;
&#13;
cF3dKfF5j14:APA91bEruizX883Aegix-UPyQHjCgyl1ZfoXoFQUhf3JH_A8W_iITk-SyEsBjnnWlvTgAONEspAkTpy8IonqvL0bYFGGm9jDj-Kbjf3bF_T0LFiQ2fUQIHcP1uHsiby3AcGi-dlL6aP6
&#13;
&#13;
&#13;

两个令牌都会导致相同的错误。

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

我会问Telerik推送插件开发人员他们为什么会有另一种令牌格式,即他们的令牌之间没有破折号。令牌由FCM,APNS或WNS提供,格式不能因插件而异。

我只会使用 phonegap-plugin-push 中的ID。我经常使用此插件收到的FCM令牌采用以下格式:

eb1-bYqMrQ8:APC97bHXxUTb_dbAK255ew4uvBR8gRDo-1_9RyEX_Be6WiRAy3qS5f1bIEWT2e8FtIBbWj_0x1ep2uo7H8TOG0hGc4Be4hBdx1VPcwn_Mrfbo8NscxjMJZfCZRLbGCE_mGPK_-1_rgh3

我记得我遇到了一些问题,因为当我发送registrationID时,它被AJAX请求更改(缺少破折号或类似的东西),因此您必须进行三重检查以比较您收到的ID和你发送到Azure。

相关问题