示例#1
0
    $rq = new HTTP_Request("https://android.googleapis.com/gcm/send");
    $rq->setMethod(HTTP_REQUEST_METHOD_POST);
    $rq->addHeader("Authorization", "key=" . $apikey);
    $rq->addPostData("registration_id", $regId);
    $rq->addPostData("collapse_key", "1");
    $rq->addPostData("data.message", $message);
    if (!PEAR::isError($rq->sendRequest())) {
        print "\n" . $rq->getResponseBody();
    } else {
        print "\nError has occurred";
    }
}
if (filter_input(INPUT_POST, "date") != NULL && filter_input(INPUT_POST, "extension") != NULL) {
    $date = filter_input(INPUT_POST, 'date');
    $extension = filter_input(INPUT_POST, 'extension');
    $notificationList = checkNotification($date, $extension);
    if ($extension == '+1 minute') {
        $extension = '1分前';
    } else {
        if ($extension == '+1 hour') {
            $extension = '1時間前';
        }
    }
    $apikey = "AIzaSyDh3_C0r5OxdGGHN516XleJ1G_-aAMxEC4";
    foreach ($notificationList as $notification) {
        $regid = $notification['notificationID'];
        if ($notification['type'] == 'スケジュール') {
            $ref = '開始';
        } else {
            if ($notification['type'] == 'タスク') {
                $ref = '終了';
示例#2
-1
        print "\nError has occurred";
    }
}
function setNotification($message, $user_id)
{
    try {
        $dbh = new PDO('mysql:host=mysql488.db.sakura.ne.jp;dbname=meganeshibu_db;charset=utf8', 'meganeshibu', 'DBmaster777', array(PDO::ATTR_EMULATE_PREPARES => false));
    } catch (PDOException $e) {
        exit('データベース接続失敗。' . $e->getMessage());
    }
    $registTime = new DateTime();
    $sql = "insert into NotificationTable(UserID, NotificationInfo, RegistTime) values('" . $user_id . "',' " . $message . "',' " . $registTime->format('Y-m-d H:i:s') . "')";
    $stmt = $dbh->query($sql);
    $dbh = null;
}
$notificationList = checkNotification('', '+1 hour');
foreach ($notificationList as $notification) {
    $regId = $notification['notificationID'];
    if ($notification['type'] == 'スケジュール') {
        $ref = '開始';
    } else {
        if ($notification['type'] == 'タスク') {
            $ref = '終了';
        }
    }
    $message = $notification['type'] . '「' . $notification['name'] . '」の' . $ref . '1時間前です';
    if ($regId) {
        sendNotification($message, $regId);
    }
    setNotification($message, $notification['user_id']);
}