Exemplo n.º 1
0
                $sub->send($msg);
            }
            echo json_encode($stock);
            break;
        case 'stocks':
            $stocks = Stock::findAll();
            echo json_encode($stocks);
            break;
        case 'delete':
            $company = Request::any('company');
            $stock = Stock::find($company);
            $stock->delete();
            echo json_encode($stock);
            break;
        case 'subscribers':
            $subscribers = Subscriber::findAll();
            echo json_encode($subscribers);
            break;
        case 'send':
            $msg = Request::any('message');
            $recs = Subscriber::findAll();
            foreach ($recs as $r) {
                SMS::send($r->phone, $msg);
            }
            echo json_encode(["success" => true]);
            break;
    }
} catch (Exception $e) {
    http_response_code(500);
    echo $e->getMessage();
}
Exemplo n.º 2
0
<?php

require_once '../Lib.php';
while (true) {
    echo "\n\nPreparing Broadcast...\n";
    $stocks = Stock::findAll();
    $recipients = Subscriber::findAll();
    $msg = "==Stocks Update==\n";
    foreach ($stocks as $stock) {
        $msg .= $stock->company . ":" . $stock->price . "\n";
    }
    echo "Message is:\n{$msg}\n";
    foreach ($recipients as $r) {
        SMS::send($r->phone, $msg);
        echo "Sent to {$r->phone}\n";
    }
    echo "Send Complete. About to sleep...\n";
    echo "Sleeping...";
    //wait for 60
    sleep(30);
}