Giter Site home page Giter Site logo

terry-fei / jpush-api-nodejs-client Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jpush/jpush-api-nodejs-client

0.0 1.0 0.0 144 KB

JPush's officially supported Node.js client library for accessing JPush APIs. 极光推送官方支持的 Node.js 版本服务器端 SDK。

License: GNU General Public License v2.0

Makefile 0.39% JavaScript 99.61%

jpush-api-nodejs-client's Introduction

Build Status

JPush API client library for Node.js

概述

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

REST API 文档
NodeJS API DOC

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);
            console.log('------------');
        }
    }
});

关闭Log

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

单元测试

在程序根目录下执行.

mocha test 

jpush-api-nodejs-client's People

Contributors

xiezefan avatar zhuangya avatar appleboy avatar fity avatar javenfang avatar nocturnana avatar linbo avatar

Watchers

Terry Fei avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.