[英]Push notification to android with php codeigniter
我是 android 和 php 的新手。 我现在开始用 codeigniter 框架学习 php。 如何使用此框架向 android 发送推送通知?
感谢新程序员的帮助!
您只需要在控制器中粘贴以下功能并需要更改 GCM 密钥。
public function androidPushNotification($registration_ids, $message) { $registrationIds = array($registration_ids); $msg = array('message' => $message, 'title' => 'test notification', 'vibrate' => 1, 'sound' => 1); $fields = array('registration_ids' => $registrationIds, 'data' => $msg); $headers = array('Authorization: key=', 'Content-Type: application/json'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://android.googleapis.com/gcm/send'); 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); curl_close($ch); $data = json_decode($result); if ($data->success == 1) { $return = 'SUCCESS'; } else if ($data->failure == 1) { $return = 'FAILURE'; } return $return; }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.