106 lines
3.2 KiB
PHP
106 lines
3.2 KiB
PHP
<?php
|
||
// +----------------------------------------------------------------------
|
||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||
// +----------------------------------------------------------------------
|
||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||
// | 开源版本可自由商用,可去除界面版权logo
|
||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||
// | 访问官网:https://www.likeadmin.cn
|
||
// | likeadmin团队 版权所有 拥有最终解释权
|
||
// +----------------------------------------------------------------------
|
||
// | author: likeadminTeam
|
||
// +----------------------------------------------------------------------
|
||
|
||
namespace app\api\controller;
|
||
|
||
use think\Exception;
|
||
use think\facade\Cache;
|
||
|
||
/**
|
||
* 文章管理
|
||
* Class ArticleController
|
||
* @package app\api\controller
|
||
*/
|
||
class GpsController extends BaseApiController
|
||
{
|
||
public array $notNeedLogin = ['getCarInfo','getCarStatus','getHistory','exportHistory'];
|
||
|
||
private string $authName = 'lihai';
|
||
private string $authPwd = 'a123456';
|
||
private int $expTime = 432000;
|
||
|
||
private function getToken() {
|
||
$gps_token = Cache::get('gps_token');
|
||
if(!empty($gps_token)){
|
||
return $gps_token;
|
||
}
|
||
$url = 'https://www.gpsnow.net/user/login.do';
|
||
$data = [
|
||
'name' => $this->authName,
|
||
'password' => $this->authPwd
|
||
];
|
||
try {
|
||
$result = curl_post($url,[],$data);
|
||
if(!empty($result) && !empty($result['data']['token'])){
|
||
Cache::set('gps_token', $result['data']['token'], $this->expTime);
|
||
return $result['data']['token'];
|
||
|
||
}else{
|
||
return '';
|
||
}
|
||
}catch (\Exception $e) {
|
||
return '';
|
||
}
|
||
}
|
||
|
||
public function getCarInfo() {
|
||
//获取token
|
||
$token = $this->getToken();
|
||
//请求地址
|
||
$url = 'https://www.gpsnow.net/car/getByImei.do';
|
||
//请求参数
|
||
$data = [
|
||
'token' => $token,
|
||
'imei' => '863010000029350'
|
||
];
|
||
$result = curl_post($url,[],$data);
|
||
dump($result);
|
||
}
|
||
|
||
public function getCarStatus() {
|
||
//获取token
|
||
$token = $this->getToken();
|
||
//请求地址
|
||
$url = 'https://www.gpsnow.net/car/getCarAndStatus.do';
|
||
//请求参数
|
||
$data = [
|
||
'token' => $token,
|
||
'carId' => '629942',
|
||
'mapType' => 1
|
||
];
|
||
$result = curl_post($url,[],$data);
|
||
dump($result);
|
||
}
|
||
|
||
public function getHistory() {
|
||
dump(PHP_VERSION);die;
|
||
//获取token
|
||
$token = $this->getToken();
|
||
//请求地址
|
||
$url = 'https://www.gpsnow.net/position/queryHistory.do';
|
||
//请求参数
|
||
$data = [
|
||
'token' => $token,
|
||
'carId' => '629942',
|
||
'startTime' => '2023-08-15 00:00:00',
|
||
'endTime' => '2023-08-15 23:59:59',
|
||
'filter' => true,
|
||
'interval' => 1,
|
||
'pointType' => 2,
|
||
];
|
||
$result = curl_post($url,[],$data);
|
||
dump($result);
|
||
}
|
||
}
|