如何使用Gp为Android发送使用Php的多个通知和多个设备?帮助我向多个设备发送多个消息 [英] How Do I Send Multiple Notification And Multiple Devices Using Gcm For Android Using Php? Help Me To Send Multiple Messages To Multiple Devices
本文介绍了如何使用Gp为Android发送使用Php的多个通知和多个设备?帮助我向多个设备发送多个消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$var = select * from table;
foreach($var as $varliable)
{
$to_device_id = $varliable['id']
$message = array("unread"=>$msg); // storing multiple messages
$device_id = array($to_device_id); // storing multiple device ids
$gcmObj->send_notification($device_id, $message); // this function is called in another page test.php
}
test.php
========
test.php
========
function send_notification($device_id, $message="")
{
$curl = 'https://android.googleapis.com/gcm/send';
// how to replace the device id and messages here.
$field= array(
'registration_ids' => $device_id,
'field' => $message,
);
$headers = array(
'Authorization: key=' . GOOGLE_API_KEY,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $curl);
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($field));
$result = curl_exec($ch);
curl_close($ch);
echo $result;
}
推荐答案
var = select * 来自 table;
foreach(
var = select * from table; foreach(
var as
varliable)
{
varliable) {
这篇关于如何使用Gp为Android发送使用Php的多个通知和多个设备?帮助我向多个设备发送多个消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文