|
@@ -6,6 +6,7 @@ use App\Http\Controllers\Api\BaseController;
|
|
use Illuminate\Contracts\Support\Renderable;
|
|
use Illuminate\Contracts\Support\Renderable;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Routing\Controller;
|
|
use Illuminate\Routing\Controller;
|
|
|
|
+use Illuminate\Support\Facades\Redis;
|
|
|
|
|
|
class OPCDataTurboController extends BaseController
|
|
class OPCDataTurboController extends BaseController
|
|
{
|
|
{
|
|
@@ -16,8 +17,27 @@ class OPCDataTurboController extends BaseController
|
|
return $this->error(-1, '参数错误');
|
|
return $this->error(-1, '参数错误');
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ $redis_key = $sys_key.'_'.$sys_name;
|
|
|
|
+
|
|
|
|
+ $redis = Redis::connection('default'); //指定连接user配置节点信息
|
|
|
|
+
|
|
|
|
+ $data = $redis->get($redis_key);
|
|
|
|
+ if (isset($data)) {
|
|
|
|
+ return $data;
|
|
|
|
+ } else {
|
|
|
|
+ return $this->error(-1, "接口数据获取错误");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ return $data;
|
|
|
|
+
|
|
|
|
+// $json_data = $this->get_redis_data($redis_key);
|
|
|
|
+
|
|
$db_conf = config('database');
|
|
$db_conf = config('database');
|
|
- $api_url = 'http://'.$db_conf['python_api'][$sys_key]['url'].'/get/?sys_key='.$sys_key.'&sys_name='.$sys_name;
|
|
|
|
|
|
+ $api_key = 'get';
|
|
|
|
+ $api_url = 'http://'.$db_conf['python_api'][$sys_key]['url'].'/'.$api_key.'/?sys_key='.$sys_key.'&sys_name='.$sys_name;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
$response = $this->request_post($api_url);
|
|
$response = $this->request_post($api_url);
|
|
|
|
|
|
@@ -34,23 +54,28 @@ class OPCDataTurboController extends BaseController
|
|
$error_info = '未知错误:'.$response;
|
|
$error_info = '未知错误:'.$response;
|
|
}
|
|
}
|
|
return $this->error($response, $error_info);
|
|
return $this->error($response, $error_info);
|
|
- } else {
|
|
|
|
- $data = json_decode($response);
|
|
|
|
|
|
+ } else if($data = json_decode($response, true)){
|
|
|
|
+
|
|
if ($data == null) {
|
|
if ($data == null) {
|
|
return $this->error(500, preg_replace('/<[^>]*>/','',$response));
|
|
return $this->error(500, preg_replace('/<[^>]*>/','',$response));
|
|
} else {
|
|
} else {
|
|
- return $this->success($data);
|
|
|
|
|
|
+ $arr = $this->data_handling($data);
|
|
|
|
+ return $this->success($arr);
|
|
}
|
|
}
|
|
|
|
+ } else {
|
|
|
|
+ return $this->error(500, '接口服务错误');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+ // 取OPC数据接口
|
|
private function request_post($url = '', $param = '') {
|
|
private function request_post($url = '', $param = '') {
|
|
if (empty($url)) {
|
|
if (empty($url)) {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
$postUrl = $url;
|
|
$postUrl = $url;
|
|
$curlPost = $param;
|
|
$curlPost = $param;
|
|
|
|
+
|
|
$curl = curl_init();//初始化curl
|
|
$curl = curl_init();//初始化curl
|
|
curl_setopt($curl, CURLOPT_URL,$postUrl);//抓取指定网页
|
|
curl_setopt($curl, CURLOPT_URL,$postUrl);//抓取指定网页
|
|
curl_setopt($curl, CURLOPT_HEADER, 0);//设置header
|
|
curl_setopt($curl, CURLOPT_HEADER, 0);//设置header
|
|
@@ -60,15 +85,46 @@ class OPCDataTurboController extends BaseController
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
|
|
|
|
|
-// curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
|
|
|
|
$data = curl_exec($curl);//运行curl
|
|
$data = curl_exec($curl);//运行curl
|
|
$errno = curl_errno($curl);
|
|
$errno = curl_errno($curl);
|
|
curl_close($curl);
|
|
curl_close($curl);
|
|
|
|
+
|
|
if ($errno > 0) return $errno;
|
|
if ($errno > 0) return $errno;
|
|
|
|
|
|
return $data;
|
|
return $data;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private function data_handling($data) {
|
|
|
|
+// $redis = new Redis();
|
|
|
|
+// $redis->connect();
|
|
|
|
+
|
|
|
|
+ $redis = Redis::connection('default'); //指定连接user配置节点信息
|
|
|
|
+
|
|
|
|
+ foreach ($data['sys_point'] as $key => $val) {
|
|
|
|
+ foreach ($val as $k => $v) {
|
|
|
|
+ $data_value = $v['val'];
|
|
|
|
+ $data_key = $v['key'];
|
|
|
|
+ if ($data_value) {
|
|
|
|
+// $userData = $redis->get($data_key);
|
|
|
|
+ $data['sys_point'][$key][$k]['val'] = round($data_value, 2);
|
|
|
|
+ # 数据持久化
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return $data;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private function get_redis_data($key) {
|
|
|
|
+
|
|
|
|
+ $redis = Redis::connection('default'); //指定连接user配置节点信息
|
|
|
|
+ $data = $redis->get($key);
|
|
|
|
+ if (isset($data)) {
|
|
|
|
+ return $data;
|
|
|
|
+ } else {
|
|
|
|
+ return $this->error(-1, "接口数据获取错误");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
/**
|
|
/**
|
|
* Display a listing of the resource.
|
|
* Display a listing of the resource.
|