//放到public/index.php中
header('Content-Type: text/html;charset=utf-8');
header('Access-Control-Allow-Origin:*'); // *代表允许任何网址请求
header('Access-Control-Allow-Methods:POST,GET,OPTIONS,DELETE'); // 允许请求的类型
header('Access-Control-Allow-Credentials: true'); // 设置是否允许发送 cookies
header('Access-Control-Allow-Headers: Content-Type,Content-Length,Accept-Encoding,X-Requested-with, Origin,User-Token'); // 设置允许自定义请求头的字段
route/route.php
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
Route::get('think', function () {
return 'hello,ThinkPHP5!';
});
Route::get('hello/:name', 'index/hello');
Route::rule('api/:version/:hash','api/base/iniApi','GET|POST|ORIGIN|OPTIONS');
// API文档列表
Route::rule('apilist','api/apihelp.index/index','GET');
// API文档详情
Route::rule('apiinfo/:hash','api/apihelp.index/apiinfo','GET');
// API错误码详情
Route::rule('errorlist','api/apihelp.index/errorlist','GET');
return [
];