Advertisement
Guest User

Untitled

a guest
Apr 9th, 2018
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.71 KB | None | 0 0
  1. <?php
  2. define("GOOGLE_API_KEY", "AIzaSyCLQbnBMNcuqmR7CuUw49oKIbXL_Yuezjw");
  3. include("config.php");
  4. function sendRequest($regids,$message) {
  5. /*
  6. $result = $this->celery->PostTask('task2.tasks.notify_answer_done', array($regids, $message, "Doubtnut Update"));
  7. */
  8. // Set POST variables
  9. //$message = array("price" => $message);
  10. $url = 'https://fcm.googleapis.com/fcm/send';
  11.  
  12. $reg = $regids;
  13. $data = [$message];
  14. $fields = array(
  15. 'registration_ids' => $reg,
  16. 'data' => $message
  17. );
  18. $headers = array(
  19. //'Authorization: key=AIzaSyAXu2kaXxlwcRDMKd4qBinskEvsXV18FrM',
  20. 'Authorization: key='.GOOGLE_API_KEY.'',
  21. 'Content-Type: application/json'
  22. );
  23. // /print_r($fields);exit;
  24. // Open connection
  25. $ch = curl_init();
  26.  
  27. // Set the url, number of POST vars, POST data
  28. curl_setopt($ch, CURLOPT_URL, $url);
  29.  
  30. curl_setopt($ch, CURLOPT_POST, true);
  31. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  32. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  33.  
  34. // Disabling SSL Certificate support temporarly
  35. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  36. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
  37.  
  38. // Execute post
  39. $result = curl_exec($ch);
  40. if ($result === FALSE) {
  41. die('Curl failed: ' . curl_error($ch));
  42. }
  43. // Close connection
  44. curl_close($ch);
  45.  
  46. }
  47. $servername = "52.187.1.240";
  48. $username = "name";
  49. $password = "abc123";
  50. $dbname = "classzoo1";
  51.  
  52. // Create connection
  53. $conn = new mysqli($servername, $username, $password, $dbname);
  54. $sql = "select * from students where gcm_reg_id is not null and gcm_reg_id <> '' and mobile in ('8743037055', '9717312196')";
  55. $result = $conn->query($sql);
  56. if ($result->num_rows > 0) {
  57. // output data of each row
  58. $regids = array();
  59. $i=1;
  60. while($row = $result->fetch_assoc()) {
  61. $message_to_send = array(
  62. "message"=>"Math Video Solutions Live First on Doubtnut",
  63. "image-url" => "https://www.dropbox.com/s/jkz0uvvqwks75tb/2018_JEEMains_3.png?dl=1",
  64. "notify-activity" => "com.doubtnutapp.ui.Learn.LearnVideosActivity",
  65. "type" => "marketing",
  66. "title" => "[JEE MAINS] DOUBTNUT FIRST TO PUBLISH VIDEO SOLUTIONS",
  67. "category" => "marketing",
  68. "question_id" => "1241886",
  69. "learntype" => "NCERT ALL CLASSES",
  70. "chapter" => "PERMUTATIONS AND COMBINATIONS",
  71. "grade"=>"11",
  72. "exercise" => "E01",
  73. //"learntype" => "JEE MAINS",
  74. //"year" => "14"
  75. //"learntype" => "JEE ADVANCED",
  76. //"year" => "14"
  77. //"learntype" => "XII BOARDS",
  78. //"year" => "15"
  79. //"learntype" => "X BOARDS",
  80. //"year" => "14"
  81. //"learntype" => "IIT JEE PREP",
  82. //"chapter" => "CIRCLES",
  83. //"exercise" => "Chord Of Contact",
  84. "buttons"=> array(
  85. array(
  86. "title" => "SHARE",
  87. "action" => "share",
  88. "params"=> array(
  89. "content"=> "This is test",
  90. "image" => "https://doubtnutvideobiz.blob.core.windows.net/q-thumbnail/1136459.png",
  91. "question_id"=> "1136459"
  92. )
  93. ),
  94. array(
  95. "title" => "SHARE",
  96. "action" => "share",
  97. "params"=> array(
  98. "content"=> "This is test",
  99. "image" => "https://doubtnutvideobiz.blob.core.windows.net/q-thumbnail/1136459.png",
  100. "code"=> "1136459",
  101. "link" => "https://play.google.com/store/apps/details?id=com.doubtnutapp&hl=en"
  102. )
  103. )
  104. )
  105. );
  106.  
  107.  
  108.  
  109. if ($row["gcm_reg_id"]) {
  110. //$retu = $this->sendRequest($student["gcm_reg_id"], $message_to_send);
  111. //var_dump($retu);
  112. $regids[]= $row["gcm_reg_id"];
  113. }
  114. if($i%1000 == 0 || $i == $result->num_rows){
  115. $ret = sendRequest($regids, $message_to_send);
  116. $regids = array();
  117. }
  118. echo $i;
  119. $i++;
  120. }
  121. }
  122. $date = new DateTime();
  123. echo "send push notification ran successfully at ".$date->format("y:m:d h:i:s");
  124. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement