Giter Club home page Giter Club logo

jpush-api-nodejs-client's Introduction

JPush API client library for Node.js

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

Node >= 7.6(async/await 语法支持),若 node 版本小于 7.6 请使用 legacy 分支的代码

REST API 文档

NodeJS API 文档

Install

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

Example

Quick start

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

var JPush = require("../lib/JPush/JPushAsync.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()
    .then(function(result) {
        console.log(result)
    }).catch(function(err) {
        console.log(err)
    })

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()
    .then(function(result) {
        console.log(result)
    }).catch(function(err) {
        console.log(err)
    });

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

关闭 Log

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

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

jpush-api-nodejs-client's People

Contributors

appleboy avatar bambooom avatar fity avatar isayme avatar jackywxd avatar javenfang avatar lhw5123 avatar linbo avatar nocturnana avatar ruibozhang1 avatar tauleos avatar txhdqzy avatar wong2 avatar xiezefan avatar zhuangya avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jpush-api-nodejs-client's Issues

Push Fail....

Push Fail, HttpStatusCode: 400 result: {"msg_id": 1309530630, "error": {"message": "cannot find user by this audience", "code": 1011}}
Push Fail, HttpStatusCode: 400 result: {"msg_id": 826925120, "error": {"message": "cannot find user by this audience", "code": 1011}}
Push Fail, HttpStatusCode: 400 result: {"msg_id": 3496549945, "error": {"message": "cannot find user by this audience", "code": 1011}}
Push Fail, HttpStatusCode: 400 result: {"msg_id": 4162638415, "error": {"message": "cannot find user by this audience", "code": 1011}}
Push Fail, HttpStatusCode: 400 result: {"msg_id": 826720074, "error": {"message": "cannot find user by this audience", "code": 1011}}
Push Fail, HttpStatusCode: 400 result: {"msg_id": 826925121, "error": {"message": "cannot find user by this audience", "code": 1011}}
Push Fail, HttpStatusCode: 400 result: {"msg_id": 240864233, "error": {"message": "cannot find user by this audience", "code": 1011}}

我以为适合这个问题一样的(https://github.com/lanceli/cnodejs-ionic/issues/10),我重新登录了并不起作用。。这是所用的用户都挂了吗?

TAG_PATH BUG

here
此处的路径,添加'/', getTagList接口报错
不添加'/', addRemoveDevicesFromTag接口报错

JPush.ios()中alert不能为空字符串

JPush.ios()中alert不能为空字符串,但是文档中要实现静默推送,ios.alert必须为空字符串。node sdk中不可以。页面上是可以的

为啥不在原项目那里直接fork.....

今天,忽然发现...

话说,为啥不直接在我那里fork 过来....以后有什么更新的好合并...或者维护

现在特地在readme 那里写明..

接着,我看了一下实际也没什么变动....

虽然,大体上没什么问题,但是感觉怪怪 的..对了其实可以参考一下phonegap..项目的构建..

如果不是有什么大的变动..直接fork 一个分支更加符合git 的使用流程......

推送结果中返回 headers 结果

根据最新文档:http://docs.jpush.cn/pages/viewpage.action?pageId=7864690

每个请求头里面会塞入

所有的 HTTP API Response Header 里都加了三项频率控制信息:

X-Rate-Limit-Limit:当前 AppKey 一个时间窗口内可调用次数
X-Rate-Limit-Remaining:当前时间窗口剩余的可用次数
X-Rate-Limit-Reset:距离时间窗口重置剩余的秒数

如果能在推送之后的回调里面返回这些信息,我们就可以根据这个信息来决定要不要继续推送,以避免过多的错误造成服务器过大的压力和业务端处理逻辑的复杂化。

如果可以,我愿意提供 patch

增加代理推送功能

现在大部份部署后台程序的服务器都没有上网功能,需要走代理才能发送推送消息。为了解决这个问题,我是自己修改了SDK的代码,不想自己维护一套SDK的代码,希望jpush-api-client在后续的版本中,支持该功能,如果有需要我可以提交我修改的代码。

貌似不好使了

通过jpush的管理后台能发出去消息,通过这个就不行,请检查一下。

node SDK,如何是设置客户端角标自增

nodejs SDK ios推送是有提供这个字段,但是文档是这样描述的 “badge字段 接受参数 如果为 null,表示不改变角标数字;否则把角标数字改为指定的数字;为 0 表示清除”。并没有+1的参数

node 推送显示成功,但是手机并没有接受到推送

  • node + react-native
  • react-native : 0.41.2
  • IOS推送

我在控制台发送推送是可以接收到推送的,通过API调用则不可以

node后端调用该方法:通过设置别名发送

pushIOS:function(push_data, callback){
    client.push()
    .setPlatform('ios') 
    .setAudience(JPush.alias(push_data.alias)) 
    .setNotification('Alert_name',JPush.ios(push_data.message)) 
    .setOptions(null, 60) 
    .send(function(err, res) {
      if (err) return callback(err)
      callback(err,res)
    });
  }

终端输出如下:

Push URL :https://api.jpush.cn/v3/push

Body :{"options":{"sendno":239681430,"time_to_live":60,"apns_production":true},"notification":{"ios":{"alert":"2rwerwe1","sound":"","badge":"+1"},"alert":"Alert_name"},"audience":{"alias":["1"]},"platform":["ios"]}
Headers :{"User-Agent":"JPush-API-NodeJS-Client","Connection":"Keep-Alive","Charset":"UTF-8","Content-Type":"application/json"}
Method :POST
Times/MaxTryTimes : 1/3
Success, response : {"sendno":"239681430","msg_id":"7827150492"}

我看到apns_production:true,我是测试环境,这个属性在哪里设置的,跟这个有关吗?

setOptions我只设apns_production,其他选项不能用默认值么

我现在发现推送的平台是android,weiphone,ios-dev
我想设置apns_production为true后,就能正常推送到ios而非ios-dev了吧。

如果我不调用setOptions就没问题,可以正常发送,虽然发送到的是ios-dev,因为sendno之类的都会有默认值。

但是我调用setOptions后,会报错,提示我必须设置sendno,我希望sendno之类的参数仍然用默认值。

TAG_PATH ERROR

Push Fail, HttpStatusCode: 404 result: {"error":{"code":7010,"message":"request api doesn't exist"}} Error at new APIRequestError (node_modules/jpush-async/lib/JPush/JPushError.js:25:17) at _request (node_modules/jpush-async/lib/JPush/JPushAsync.js:314:13)
node_modules/jpush-async/lib/JPush/JPushAsync.js:23

it should be:
var TAG_PATH = '/v3/tags/'

请不要console输出日志

请不要console输出日志:
现sdk中很多地方都使用console.log直接输出了日志信息, 造成实际使用过程中, 输出了jpush的日志,
让项目日志很凌乱.
推荐使用debug模块, 进行console.log的替换.

missing 'style' in output from JPushAsync.android() if style is not 0

for my case, I want to use big image picture style (style = 3) for the android notification. However, I cannot get any data with bundle.getString(JPushInterface.EXTRA_BIG_PIC_PATH); at onReceive() on android. Compared to the restful api documents, I found that the android notification data created by JPushAsync.android() is missing the field "style". If I add the style by myself data.android.style = 3. I can get the data from bundle.getString(JPushInterface.EXTRA_BIG_PIC_PATH); in android.

tag, alias 不能同时在 .setAudience 的参数里

var tag = ['[email protected]', '[email protected]', '[email protected]'];
var alias = ['[email protected]', '[email protected]', '[email protected]'];
.setAudience(JPush.tag(tag), JPush.alias(alias.join(',')) // 不正常,全部无效

// ---------------------------------------------------------------------------

.setAudience(JPush.alias('[email protected]')) // 正常
.setAudience(JPush.tag('[email protected]')) // 也正常

.setAudience(JPush.alias('[email protected]'), JPush.tag('[email protected]')) // 不正常,只有前面的有效

// ---------------------------------------------------------------------------

.setAudience({tag:['[email protected]']}, {alias:['[email protected]']}) // 全部无效
.setAudience({tag:['[email protected]']}) // 正常
.setAudience({alias:['[email protected]']}) // 正常

// ---------------------------------------------------------------------------

也就是 tag, alias 不能同时在 .setAudience 的参数里。

npm 安装jpush-sdk 导入出错

项目中 import Jpush from 'jpush-sdk'
编译通过,但是打开网页,控制台提示

fs.readFileSync is not a function

Jpush v3.4.3

function toJSON () {
this.payload.options = JUtil.extend({
'sendno': generateSendno(),
'apns_production': false
}, this.payload.options)
return JSON.stringify(this.payload)
}

为什么 Jpush apns_production 一直是false 推不了正式环境

需要把tag_not从包里抛出来

在PushPayloadloadAsync.js文件中 有tag_not这个方法 但是并没有抛出来给用户引用 麻烦抛出来下,类似于JPushAsync.js 里的
exports.tag_and = JModel.tag_and
增加一个
exports.tag_not = JModel.tag_not,
谢谢

wx22db7o9p _a3jup 1k 5
8e5r_df9xs y r8 bp

update node require, or recover the 'default parameter' usage

function JPushClient (appKey, masterSecret, retryTimes, isDebug, readTimeOut = null, proxy = null) {

function JPushClient (appKey, masterSecret, retryTimes, isDebug, readTimeOut = null, proxy = null) {
  if (!appKey || !masterSecret) {
    throw JError.InvalidArgumentError('appKey and masterSecret are both required.')
  }
 ...
}

default parameters is supported after node 6.4.0, but hey, you only need nodejs version greater than 0.12.0?

  "engines": {
    "node": ">=0.12"
  },

IOS推送无法自定义title的问题

问题:ios无法自定义标题
原因:在查找了api之后,与node.js SDK源码进行比较,发现一个比较明显的问题,如下:
https://docs.jiguang.cn/jpush/server/push/rest_api_v3_push/
image
api里面alert关键字不止是string类型,还可以是JSON Object,但是在最新的sdk源码中是不允许JSON Objet的
image
所以我就只能去更改源码,然后不能以模块node_modules的形式引入到项目中了。
jpush-sdk版本是最新的:
image

Some vulnerabilities in dependency of jpush-async

Some dependency of jpush-async required to update to fix security vulnerabilities. Please see below output of 'npm audit' in a project which is using jpush-async. So basically packages request and debug need to be updated to the latest version.

Thanks!
Jacky

=== npm audit security report ===

┌──────────────────────────────────────────────────────────────────────────────┐
│ Manual Review │
│ Some vulnerabilities require your attention to resolve │
│ │
│ Visit https://go.npm.me/audit-guide for additional guidance │
└──────────────────────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate │ Prototype pollution │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package │ hoek │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in │ > 4.2.0 < 5.0.0 || >= 5.0.3 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ jpush-async │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path │ jpush-async > request > hawk > boom > hoek │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info │ https://nodesecurity.io/advisories/566
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate │ Prototype pollution │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package │ hoek │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in │ > 4.2.0 < 5.0.0 || >= 5.0.3 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ jpush-async │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path │ jpush-async > request > hawk > cryptiles > boom > hoek │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info │ https://nodesecurity.io/advisories/566
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate │ Prototype pollution │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package │ hoek │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in │ > 4.2.0 < 5.0.0 || >= 5.0.3 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ jpush-async │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path │ jpush-async > request > hawk > hoek │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info │ https://nodesecurity.io/advisories/566
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate │ Prototype pollution │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package │ hoek │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in │ > 4.2.0 < 5.0.0 || >= 5.0.3 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ jpush-async │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path │ jpush-async > request > hawk > sntp > hoek │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info │ https://nodesecurity.io/advisories/566
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate │ Memory Exposure │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package │ tunnel-agent │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in │ >=0.6.0 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ jpush-async │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path │ jpush-async > request > tunnel-agent │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info │ https://nodesecurity.io/advisories/598
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Low │ Regular Expression Denial of Service │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package │ debug │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in │ >= 2.6.9 < 3.0.0 || >= 3.1.0 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ jpush-async │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path │ jpush-async > debug │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info │ https://nodesecurity.io/advisories/534
└───────────────┴──────────────────────────────────────────────────────────────┘
found 6 vulnerabilities (1 low, 5 moderate) in 32897 scanned packages
6 vulnerabilities require manual review. See the full report for details.

iOS 生产环境接收不到推送通知

之前的开发环境,能用如下代码和在极光的网页发送推送消息时,可以接收到;
但转向开发环境,只能在网页发送推送消息能收到,而用如下代码却收不到。
怎么解决?求帮助。
多谢!

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)
}
});

ios推送,默认options['apns_production'] = false

代码中默认为推送开发环境,
options['apns_production'] = false
文档中说明如下:
如果目标平台为 iOS 平台 需要在 options 中通过 apns_production 字段来设定推送环境。True 表示推送生产环境,False 表示要推送开发环境; 如果不指定则为推送生产环境

按照文档开发容易误导,建议更新文档

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.