cname方式实现无服务器302显性转发

各种云的DNS实现显性转发需要ICP,本来不用服务器就可以302转发的这下操作麻烦了。自己搭建一个DNS服务器,动作太大,且使用可信度不高。奇思妙想通过cname和txt记录,实现一下无服务器DNS显性302跳转。

搭建:

1)cname302.com解析到服务器IP,比如:IP.IP.IP.IP

2)建立一个PHP网站,并设置为默认网站(即解析到这个IP的域名都可以访问):

代码内容:

php laravel json反序列化输出xml格式

$result = '{"code":"Success","data":{"continent":"保留IP","country":"","zipcode":"","timezone":"","accuracy":"保留IP","owner":"","isp":"","source":"数据挖掘","areacode":"B1","adcode":"","asnumber":"","lat":"","lng":"","radius":"","prov":"","city":"","district":""},"charge":false,"msg":"查询成功","ip":"127.0.0.1","coordsys":"BD09"}';
$obj = json_decode($result, true);
if($format == 'xml'){
 return response()->xml($obj);
//     $data = [
//         'status' => 'success',
//         'data' => [
//             'first_name' => 'John',
//             'last_name' => 'Smith',
//         ]
//     ];
//     return response()->xml($data);
}

PHP反向代理ipplus360的API

Route::get('/ip/geo/v1/district/', function (Request $request) {
    // return '我是中文';
    $ipAddress = $request->ip();
    $coordsys = $request->input('coordsys');
    $result = file_get_contents('https://api.example.com/ip/geo/v1/district/?key=xxxxxxxxxxxx&ip='.$ipAddress.'&coordsys='.$coordsys);
    return response(json_encode(json_decode($result), JSON_UNESCAPED_UNICODE))
        ->header('Content-Type', 'application/json;charset=UTF-8');
});