0
我使用php(curl)發送android推送通知。 以下是我的班級發送通知。使用php發送其他內容與GCM一起使用php
public function send_notification($registatoin_ids, $message)
{
include_once 'config.php';
$url = 'https://android.googleapis.com/gcm/send';
//issue here
$fields = array('registration_ids' => $registatoin_ids, 'data' => $message);
$headers = array('Authorization: key=' . GOOGLE_API_KEY, 'Content-Type: application/json');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
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);
if ($result === FALSE)
{
die('Curl failed: ' . curl_error($ch));
}
像這樣我能夠將消息發送到所需的收件人,我成功。 但是,我只能發送這樣的消息。
假設我想發送附加信息,如站點鏈接或其他不會附加到郵件的數據。
我在哪裏添加?
'registration_ids'和'data'是唯一值嗎?
androids文檔不包含php示例。
我怎麼把它在我的onMessage()內GCMIntentService(延伸GCMBaseIntentService)方法 – tony9099 2013-05-07 20:40:47
試試這個保護無效的onMessage(上下文爲arg0,意圖意圖){// TODO自動生成方法存根 日誌。我(LOG_TAG,「GCMIntentService onMessage調用」); Log.i(LOG_TAG,「Message is:」+ intent.getStringExtra(「url」)); } – user2359826 2013-05-07 21:22:00