CodeIgniter code for android GCM services |
We are using codeIgniter 3.0.0 version for my php website. Now we our planning to launch android app for the same website.
I know who to write gcm push notification service in php but do not know how to do it in CodeIgniter using MVC. my current php script for android app is " <?php function storeUser($pid, $gcm_regid) { include "../includes/connect.php"; $result = $db->query("SELECT * FROM parent_user WHERE parent_id='$pid'"); if(mysqli_num_rows($result)) { $result = $db->query("UPDATE parent_user SET gcm_regid='$gcm_regid' WHERE parent_id='$pid'"); } else { $result = $db->query("INSERT INTO parent_user (parent_id, gcm_regid, created_at) VALUES('$pid','$gcm_regid', NOW())"); } // check for successful store if ($result) { $result = $db->query("SELECT * FROM parent_user WHERE parent_id = $pid") or die(mysql_error()); // return user details if (mysqli_num_rows($result) > 0) { $res=$result->fetch_array(MYSQLI_ASSOC); return $res; } else { return false; } } else { return false; } } function getAllUsers() { $result = $db->query("select * FROM parent_user"); return $result; } function send_notification($registatoin_ids, $message) { // include config // Set POST variables $url = 'https://android.googleapis.com/gcm/send'; $fields = array( 'registration_ids' => $registatoin_ids, 'data' => $message, ); $headers = array( 'Authorization: key=' . GOOGLE_API_KEY, 'Content-Type: application/json' ); // Open connection $ch = curl_init(); // Set the url, number of POST vars, POST data curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Disabling SSL Certificate support temporarly curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields)); // Execute post $result = curl_exec($ch); if ($result === FALSE) { die('Curl failed: ' . curl_error($ch)); } // Close connection curl_close($ch); echo $result; } ?> " Kingly help. |
Welcome Guest, Not a member yet? Register Sign In |