我想通过pushwoosh从客户端(我的科尔多瓦(离子)应用程序)发送推送通知。
是否有任何示例代码或指南?
谢谢!
您必须使用需要付费计划的远程访问 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);
}
}
查看 Phonegap 的插件https://github.com/Pushwoosh/pushwoosh-phonegap-3.0-plugin和 Pushwoosh 网站上的文档https://www.pushwoosh.com/programming-push-notification/ios/ios -additional-platforms/push-notification-sdk-integration-for-phonegap/。
这是我使用的东西
$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);
}