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