我研究过pushwoosh romote api,发送通知的基本过程是将一段JSON数据发布到http://cp.pushwoosh.com/json/1.3/createMessage,具体地说,数据将以如下格式打包
{'application' : PW_APPLICATION,
'auth' : PW_AUTH,
'notifications':{
'send_date' : 'now',
'content' : 'test',
'data' : {
'custom' : 'json data'
},
'link' : 'http://pushwoosh.com/'
}
}pushwoosh指南列出了Java、PHP、Ruby等语言的一些示例代码。我很困惑,因为pushwoosh没有提供nodejs版本,所以我必须自己实现它。我使用'http‘模块发送请求,参数和部分主要代码如下所示
var bodyArgs =
{'application' : PW_APPLICATION,
'auth' : PW_AUTH,
'notifications':{
'send_date' : 'now',
'content' : 'test',
'data' : {
'custom' : 'json data'
},
'link' : 'http://pushwoosh.com/'
}
}
var bodyArgsArray = [];
for (var i in bodyArgs) {
if (bodyArgs.hasOwnProperty(i)) {
if(typeof bodyArgs[i] == 'object'){
bodyArgsArray.push(i + '=' + (JSON.stringify(bodyArgs[i])));
}else{
bodyArgsArray.push(i + '=' + (bodyArgs[i]));
}
}
}
var options = {
host: 'cp.pushwoosh.com',
method: 'POST',
path: '/json/1.3/createMessage',
headers: {'Content-Length': bodyStr.length,
'Content-Type':'application/json',
'Access-Control-Allow-Origin':'*'
}
var req = http.request(options, function (res){...});不幸的是,我得到了格式错误的响应
[syntax error at end of input]如果请求被成功处理,正确的响应应该是
{
"status_code":200,
"status_message":"OK",
"response": {
"Messages":["{Notification code}", "{Notification code}", ...]
}
}我非常想弄清楚正确的请求格式,如果可能的话,我会非常感谢有人的nodejs版本!
和pushwoosh remote-api-guide网站
https://www.pushwoosh.com/programming-push-notification/pushwoosh-push-notification-remote-api/
发布于 2014-10-08 13:28:32
我想出了如何让它工作的方法。你真的很接近
{ "request":{ "application":"APPLICATION_CODE","applications_group":"GROUP_CODE",//可选。可以代替"application“"auth":"api_access_token","notifications":[] }}
因此,您需要将json请求包装在名为" request“的对象中,正如您在上面看到的。实际上,我正在编写一个使用pushwoosh的节点模块。我想我会把这篇文章贴出来,以防有人在寻找答案。我会张贴npm模块的名称,一旦我完成它,但如果你真的想让它现在工作,这是所有你必须做的。
发布于 2015-04-21 11:31:11
嘿,我写了一个用Pushwoosh API向移动设备发送推送通知的node module
https://stackoverflow.com/questions/25563386
复制相似问题