使用自定义GCM参数将通知推送到Android设备

时间:2016-07-01 11:28:40

标签: javascript quickblox

我正在使用JavaScript SDK - v2.1.2:

我的查询:如何使用JavaScript在Android设备中使用自定义gcm参数发送推送通知。

我正在尝试使用我的JavaScript代码向Android设备发送推送通知,但在我们的应用中,我们使用名为 CleverTap 的第三方接收器进行通知。 以下是CleverTap接收器的必备参数: 的" wzrk_pn" " wzrk_sound" " NT" "纳米" " wzrk_dl" 我需要将其作为自定义参数发送。

以下是推送通知的代码:

var pushCustomParams = {
    message: 'Message received from Bob',
    wzrk_pn: 1,
    wzrk_sound: 1,
    nt: 'Revofit',
    nm: 'This msg is from application',
    wzrk_dl: ''
}
var params = {
    notification_type : 'push',
    push_type : 'gcm', // 'gcm' is for Android, 'apns' - for iOS.
    user : { ids: [14411551] }, // recipients.
    environment : 'development', // environment, can be 'production' as well.
    message :   QB.pushnotifications.base64Encode(JSON.stringify(pushCustomParams)), // See how to form iOS or Android spesific push notifications
};

 QB.pushnotifications.events.create(params, function(err, response) {
    if (err) {
        console.log(err);
    } else {
        // success
        console.log(response);
    }
  });

执行上述代码后生成的日志如下:

 {
    "notification": {
        "registration_ids": ["dFCRdN7MJD0:APA91bFsaOdorqhvRyMuUGH-Ds8Z_EB6pQWHpQIYy5YVUefwYFwqK39E5BsLtJ2cHYDLv9mPXDQc4mAQRhJTdM2unUgy6-kmWSWMorp0ZSbBL1EdjFZLiorh4LQT3JR454dqEP1bL2_l"],
        "delay_while_idle": false,
        "data": {
             "message": "{\"message\":\"Message received from Bob\",\"wzrk_pn\":1,\"wzrk_sound\":1,\"nt\":\"Revofit\",\"nm\":\"This msg is from application\"}",
             "collapse_key": "event7637817"
    },
          "priority": "high",
         "time_to_live": 86400
     },
     "log": [{
        "device_token": null,
        "created_at": "2016-06-30T14:26:46Z",
        "delivered_at": "2016-06-30T14:26:47Z",
        "failed_at": null,
        "error_code": null,
       "error_description": null
     }]
    }

但是当我尝试使用我自定义的GCM参数通道设置从管理面板发送推送通知时,它运行正常。 从管理面板生成的通知日志:

 {
     "notification": {
        "registration_ids":     ["eShiPWpBngA:APA91bFzFeaB0LryAt9FmEJ9xl2KHWhZWlfzpYhng4KONN60yr3ySl2R58Eye-qSmhzQ56T2Fyuzr0Yg4y1VWMIm20LH74U7BWO_Az7MgogBD2IGvmWEKvJWWgVH6sD-3wP_gaIgJEAY"],
        "delay_while_idle": false,
         "data": {
            "message": "hii",
            "wzrk_pn": "1",
            "nm": "New message",
            "nt": "revofit",
            "collapse_key": "event7632938"
         },
        "priority": "high",
        "time_to_live": 86400
     },
    "log": [{
        "device_token": null,
        "created_at": "2016-06-30T08:17:25Z",
         "delivered_at": "2016-06-30T08:17:26Z",
        "failed_at": null,
        "error_code": null,
        "error_description": null
    }]
 }

我无法纠正我的错误 请帮我解决这个问题。

抱歉我的英语不好。我尽我所能。

1 个答案:

答案 0 :(得分:0)

由于我们无法按要求获得解决方案,因此我们更改了GCM接收器。