Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- define("GOOGLE_API_KEY", "AIzaSyCLQbnBMNcuqmR7CuUw49oKIbXL_Yuezjw");
- include("config.php");
- function sendRequest($regids,$message) {
- /*
- $result = $this->celery->PostTask('task2.tasks.notify_answer_done', array($regids, $message, "Doubtnut Update"));
- */
- // Set POST variables
- //$message = array("price" => $message);
- $url = 'https://fcm.googleapis.com/fcm/send';
- $reg = $regids;
- $data = [$message];
- $fields = array(
- 'registration_ids' => $reg,
- 'data' => $message
- );
- $headers = array(
- //'Authorization: key=AIzaSyAXu2kaXxlwcRDMKd4qBinskEvsXV18FrM',
- 'Authorization: key='.GOOGLE_API_KEY.'',
- 'Content-Type: application/json'
- );
- // /print_r($fields);exit;
- // 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);
- }
- $servername = "52.187.1.240";
- $username = "name";
- $password = "abc123";
- $dbname = "classzoo1";
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- $sql = "select * from students where gcm_reg_id is not null and gcm_reg_id <> '' and mobile in ('8743037055', '9717312196')";
- $result = $conn->query($sql);
- if ($result->num_rows > 0) {
- // output data of each row
- $regids = array();
- $i=1;
- while($row = $result->fetch_assoc()) {
- $message_to_send = array(
- "message"=>"Math Video Solutions Live First on Doubtnut",
- "image-url" => "https://www.dropbox.com/s/jkz0uvvqwks75tb/2018_JEEMains_3.png?dl=1",
- "notify-activity" => "com.doubtnutapp.ui.Learn.LearnVideosActivity",
- "type" => "marketing",
- "title" => "[JEE MAINS] DOUBTNUT FIRST TO PUBLISH VIDEO SOLUTIONS",
- "category" => "marketing",
- "question_id" => "1241886",
- "learntype" => "NCERT ALL CLASSES",
- "chapter" => "PERMUTATIONS AND COMBINATIONS",
- "grade"=>"11",
- "exercise" => "E01",
- //"learntype" => "JEE MAINS",
- //"year" => "14"
- //"learntype" => "JEE ADVANCED",
- //"year" => "14"
- //"learntype" => "XII BOARDS",
- //"year" => "15"
- //"learntype" => "X BOARDS",
- //"year" => "14"
- //"learntype" => "IIT JEE PREP",
- //"chapter" => "CIRCLES",
- //"exercise" => "Chord Of Contact",
- "buttons"=> array(
- array(
- "title" => "SHARE",
- "action" => "share",
- "params"=> array(
- "content"=> "This is test",
- "image" => "https://doubtnutvideobiz.blob.core.windows.net/q-thumbnail/1136459.png",
- "question_id"=> "1136459"
- )
- ),
- array(
- "title" => "SHARE",
- "action" => "share",
- "params"=> array(
- "content"=> "This is test",
- "image" => "https://doubtnutvideobiz.blob.core.windows.net/q-thumbnail/1136459.png",
- "code"=> "1136459",
- "link" => "https://play.google.com/store/apps/details?id=com.doubtnutapp&hl=en"
- )
- )
- )
- );
- if ($row["gcm_reg_id"]) {
- //$retu = $this->sendRequest($student["gcm_reg_id"], $message_to_send);
- //var_dump($retu);
- $regids[]= $row["gcm_reg_id"];
- }
- if($i%1000 == 0 || $i == $result->num_rows){
- $ret = sendRequest($regids, $message_to_send);
- $regids = array();
- }
- echo $i;
- $i++;
- }
- }
- $date = new DateTime();
- echo "send push notification ran successfully at ".$date->format("y:m:d h:i:s");
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement