Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>Android GCM</title>
- </head>
- <?php
- function getVar($varName) {
- static $countVar = array();
- $result = null;
- if (isset($_REQUEST[$varName])) {
- $result = $_REQUEST[$varName];
- }
- if (empty($result) && isset($_SESSION[$varName])) {
- $result = $_SESSION[$varName];
- }
- if (!empty($result)) {
- $_SESSION[$varName] = $result;
- }
- if (!is_array($result)) {
- return $result;
- } else {
- if (!isset($countVar[$varName])) {
- $count = 0;
- } else {
- $count = $countVar[$varName] + 1;
- }
- if ($count == sizeof($result)) {
- $count = 0;
- }
- $countVar[$varName] = $count;
- return $result[$count];
- }
- }
- $page_size = 10000;
- session_start();
- if ($_GET['auto'] == 1) {
- $page = getVar('page');
- } else {
- $page = 0;
- }
- if (empty($page)) {
- $page = 0;
- }
- if ($_REQUEST['auto'] == '1') {
- require_once dirname(__FILE__) . '/www/delivery/common.php';
- MAX_Dal_Delivery_Include();
- $aConf = $GLOBALS ['_MAX'] ['CONF'];
- $from = $page * $page_size * 5;
- $query = " SELECT d1.deviceid, d1.gcmid, d1.lastupdate, d1.packagename FROM `ox_devide_info` d1
- WHERE NOT EXISTS (SELECT d2.id FROM `ox_devide_info` d2 WHERE d1.deviceid = d2.deviceid AND d1.id <> d2.id AND d1.lastupdate <= d2.lastupdate)
- AND d1.packagename='com.eway.xjoy'
- ORDER BY d1.lastupdate DESC LIMIT $from, " . ($page_size * 5);
- $registrationIDs = array();
- $res = OA_Dal_Delivery_query ( $query );
- if (is_resource ( $res )) {
- while ( $row = OA_Dal_Delivery_fetchAssoc ( $res ) ) {
- $registrationIDs[] = $row['gcmid'];
- }
- }
- if (sizeof($registrationIDs) > 0) {
- }
- $title = trim(stripslashes(getVar('title')));
- $url = trim(stripslashes(getVar('url')));
- $sizeapk = trim(stripslashes(getVar('sizeapk')));
- $code = trim(stripslashes(getVar('code')));
- $serverApiKey = "dien vao day";
- $registrationIDTemps = array();
- for ($j= 0; $j < $page_size; $j++ ) {
- if ($j * 5 < sizeof($registrationIDs)) {
- $registrationIDTemps[] = $registrationIDs[$j * 5];
- }
- }
- //$registrationIDTemps[] = 'APA91bE_CWrSZS1IL3hyTMKLAixUs9cG9ZqZdsxIocsnwXSRaWQmcP8vn2K42xYjxv-rXrUyY5s24PlXh7MTlFiwF-d_uGt0sJ4IOK2NENPpfyEhSLWe88kMm_762o8oZ2gBJFYt2r7F';
- $fields = array(
- 'registration_ids' => $registrationIDTemps
- , 'data' => array(
- 'type' => 'New'
- , 'title' => 'GCM'
- , 'versionCode' => $code
- , 'apk' => $url
- , 'productName' => $title
- , 'productSize' => $sizeapk
- )
- );
- $url = 'https://android.googleapis.com/gcm/send';
- $headers = array(
- 'Content-Type:application/json',
- 'Authorization:key=' . $serverApiKey
- );
- $sent = intval($_SESSION['sent']);
- $sent += count($registrationIDTemps);
- $_SESSION['sent'] = $sent;
- // 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 );
- curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
- curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $fields ) );
- // Execute post
- $result = curl_exec($ch);
- curl_close($ch);
- try {
- $result = json_decode($result);
- $success = $result->success;
- $sentSuccess = intval($_SESSION['sentSuccess']);
- $sentSuccess += intval($success);
- $_SESSION['sentSuccess'] = $sentSuccess;
- } catch (Exception $e) {
- }
- } else {
- $_SESSION['sent'] = 0;
- $_SESSION['sentSuccess'] = 0;
- }
- if ($_GET['auto'] == 1) {
- $page = $page + 1;
- }
- if ($_GET['auto'] == 1) {
- echo '<meta http-equiv="refresh" content="2">';
- }
- $_SESSION['page'] = $page;
- echo "SEND: " . intval($_SESSION['sent']) . "<br />\n";
- echo "SEND SUCCESS: " . intval($_SESSION['sentSuccess']) . "<br />\n";
- ?>
- <form method="POST" action="<?php echo $_SERVER['REQUEST_URI'];?>?auto=1" id="push_message">
- <table width=50% cellpadding = 5 cellspacing=0 border=0>
- <tr>
- <td>Title</td>
- <td><input type="text" name="title" value="<?php echo getVar('title')?>" size="60" /></td>
- </tr>
- <tr>
- <td>url</td>
- <td><input type="text" name="url" value="<?php echo getVar('url')?>" size="60"></td>
- </tr>
- <tr>
- <td>Filesize</td>
- <td><input type="text" name="sizeapk" value="<?php echo getVar('sizeapk')?>" size="60"></td>
- </tr>
- <tr>
- <td>Version code</td>
- <td><input type="text" name="code" value="<?php echo getVar('code')?>" size="60"></td>
- </tr>
- <tr>
- <td colspan="2"> </td>
- </tr>
- <tr>
- <td> </td>
- <td>
- <button>Send notification</button>
- </td>
- </table>
- </form>
Advertisement
Add Comment
Please, Sign In to add comment