Socket
Book a DemoInstallSign in
Socket

jpush-sdk

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jpush-sdk

JPush's officially supported Node.js client library.

latest
Source
npmnpm
Version
3.5.0
Version published
Maintainers
1
Created
Source

JPush API client library for Node.js

本 SDK 提供 JPush 服务端接口的 Node 封装,与 JPush Rest API 组件通信。使用时引用该模块即可,可参考附带 Demo 学习使用方法。

REST API 文档

NodeJS API 文档

Install

npm install jpush-sdk
#or
{
    "dependencies": {
        "jpush-sdk": "*"
    }
}

Example

Quick start

此 Demo 展示如何使用 Node lib 向所有用户推送通知。

var JPush = require("../lib/JPush/JPush.js")
var client = JPush.buildClient('your appKey', 'your masterSecret')

//easy push
client.push().setPlatform(JPush.ALL)
    .setAudience(JPush.ALL)
    .setNotification('Hi, JPush', JPush.ios('ios alert', 'happy', 5))
    .send(function(err, res) {
        if (err) {
            console.log(err.message)
        } else {
            console.log('Sendno: ' + res.sendno)
            console.log('Msg_id: ' + res.msg_id)
        }
    });

Expert mode(高级版)

client.push().setPlatform('ios', 'android')
    .setAudience(JPush.tag('555', '666'), JPush.alias('666,777'))
    .setNotification('Hi, JPush', JPush.ios('ios alert'), JPush.android('android alert', null, 1))
    .setMessage('msg content')
    .setOptions(null, 60)
    .send(function(err, res) {
        if (err) {
            console.log(err.message)
        } else {
            console.log('Sendno: ' + res.sendno)
            console.log('Msg_id: ' + res.msg_id)
        }
    });

关于 Payload 对象的方法,参考详细 API 文档

获取统计信息

本 Node lib 简易封装获取统计信息的接口,传入推送 API 返回的 msg_id 列表,多个 msg_id 用逗号隔开,最多支持 100 个 msg_id。 更多详细要求,请参考 Report API 文档

var JPush = require("../lib/JPush/JPush.js");
var client = JPush.buildClient('your appKey', 'your masterSecret');

client.getReportReceiveds('746522674,344076897', function(err, res) {
    if (err) {
        console.log(err.message)
    } else {
        for (var i = 0; i < res.length; i++) {
            console.log(res[i].android_received)
            console.log(res[i].ios_apns_sent)
            console.log(res[i].msg_id)
        }
    }
});

关闭 Log

// 在构建 JPushClient 对象的时候, 指定 isDebug 参数。
var client = JPush.buildClient({
    appKey:'47a3ddda34b2602fa9e17c01',
    masterSecret:'d94f733358cca97b18b2cb98',
    isDebug:false
});
// or
var client = JPush.buildClient('47a3ddda34b2602fa9e17c01', 'd94f733358cca97b18b2cb98', null, false);

目前使用了 debug 模块来控制日志输出,若要查看 JPush 的相关日志信息,请先配置 DEBUG 环境变量 'jpush'。

Keywords

jpush

FAQs

Package last updated on 04 Jun 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts