Mark/api.php

37 lines
940 B
PHP

<?php
use Mark\App;
use Workerman\Protocols\Http\Response;
require 'vendor/autoload.php';
$api = new App('http://0.0.0.0:3500');
$api->count = 4; // process count
$api->any('/', function ($requst) {
$filename = "wifi.png";
$headers = [];
if (file_exists($filename)) {
$headers[] = "Cache-Control: public";
$headers[] = "Content-Type: image/png";
$headers[] = "Content-Transfer-Encoding: Binary";
$headers[] = "Content-Length:".filesize($filename);
$headers[] = "Content-Disposition: attachment; filename={$filename}";
// die();
} else {
die("Error: File not found.");
}
return new Response(200, $headers, readfile($filename));
});
$api->get('/hello/{name}', function ($requst, $name) {
return "Hello $name";
});
$api->post('/user/create', function ($requst) {
return json_encode(['code'=>0 ,'message' => 'ok']);
});
$api->start();