Getui Rest SDK
Getting Started
详细原接口文档:http://docs.getui.com/server/rest/start/
除了原文档中的接口,其中另外还提供了
pushMessageByTag
方法,可以用来发送按 tag 或者说按 topic 方式推送数据。
Installing
npm i getui-rest-sdk --save
建议使用 vscode 开发,typing 代码提示更加完善
Usage
以下样例均使用 TypeScript 展示,可轻易修改为 ES6
初始化
; ;
初始化透传模板
;alert.title = 'Title: push test';alert.body = `Body: push test`; ; ;apnsInfo.alert = alert;apnsInfo.customMsg =; ;template.transmissionContent = payload;
单个推送
;message.template = template;message.apnsInfo = apnsInfo; ; ;
APP推送
;message.template = template;message.apnsInfo = apnsInfo;message.conditions = ;
按 tag 推送
;message.template = template;message.apnsInfo = apnsInfo;message.tag = testTag; ;
更多样例,请见测试代码
Test
测试基于 nock 来模拟服务器,但是你可以设置环境变量与真实个推服务器测试进行交互,以下测试账号数据需要用你自己的
export GETUI_APP_ID=<app id>export GETUI_APP_SECRET=<app secret>export GETUI_APP_KEY=<app key>export GETUI_MASTER_SECRET=<master secret>export GETUI_CID=<cid>export GETUI_TEST_TAG=<tag> export GETUI_TEST_USE_REAL_CONNECTION=true export DEBUG=getui npm test
TODO
- 测试代码完善
License
This project is licensed under the MIT License - see the LICENSE file for details