4 changed files with 0 additions and 635 deletions
@ -1,188 +0,0 @@ |
|||
<?php |
|||
|
|||
if (!function_exists('get_access_token')) { |
|||
|
|||
/** |
|||
* 获取 接口 accessToken |
|||
* @return mixed |
|||
*/ |
|||
function get_access_token(){ |
|||
|
|||
// 记录缓存, 时效2小时分钟 |
|||
$token = get_cache('api_access_token'); |
|||
|
|||
if (empty($token)) { |
|||
$config = config('api_config'); |
|||
// |
|||
$url = $config['host_url']."/oauth/token?client_id=".$config['cid']."&client_secret=".$config['cskey']; |
|||
// do post |
|||
$ret = curl_post($url); |
|||
$res = json_decode($ret,true); |
|||
if ($res['access_token']) { |
|||
set_cache('api_access_token', $res['access_token'], 7200); |
|||
$token = $res['access_token']; |
|||
} |
|||
} |
|||
|
|||
return $token; |
|||
} |
|||
} |
|||
|
|||
if (!function_exists('get_target_date')) { |
|||
/** |
|||
* 获取当前时间日期 |
|||
* @param $granularity // 返回当前日期 all = 所有 |
|||
* @return array |
|||
*/ |
|||
function get_target_date($granularity = 'all') { |
|||
|
|||
$data = []; |
|||
|
|||
if ($granularity === 'day' || $granularity === 'all') { |
|||
$date = $granularity !== 'all' ? $granularity : 'day'; |
|||
$data[$date] = [ |
|||
'start_time' => strtotime('today'), |
|||
'end_time' => strtotime('tomorrow - 1 second'), |
|||
]; |
|||
} |
|||
if ($granularity === 'week' || $granularity === 'all') { |
|||
$date = $granularity !== 'all' ? $granularity : 'week'; |
|||
$data[$date] = [ |
|||
'start_time' => strtotime('this week midnight'), |
|||
'end_time' => strtotime('next week midnight - 1 second'), |
|||
]; |
|||
} |
|||
if ($granularity === 'month' || $granularity === 'all') { |
|||
$date = $granularity !== 'all' ? $granularity : 'month'; |
|||
$data[$date] = [ |
|||
'start_time' => strtotime(date('Y-m-01 00:00:00')), |
|||
'end_time' => strtotime(date('Y-m-t 23:59:59')), |
|||
]; |
|||
} |
|||
if ($granularity === 'year' || $granularity === 'all') { |
|||
$date = $granularity !== 'all' ? $granularity : 'year'; |
|||
$data[$date] = [ |
|||
'start_time' => strtotime('first day of January this year'), |
|||
'end_time' => strtotime('first day of January next year - 1 second'), |
|||
]; |
|||
} |
|||
|
|||
foreach ($data as &$val) { |
|||
$val['c_start_time'] = date("c",$val['start_time']); |
|||
$val['c_end_time'] = date("c",$val['end_time']); |
|||
$val['start_time'] = date("Y-m-d H:i:s",$val['start_time']); |
|||
$val['end_time'] = date("Y-m-d H:i:s",$val['end_time']); |
|||
} |
|||
return $data; |
|||
} |
|||
} |
|||
|
|||
if (!function_exists('get_cache')) { |
|||
|
|||
function get_cache($key){ |
|||
|
|||
|
|||
return ''; |
|||
} |
|||
} |
|||
|
|||
|
|||
if (!function_exists('set_cache')) { |
|||
|
|||
function set_cache($key, $value,$expire_time = 0) |
|||
{ |
|||
|
|||
} |
|||
} |
|||
|
|||
if (!function_exists('config')) { |
|||
/** |
|||
* 获取配置数据 |
|||
* @param $key |
|||
* @return array|mixed |
|||
*/ |
|||
function config($key = 'all') { |
|||
$config = include 'config.php'; |
|||
if ($key == 'all') { |
|||
return $config; |
|||
} else { |
|||
return isset($config[$key]) ? $config[$key] : []; |
|||
} |
|||
} |
|||
} |
|||
|
|||
if (!function_exists('curl_post')) { |
|||
/** |
|||
* curl请求指定url (post) |
|||
* @param $url |
|||
* @param array $data |
|||
* @return mixed |
|||
*/ |
|||
function curl_post($url, $data = []) |
|||
{ |
|||
$ch = curl_init(); |
|||
curl_setopt($ch, CURLOPT_POST, 1); |
|||
curl_setopt($ch, CURLOPT_HEADER, 0); |
|||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|||
curl_setopt($ch, CURLOPT_URL, $url); |
|||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); |
|||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
|||
$result = curl_exec($ch); |
|||
curl_close($ch); |
|||
return $result; |
|||
} |
|||
} |
|||
|
|||
if (!function_exists('post_token')) { |
|||
/** |
|||
* 模拟POST请求 |
|||
* @param string $url 请求地址 |
|||
* @param mixed $data 请求数据 |
|||
* @param false $useCert 是否引入微信支付证书 |
|||
* @param array $sslCert 证书路径 |
|||
* @param string $token 请求token |
|||
* @return bool|mixed|string |
|||
*/ |
|||
function post_token($url, $data = [], $useCert = false, $sslCert = [], $token = '') |
|||
{ |
|||
$header = [ |
|||
'Content-type: application/json;', |
|||
"access_token: {$token}" |
|||
]; |
|||
$curl = curl_init(); |
|||
curl_setopt($curl, CURLOPT_URL, $url); |
|||
curl_setopt($curl, CURLOPT_HTTPHEADER, $header); |
|||
curl_setopt($curl, CURLOPT_HEADER, false); |
|||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); |
|||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); |
|||
curl_setopt($curl, CURLOPT_POST, TRUE); |
|||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data); |
|||
if ($useCert == true) { |
|||
// 设置证书:cert 与 key 分别属于两个.pem文件 |
|||
curl_setopt($curl, CURLOPT_SSLCERTTYPE, 'PEM'); |
|||
curl_setopt($curl, CURLOPT_SSLCERT, $sslCert['certPem']); |
|||
curl_setopt($curl, CURLOPT_SSLKEYTYPE, 'PEM'); |
|||
curl_setopt($curl, CURLOPT_SSLKEY, $sslCert['keyPem']); |
|||
} |
|||
$result = curl_exec($curl); |
|||
if ($result === false) { |
|||
curl_error($curl); |
|||
} |
|||
curl_close($curl); |
|||
return $result; |
|||
} |
|||
} |
|||
|
|||
if (!function_exists('dump')) { |
|||
/** |
|||
* 输出数据 |
|||
* @param $data // 待数据 |
|||
* @param $is_die // 是否停止运行 |
|||
* @return void |
|||
*/ |
|||
function dump($data, $is_die = true) { |
|||
var_dump($data); |
|||
if ($is_die) die; |
|||
} |
|||
} |
|||
|
|||
@ -1,68 +0,0 @@ |
|||
<?php |
|||
// +---------------------------------------------------------------------- |
|||
// | ThinkPHP [ WE CAN DO IT JUST THINK ] |
|||
// +---------------------------------------------------------------------- |
|||
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved. |
|||
// +---------------------------------------------------------------------- |
|||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) |
|||
// +---------------------------------------------------------------------- |
|||
// | Author: liu21st <liu21st@gmail.com> |
|||
// +---------------------------------------------------------------------- |
|||
|
|||
$dm_db = [ |
|||
'host' => 'localhost', |
|||
'database' => 'CXK', |
|||
'username' => 'SYSDBA', |
|||
'password' => 'SYSDBA', |
|||
'port' => '5236', |
|||
'charset' => 'utf8', |
|||
]; |
|||
|
|||
return [ |
|||
// +---------------------------------------------------------------------- |
|||
// | 数据库配置 |
|||
// +---------------------------------------------------------------------- |
|||
|
|||
'database' => [ |
|||
# 达梦数据库 |
|||
'dm' => [ |
|||
// 服务器地址 |
|||
'hostname' => $dm_db['host'], |
|||
// 数据库名 |
|||
'database' => $dm_db['database'], |
|||
// 用户名 |
|||
'username' => $dm_db['username'], |
|||
// 密码 |
|||
'password' => $dm_db['password'], |
|||
// 端口 |
|||
'hostport' => $dm_db['port'], |
|||
// 数据库编码默认采用utf8 |
|||
'charset' => $dm_db['charset'], |
|||
] |
|||
], |
|||
|
|||
// +---------------------------------------------------------------------- |
|||
// | 自定义配置 |
|||
// +---------------------------------------------------------------------- |
|||
'api_config' => [ |
|||
# 调用网址地址 |
|||
'host' => '192.168.66.13', |
|||
# 端口号 |
|||
'port' => '443', |
|||
# 请求key |
|||
'cid' => '29940726', |
|||
# 请求密钥 |
|||
'cskey' => 'SkTCnQdFbNW4Z2suNj8P', |
|||
# 请求智慧景区接口地址 |
|||
'host_url' => 'https://192.168.66.13:443/artemis', |
|||
# 脚本数据推送创建数据地址 |
|||
//'host_path' => 'http://btgym.xingtongworld.com/index.php?s=', |
|||
// 'host_path' => 'http://192.168.66.16/index.php?s=', |
|||
'host_path' => 'http://www.stadium.com/index.php?s=', |
|||
# 允许跨域 请求的IP地址 |
|||
'access_control_allow_origin' => [ |
|||
'http://192.168.66.220:8080', |
|||
'http://192.168.66.220:8081' |
|||
] |
|||
] |
|||
]; |
|||
@ -1,104 +0,0 @@ |
|||
<?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); |
|||
} |
|||
} |
|||
@ -1,275 +0,0 @@ |
|||
<?php |
|||
|
|||
namespace task\module\dm; |
|||
|
|||
class Dm |
|||
{ |
|||
private $host = 'localhost:5236'; // IP 地址 |
|||
private $port = '5236'; // 端口号 |
|||
private $dbname = 'CXK'; // 数据库名 |
|||
private $username = 'SYSDBA'; // 用户名 |
|||
private $password = 'SYSDBA'; // 密码 |
|||
private $charset = 'GBK'; // 字符集 |
|||
|
|||
public $conn; |
|||
public $database = 'STADIUM'; |
|||
public $sql; |
|||
|
|||
public function __construct() |
|||
{ |
|||
# 获取配置数据 |
|||
$database = config('database'); |
|||
$dm = $database['dm']; |
|||
# 模式名称 |
|||
$this->database = $dm['database']; |
|||
# 连接达梦数据库 |
|||
$this->conn = dm_connect($dm['hostname'].':'.$dm['hostport'], $dm['username'], $dm['password']); |
|||
if (!$this->conn) { |
|||
die('连接数据库失败!'); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 拼接达梦查询数据表名 |
|||
* @param string $tableName // 表名 |
|||
* @return string |
|||
*/ |
|||
protected function splitTableName($tableName) { |
|||
if (strpos($tableName,$this->database) !== false) return $tableName; |
|||
return '"' . $this->database . '"."' . $tableName .'"'; |
|||
} |
|||
|
|||
/** |
|||
* 创建数据 |
|||
* @param string $table // 创建数据表名 |
|||
* @param array $data // 创建数据 |
|||
* @return mixed |
|||
*/ |
|||
public function insert($table, $data) |
|||
{ |
|||
$fields = '"' . implode('","', array_keys($data)) . '"'; |
|||
$values = "'" . implode("','", array_values($data)) . "'"; |
|||
$tableName = $this->splitTableName($table); |
|||
$sql = 'INSERT INTO '.$tableName.'('.$fields.') VALUES ('.$values.')'; |
|||
|
|||
$res = dm_exec($this->conn, $sql); |
|||
|
|||
$this->sql = $sql; |
|||
|
|||
dm_free_result($res); |
|||
|
|||
return $res; |
|||
} |
|||
|
|||
/** |
|||
* 更新数据 |
|||
* @param string $table // 更新数据表名 |
|||
* @param array $data // 更新数据 |
|||
* @param string $where // 更新数据条件 |
|||
* @return mixed |
|||
*/ |
|||
public function update($table, $data, $where) |
|||
{ |
|||
$set = array(); |
|||
foreach ($data as $key => $value) { |
|||
$set[] = '"'.$key.'"' . '=' . "'{$value}'"; |
|||
} |
|||
|
|||
$tableName = $this->splitTableName($table); |
|||
$sql = 'UPDATE '.$tableName." SET " . implode(",", $set) . ' WHERE '.$where; |
|||
|
|||
$res = dm_exec($this->conn, $sql); |
|||
|
|||
$this->sql = $sql; |
|||
|
|||
dm_free_result($res); |
|||
|
|||
return $res; |
|||
} |
|||
|
|||
/** |
|||
* 删除数据 |
|||
* @param string $table // 删除数据表名 |
|||
* @param string $where // 删除数据条件 |
|||
* @return mixed |
|||
*/ |
|||
public function delete($table, $where) |
|||
{ |
|||
$tableName = $this->splitTableName($table); |
|||
$sql = 'DELETE FROM '.$tableName.' WHERE '.$where; |
|||
|
|||
$result = dm_exec($this->conn, $sql); |
|||
|
|||
$this->sql = $sql; |
|||
|
|||
dm_free_result($result); |
|||
|
|||
return $result; |
|||
} |
|||
|
|||
/** |
|||
* 清空表 |
|||
* @param string $table // 清空表名 |
|||
* @return mixed |
|||
*/ |
|||
public function truncate($table) |
|||
{ |
|||
|
|||
$tableName = $this->splitTableName($table); |
|||
$sql = 'truncate table '.$tableName; |
|||
|
|||
$result = dm_exec($this->conn, $sql); |
|||
|
|||
$this->sql = $sql; |
|||
|
|||
dm_free_result($result); |
|||
|
|||
return $result; |
|||
} |
|||
|
|||
/** |
|||
* 查询多条数据 |
|||
* @param string $table // 查询表名 |
|||
* @param string $where // 查询条件 |
|||
* @param string $fields // 查询字段 |
|||
* @param string $order // 查询排序 |
|||
* @param string $limit // 查询条数 |
|||
* @param string $group // 查询分组 |
|||
* @return array // 返回数组 |
|||
*/ |
|||
public function select($table, $where = null, $fields = '*', $order = null, $limit = null, $group = null) |
|||
{ |
|||
$tableName = $this->splitTableName($table); |
|||
$sql = 'SELECT '.$fields.' FROM '.$tableName; |
|||
if ($where != null) { |
|||
$sql .= ' WHERE '.$where; |
|||
} |
|||
if ($group != null) { |
|||
$sql .= ' GROUP BY '.$group; |
|||
} |
|||
if ($order != null) { |
|||
$sql .= ' ORDER BY '.$order; |
|||
} |
|||
if ($limit != null) { |
|||
$sql .= ' LIMIT '.$limit; |
|||
} |
|||
|
|||
$result = dm_exec($this->conn, $sql); |
|||
|
|||
$this->sql = $sql; |
|||
|
|||
$data = array(); |
|||
|
|||
while ($row = dm_fetch_array($result)) { |
|||
$data[] = $row; |
|||
} |
|||
|
|||
dm_free_result($result); |
|||
|
|||
return $data; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 查询单条数据 |
|||
* @param string $table // 查询表名 |
|||
* @param string $where // 查询条件 |
|||
* @param string $fields // 查询字段 |
|||
* @param string $order // 查询排序 |
|||
* @return array // 返回数组 |
|||
*/ |
|||
public function find($table, $where = null, $fields = '*', $order = null) |
|||
{ |
|||
$tableName = $this->splitTableName($table); |
|||
$sql = 'SELECT '.$fields.' FROM '.$tableName; |
|||
if ($where != null) { |
|||
$sql .= ' WHERE '.$where; |
|||
} |
|||
if ($order != null) { |
|||
$sql .= ' ORDER BY '.$order; |
|||
} |
|||
$sql .= ' LIMIT 1'; |
|||
|
|||
|
|||
$result = dm_exec($this->conn, $sql); |
|||
|
|||
$this->sql = $sql; |
|||
|
|||
$data = array(); |
|||
|
|||
while ($row = dm_fetch_array($result)) { |
|||
$data = $row; |
|||
} |
|||
|
|||
dm_free_result($result); |
|||
|
|||
return $data; |
|||
} |
|||
|
|||
/** |
|||
* 查询数据总数 |
|||
* @param string $table // 查询表名 |
|||
* @param string $where // 查询条件 |
|||
* @return array // 返回数组 |
|||
*/ |
|||
public function count($table, $where = null) |
|||
{ |
|||
$tableName = $this->splitTableName($table); |
|||
$sql = 'SELECT COUNT(*) as count FROM '.$tableName; |
|||
|
|||
if ($where != null) { |
|||
$sql .= ' WHERE '.$where; |
|||
} |
|||
|
|||
$result = dm_exec($this->conn, $sql); |
|||
|
|||
$this->sql = $sql; |
|||
|
|||
$count = 0; |
|||
|
|||
while ($row = dm_fetch_array($result)) { |
|||
$count = $row['COUNT']; |
|||
} |
|||
|
|||
dm_free_result($result); |
|||
|
|||
return $count; |
|||
} |
|||
|
|||
/** |
|||
* 获取上次执行数据Sql |
|||
* @return mixed |
|||
*/ |
|||
public function getLastSql() |
|||
{ |
|||
return $this->sql; |
|||
} |
|||
|
|||
/** |
|||
* @param $table |
|||
* @param $where |
|||
* @param $fields |
|||
* @param $order |
|||
* @param $limit |
|||
* @param $page |
|||
* @return array |
|||
*/ |
|||
public function getPaginate($table, $where = null, $fields = '*', $order = null, $limit = 10, $page = 1) |
|||
{ |
|||
# 查询条数 |
|||
$pageLimit = ($page - 1) * $limit; |
|||
# 总数 |
|||
$total = $this->count($table); |
|||
# 数据 |
|||
$list = $this->select($table,$where,$fields,$order,$pageLimit.','.$limit); |
|||
# 计算总页数 |
|||
$totalPages = ceil($total / $limit); |
|||
# 组合分页按钮 |
|||
$pageData = $totalPages >= 2 ? get_paginate($totalPages,$page,'/?s=/admin/pass.pass/index') : ''; |
|||
|
|||
return [ |
|||
'list' => $list ?: [], |
|||
'pageData' => $pageData, |
|||
]; |
|||
} |
|||
} |
|||
Loading…
Reference in new issue