73 lines
1.6 KiB
PHP
Raw Permalink Normal View History

2024-11-02 15:27:08 +08:00
<?php
use think\exception\HttpResponseException;
$version = request()->post('version');
//var_dump($version);die;
if(!$version){
$version = request()->param('version');
}
app()->http->name('gateway'); #应用
//#设置指定应用的命名空间
app()->setNamespace('app\gateway'); #应用的命名空间
//默认跳转到v1版本
2024-11-02 15:27:08 +08:00
if ($version == null) $version = "api";#api.notify,url
if (str_contains($version, '.')) {
$version = explode('.', $version);
if($version[1] == '0'){
$version = $version[0];
}else{
$version = $version[0].'_'.$version[1];
}
}
2024-11-02 15:27:08 +08:00
$pathInfo = request()->pathinfo();
if ($pathInfo == null) {
$json = [
'code' => -802,
'data'=>'',
'msg' =>'请求错误'
];
throw new HttpResponseException(json($json));
}
if($version!='api'){
if(!str_contains($pathInfo, 'api.')){
2024-11-02 15:54:47 +08:00
if(str_contains($version, '.')){
$versions = str_replace(".", "", $version);
#支持小版本的更新
app()->route->any('call','/gateway/'.$versions.'.notify/call');
app()->route->any('kuaijiaofei','/gateway/'.$versions.'.notify/kuaijiaofei');
2024-11-02 15:54:47 +08:00
}else{
app()->route->any('call','/gateway/'.$version.'.notify/call');
app()->route->any('kuaijiaofei','/gateway/'.$version.'.notify/kuaijiaofei');
2024-11-02 15:54:47 +08:00
}
2024-11-02 15:27:08 +08:00
}
}else{
if(!str_contains($pathInfo, 'api.')){
2024-11-02 15:54:47 +08:00
// app()->route->any('call','/gateway/'.$version.'.notify/call');
app()->route->any('call','/gateway/api.notify/call');
app()->route->any('kuaijiaofei','/gateway/api.notify/kuaijiaofei');
2024-11-02 15:27:08 +08:00
}
}