diff --git a/app/Api/controller/indexController.php b/app/Api/controller/indexController.php index e765909..e94dd0e 100644 --- a/app/Api/controller/indexController.php +++ b/app/Api/controller/indexController.php @@ -6,6 +6,6 @@ public function index(){ return "api"; } public function api(){ - return ['api'=>1]; + return ['api'=>1,'TO_JSONP'=>true]; } } \ No newline at end of file diff --git a/app/Home/controller/IndexController.php b/app/Home/controller/IndexController.php index 168a52b..3923f4c 100644 --- a/app/Home/controller/IndexController.php +++ b/app/Home/controller/IndexController.php @@ -112,5 +112,9 @@ public function json(){ return ['data'=>'json','status'=>1]; // return ['data'=>'json','status'=>1,'to_array'=>1]; } + public function url1(){ + $b = route()->action; + dump($b);die; + } } \ No newline at end of file diff --git a/core/common/function.php b/core/common/function.php index 1c70466..1e86c17 100644 --- a/core/common/function.php +++ b/core/common/function.php @@ -123,6 +123,15 @@ function json($array) header('Content-Type:application/json; charset=utf-8'); return json_encode($array); } +function jsonp($array) +{ + header('Content-Type:application/javascript; charset=utf-8'); + $data = json_encode($array); + + $handler = !empty($_GET['callback']) ? $_GET['callback'] :'jsonpReturn' ; + $data = $handler . '(' . $data . ');'; + return $data; +} function show404() { @@ -130,16 +139,15 @@ function show404() header("status: 404 Not Found"); exit(); } -function model($name=''){ - $model_path = '\\app\\'.ucfirst($name); - return (class_exists($model_path))? - new $model_path : - new \thunder\Model($name); -} + + function microtime_float(){ list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } + + + function input($name,$default='',$filter=null,$datas=null) { static $_PUT = null; if(strpos($name,'/')){ // 指定修饰符 @@ -274,6 +282,8 @@ function input($name,$default='',$filter=null,$datas=null) { is_array($data) && array_walk_recursive($data,'thunder_filter'); return $data; } + + function array_map_recursive($filter, $data) { $result = array(); foreach ($data as $key => $val) { @@ -283,12 +293,31 @@ function array_map_recursive($filter, $data) { } return $result; } + + + function thunder_filter(&$value){ // 过滤查询特殊字符 if(preg_match('/^(EXP|NEQ|GT|EGT|LT|ELT|OR|XOR|LIKE|NOTLIKE|NOT BETWEEN|NOTBETWEEN|BETWEEN|NOTIN|NOT IN|IN)$/i',$value)){ $value .= ' '; } } + + +function model($name=''){ + $model_path = '\\app\\'.ucfirst($name); + return (class_exists($model_path))? + new $model_path : + new \thunder\Model($name); +} + + function session(){ return new \thunder\Session(); } + + + +function route(){ + return \thunder\Route::get_instance(); +} \ No newline at end of file diff --git a/core/thunder/Response.php b/core/thunder/Response.php index 99af84f..f7aea09 100644 --- a/core/thunder/Response.php +++ b/core/thunder/Response.php @@ -10,7 +10,7 @@ public static function send($data){ $data = self::setContent($dataType,$data); if(!is_array($data)){ - echo($data); + echo $data; }else{ dump($data); } @@ -23,20 +23,22 @@ protected static function getDataType($data){ protected static function setContent($dataType,$data){ switch($dataType){ case 'array' :{ - $data = - (array_key_exists('to_array',$data) && $data['to_array']==1)? - self::getData(): - $data = json($data); - break; - } - case 'integer' :{ - $data = (int)$data; - break; - } - case 'string' :{ - $data = (string)$data; + switch(true){ + case (array_key_exists('TO_ARRAY',$data) && $data['TO_ARRAY']===true):{ + $data = self::getData(); + break; + } + case (array_key_exists('TO_JSONP',$data) && $data['TO_JSONP']===true):{ + $data = jsonp($data); + break; + } + default:{ + $data = json($data); + } + } break; } + default:{ $data = self::getData(); } diff --git a/core/thunder/Route.php b/core/thunder/Route.php index dea9436..fa48c74 100644 --- a/core/thunder/Route.php +++ b/core/thunder/Route.php @@ -87,9 +87,9 @@ public static function _get_route_path($path){ return $path; } -/* - * 提供twig - * */ + /* + * 提供twig + * */ public static function _get_pub_path(){ return self::$pub_path; } @@ -102,7 +102,6 @@ public static function init($rules,$route){ self::$rules = array_merge(self::$rules,$r); } - /* * * 解析路由 diff --git a/index.php b/index.php index 2ae879a..9790ed6 100644 --- a/index.php +++ b/index.php @@ -3,6 +3,7 @@ if(version_compare(PHP_VERSION,'5.4.0','<')) die('require PHP > 5.4.0 !'); header("Content-type:text/html;charset=utf-8"); date_default_timezone_set('PRC'); +header("Access-Control-Allow-Origin: *"); define('_PHP_FILE_',rtrim($_SERVER['SCRIPT_NAME'],'/')); $_root = rtrim(dirname(_PHP_FILE_),'/'); define('__ROOT__', (($_root=='/' || $_root=='\\')?'':$_root)); diff --git a/log/20170916/log.log b/log/20170916/log.log index 79141e1..513e75e 100644 --- a/log/20170916/log.log +++ b/log/20170916/log.log @@ -9,3 +9,94 @@ 2017-09-16 10:02:04"MODULE==>Api;CTRL==>Index;ACTION==>index" 2017-09-16 10:02:19"MODULE==>Api;CTRL==>Index;ACTION==>index" 2017-09-16 10:02:56"MODULE==>Api;CTRL==>Index;ACTION==>index" +2017-09-16 10:04:18"MODULE==>Api;CTRL==>Index;ACTION==>index" +2017-09-16 10:48:39"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 10:51:04"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 10:51:21"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 10:51:44"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 10:53:31"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 10:53:32"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 10:54:26"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 10:55:07"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 10:58:28"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 10:58:57"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 11:49:35"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 11:49:38"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 11:50:12"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 11:50:16"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 11:53:40"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 11:53:53"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 11:56:12"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 11:56:42"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 11:56:51"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 11:57:08"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 11:57:27"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 11:57:28"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 11:57:33"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 12:02:30"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 12:02:34"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 12:02:44"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 12:02:45"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 12:02:47"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 12:02:49"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 12:02:51"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 12:02:57"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 12:03:00"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 12:03:08"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 12:03:10"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 12:03:17"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 12:03:18"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 12:03:19"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 12:03:29"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 12:03:49"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 12:05:14"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 12:06:21"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 12:06:22"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 12:06:28"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 12:06:36"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 12:06:48"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 12:06:57"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 12:07:09"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 12:07:30"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 12:08:45"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 12:08:47"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 12:14:37"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 12:15:23"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 12:15:48"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 12:16:49"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 12:24:21"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 12:24:25"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 12:25:01"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 12:25:03"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 12:25:05"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 12:25:07"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 12:25:29"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 13:20:27"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 13:20:40"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 13:20:42"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 13:20:55"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 13:20:58"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 13:24:06"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 13:26:38"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 13:26:44"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 13:26:47"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 13:26:52"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 13:42:02"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 13:48:43"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 13:48:47"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 13:51:51"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 13:53:50"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 13:54:02"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 13:54:10"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 13:54:45"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 13:55:11"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 13:55:55"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 13:55:56"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 13:55:57"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 13:56:13"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 14:08:33"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 14:18:04"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 14:23:07"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 14:23:17"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 14:23:21"MODULE==>Api;CTRL==>Index;ACTION==>api" +2017-09-16 14:24:39"MODULE==>Api;CTRL==>Index;ACTION==>api" diff --git a/routes/web.php b/routes/web.php index b044dc0..d7ce687 100644 --- a/routes/web.php +++ b/routes/web.php @@ -5,7 +5,7 @@ * 注册路由 * * */ -Route::init('goapi','api/index/index'); +Route::init('goapi','api/index/api'); Route::init('goapi2/add/{param}','api/index/index');