Пример #1
0
try {
    // Get the JSON payload sumbitted from SMSified.
    $json = file_get_contents("php://input");
    // Create a new instance of the custom object.
    $sms = new InboundMessage($json);
    // Get the message sent with the inbound message.
    $message = $sms->getMessage();
    // Get the number message was sent from.
    $number = $sms->getSenderAddress();
    // Look up latest review for establishment.
    $conn = new DBConnect(DB_HOST, DB_USER, DB_PASSWORD);
    $conn->selectDB(DB_NAME);
    $query = str_replace("{NAME}", $conn->escapeInput($message), SQL_QUERY_TEMPLATE);
    $result = $conn->runQuery($query);
    // Construct response to send back to user.
    if ($conn->getNumRowsAffected() == 0) {
        $response = "No establishments found";
    } else {
        $review = mysql_fetch_assoc($result);
        $response = 'Name: ' . $review["Est_Name"] . ' ';
        $response .= 'Insp. Date: ' . $review["I_Date"] . ' ';
        $response .= 'Score: ' . $review["Score"] . ' ';
        $response .= 'Grade: ' . $review["Grade"];
    }
    // Create a new instance of the SMSified object.
    $sms = new SMSified(SMS_USER, SMS_PASSWORD);
    $sms->sendMessage(SMS_SENDER_NUMBER, $number, $response);
} catch (Exception $ex) {
    openlog("DERBYCITYFOOD", LOG_ODELAY, LOG_USER);
    syslog(LOG_ERR, "There was a problem.");
    closelog();