npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

getui-node-sdk

v0.3.4

Published

Node wrapper for getui OS SDK API

Downloads

5

Readme

说明

996.icu LICENSE

Node wrapper for getui OS SDK API 基于个推 nodejs sdk 4.0.1.0 进行 Promise 封装

api

个推官方文档

使用 bluebird 对 GeTui 进行 Promise 封装


    // http的域名
    var HOST = 'http://sdk.open.api.igexin.com/apiex.htm';

    //https的域名
    // var HOST = 'https://api.getui.com/apiex.htm';

    //Android用户测试
    var APPID = '';
    var APPKEY = '';
    var MASTERSECRET = '';
    var CID = '';
    var gt = new GeTui(HOST, APPKEY, MASTERSECRET);
    // 使用Promise
    gt.getUserTagsAsync(APPID, CID).then(function (err, res) {
        console.log(res);
    })
    // 使用callback
    gt.getUserTags(APPID, CID, function (err, res) {
        console.log(res);
    })

快速开始

    npm install getui-node-sdk
    'use strict';
    const {
        // basic
        GeTui,
        Target,
        // template
        APNTemplate,
        BaseTemplate,
        NotyPopLoadTemplate,
        LinkTemplate,
        NotificationTemplate,
        PopupTransmissionTemplate,
        TransmissionTemplate,
        // payload
        APNPayload,
        DictionaryAlertMsg,
        SimpleAlertMsg,
        // message
        SingleMessage,
        AppMessage,
        ListMessage,
    }=require('getui-node-sdk')

'use strict';
var getuiNodeSdk = require('getui-node-sdk');
var GeTui = getuiNodeSdk.GeTui;
var Target = getuiNodeSdk.Target;
var APNTemplate = getuiNodeSdk.APNTemplate;
var BaseTemplate = getuiNodeSdk.BaseTemplate;
var APNPayload = getuiNodeSdk.APNPayload;
var DictionaryAlertMsg = getuiNodeSdk.DictionaryAlertMsg;
var SimpleAlertMsg = getuiNodeSdk.SimpleAlertMsg;
var NotyPopLoadTemplate = getuiNodeSdk.NotyPopLoadTemplate;
var LinkTemplate = getuiNodeSdk.LinkTemplate;
var NotificationTemplate = getuiNodeSdk.NotificationTemplate;
var PopupTransmissionTemplate = getuiNodeSdk.PopupTransmissionTemplate;
var TransmissionTemplate = getuiNodeSdk.TransmissionTemplate;

var SingleMessage = getuiNodeSdk.SingleMessage;
var AppMessage = getuiNodeSdk.AppMessage;
var ListMessage = getuiNodeSdk.ListMessage;


// http的域名
var HOST = 'http://sdk.open.api.igexin.com/apiex.htm';

//https的域名
// var HOST = 'https://api.getui.com/apiex.htm';

//Android用户测试
var APPID = '';
var APPKEY = '';
var MASTERSECRET = '';
var CID = '';
//IOS用户测试
//var DEVICETOKEN='';
var alias = 'demo';

var gt = new GeTui(HOST, APPKEY, MASTERSECRET);
getUserStatus();
pushMessageToSingle();
// pushMessageToSingleBatch();
// pushMessageToList();
// pushMessageToApp();
// stoptask();
// setClientTag();
// getUserTags()

//别名绑定操作
// aliasBind();
// queryCID();
//queryAlias();
//aliasBatch();
//aliasUnBindAll();
//aliasUnBind();

//结果查询操作
// getPushResult();
// queryAppPushDataByDate();
// queryAppUserDataByDate();


//推送任务停止
function stoptask() {
    gt.stop('OSA-1125_FBLl4mxYjG9eZzVR18edd8', function (err, res) {
        console.log(res);
    });
}
function setClientTag() {
    // gt.setClientTag(APPID, CID, ['aa', '哔哔', '》?》', '!@#¥%……&*()'], function (err, res) {
    //     console.log(err, res);
    // })
}
function getUserTags() {
    gt.getUserTags(APPID, CID, function (err, res) {
        console.log(res);
    })
}
function getUserStatus() {
    gt.getClientIdStatus(APPID, CID, function (err, res) {
        console.log(res);
    });
}

