2012-11-25 38 views
1

我不是專業程序員。我使用PHP和Javascript進行管理,但是我很難將Pushwoosh方法轉換爲功能性PHP或Javascript。這是我需要幫助轉換方法:Pushwoosh Phonegap通知PHP方法集標籤

方法/ setTags

設置標籤值設備

請求:

{ 
    "request":{ 
    "application":"DEAD0-BEEF0", 
    "hwid": 'device hardware id', 
    "tags": { 
     "tag1": "string value", 
     "tag2": 42, 
     "tag3": "string", 
     "tag4": 3.14 
    } 
    } 
} 

這是他們張貼他們的方法。任何幫助?

我寫了一個PHP setTags,但我無法驗證它,因爲我仍在努力檢索令牌。我有這個環節上是一個問題:

Phonegap/Pushwoosh Android retrieving Device id/Token

這是我的PHP的setTags。這看起來是否正確使用JSON? (我在我的項目運行晚了!)

<?php 

define('PW_AUTH', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); 
define('PW_APPLICATION', 'xxxxxxxxxx'); 
define('HW_ID', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); 

function doPostRequest($url, $data, $optional_headers = null) { 
    $params = array(
     'http' => array(
      'method' => 'POST', 
      'content' => $data 
     )); 
    if ($optional_headers !== null) 
     $params['http']['header'] = $optional_headers; 

    $ctx = stream_context_create($params); 
    $fp = fopen($url, 'rb', false, $ctx); 
    if (!$fp) 
     throw new Exception("Problem with $url, $php_errmsg"); 

    $response = @stream_get_contents($fp); 
    if ($response === false) 
     return false; 
    return $response; 
} 

function pwCall($action, $data = array()) { 
    $url = 'https://cp.pushwoosh.com/json/1.3/' . $action; 
    $json = json_encode(array('request' => $data)); 
    $res = doPostRequest($url, $json, 'Content-Type: application/json'); 
    print_r(@json_decode($res, true)); 
} 

pwCall('setTags', array(
    'application' => PW_APPLICATION, 
    'auth' => PW_AUTH, 
    'hwid' => HW_ID, 
    'tags' => array(
       array(
        'tag1' => 'string value', 
        'tag2' => 42, 
        'tag3' => 'string', 
        'tag4' => 3.14 
       ) 
      ) 
     ) 
    ); 

?>

+0

pushwoosh的鏈接RemoteAPI指南http://www.pushwoosh.com/programming-push-notification/pushwoosh-push-notification-remote-api/ – Elie

回答

0

你不需要這個JSON轉換成代碼發送給Pushwoosh。它直接從設備發送到Pushwoosh服務器。

+0

謝謝。現在我知道如何使用它! – Elie