REAPI/app/gateway/route/index.php

53 lines
1.1 KiB
PHP
Raw Normal View History

2024-09-29 15:43:18 +08:00
<?php
use think\exception\HttpResponseException;
2024-11-02 15:27:08 +08:00
2024-09-29 15:43:18 +08:00
app()->route->get('api/open/code1','gateway/api.card/add');
$version = request()->post('version');
//var_dump($version);die;
if(!$version){
$version = request()->param('version');
}
//默认跳转到v1版本
if ($version == null) $version = "api";#api.notify,url
2024-11-02 15:48:19 +08:00
2024-09-29 15:43:18 +08:00
$pathInfo = request()->pathinfo();
if ($pathInfo == null) {
$json = [
'code' => -802,
'data'=>'',
'msg' =>'请求错误'
];
throw new HttpResponseException(json($json));
}
if($version!='api'){
2024-11-02 15:27:08 +08:00
if(!str_contains($pathInfo, 'api.')){
2024-11-02 15:48:19 +08:00
if(str_contains($version, '.')){
$versions = str_replace(".", "", $version);
#支持小版本的更新
app()->route->rule(':controller/:function', $versions . '.:controller/:function');
}else{
app()->route->rule(':controller/:function', $version . '.:controller/:function');
}
2024-09-29 15:43:18 +08:00
}
}else{
2024-11-02 15:27:08 +08:00
if(!str_contains($pathInfo, 'api.')){
2024-09-29 15:43:18 +08:00
app()->route->rule(':controller/:function', 'api' . '.:controller/:function');
}
}