發送推送通知從服務器到Android應用程序我使用以下腳本。發送推送通知到Android應用程序開發鈦(跨平臺)使用PHP
<?php
$message = "hi there";
$apiKey = "xxxxxxxxxxxx";
$registrationIDs = array("xxxxxxx");
$url = 'https://android.googleapis.com/gcm/send';
// Set POST variables
$fields = array(
'registration_ids' => $registrationIDs,
'data' => array("message" => $message,
)
);
$headers = array(
'Authorization: key=' . $apiKey,
'Content-Type: application/json'
);
$ch = curl_init(); // Open connection
curl_setopt($ch, CURLOPT_URL, $url);
// Set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch); // Execute post
if($result === false)
die('Curl failed ' . curl_error());
curl_close($ch);
//return $result;
// curl_close($ch); // Close connection
$response = json_decode($result);
print_r($response);
?>
此代碼工作正常的原生Android應用程序,但在鈦開發當我發送推送通知,上面的腳本應用程序,設備接收通知,但與「NULL」。
我想知道,爲什麼?我的PHP腳本有什麼問題。
UPDATE
這是我的代碼接收通知
// These events monitor incoming push notifications
CloudPush.addEventListener('callback', function (evt) {
//Ti.API.info('This is the payload data i got'+JSON.parse(evt.payload));
Ti.API.log("This is the GCM response "+JSON.stringify(evt));
alert(evt.payload);
//var payload = JSON.parse(evt.payload);
//Ti.API.info('This is the message data i got'+payload.message);
});
CloudPush.addEventListener('trayClickLaunchedApp', function (evt) {
Ti.API.info('Tray Click Launched App (app was not running)');
});
CloudPush.addEventListener('trayClickFocusedApp', function (evt) {
Ti.API.info('Tray Click Focused App (app was already running)');
});
,這是響應
[INFO] : APSCloudPush: receivePayload: null
[INFO] : APSCloudPush: background: true
[INFO] : APSCloudPush: queuePayload: null
[INFO] : APSCloudPush: showTrayNotification
[ERROR] : APSCloudPush: Payload is null!
沒有錯的腳本,顯示接收推送消息 –
您的鈦代碼@MurtazaKhursheedHussain請採取更新的問題,一起來看看。 – AkshayP
您正在使用哪種版本的CloudPush? –