示例#1
0
switch ($_REQUEST["action"]) {
    case "addUser":
        if (!($id = checkValue($_REQUEST, "id"))) {
            die("ERROR");
        }
        include 'config.php';
        include 'connect.php';
        echo addUser($id, $db);
        $db->close();
        break;
    case "removeUser":
        if (!($id = checkValue($_REQUEST, "id"))) {
            die("ERROR");
        }
        include 'config.php';
        include 'connect.php';
        echo removeUser($id, $db);
        $db->close();
        break;
    case "sendMessage":
        if (!($message = checkValue($_REQUEST, "message"))) {
            die("ERROR");
        }
        include 'config.php';
        include 'connect.php';
        echo sendGCM($message, $db);
        break;
    default:
        echo "Error";
        break;
}
<?php

require_once 'dbauth.php';
require_once 'gcm_sendmsg.php';
$name = $_POST['name'];
$feedback = $_POST['feedback'];
/////////////////////////////////////////////////////////////////////////////
$sql = "INSERT INTO `{$mysql_database}`.`feedback` (`id` ,`name` ,`feedback`)VALUES (NULL ,'{$name}', '{$feedback}');";
if ($conn->query($sql) === TRUE) {
    echo "SUCCESS";
    sendGCM("A feedback recieved");
} else {
    echo "ERROR";
}
/////////////////////////////////////////////////////////////////////////////
$conn->close();
示例#3
0
$sql = "SELECT `GCMId` FROM `Users`";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        $registrationIds[] = $row['GCMId'];
    }
} else {
    die("NO_USERS");
}
function sendGCM($registrationIds, $message)
{
    $msg = array('message' => $message);
    $fields = array('registration_ids' => $registrationIds, 'data' => $msg);
    $headers = array('Authorization: key=' . API_ACCESS_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);
    echo $result;
    echo json_decode($result, true);
    echo 'Finish';
}
sendGCM($registrationIds, $message);
$conn->close();
?>
			
<?php

require_once 'dbauth.php';
require_once 'gcm_sendmsg.php';
$orderId = $_POST['orderId'];
//$orderId = 35;
//$sql = "INSERT INTO orders (userId, orderJSON) VALUES ('$itemId', '$price')";
$sql = "UPDATE `orders` SET `status` = 'CANCELED' WHERE `orderid` = {$orderId};";
if ($conn->query($sql) === TRUE) {
    $sql3 = "SELECT `userName`,`totalPrice` FROM `OwnerBankAccount` WHERE `orderId` = {$orderId}";
    $result = $conn->query($sql3);
    $result = $result->fetch_array();
    $userName = $result[0];
    $totalPrice = $result[1];
    $sql2 = "INSERT INTO `a1575314_sulthan`.`OwnerBankAccount` (`userName` , `orderId`, `payDirection` ,`totalPrice`) VALUES ('{$userName}', {$orderId}, 'SENT', {$totalPrice});";
    echo $sql2;
    $conn->query($sql2);
    echo "Order canceled";
    sendGCM("An order has been cancelled");
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
<?php

require_once 'dbauth.php';
require_once 'gcm_sendmsg.php';
$userId = $_POST['userId'];
$userName = $_POST['userName'];
$orderJSON = $_POST['orderJSON'];
$date = $_POST['date'];
$totalPrice = $_POST['totalPrice'];
$conn = new mysqli($mysql_host, $mysql_user, $mysql_password, $mysql_database);
if ($conn->connect_error) {
    die("Error");
}
//$sql = "INSERT INTO orders (userId, orderJSON) VALUES ('$itemId', '$price')";
$sql = "INSERT INTO `a1575314_sulthan`.`orders` (`userid` , `userName`, `itemjson` ,`status`, `date`, `totalPrice`) VALUES ( {$userId}, '{$userName}', '{$orderJSON}', 'PLACED', '{$date}', '{$totalPrice}');";
//echo $sql;
if ($conn->query($sql) === TRUE) {
    $sql2 = "SELECT max(`orderid`) FROM `{$mysql_database}`.`orders`;";
    $result = $conn->query($sql2);
    $result = $result->fetch_array();
    $id = $result[0];
    $transTime = date("Y-m-d H:i:s");
    $sql2 = "INSERT INTO `a1575314_sulthan`.`OwnerBankAccount` (`userName` , `orderId`, `transTime`, `payDirection` ,`totalPrice`) VALUES ('{$userName}', {$id}, '{$transTime}', 'RECIEVED', {$totalPrice});";
    $conn->query($sql2);
    echo "Order placed successfully";
    sendGCM("New order placed");
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();