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.
104 lines
3.1 KiB
104 lines
3.1 KiB
<?php
|
|
|
|
namespace task\module\Pass;
|
|
|
|
use task\module\dm\Dm;
|
|
|
|
class Pass
|
|
{
|
|
/**
|
|
* 请求创建数据
|
|
* @param $requestData
|
|
* @param $url
|
|
* @param $host_path
|
|
* @return array|int[]
|
|
*/
|
|
public static function requestCreateData($requestData,$url,$host_path = '')
|
|
{
|
|
# 验证传输数据
|
|
if (empty($requestData) && is_array($requestData)) return ['status' => 0, 'msg' => 'requestData不能为空,且必须是数组'];
|
|
if (empty($url)) return ['status' => 0, 'msg' => 'url不能为空'];
|
|
# 获取请求路径
|
|
if (empty($host_path)) {
|
|
$config = config('api_config');
|
|
$host_path = $config['host_path'];
|
|
}
|
|
# 验证令牌
|
|
$token = '9c4cb25665cf08667c815420ab383cb5';
|
|
# 请求接口数据
|
|
$data = [
|
|
'data' => base64_encode(json_encode($requestData)),
|
|
'token' => md5($token . date('Ymd'))
|
|
];
|
|
$json_data = json_encode($data);
|
|
$createUrl = $host_path . $url;
|
|
# 发起请求
|
|
$result = post_token($createUrl,$json_data,false,[],$token);
|
|
$result = json_decode($result,true);
|
|
# 判断返回信息
|
|
if ($result['code'] != 1) return ['status' => 0, 'msg' => $result['msg']];
|
|
return ['status' => 1];
|
|
}
|
|
|
|
/**
|
|
* 获取统计组ID
|
|
* @param $dataType // 1 返回字符串 2 返回数组
|
|
* @return array|string
|
|
*/
|
|
public static function getGroupIds($dataType)
|
|
{
|
|
include '../module/dm/Dm.php';
|
|
$dm = new Dm();
|
|
$groupRes = $dm->select('bt_passenger_monitor_group',null,'"groupId"');
|
|
$groupIdArr = array_column($groupRes,'groupId') ?: [];
|
|
return $dataType == 2 ? $groupIdArr : implode(",",$groupIdArr);
|
|
}
|
|
|
|
/**
|
|
* 获取实时统计组id
|
|
* @param $config
|
|
* @param $token
|
|
* @param $dataType
|
|
* @return array|string
|
|
*/
|
|
public static function getRealGroupIds($config,$token,$dataType)
|
|
{
|
|
$url = $config['host_url'] . "/api/cfas/v2/countGroup/groups/page";
|
|
$pageNo = 1;
|
|
$pageSize = 1;
|
|
|
|
$groupIdArr = [];
|
|
while (1) {
|
|
|
|
$dataArr = [
|
|
"regionId"=> "root000000",
|
|
"isCascade"=> 1,
|
|
"groupType"=> 0,
|
|
"statType"=> 0,
|
|
"pageNo"=> $pageNo,
|
|
"pageSize"=> $pageSize
|
|
];
|
|
|
|
$json_data = json_encode($dataArr);
|
|
$result = post_token($url,$json_data,false,[],$token);
|
|
$res_data = json_decode($result,true);
|
|
|
|
# 存在错误结束循环
|
|
if ($res_data['code'] != 0) break;
|
|
# 数据不存在结束循环
|
|
$list = (array)$res_data['data']['list'];
|
|
if (empty($list)) break;
|
|
|
|
foreach ($list as $value) {
|
|
|
|
$groupIdArr[] = $value['groupId'];
|
|
}
|
|
|
|
# 总条数不够结束循环
|
|
if (count($list) < $pageSize) break;
|
|
++$pageNo;
|
|
}
|
|
|
|
return $dataType == 2 ? $groupIdArr : implode(",",$groupIdArr);
|
|
}
|
|
}
|