宝体数据调用接口
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

78 lines
2.3 KiB

<?php
namespace app\task\controller;
use think\Db;
class Passreal
{
/**
* 执行函数
* @return bool
* @throws \think\Exception
* @throws \think\exception\PDOException
*/
public function run()
{
$config = config('api_config');
#Db::table('bt_passenger_flow_real')->where('id','>',1)->delete();
$requestData = [];
try{
$url = $config['host_url'] . "/api/cfas/v3/passenger/realTime";
$dataArr = [
'01' // --- <replace> --- //
];
$token = getAccessToken();
$json_data = json_encode($dataArr);
$result = postToken($url,$json_data,false,[],$token);
$res_data = json_decode($result,true);
$list = (array) $res_data['data'];
foreach ($list as $value) {
$insert_arr = [
'groupId' => $value['groupId'],
'regionId' => $value['regionId'],
'statisticsTime' => $value['statisticsTime'],
'enter' => $value['enter'],
'exit' => $value['exit'],
'pass' => $value['pass'],
'holdValue' => $value['holdValue'],
'allEnter' => $value['allEnter'],
'allExit' => $value['allExit']
];
Db::table('bt_passenger_flow_real')->insert($insert_arr);
$requestData[] = $insert_arr;
}
} catch (\Exception $e) {
exit( $e->getMessage() );
}
if (!empty($requestData)) {
$token = '9c4cb25665cf08667c815420ab383cb5';
$data = [
'data' => json_encode($requestData),
'token' => md5('9c4cb25665cf08667c815420ab383cb5' . date('Ymd'))
];
$json_data = json_encode($data);
$createUrl = $config['host_path'] . '/api/pass.create/bt_passenger_flow_real';
$result = postToken($createUrl,$json_data,false,[],$token);
$result = json_decode($result,true);
if ($result['code'] != 1) exit($result['msg']);
}
return true;
}
}