2014-10-09 77 views

回答

1
+0

我已經成功建立家居科爾多瓦的Android,我的設備接收推送通知,當我從pushwoosh.com發送。我無法找到存儲庫中的任何示例代碼插件的phonegap **發送**推送通知從客戶端。我忽略了什麼? – huahax 2014-10-09 11:58:43

+0

您無法從客戶端推送。客戶端(設備)只能註冊接收通知。 – 2014-10-09 14:12:42

+0

我遇到了同樣的問題,您是否找到了解決方案? – mcneela86 2014-11-17 11:11:25

2

您必須使用需要付費方案的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); 
    } 
} 
0

這裏是像我使用

  • 發送請求到服務器

$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) 
 
{ 
 
\t $url  = 'https://cp.pushwoosh.com/json/1.3/' . $method; 
 
\t $request = json_encode(['request' => $data]); 
 

 
\t $ch = curl_init($url); 
 
\t curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
 
\t curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
 
\t curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate'); 
 
\t curl_setopt($ch, CURLOPT_HEADER, TRUE); 
 
\t curl_setopt($ch, CURLOPT_POST, TRUE); 
 
\t curl_setopt($ch, CURLOPT_POSTFIELDS, $request); 
 

 
\t $response = curl_exec($ch); 
 
\t $info  = curl_getinfo($ch); 
 
\t curl_close($ch); 
 

 
\t if (defined('PW_DEBUG') && PW_DEBUG) { 
 
\t \t var_dump(json_decode($request)); 
 
\t \t var_dump($response); 
 
\t \t var_dump($info); 
 
\t } 
 
} 
 

 
if (isset($_GET['message']) && isset($_GET['token'])) { 
 
\t $payload = [ 
 
\t \t 'application' => PW_APPLICATION, 
 
\t \t 'auth'   => PW_AUTH, 
 
\t \t 'notifications' => [ 
 
\t \t \t [ 
 
\t \t \t \t 'send_date' => 'now', 
 
\t \t \t \t 'content' => $_GET['message'], 
 
\t \t \t \t 'devices' => [$_GET['token']] 
 
\t \t \t ] 
 
\t \t ] 
 
\t ]; 
 

 
\t pwCall('createMessage', $payload); 
 
}