function pushMessageToSingle() {
    for (var i = 0; i < 10; i++) {
        var template = TransmissionTemplateDemo(i);
        //    var template = LinkTemplateDemo();
        //    var template = NotificationTemplateDemo();
        //    var template = NotyPopLoadTemplateDemo();

        //个推信息体
        var message = new SingleMessage({
            isOffline: true,                        //是否离线
            offlineExpireTime: 3600 * 12 * 1000,    //离线时间
            data: template,                          //设置推送消息类型
            pushNetWorkType: 0                     //是否wifi ,0不限,1wifi
        });

        //接收方
        var target = new Target({
            appId: APPID,
            clientId: CID
        });
        gt.pushMessageToSingle(message, target, function (err, res) {
            console.log(res);
            if (err != null && err.exception != null && err.exception instanceof RequestError) {
                var requestId = err.exception.requestId;
                console.log(err.exception.requestId);
                gt.pushMessageToSingle(message, target, requestId, function (err, res) {
                    console.log(err);
                    console.log(res);
                });
            }
        });
    }

}
function pushMessageToSingleBatch() {
    process.env.gexin_pushSingleBatch_needAsync = true;
    var Batch = gt.getBatch();

    var template = TransmissionTemplateDemo();
    //    var template = LinkTemplateDemo();
    //    var template = NotificationTemplateDemo();
    //    var template = NotyPopLoadTemplateDemo();

    //个推信息体
    var message = new SingleMessage({
        isOffline: true,                        //是否离线
        offlineExpireTime: 3600 * 12 * 1000,    //离线时间
        data: template                          //设置推送消息类型
    });

    //接收方
    var target = new Target({
        appId: APPID,
        clientId: CID
        //        alias:'_lalala_'
    });
    Batch.add(message, target);

    Batch.submit(function (err, res) {
        if (err != null) {
            Batch.retry(function (err, res) {
                console.log("demo batch retry", res);
            });
        }
        console.log("demo batch submit", res);
    });


}

function pushMessageToList() {
    //process.env.gexin_pushList_needDetails = true;
    //process.env.gexin_pushList_needAsync=true;
    //process.env.=true;
    // var taskGroupName = 'test';
    var taskGroupName = "toList任务组名";
    var template = TransmissionTemplateDemo();

    //个推信息体
    var message = new ListMessage({
        isOffline: true,
        offlineExpireTime: 3600 * 12 * 1000,
        data: template
    });

    gt.getContentId(message, taskGroupName, function (err, res) {
        var contentId = res;
        //接收方1
        var target1 = new Target({
            appId: APPID,
            clientId: CID
            //            alias:'_lalala_'
        });

        var targetList = [target1];
        //        gt.needDetails = true;

        console.log("getContentId", res);
        gt.pushMessageToList(contentId, targetList, function (err, res) {
            console.log(res);
        });
    });
}

function pushMessageToApp() {
    // var taskGroupName = 'test';
    var taskGroupName = null;
    var template = TransmissionTemplateDemo();

    //个推信息体
    //基于应用消息体
    var message = new AppMessage({
        isOffline: false,
        offlineExpireTime: 3600 * 12 * 1000,
        data: template,
        appIdList: [APPID],
        //        phoneTypeList: ['IOS'],
        //        provinceList: ['浙江'],
        //tagList: ['阿百川']
        speed: 10000
    });

    gt.pushMessageToApp(message, taskGroupName, function (err, res) {
        console.log(res);
    });
}

//消息模版:
// 1.TransmissionTemplate:透传功能模板
// 2.LinkTemplate:通知打开链接功能模板
// 3.NotificationTemplate:通知透传功能模板
// 4.NotyPopLoadTemplate:通知弹框下载功能模板

function NotyPopLoadTemplateDemo() {
    var template = new NotyPopLoadTemplate({
        appId: APPID,
        appKey: APPKEY,
        notyTitle: '个推',
        notyContent: '个推最新版点击下载',
        notyIcon: 'http://wwww.igetui.com/logo.png',    // 通知栏logo
        isRing: true,
        isVibrate: true,
        isClearable: true,
        popTitle: '弹框标题',
        setPopContent: '弹框内容',
        popImage: '',
        popButton1: '下载',                             // 左键
        popButton2: '取消',                             // 右键
        loadIcon: 'http://www.photophoto.cn/m23/086/010/0860100017.jpg', // 弹框图片
        loadUrl: 'http://dizhensubao.igexin.com/dl/com.ceic.apk',
        loadTitle: '地震速报下载',
        autoInstall: false,
        actived: true
    });
    return template;
}

