宝体数据调用接口
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.
 
 
 
 
 
 

136 lines
5.0 KiB

<?php
namespace app\controller;
use app\BaseController;
class Index extends BaseController
{
public function index()
{
return phpinfo();
//return '<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }</style><div style="padding: 24px 48px;"> <h1>:) </h1><p> ThinkPHP V' . \think\facade\App::version() . '<br/><span style="font-size:30px;">14载初心不改 - 你值得信赖的PHP框架</span></p><span style="font-size:25px;">[ V6.0 版本由 <a href="https://www.yisu.com/" target="yisu">亿速云</a> 独家赞助发布 ]</span></div><script type="text/javascript" src="https://tajs.qq.com/stats?sId=64890268" charset="UTF-8"></script><script type="text/javascript" src="https://e.topthink.com/Public/static/client.js"></script><think id="ee9b1aa918103c4fc"></think>';
}
public function hello($name = 'ThinkPHP6')
{
return 'hello,' . $name;
}
public function getAccessToken(){
$config = config('app');
//
$url = $config['host_url']."/oauth/token?client_id=".$config['cid']."&client_secret=".$config['cskey'];
// do post
$ret = post($url);
return $ret;
}
/**
* 总览总数据接口
* @return array
*/
public function allGroupNum() {
$config = config('app');
$dayStatTime = date('c',strtotime(date("Y-m-d 00:00:00")));
$monday = date('Y-m-d 00:00:00', strtotime("last Monday", strtotime(date('Y-m-d'))));
$weekStatTime = date('c',strtotime($monday));
$monthStatTime = date('c',strtotime(date("Y-m-01 00:00:00")));
$dateArr = ['day' => $dayStatTime, 'week' => $weekStatTime, 'month' => $monthStatTime];
$returnData = [];
foreach ($dateArr as $date => $statTime) {
$url = $config['host_url'] . "/api/cfas/v2/passengerFlow/allGroup";
$granularity = $date == 'month' ? 'monthly' : 'daily';
$data = [
'granularity' => $granularity,
'statTime' => $statTime
];
$json_data = json_encode($data);
$result = postToken($url,$json_data,false,[],'60NDtZnTUiPtXEFC2MAszjZ9fbedfBTQ');
$res_data = json_decode($result,true);
if ($res_data['code'] != 0) {
return ['code' => 404, 'msg' => $res_data['msg']];
}
$list = $res_data['data']['list'];
$returnData[$date]['flowInNum'] = 0;
foreach ($list as $value) {
$returnData[$date]['flowInNum'] += $value['flowInNum'];
}
}
return ['code' => 0, 'data' => $returnData];
}
/**
* 进馆人数趋势
* @return array|void
*/
public function groups() {
$config = config('app');
$dayStatTime = date('c',strtotime(date("Y-m-d 00:00:00")));
$monday = date('Y-m-d 00:00:00', strtotime("last Monday", strtotime(date('Y-m-d'))));
$weekStatTime = date('c',strtotime($monday));
$monthStatTime = date('c',strtotime(date("Y-m-01 00:00:00")));
$dateArr = [
'day' => [
'startTime' => $dayStatTime,// 当天开始时间
'endTime' => date('c',strtotime(date("Y-m-d 23:59:59"))),// 当天结束时间
],
'week' => [
'startTime' => $weekStatTime,
'endTime' => date('c',strtotime(date("Y-m-d 23:59:59"))),
],
'month' =>[
'startTime' => $monthStatTime,
'endTime' => date('c',strtotime(date("Y-m-t 23:59:59")))
]
];
$returnData = [];
foreach ($dateArr as $date => $dateTime) {
$url = $config['host_url'] . "/api/cfas/v2/passengerFlow/groups";
$granularity = $date == 'month' ? 'monthly' :'daily';
$data = [
'granularity' => $granularity,
'startTime' => $dateTime['startTime'],
'endTime' => $dateTime['endTime'],
'ids' => '01'
];
$json_data = json_encode($data);
$result = postToken($url,$json_data,false,[],'60NDtZnTUiPtXEFC2MAszjZ9fbedfBTQ');
$res_data = json_decode($result,true);
if ($res_data['code'] != 0) {
return ['code' => 404, 'msg' => $res_data['msg']];
}
$list = $res_data['data']['list'];
$returnData[$date]['flowInNum'] = 0;
foreach ($list as $value) {
// $createTime = date("H",$value['createTime'] /1000 + (3600*8));
$returnData[$date]['flowInNum'] += $value['flowInNum'];
}
$returnData['sumNum'] += $returnData[$date]['flowInNum'];
}
return $returnData;
}
}