iOS:推送通知未接收 - Urban airship - PHP

时间:2015-01-08 18:04:02

标签: php urbanairship.com

我有以下代码将推送通知发送到iOS设备。 我使用过php,我收到'通知已发送'消息,但无法收到通知消息, 我的代码中有任何错误,

<?php
define('APPKEY','xxxxxxxxxxxxxxxxxx');    


define('PUSHSECRET','xxxxxxxxxxxxxxxxxxx');

 define('PUSHURL', 'https://go.urbanairship.com/api/push/');



class PushNotification {
    public function api($devicetokens,$messages,$devicename){


            $contents = array();
            $contents['alert'] = $messages;
            $notification = array();
            $platform = array();
            $devicetoken = array();
            if($devicename ==1){
                array_push($platform, "ios");
                $notification['ios'] = $contents;
                $devicetoken['device_token'] = $devicetokens;
                $push = array("audience"=>$devicetoken, "notification"=>$notification, "device_types"=>$platform);
            }else{
                array_push($platform, "android");
                $notification['android'] = $contents;
                $devicetoken['apid'] = $devicetokens;
                $push = array("audience"=>$devicetoken, "notification"=>$notification, "device_types"=>$platform);
            }

            $json = json_encode($push);
           //echo "Payload: " . $json . "\n"; //show the payload

            $session = curl_init(PUSHURL);
            curl_setopt($session, CURLOPT_USERPWD, APPKEY . ':' . PUSHSECRET);
            curl_setopt($session, CURLOPT_POST, True);
            curl_setopt($session, CURLOPT_VERBOSE, True);
            curl_setopt($session, CURLOPT_POSTFIELDS, $json);
            curl_setopt($session, CURLOPT_HEADER, False);
            curl_setopt($session, CURLOPT_RETURNTRANSFER, True);
            curl_setopt($session, CURLOPT_HTTPHEADER, array('Content-Type:application/json', 'Accept: application/vnd.urbanairship+json; version=3;'));
            $content = curl_exec($session);
           // echo "Response: " . $content . "\n";

            // Check if any error occured
            $response = curl_getinfo($session);

            if($response['http_code'] != 202) {
                echo "Got negative response from server: " . $response['http_code'] . "\n";
            } else {

                echo "notification has been sent";
            }

            curl_close($session);
    }
}
?>

和$ response打印以下内容

array(
    'url' => 'https://go.urbanairship.com/api/push/',
    'content_type' => 'application/vnd.urbanairship+json; version=3',
    'http_code' => (int) 202,
    'header_size' => (int) 375,
    'request_size' => (int) 427,
    'filetime' => (int) -1,
    'ssl_verify_result' => (int) 0,
    'redirect_count' => (int) 0,
    'total_time' => (float) 0.030794,
    'namelookup_time' => (float) 0.002246,
    'connect_time' => (float) 0.003368,
    'pretransfer_time' => (float) 0.017076,
    'size_upload' => (float) 182,
    'size_download' => (float) 152,
    'speed_download' => (float) 4936,
    'speed_upload' => (float) 5910,
    'download_content_length' => (float) -1,
    'upload_content_length' => (float) 0,
    'starttransfer_time' => (float) 0.030735,
    'redirect_time' => (float) 0,
    'redirect_url' => '',

    'certinfo' => array()
)

0 个答案:

没有答案