使用PHP向Tianium(跨平台)开发的android应用程序发送推送通知
要将推送通知从服务器发送到android应用程序,我使用以下脚本使用PHP向Tianium(跨平台)开发的android应用程序发送推送通知,php,android,push-notification,titanium,Php,Android,Push Notification,Titanium,要将推送通知从服务器发送到android应用程序,我使用以下脚本 <?php $message = "hi there"; $apiKey = "xxxxxxxxxxxx"; $registrationIDs = array("xxxxxxx"); $url = 'https://android.googleapis.com/gcm/send'; // Set POST variables $fields = array(
<?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);
?>
这就是答案
[INFO] : APSCloudPush: receivePayload: null
[INFO] : APSCloudPush: background: true
[INFO] : APSCloudPush: queuePayload: null
[INFO] : APSCloudPush: showTrayNotification
[ERROR] : APSCloudPush: Payload is null!
上面给出的代码是绝对正确的。我想问题只在于关键字有效负载。只需在服务器端脚本中将单词“message”替换为“payload”,如下所示
$fields = array(
'registration_ids' => $registrationIDs,
'data' => array( "payload" => $message,
)
);
因为在Tianium
ti.cloudePush
模块内部搜索单词payload脚本没有错误,所以显示接收推送的Tianium代码messages@MurtazaKhursheedHussain请查看更新的问题。您使用的是哪个版本的CloudPush?SDK版本3.5.1.g可能是插件损坏或其他原因。尝试使用早期版本,如3.2.1Thanks,获取有关“message”-->“payload”的提示,这也解决了我的问题。
$fields = array(
'registration_ids' => $registrationIDs,
'data' => array( "payload" => $message,
)
);