TrafficController.php
1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
/**
* Created by PhpStorm.
* User: zhl
* Date: 2024/1/6
* Time: 16:06
*/
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Repositories\SyncSubmitRepository;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
/**
* Class TrafficController
* @package App\Http\Controllers\Api
*/
class TrafficController extends Controller
{
/**
* 特殊访问引流接口
* @param Request $request
* @return string
*/
public function trafficVisit(Request $request)
{
//获取参数
$data = $request->all();
$ip = $request->input('ip');
$url = $request->input('url');
$device_port = intval($request->input('device_port'));
$referrer_url = $request->input('referrer_url');
$user_agent = $request->input('user_agent');
// FIXME 些日志 观察数据, 完成以后删除代码
file_put_contents(storage_path('logs/trafficVisit' . date('Y-m-d') . '.log'), var_export($data, true));
//验证参数
$validator = Validator::make($data, [
'ip' => 'required',
'url' => 'required',
'user_agent' => 'required',
], [
'ip.required' => 'IP不能为空',
'url.required' => '访问链接不能为空',
'user_agent.required' => '请求头信息user_agent不能为空',
]);
//判断参数是否正确
if ($validator->fails()) {
return $this->error($validator->errors()->first());
}
$result = app(SyncSubmitRepository::class)->trafficVisit($ip, $url, $user_agent, $referrer_url, $device_port, 1);
return $result ? $this->success() : $this->error();
}
}