【发布时间】:2014-10-09 08:49:24
【问题描述】:
【问题讨论】:
标签: javascript cordova ionic-framework pushwoosh
【问题讨论】:
标签: javascript cordova ionic-framework pushwoosh
您必须使用需要付费计划的Remote Access API。 我创建了一个对象,其中包含我要发送的文本和我要发送到的设备令牌,并将其作为参数传递给以下函数:
function push(object) {
var params = {
"request": {
"application": "PW_ID GOES HERE",
"auth": "Find in your API Access page",
"notifications": [{
// Content Settings
"send_date": "now",
"ignore_user_timezone": true,
"content": {
"en": object.text
},
"platforms": [1, 3], // 1 - iOS; 3 - Android;
// iOS Related
"ios_category_id": "1",
"ios_badges": "+1",
// Android Related
"android_icon": "icon",
// Who to send it to
"devices": object.tokens
}]
}
};
$http.post('https://cp.pushwoosh.com/json/1.3/createMessage', params).then(success, failure);
function success() {
console.log("successful notification push");
}
function failure(error) {
console.log('error sending notification', error);
}
}
【讨论】:
【讨论】:
这是我使用的东西
$http.get('http://test.com/push.php?token=' + ushToken + '&message=' + encodeURIComponent(message)).then(function (resp) {
}, function (err) {
console.error(err);
});
<?php
define('PW_AUTH', '...');
define('PW_APPLICATION', '...');
define('PW_DEBUG', FALSE);
function pwCall($method, $data)
{
$url = 'https://cp.pushwoosh.com/json/1.3/' . $method;
$request = json_encode(['request' => $data]);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if (defined('PW_DEBUG') && PW_DEBUG) {
var_dump(json_decode($request));
var_dump($response);
var_dump($info);
}
}
if (isset($_GET['message']) && isset($_GET['token'])) {
$payload = [
'application' => PW_APPLICATION,
'auth' => PW_AUTH,
'notifications' => [
[
'send_date' => 'now',
'content' => $_GET['message'],
'devices' => [$_GET['token']]
]
]
];
pwCall('createMessage', $payload);
}
【讨论】: