使用php codeigniter向android推送通知

使用php codeigniter向android推送通知,php,android,codeigniter,rest,push-notification,Php,Android,Codeigniter,Rest,Push Notification,我是android和php的新手。我现在开始学习使用codeigniter框架的php。如何使用此框架向android发送推送通知 感谢对新程序员的帮助 您只需将下面的函数粘贴到控制器中,并需要更改GCM键 public function androidPushNotification($registration_ids, $message) { $registrationIds = array($registration_ids); $msg = array(

我是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; } 公共函数androidPushNotification($registration\u id,$message){ $registrationIds=数组($registration\u id); $msg=array('message'=>$message,'title'=>'test notification','swible'=>1,'sound'=>1); $fields=array('registration\u 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\u exec($ch); 卷曲关闭($ch); $data=json_decode($result); 如果($data->success==1){ $return='SUCCESS'; }如果($data->failure==1),则为else{ $return='FAILURE'; } return$return; }