function LinkTemplateDemo() {
    var template = new LinkTemplate({
        appId: APPID,
        appKey: APPKEY,
        title: '个推',
        text: '个推最新版点击下载',
        logo: 'http://wwww.igetui.com/logo.png',
        logoUrl: 'https://www.baidu.com/img/bdlogo.png',
        isRing: true,
        isVibrate: true,
        isClearable: true,
        url: 'http://www.igetui.com'
    });

    return template;
}

function NotificationTemplateDemo() {
    var template = new NotificationTemplate({
        appId: APPID,
        appKey: APPKEY,
        title: '个推',
        text: '个推最新版点击下载',
        // logo: 'http://www.igetui.com/logo.png',
        isRing: true,
        isVibrate: true,
        isClearable: true,
        transmissionType: 1,
        transmissionContent: JSON.stringify({
            "action": "detail",
            "type": "message",
            "subType": "attendance",
            "id": "",
            "url": "",
            "title": "考勤通知",
            "content": "您的孩子在7点50分到校",
            "date": "2017-08-25",
            "time": "07:50:21"
        })
    });
    return template;
}

function TransmissionTemplateDemo(i) {
    var template = new TransmissionTemplate({
        appId: APPID,
        appKey: APPKEY,
        transmissionType: 2,
        transmissionContent: JSON.stringify({
            "action": "detail",
            "type": "message",
            "subType": "attendance",
            "id": "",
            "url": "",
            "title": "考勤通知" + i,
            "content": "您的孩子在7点50分到校" + i,
            "date": "2017-08-25",
            "time": "07:50:21"
        })
    });
    //iOS推送需要设置的setApnInfo字段
    //    var payload = new APNPayload();
    //    var alertMsg = new DictionaryAlertMsg();
    //    alertMsg.body = "";
    //    alertMsg.actionLocKey = "";
    //    alertMsg.locKey = "";
    //    alertMsg.locArgs = Array("");
    //    alertMsg.launchImage = "";
    //    //ios8.2以上版本支持
    //    alertMsg.title = "";
    //    alertMsg.titleLocKey = "";
    //    alertMsg.titleLocArgs = Array("");
    //
    ////    payload.alertMsg=alertMsg;
    //    payload.badge=5;
    ////    payload.contentAvailable =1;
    ////    payload.category="";
    ////    payload.sound="";
    ////    payload.customMsg.payload1="payload";
    //    template.setApnInfo(payload);
    //    template.setDuration("2015-01-16 11:40:00", "2015-01-16 12:24:00");
    return template;
}

function aliasBind() {
    gt.bindAlias(APPID, alias, CID, function (err, res) {
        console.log(res);
    });
}

function aliasBatch() {
    //    var target = new Target()
    //        .setClientId(CID)
    //        .setAlias('_lalala_');
    var target2 = new Target({
        alias: alias,
        clientId: CID
    });
    var targetList = [target2];
    gt.bindAlias(APPID, targetList, function (err, res) {
        console.log(res);
    });
}

function queryCID() {
    gt.queryClientId(APPID, alias, function (err, res) {
        console.log(res);
    });
}

function queryAlias() {
    gt.queryAlias(APPID, CID, function (err, res) {
        console.log(res);
    });
}

function aliasUnBind() {
    gt.unBindAlias(APPID, alias, CID, function (err, res) {
        console.log(res);
    });
}

function aliasUnBindAll() {
    gt.unBindAlias(APPID, alias, function (err, res) {
        console.log(res);
    });
}

function queryAppPushDataByDate() {
    gt.queryAppPushDataByDate(APPID, "20150910", function (err, res) {
        console.log(res);
    });
}

function queryAppUserDataByDate() {
    gt.queryAppUserDataByDate(APPID, "20150910", function (err, res) {
        console.log(res);
    });
}

function getPushResult() {
    gt.getPushResult("OSA-1125_FBLl4mxYjG9eZzVR18edd8", function (err, res) {
        console.log(res);
    });
}