1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363 |
- <?php
- namespace app\admin\controller;
- use think\Controller;
- use think\Session;
- use think\Db;
- use think\Request;
- use think\Log;
- class Manage extends Controller
- {
- private $host="https://device.api.ct10649.com:8743/";
- private $appId="wvdOfp7JVe0ULwnFKwBF0edfbcAa";
- private $secret="Bihoe_rY9vebXMw6sFfpQy0jiRca";
- public function index(){
- $data_list =Db::table('managelog')->paginate();
- $pages = $data_list->render();
- $this->assign('data_list', $data_list);
- $this->assign('pages', $pages);
- //所有的服务类型
- $SetType=[
- 1=>"读取模块信息",
- 2=>"读取参数",
- 3=>"设置IOT平台IP地址",
- 4=>"设置参数",
- 5=>"复位模块",
- 6=>"配置下行波特率",
- 7=>"读取下行波特率配置",
- 8=>"设置DTU自动采集指令",
- 9=>"读取DTU自动采集指令",
- 10=>"设置APN",
- 11=>"读取APN设置",
- 12=>"AT指令",
- /* [1,"读取模块信息"],[2,"读取参数"],[3,"设置IOT平台IP地址"],[4,"设置参数"],[5,"复位模块"],[6,"配置下行波特率"],
- [7,"读取下行波特率配置"],[8,"设置DTU自动采集指令"],[9,"读取DTU自动采集指令"],[10,"设置APN"],[11,"读取APN设置"],
- [12,"AT指令"]*/
- ];
- $this->assign('SetType',$SetType);
-
- return $this->fetch();
- }
- //下发命令
- public function add(){
- if ($this->request->isPost()) {
- $data=input('');
- $list = array();
- if (is_array($data)) {
- $list['data'] = json_encode($data, 320);
- $getdata = json_decode($list['data'], true);//转成数组
- $list['type'] = 1;
- } else {
- $list['data'] = $data;
- $getdata = json_decode($list['data'], true);//转成数组
- $list['type'] = 2;
- }
- $json_string = json_encode($getdata, JSON_FORCE_OBJECT);
- Log::record('rawData:' .$json_string );
- $paras = array();
- $upData = array();
- if(!empty($getdata["dataType"])){
- if($getdata['dataType']=="setting"){
- $sql6="select * from sp_owner where id ={$getdata['sensorId']}";
- $longHuOwner = add($sql6);
- if ($longHuOwner[0]['s_interval']==7){
- $imei='&imei='.$longHuOwner[0]['owner_code'];
- if($longHuOwner[0]['dwtype']==2){
- $deviceType=1;
- }elseif ($longHuOwner[0]['dwtype']==5){
- $deviceType=2;
- }
- $sendata['imei']=$longHuOwner[0]['owner_code'];
- $sendata['deviceType']=$deviceType;
- $sendingGap = '';
- if (!empty($getdata["sendTime"])){
- if($getdata['sendTime']<1800) {
- $sendingGap = '&sendingGap=1800';
- $upData['send_time'] = 1800;
- $sendata['sendingGap']=1800;
- }else{
- $sendingGap = '&sendingGap='.$getdata["sendTime"];
- $upData['send_time'] = $getdata["sendTime"];
- $sendata['sendingGap']=$getdata["sendTime"];
- }
- }
- $unipathThresholdLimit = '';
- if (!empty($getdata["lowThreshold"])){
- $sendata['unipathThresholdLimit'] = $getdata["lowThreshold"]*1000;
- $upData['low_threshold'] = $getdata['lowThreshold'];
- }
- $unipathThresholdUpper = '';
- if (!empty($getdata["highThreshold"])){
- $sendata['unipathThresholdUpper'] = $getdata["highThreshold"]*1000;
- $upData['high_threshold'] = $getdata['highThreshold'];
- }
- $header=[
- "Content-Type:application/json"
- ];
- $rescurl=$this->s_curl("https://api.topsailiot.com/dmp/deviceConfig?appkey=3a3e533818a9604dfec0388b2d817dbc2f9f7b05dd4b153c403897cd93a9c04d0edfe3d86ebd3ad0&userid=TS2020120110122980052",json_encode($sendata),$header);
- // $rep_url = "https://api.topsailiot.com/dmp/deviceConfig?appkey=3a3e533818a9604dfec0388b2d817dbc2f9f7b05dd4b153c403897cd93a9c04d0edfe3d86ebd3ad0&userid=TS2020120110122980052".$imei.$deviceType.$sendingGap.$unipathThresholdLimit.$unipathThresholdUpper;
- // $res = $this->s_curl($rep_url,'');
- Log::record('longhulorasend' . ':' . json_encode($sendata));
- Log::record('longhuloraresult' . ':' . $rescurl);
- // if (is_array($rescurl)) {
- //
- // }else{}
- $resArr = json_decode($rescurl,true);
- if ($resArr['code']==0){
- $deviceConfigure = Db::name('deviceConfigure')->where('device_code', trim($longHuOwner[0]['owner_code']))->find();
- if (!empty($deviceConfigure['device_code'])) {
- sleep(1);
- $upDataRes = Db::name('deviceConfigure')->where('device_code', trim($longHuOwner[0]['owner_code']))->update($upData);
- }else{
- sleep(1);
- $upData['device_code'] = $longHuOwner[0]['owner_code'];
- $insertRes = Db::name('deviceConfigure')->insertGetId($upData);
- }
- }
- return $rescurl;
- }else{
- $deviceCode = '';
- $deviceArr = str_split($longHuOwner[0]['owner_code'],1);
- for ($i=0;$i<count($deviceArr);$i++){
- $deviceCode.='3'.$deviceArr[$i];
- }
- $deviceCode = $deviceCode.'30';
- $sendingInterval = "";//发送间隔
- if (!empty($getdata['sendTime'])) {
- if($getdata['sendTime']<1800){
- $sendingInterval = "020400000708";
- $upData['send_time'] = 1800;
- }else{
- $liuSendTime1 = dechex($getdata['sendTime']);
- $liuSendTime = str_pad($liuSendTime1,8,0,STR_PAD_LEFT);
- $sendingInterval = "0204".$liuSendTime;
- $upData['send_time'] = $getdata['sendTime'];
- }
- }
- $lowThreshold = "";//告警下限
- if (!empty($getdata['lowThreshold'])) {
- $shiLowThreshold = $getdata['lowThreshold']*1000;
- $liuLowThreshold1 = dechex($shiLowThreshold);
- $liuLowThreshold = str_pad($liuLowThreshold1,4,0,STR_PAD_LEFT);
- $lowThreshold = "0602".$liuLowThreshold;
- $upData['low_threshold'] = $getdata['lowThreshold'];
- }
- $highThreshold = "";//告警上限
- if (!empty($getdata['highThreshold'])) {
- $shiHighThreshold = $getdata['highThreshold']*1000;
- $liuHighThreshold1 = dechex($shiHighThreshold);
- $liuHighThreshold = str_pad($liuHighThreshold1,4,0,STR_PAD_LEFT);
- $highThreshold = "0702".$liuHighThreshold;
- $upData['high_threshold'] = $getdata['highThreshold'];
- }
- if($longHuOwner[0]['dwtype']==2){
- $dwType = "01";
- }elseif ($longHuOwner[0]['dwtype']==5){
- $dwType = "02";
- }
- $shiLength = strlen($dwType.$deviceCode.$sendingInterval.$lowThreshold.$highThreshold)/2;
- $liuLength = dechex($shiLength);
- $length = str_pad($liuLength,4,0,STR_PAD_LEFT);
- //调用电信接口
- $token=json_decode(gettoken(),true);
- $a = "7470736c04".$length.$dwType.$deviceCode.$sendingInterval.$lowThreshold.$highThreshold;
- $s = pack('H*',$a);
- $t = crc166($s);
- $t = unpack("H*", $s.$t);
- $paras['value'] = $t[1]."696f74";
- // $t = crc16($paras['value'],0X1021,0Xffff,0X0000,false,false);
- $device = Db::name('device')->where('device_id', trim($longHuOwner[0]['owner_code']))->find();
- $sendata=[
- "appId"=>$this->appId,
- "deviceId"=>$device['iot_id'],// c448d5e3-2ec5-4e42-99d7-0ad27668614f 137effbe-4980-4719-a768-0ae301fc5000
- "command"=>[
- "serviceId"=>"topsailSensorData",
- "method"=>"SET_DEVICE_LEVEL",
- "paras"=>$paras
- ],
- "callbackUrl"=>"http://iot.usky.cn:80/ytapi/admin/Manage/status",
- ];
- $header=[
- "Content-Type:application/json",
- "app_key:".$this->appId,
- "Authorization:Bearer ".$token["accessToken"]
- ];
- $rescurl=curl($this->host."iocm/app/cmd/v1.4.0/deviceCommands",json_encode($sendata),$header);
- // var_dump($rescurl);
- Log::record('nbmanage1:' .$rescurl[0].$sendata['command']['paras']['value'] );
- if($rescurl[0]==201){//成功
- $res1=json_decode($rescurl[1],true);
- // var_dump($res1);
- }else{//失败
- // $res2=json_decode($res1[1],true);
- // return $this->error($rescurl[1]);
- Log::record('nbmanageerror:' .json_encode($this->error($rescurl[1])));
- $returnInformation['code'] = 60001;
- $returnInformation['msg'] = "操作失败,请联系管理员";
- return json_encode($returnInformation);
- }
- }
- }else if($getdata['dataType']=="bendi"){
- $deviceCode = '';
- $deviceArr = str_split($getdata['IMEI'],1);
- for ($i=0;$i<count($deviceArr);$i++){
- $deviceCode.='3'.$deviceArr[$i];
- }
- $deviceCode = $deviceCode.'30';
- //调用电信接口
- $collectionInterval = "";//发送间隔
- if (!empty($getdata['collectionTime'])) {
- $liuCollectionTime1 = dechex($getdata['collectionTime']);
- $liuCollectionTime = str_pad($liuCollectionTime1,8,0,STR_PAD_LEFT);
- $collectionInterval = "0104".$liuCollectionTime;
- }
- $sendingInterval = "";//发送间隔
- if (!empty($getdata['sendTime'])) {
- $liuSendTime1 = dechex($getdata['sendTime']);
- $liuSendTime = str_pad($liuSendTime1,8,0,STR_PAD_LEFT);
- $sendingInterval = "0204".$liuSendTime;
- }
- $lowThreshold = "";//告警下限
- if (!empty($getdata['alarmLowerLimit'])) {
- $shiLowThreshold = $getdata['alarmLowerLimit']*1000;
- $liuLowThreshold1 = dechex($shiLowThreshold);
- $liuLowThreshold = str_pad($liuLowThreshold1,4,0,STR_PAD_LEFT);
- $lowThreshold = "0602".$liuLowThreshold;
- }
- $highThreshold = "";//告警上限
- if (!empty($getdata['alarmUpperLimit'])) {
- $shiHighThreshold = $getdata['alarmUpperLimit']*1000;
- $liuHighThreshold1 = dechex($shiHighThreshold);
- $liuHighThreshold = str_pad($liuHighThreshold1,4,0,STR_PAD_LEFT);
- $highThreshold = "0702".$liuHighThreshold;
- }
- if($getdata['deviceType']==2){
- $dwType = "01";
- }elseif ($getdata['deviceType']==5){
- $dwType = "02";
- }
- $shiLength = strlen($dwType.$deviceCode.$collectionInterval.$sendingInterval.$lowThreshold.$highThreshold)/2;
- $liuLength = dechex($shiLength);
- $length = str_pad($liuLength,4,0,STR_PAD_LEFT);
- //调用电信接口
- $token=json_decode(gettoken(),true);
- $a = "7470736c04".$length.$dwType.$deviceCode.$collectionInterval.$sendingInterval.$lowThreshold.$highThreshold;
- $s = pack('H*',$a);
- $t = crc166($s);
- $t = unpack("H*", $s.$t);
- $paras['value'] = $t[1]."696f74";
- $sendata=[
- "appId"=>$this->appId,
- "deviceId"=>$getdata['deviceId'],// c448d5e3-2ec5-4e42-99d7-0ad27668614f 137effbe-4980-4719-a768-0ae301fc5000
- "command"=>[
- "serviceId"=>"topsailSensorData",
- "method"=>"SET_DEVICE_LEVEL",
- "paras"=>$paras
- ],
- "callbackUrl"=>"http://iot.usky.cn:80/ytapi/admin/Manage/status",
- ];
- $header=[
- "Content-Type:application/json",
- "app_key:".$this->appId,
- "Authorization:Bearer ".$token["accessToken"]
- ];
- $rescurl=curl($this->host."iocm/app/cmd/v1.4.0/deviceCommands",json_encode($sendata),$header);
- var_dump($rescurl);
- Log::record('nbmanage1:' .$rescurl[0].$sendata['command']['paras']['value'] );
- if($rescurl[0]==201){//成功
- $res1=json_decode($rescurl[1],true);
- // var_dump($res1);
- }else{//失败
- // $res2=json_decode($res1[1],true);
- return $this->error($rescurl[1]);
- }
- }else{
- $returnInformation['code'] = 60001;
- $returnInformation['msg'] = "操作失败,请联系管理员";
- return json_encode($returnInformation);
- }
- }else{
- $returnInformation['code'] = 60001;
- $returnInformation['msg'] = "操作失败,请联系管理员";
- return json_encode($returnInformation);
- }
- //将请求的结果存入managelog中
- $list=array();
- $list['commandId']=$res1['commandId'];
- $list['deviceId']=$res1['deviceId'];
- $list['status']=$res1['status'];
- $list['command']= json_encode($res1['command'],320) ;
- if($getdata['dataType']=="setting"){
- $list['IMEI']=$longHuOwner[0]['owner_code'];
- }else{
- $list['IMEI']=$getdata['IMEI'];
- }
- $list['HexStr']=json_encode($upData,320) ;;
- $list['settype']="";
- $list['addtime']= date('Y-m-d H:i:s');
- $res = Db::name('managelog')->insertGetId($list);//将推送的数据存入总表
- if($res) {
- $returnInformation['code'] = 200;
- $returnInformation['msg'] = "操作成功";
- if($getdata['dataType']=="setting"){
- return json_encode($returnInformation);
- }else{
- return $this->success('添加成功','index');
- }
- }else{
- $returnInformation['code'] = 60001;
- $returnInformation['msg'] = "操作失败,请联系管理员";
- if($getdata['dataType']=="setting"){
- return json_encode($returnInformation);
- }else{
- return $this->error("添加失败,请稍后再试");
- }
- }
- }
- if($this->request->isGet()){
- $deviceId=input('deviceId');
- $IMEI=input('IMEI');
- //所有的服务类型
- $SetType=[
- [1,"读取模块信息"],[2,"读取参数"],[3,"设置IOT平台IP地址"],[4,"设置参数"],[5,"复位模块"],[6,"配置下行波特率"],
- [7,"读取下行波特率配置"],[8,"设置DTU自动采集指令"],[9,"读取DTU自动采集指令"],[10,"设置APN"],[11,"读取APN设置"],
- [12,"AT指令"]
- ];
- $this->assign('SetType',$SetType);
- $this->assign('deviceId',$deviceId);
- $this->assign('IMEI', $IMEI);
- return $this->fetch();
- }
- }
- public function status(){
- $data=input('');
-
- if(is_array($data)){
- $getdata= json_encode($data,320);
- $getdata=json_decode($getdata,true);//转成数组
- $list['type']=1;
-
- }else{
- $getdata=$data;
- $getdata=json_decode($getdata,true);//转成数组
- $list['type']=2;
- }
- $list=array();
- $list['deviceId']=$getdata['deviceId'];
- $list['commandId']=$getdata['commandId'];
- $list['resultCode']=$getdata['result']['resultCode'];
- $list['result']= json_encode($getdata['result'],320) ;
- $list['addtime']= date('Y-m-d H:i:s');
- $res = Db::name('managedata')->insertGetId($list);//将推送的数据存入总表
- if($getdata['result']['resultCode']=='SENT'||$getdata['result']['resultCode']=='TIMEOUT'||$getdata['result']['resultCode']=='DELIVERED'||$getdata['result']['resultCode']=='SUCCESSFUL'){
- $device = Db::name('device')->where('iot_id', trim($getdata['deviceId']))->find();
- $deviceConfigure = Db::name('deviceConfigure')->where('device_code', trim($device['device_id']))->find();
- $managelog = Db::name('managelog')->where('commandId', trim($getdata['commandId']))->find();
- $upData = json_decode($managelog['HexStr'],true);
- if (!empty($deviceConfigure['device_code'])) {
- sleep(1);
- $upDataRes = Db::name('deviceConfigure')->where('device_code', trim($device['device_id']))->update($upData);
- }else{
- sleep(1);
- $upData['device_code'] = $device['device_id'];
- $insertRes = Db::name('deviceConfigure')->insertGetId($upData);
- }
- }
- echo 111;
- }
- public function delete(){
- echo 111;
- }
- public function manualPush(){
- $data=input('');
- if(is_array($data)){
- $getdata= json_encode($data,320);
- $getdata=json_decode($getdata,true);//转成数组
- $list['type']=1;
- }else{
- $getdata=$data;
- $getdata=json_decode($getdata,true);//转成数组
- $list['type']=2;
- }
- if ($getdata['deviceType']==2){
- $sql6="select * from sp_sj2017 where device_code ='{$getdata["deviceCode"]}'";
- $longHuOwner = add($sql6);
- Log::record('yangpuxiaoyuan12' . ':' . $longHuOwner[0]["id"]);
- foreach ($longHuOwner as $row) {
- $waterData["SubType"] = 2;
- $waterData["DeviceId"] = $getdata["deviceCode"];
- $waterData["InsertId"] = $row["id"];
- $waterData["Confirmed"] = false;
- $data6 = json_encode($waterData);
- $rep_url = "http://47.98.201.187:55335/report";
- $res = $this->ypxycurl($rep_url, $data6);
- Log::record('yangpuxiaoyuan' . ':' . $res);
- sleep(1);
- }
- }
- // $list=array();
- // $list['deviceId']=$getdata['deviceId'];
- // $list['commandId']=$getdata['commandId'];
- // $list['resultCode']=$getdata['result']['resultCode'];
- // $list['result']= json_encode($getdata['result'],320) ;
- // $list['addtime']= date('Y-m-d H:i:s');
- // $res = Db::name('managedata')->insertGetId($list);//将推送的数据存入总表
- // if($getdata['result']['resultCode']=='SENT'||$getdata['result']['resultCode']=='TIMEOUT'||$getdata['result']['resultCode']=='DELIVERED'||$getdata['result']['resultCode']=='SUCCESSFUL'){
- // $device = Db::name('device')->where('iot_id', trim($getdata['deviceId']))->find();
- // $deviceConfigure = Db::name('deviceConfigure')->where('device_code', trim($device['device_id']))->find();
- // $managelog = Db::name('managelog')->where('commandId', trim($getdata['commandId']))->find();
- // $upData = json_decode($managelog['HexStr'],true);
- // if (!empty($deviceConfigure['device_code'])) {
- // sleep(1);
- // $upDataRes = Db::name('deviceConfigure')->where('device_code', trim($device['device_id']))->update($upData);
- // }else{
- // sleep(1);
- // $upData['device_code'] = $device['device_id'];
- // $insertRes = Db::name('deviceConfigure')->insertGetId($upData);
- // }
- // }
- echo 111;
- }
- // public function alarmHandling(){
- // $data=input('');
- // if(is_array($data)){
- // $getDataJson= json_encode($data,320);
- // $getdata=json_decode($getDataJson,true);//转成数组
- //// $list['type']=1;
- //
- // }else{
- // $getDataJson=$data;
- // $getdata=json_decode($getDataJson,true);//转成数组
- //// $list['type']=2;
- //
- // }
- // Log::record('yangpuerqi' . ':' .$getDataJson);
- // if (!empty($getdata['userName']) && !empty($getdata['userPassword'])){
- // if ($getdata["userName"]=="ypsgec" && $getdata["userPassword"]=="ypsgec123"){
- // if (empty($getdata['recordId'])){
- // $returnInformation['code'] = 60001;
- // $returnInformation['msg'] = "操作失败,缺少记录Id";
- // return json_encode($returnInformation);
- // }elseif (empty($getdata['deviceCode'])){
- // $returnInformation['code'] = 60001;
- // $returnInformation['msg'] = "操作失败,缺少设备编号";
- // return json_encode($returnInformation);
- // }elseif (empty($getdata['deviceType'])){
- // $returnInformation['code'] = 60001;
- // $returnInformation['msg'] = "操作失败,缺少设备类型";
- // return json_encode($returnInformation);
- // }elseif (is_int($getdata['confirmAll'])==true&&$getdata['confirmAll']!=0&&$getdata['confirmAll']!=1){
- // $returnInformation['code'] = 60001;
- // $returnInformation['msg'] = "操作失败,缺少是否批量处理类型";
- // return json_encode($returnInformation);
- // }elseif ($getdata['misinformation']!=0&&$getdata['misinformation']!=1){
- // $returnInformation['code'] = 60001;
- // $returnInformation['msg'] = "操作失败,缺少是否误报字段";
- // return json_encode($returnInformation);
- // }elseif (empty($getdata['handlerName'])){
- // $returnInformation['code'] = 60001;
- // $returnInformation['msg'] = "操作失败,缺少处理人姓名";
- // return json_encode($returnInformation);
- // }elseif (empty($getdata['handlerPhone'])){
- // $returnInformation['code'] = 60001;
- // $returnInformation['msg'] = "操作失败,缺少处理人联系方式";
- // return json_encode($returnInformation);
- // }else{
- // $returnInformation['code'] = 0;
- // $returnInformation['msg'] = "操作成功";
- // return json_encode($returnInformation);
- // }
- //
- //
- //
- //
- //
- //
- //
- // }else{
- // $returnInformation['code'] = 60002;
- // $returnInformation['msg'] = "操作失败,用户名或密码错误";
- // return json_encode($returnInformation);
- // }
- // }else{
- // $returnInformation['code'] = 60002;
- // $returnInformation['msg'] = "操作失败,用户名或密码为空";
- // return json_encode($returnInformation);
- // }
- // }
- public function deviceList(){
- $data=input('');
- if(is_array($data)){
- $getDataJson= json_encode($data,320);
- $getdata=json_decode($getDataJson,true);//转成数组
- }else{
- $getDataJson=$data;
- $getdata=json_decode($getDataJson,true);//转成数组
- }
- $clientIp=$this->ip();
- Log::record('yangpuerqi_deviceList' . ':' .'<<<'.$clientIp.'>>>'.$getDataJson);
- $allowIp = ['222.69.153.207','120.253.238.34','114.86.176.11','120.253.238.37'];
- if (!in_array($clientIp, $allowIp)){
- $returnInformation['code'] = 60001;
- $returnInformation['msg'] = "操作失败,IP地址不在白名单中";
- $returnInformation['data']=null;
- return json_encode($returnInformation);
- }else{
- if (!empty($getdata['userName']) && !empty($getdata['userPassword'])){
- if ($getdata["userName"]=="sgec68" && $getdata["userPassword"]=="sgec68123"){
- if(!empty($getdata['commandType'])){
- if($getdata['commandType']=="FRONTPAGE"){
- $sql="select device_code as deviceCode,device_name as deviceName,CONVERT(type, UNSIGNED INTEGER) as deviceType,type_name as deviceTypeName,unitinfo as deviceAddress,CONVERT(louyu, UNSIGNED INTEGER) as deviceFloor,company_name as companyName,company_code as companyCode,contacts,contacts_phone as contactsPhone,address as detailedAddress,street,posistion,time as dataTime,'在线' as status from sp_v_yp_device where company_code='10246'";
- $res=add($sql);
- if (!empty($res)){
- $returnInformation['code'] = 0;
- $returnInformation['msg'] = "操作成功";
- $returnInformation['data']=$res;
- return json_encode($returnInformation);
- }else{
- $returnInformation['code'] = 60001;
- $returnInformation['msg'] = "操作失败";
- $returnInformation['data']=null;
- return json_encode($returnInformation);
- }
- }else{
- $returnInformation['code'] = 60001;
- $returnInformation['msg'] = "操作失败,参数错误";
- $returnInformation['data']=null;
- return json_encode($returnInformation);
- }
- }else{
- $returnInformation['code'] = 60001;
- $returnInformation['msg'] = "操作失败,参数为空";
- $returnInformation['data']=null;
- return json_encode($returnInformation);
- }
- }else{
- $returnInformation['code'] = 60002;
- $returnInformation['msg'] = "操作失败,用户名或密码错误";
- $returnInformation['data']=null;
- return json_encode($returnInformation);
- }
- }else{
- $returnInformation['code'] = 60002;
- $returnInformation['msg'] = "操作失败,用户名或密码为空";
- $returnInformation['data']=null;
- return json_encode($returnInformation);
- }
- }
- }
- public function alarmHandling(){
- $data=input('');
- if(is_array($data)){
- $getDataJson= json_encode($data,320);
- $getdata=json_decode($getDataJson,true);//转成数组
- // $list['type']=1;
- }else{
- $getDataJson=$data;
- $getdata=json_decode($getDataJson,true);//转成数组
- // $list['type']=2;
- }
- Log::record('yangpuerqi_alarmHandling' . ':' .$getDataJson);
- if ($getdata['confirmAll']==""){
- $getdata['confirmAll']=0;
- }
- if ($getdata['misinformation']==""){
- $getdata['misinformation']=0;
- }
- if (!empty($getdata['userName']) && !empty($getdata['userPassword'])){
- if ($getdata["userName"]=="ypsgec" && $getdata["userPassword"]=="ypsgec123"){
- if (empty($getdata['recordId'])){
- $returnInformation['code'] = 60001;
- $returnInformation['msg'] = "操作失败,缺少记录Id";
- return json_encode($returnInformation);
- }elseif (empty($getdata['deviceCode'])){
- $returnInformation['code'] = 60001;
- $returnInformation['msg'] = "操作失败,缺少设备编号";
- return json_encode($returnInformation);
- }elseif (empty($getdata['deviceType'])){
- $returnInformation['code'] = 60001;
- $returnInformation['msg'] = "操作失败,缺少设备类型";
- return json_encode($returnInformation);
- }elseif ($getdata['confirmAll']!=0&&$getdata['confirmAll']!=1){
- $returnInformation['code'] = 60001;
- $returnInformation['msg'] = "操作失败,缺少是否批量处理类型";
- return json_encode($returnInformation);
- }elseif ($getdata['misinformation']!=0&&$getdata['misinformation']!=1){
- $returnInformation['code'] = 60001;
- $returnInformation['msg'] = "操作失败,缺少是否误报字段";
- return json_encode($returnInformation);
- }elseif (empty($getdata['handlerName'])){
- $returnInformation['code'] = 60001;
- $returnInformation['msg'] = "操作失败,缺少处理人姓名";
- return json_encode($returnInformation);
- }elseif (empty($getdata['handlerPhone'])){
- $returnInformation['code'] = 60001;
- $returnInformation['msg'] = "操作失败,缺少处理人联系方式";
- return json_encode($returnInformation);
- }
- // else{
- // $returnInformation['code'] = 0;
- // $returnInformation['msg'] = "操作成功";
- // return json_encode($returnInformation);
- // }
- // echo 'aaaaaaa';
- // exit();
- switch ($getdata['deviceType']) {
- case '1':
- $tab="sp_hj2017";
- break;
- case '2':
- $tab="sp_sj2017";
- break;
- case '6':
- $tab="sp_rtu2017";
- break;
- case '7':
- $tab="sp_ef2017";
- break;
- // case '16':
- // $tab="sp_video2017";
- // break;
- default:
- $returnInformation['code'] = 60001;
- $returnInformation['msg'] = "操作失败,缺少设备类型";
- return json_encode($returnInformation);
- break;
- }
- $time = date('Y-m-d h:i:s', time());
- if ($getdata['confirmAll']==0){
- $where = " where id=".$getdata['recordId']." and device_code='".$getdata['deviceCode']."' and clzt='0'";
- }else{
- $where = " where device_code='".$getdata['deviceCode']."' and clzt='0'";
- }
- $sql="UPDATE ".$tab." SET clsj='".$time."',clr='".$getdata['handlerName']."',clnr='".$getdata['processingContent']."',clwb='".$getdata['misinformation']."',cldh='".$getdata['handlerPhone']."',clzt=1 ".$where;
- // echo $sql;
- // print_r($sql);
- // exit();
- $res=addDataInfo($sql);
- if ($res){
- $returnInformation['code'] = 0;
- $returnInformation['msg'] = "操作成功";
- return json_encode($returnInformation);
- }else{
- $returnInformation['code'] = 60001;
- $returnInformation['msg'] = "操作失败,参数错误";
- return json_encode($returnInformation);
- }
- }else{
- $returnInformation['code'] = 60002;
- $returnInformation['msg'] = "操作失败,用户名或密码错误";
- return json_encode($returnInformation);
- }
- }else{
- $returnInformation['code'] = 60002;
- $returnInformation['msg'] = "操作失败,用户名或密码为空";
- return json_encode($returnInformation);
- }
- }
- public function ip() {
- //strcasecmp 比较两个字符,不区分大小写。返回0,>0,<0。
- if (getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
- $ip = getenv('HTTP_CLIENT_IP');
- } else if (getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
- $ip = getenv('HTTP_X_FORWARDED_FOR');
- } else if (getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {
- $ip = getenv('REMOTE_ADDR');
- } else if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
- $ip = $_SERVER['REMOTE_ADDR'];
- }
- $res = preg_match ( '/[\d\.]{7,15}/', $ip, $matches ) ? $matches [0] : '';
- return $res;
- //dump(phpinfo());//所有PHP配置信息
- }
- public function dianQiCeShiUrl(){
- $file_in = file_get_contents("php://input"); //接收post数据
- $xml = simplexml_load_string($file_in);//转换post数据为simplexml对象
- $json_string=array();
- foreach($xml->children() as $child) //遍历所有节点数据
- {
- $json_string[$child->getName()]=$child;
- // echo $child->getName() . ": " . $child . "<br />"; //打印节点名称和节点值
- //if($child->getName()=="from") //捡取要操作的节点
- //{
- //echo "i say ". ": get you!" . "<br />"; //操作节点数据
- //}
- }
- $getDataJson= json_encode($json_string,320);
- Log::record('dianQiCeShiData:' .$getDataJson );
- // $data5 = array();
- // $sensorList = array();
- // $sensorList1 = array();
- // $sensorListArray = array();
- // $data5['status'] = "0";
- // $sensorList['productId'] = "10001";
- // $sensorList['productName'] = "小米6";
- // $sensorList['productPrice'] = "2499";
- // $sensorList['productImg'] = "http://47.103.74.123/VideoAlarmPics/pic_1569859775_JYDL_XAQ_0.jpg";
- // $sensorListArray[0] = $sensorList;
- // $sensorList1['productId'] = "10002";
- // $sensorList1['productName'] = "小米笔记本";
- // $sensorList1['productPrice'] = "3999";
- // $sensorList1['productImg'] = "http://47.103.74.123/VideoAlarmPics/pic_1569859775_JYDL_XAQ_0.jpg";
- // $sensorListArray[1] = $sensorList1;
- // $data5['result'] = $sensorListArray;
- // $data6 = json_encode($data5);
- // return $getDataJson;
- }
- public function mt_rand_float($min, $max){
- return $min + abs($max-$min) * mt_rand(0,mt_getrandmax())/mt_getrandmax();
- }
- public function randomDate() {
- $begin = strtotime("now");
- $end = strtotime("-1 Month");
- $timestamp = rand($begin, $end);
- return date("Y-m-d H:i:s", $timestamp);
- }
- public function ceShiUrl(){
- header("Access-Control-Allow-Origin:*");
- // 响应类型
- header('Access-Control-Allow-Methods:POST');
- // 响应头设置
- header('Access-Control-Allow-Headers:x-requested-with, content-type');
- $data=input('');
- if(is_array($data)){
- $getDataJson= json_encode($data,320);
- $getdata=json_decode($getDataJson,true);//转成数组
- }else{
- $getDataJson=$data;
- $getdata=json_decode($getDataJson,true);//转成数组
- }
- $data1 = array();
- $data2 = array();
- $data4 = array();
- $data5 = array();
- $data6 = array();
- $data7 = array();
- $data8 = array();
- $data9 = array();
- $data10 = array();
- $data11 = array();
- $data12 = array();
- $data15 = array();
- $data16 = array();
- $data18 = array();
- $data19 = array();
- for ($i=0;$i<=14;$i++){
- $data1['standard_deviation']=round($this->mt_rand_float(1,5),2);
- $data1['variance']=round($data1['standard_deviation']*$data1['standard_deviation'],2);
- $data1['average_value']=round($this->mt_rand_float(220,227),2);
- $j=$i+1;
- if($j>=10){
- $data1['data_time']="2021-03-".$j;
- }
- $data2[$i]=$data1;
- $data4['standard_deviation']=round($this->mt_rand_float(3,8),2);
- $data4['variance']=round($data4['standard_deviation']*$data4['standard_deviation'],2);
- $data4['average_value']=round($this->mt_rand_float(7,15),2);
- if($j>=10){
- $data4['data_time']="2021-03-".$j;
- }
- $data5[$i]=$data4;
- $data6['standard_deviation']=round($this->mt_rand_float(0,2),2);
- $data6['variance']=round($data6['standard_deviation']*$data6['standard_deviation'],2);
- $data6['average_value']=round($this->mt_rand_float(17,25),2);
- if($j>=10){
- $data6['data_time']="2021-03-".$j;
- }
- $data7[$i]=$data6;
- $data8['standard_deviation']=round($this->mt_rand_float(30,70),2);
- $data8['variance']=round($data8['standard_deviation']*$data8['standard_deviation'],2);
- $data8['average_value']=round($this->mt_rand_float(30,60),2);
- if($j>=10){
- $data8['data_time']="2021-03-".$j;
- }
- $data9[$i]=$data8;
- $data11['electric_current']=round($this->mt_rand_float(8,18),2);
- $data11['voltage']=round($this->mt_rand_float(220,225),2);
- $data11['data_time']=$this->randomDate();
- $data12[$i]=$data11;
- $data15['electric_current']=round($this->mt_rand_float(20,100),2);
- $data15['voltage']=round($this->mt_rand_float(220,225),2);
- $data15['data_time']=$this->randomDate();
- $data16[$i]=$data15;
- $data18['ambient_temperature']=round($this->mt_rand_float(20,25),2);
- $data18['Cable_temperature']=round($this->mt_rand_float(10,20),2);
- $data18['generation_temperature']=round($data18['ambient_temperature']-$data18['Cable_temperature'],2);
- $data18['data_time']=$this->randomDate();
- $data19[$i]=$data18;
- }
- $data10['conclusion1']="因数据量未达到暂无法分析";
- $data3['voltage']=$data2;
- $data3['electric_current']=$data5;
- $data3['temperature']=$data7;
- $data3['leakage_current']=$data9;
- $data3['conclusion']=$data10;
- $data14['abnormal_equipment']=$data12;
- $data14['leakage_alarm']=$data16;
- $data14['conclusion']=$data10;
- $data20['visualization']=$data19;
- $data20['conclusion']=$data10;
- $data13['dispersion_rate']=$data3;
- $data13['electrical_aging']=$data14;
- $data13['thermal_aging']=$data20;
- // $data1['alarm_number']=$this->mt_rand_float(100,500);
- // $sensorList['productId'] = round($this->mt_rand_float(3,5),2);
- $data17 = json_encode($data13);
- return $data17;
- }
- public function algorithmApi(){
- header("Access-Control-Allow-Origin:*");
- // 响应类型
- header('Access-Control-Allow-Methods:POST');
- // 响应头设置
- header('Access-Control-Allow-Headers:x-requested-with, content-type');
- $data=input('');
- if(is_array($data)){
- $getDataJson= json_encode($data,320);
- $getdata=json_decode($getDataJson,true);//转成数组
- }else{
- $getDataJson=$data;
- $getdata=json_decode($getDataJson,true);//转成数组
- }
- if(!empty($getdata["dataType"])){
- if($getdata["dataType"]==1||$getdata["dataType"]==2){
- if($getdata["dataType"]==1){
- if (!empty($getdata["apiType"])){
- if ($getdata["apiType"]==4){
- if(!empty($getdata["timeType"])){
- if (!empty($getdata["companyCode"])){
- $sql6="select dispersion_rate from sp_water_analysis where company_code ='{$getdata["companyCode"]}' and data_type ={$getdata["timeType"]}";
- $longHuOwner = add($sql6);
- $returnInformation['code'] = 200;
- $returnInformation['msg'] = "success";
- $returnInformation['data']=$longHuOwner[0]['dispersion_rate'];
- return stripslashes(json_encode($returnInformation));
- }else{
- $returnInformation['code'] = 60001;
- $returnInformation['msg'] = "操作失败,单位编号不能为空";
- return json_encode($returnInformation);
- }
- }else{
- $returnInformation['code'] = 60001;
- $returnInformation['msg'] = "操作失败,时间类型不能为空";
- return json_encode($returnInformation);
- }
- }elseif ($getdata["apiType"]==5){
- if(!empty($getdata["timeType"])){
- if (!empty($getdata["companyCode"])){
- $sql6="select leakage_investigation from sp_water_analysis where company_code ='{$getdata["companyCode"]}' and data_type ={$getdata["timeType"]}";
- $longHuOwner = add($sql6);
- $returnInformation['code'] = 200;
- $returnInformation['msg'] = "success";
- $returnInformation['data']=$longHuOwner[0]['leakage_investigation'];
- return stripslashes(json_encode($returnInformation));
- }else{
- $returnInformation['code'] = 60001;
- $returnInformation['msg'] = "操作失败,单位编号不能为空";
- return json_encode($returnInformation);
- }
- }else{
- $returnInformation['code'] = 60001;
- $returnInformation['msg'] = "操作失败,时间类型不能为空";
- return json_encode($returnInformation);
- }
- }elseif ($getdata["apiType"]==6){
- if(!empty($getdata["timeType"])){
- if (!empty($getdata["companyCode"])){
- $sql6="select device_association from sp_water_analysis where company_code ='{$getdata["companyCode"]}' and data_type ={$getdata["timeType"]}";
- $longHuOwner = add($sql6);
- $returnInformation['code'] = 200;
- $returnInformation['msg'] = "success";
- $returnInformation['data']=$longHuOwner[0]['device_association'];
- return stripslashes(json_encode($returnInformation));
- }else{
- $returnInformation['code'] = 60001;
- $returnInformation['msg'] = "操作失败,单位编号不能为空";
- return json_encode($returnInformation);
- }
- }else{
- $returnInformation['code'] = 60001;
- $returnInformation['msg'] = "操作失败,时间类型不能为空";
- return json_encode($returnInformation);
- }
- }elseif ($getdata["apiType"]==7){
- if(!empty($getdata["timeType"])){
- if (!empty($getdata["companyCode"])){
- $sql6="select data_fluctuation from sp_water_analysis where company_code ='{$getdata["companyCode"]}' and data_type ={$getdata["timeType"]}";
- $longHuOwner = add($sql6);
- $returnInformation['code'] = 200;
- $returnInformation['msg'] = "success";
- $returnInformation['data']=$longHuOwner[0]['data_fluctuation'];
- return stripslashes(json_encode($returnInformation));
- }else{
- $returnInformation['code'] = 60001;
- $returnInformation['msg'] = "操作失败,单位编号不能为空";
- return json_encode($returnInformation);
- }
- }else{
- $returnInformation['code'] = 60001;
- $returnInformation['msg'] = "操作失败,时间类型不能为空";
- return json_encode($returnInformation);
- }
- }elseif ($getdata["apiType"]==2){
- if(!empty($getdata["timeType"])){
- if (!empty($getdata["companyCode"])){
- $sql6="select data_statistics from sp_water_analysis where company_code ='{$getdata["companyCode"]}' and data_type ={$getdata["timeType"]}";
- $longHuOwner = add($sql6);
- $returnInformation['code'] = 200;
- $returnInformation['msg'] = "success";
- $returnInformation['data']=$longHuOwner[0]['data_statistics'];
- return stripslashes(json_encode($returnInformation));
- }else{
- $returnInformation['code'] = 60001;
- $returnInformation['msg'] = "操作失败,单位编号不能为空";
- return json_encode($returnInformation);
- }
- }else{
- $returnInformation['code'] = 60001;
- $returnInformation['msg'] = "操作失败,时间类型不能为空";
- return json_encode($returnInformation);
- }
- }elseif ($getdata["apiType"]==3){
- if(!empty($getdata["timeType"])){
- if (!empty($getdata["companyCode"])){
- if($getdata["timeType"]==1) {
- $sql6 = "select data4,data1,`time`as dataTime from sp_d864016058809717 where `time` between '2021-07-20 00:00:00' and '2021-07-20 15:00:00'";
- $longHuOwner = add($sql6);
- $returnInformation['code'] = 200;
- $returnInformation['msg'] = "success";
- $returnInformation['data'] = $longHuOwner;
- return stripslashes(json_encode($returnInformation));
- }elseif ($getdata["timeType"]==2){
- $sql6 = "select data4,data1,`time`as dataTime from sp_d864016058809717 where `time` between '2021-07-13 00:00:00' and '2021-07-20 15:00:00'";
- $longHuOwner = add($sql6);
- $returnInformation['code'] = 200;
- $returnInformation['msg'] = "success";
- $returnInformation['data'] = $longHuOwner;
- return stripslashes(json_encode($returnInformation));
- }elseif ($getdata["timeType"]==3){
- $sql6 = "select data4,data1,`time`as dataTime from sp_d864016058809717 where `time` between '2021-06-20 00:00:00' and '2021-07-20 15:00:00'";
- $longHuOwner = add($sql6);
- $returnInformation['code'] = 200;
- $returnInformation['msg'] = "success";
- $returnInformation['data'] = $longHuOwner;
- return stripslashes(json_encode($returnInformation));
- }
- }else{
- $returnInformation['code'] = 60001;
- $returnInformation['msg'] = "操作失败,单位编号不能为空";
- return json_encode($returnInformation);
- }
- }else{
- $returnInformation['code'] = 60001;
- $returnInformation['msg'] = "操作失败,时间类型不能为空";
- return json_encode($returnInformation);
- }
- }
- }else{
- $returnInformation['code'] = 60001;
- $returnInformation['msg'] = "操作失败,api类型不能为空";
- return json_encode($returnInformation);
- }
- }else{
- if (!empty($getdata["apiType"])){
- if ($getdata["apiType"]==4){
- if(!empty($getdata["timeType"])){
- if (!empty($getdata["companyCode"])){
- $sql6="select dispersion_rate from sp_ef_analysis where company_code ='{$getdata["companyCode"]}' and data_type ={$getdata["timeType"]}";
- $longHuOwner = add($sql6);
- $returnInformation['code'] = 200;
- $returnInformation['msg'] = "success";
- $returnInformation['data']=$longHuOwner[0]['dispersion_rate'];
- return stripslashes(json_encode($returnInformation));
- }else{
- $returnInformation['code'] = 60001;
- $returnInformation['msg'] = "操作失败,单位编号不能为空";
- return json_encode($returnInformation);
- }
- }else{
- $returnInformation['code'] = 60001;
- $returnInformation['msg'] = "操作失败,时间类型不能为空";
- return json_encode($returnInformation);
- }
- }elseif ($getdata["apiType"]==5){
- if(!empty($getdata["timeType"])){
- if (!empty($getdata["companyCode"])){
- $sql6="select electrical_aging from sp_ef_analysis where company_code ='{$getdata["companyCode"]}' and data_type ={$getdata["timeType"]}";
- $longHuOwner = add($sql6);
- $returnInformation['code'] = 200;
- $returnInformation['msg'] = "success";
- $returnInformation['data']=$longHuOwner[0]['electrical_aging'];
- return stripslashes(json_encode($returnInformation));
- }else{
- $returnInformation['code'] = 60001;
- $returnInformation['msg'] = "操作失败,单位编号不能为空";
- return json_encode($returnInformation);
- }
- }else{
- $returnInformation['code'] = 60001;
- $returnInformation['msg'] = "操作失败,时间类型不能为空";
- return json_encode($returnInformation);
- }
- }elseif ($getdata["apiType"]==6){
- if(!empty($getdata["timeType"])){
- if (!empty($getdata["companyCode"])){
- $sql6="select thermal_aging from sp_ef_analysis where company_code ='{$getdata["companyCode"]}' and data_type ={$getdata["timeType"]}";
- $longHuOwner = add($sql6);
- $returnInformation['code'] = 200;
- $returnInformation['msg'] = "success";
- $returnInformation['data']=$longHuOwner[0]['thermal_aging'];
- return stripslashes(json_encode($returnInformation));
- }else{
- $returnInformation['code'] = 60001;
- $returnInformation['msg'] = "操作失败,单位编号不能为空";
- return json_encode($returnInformation);
- }
- }else{
- $returnInformation['code'] = 60001;
- $returnInformation['msg'] = "操作失败,时间类型不能为空";
- return json_encode($returnInformation);
- }
- }elseif ($getdata["apiType"]==7){
- if(!empty($getdata["timeType"])){
- if (!empty($getdata["companyCode"])){
- $sql6="select data_fluctuation from sp_water_analysis where company_code ='{$getdata["companyCode"]}' and data_type ={$getdata["timeType"]}";
- $longHuOwner = add($sql6);
- $returnInformation['code'] = 200;
- $returnInformation['msg'] = "success";
- $returnInformation['data']=$longHuOwner[0]['data_fluctuation'];
- return stripslashes(json_encode($returnInformation));
- }else{
- $returnInformation['code'] = 60001;
- $returnInformation['msg'] = "操作失败,单位编号不能为空";
- return json_encode($returnInformation);
- }
- }else{
- $returnInformation['code'] = 60001;
- $returnInformation['msg'] = "操作失败,时间类型不能为空";
- return json_encode($returnInformation);
- }
- }elseif ($getdata["apiType"]==2){
- if(!empty($getdata["timeType"])){
- if (!empty($getdata["companyCode"])){
- $sql6="select data_statistics from sp_water_analysis where company_code ='{$getdata["companyCode"]}' and data_type ={$getdata["timeType"]}";
- $longHuOwner = add($sql6);
- $returnInformation['code'] = 200;
- $returnInformation['msg'] = "success";
- $returnInformation['data']=$longHuOwner[0]['data_statistics'];
- return stripslashes(json_encode($returnInformation));
- }else{
- $returnInformation['code'] = 60001;
- $returnInformation['msg'] = "操作失败,单位编号不能为空";
- return json_encode($returnInformation);
- }
- }else{
- $returnInformation['code'] = 60001;
- $returnInformation['msg'] = "操作失败,时间类型不能为空";
- return json_encode($returnInformation);
- }
- }elseif ($getdata["apiType"]==3){
- if(!empty($getdata["timeType"])){
- if (!empty($getdata["companyCode"])){
- if($getdata["timeType"]==1) {
- $sql6 = "select point_data,point_code,data_time from sp_e00003215010144 where data_time between '2021-07-20 00:00:00' and '2021-07-20 15:00:00'";
- $longHuOwner = add($sql6);
- $returnInformation['code'] = 200;
- $returnInformation['msg'] = "success";
- $returnInformation['data'] = $longHuOwner;
- return stripslashes(json_encode($returnInformation));
- }elseif ($getdata["timeType"]==2){
- $sql6 = "select point_data,point_code,data_time from sp_e00003215010144 where data_time between '2021-07-13 00:00:00' and '2021-07-20 15:00:00'";
- $longHuOwner = add($sql6);
- $returnInformation['code'] = 200;
- $returnInformation['msg'] = "success";
- $returnInformation['data'] = $longHuOwner;
- return stripslashes(json_encode($returnInformation));
- }elseif ($getdata["timeType"]==3){
- $sql6 = "select point_data,point_code,data_time from sp_e00003215010144 where data_time between '2021-06-20 00:00:00' and '2021-07-20 15:00:00'";
- $longHuOwner = add($sql6);
- $returnInformation['code'] = 200;
- $returnInformation['msg'] = "success";
- $returnInformation['data'] = $longHuOwner;
- return stripslashes(json_encode($returnInformation));
- }
- }else{
- $returnInformation['code'] = 60001;
- $returnInformation['msg'] = "操作失败,单位编号不能为空";
- return json_encode($returnInformation);
- }
- }else{
- $returnInformation['code'] = 60001;
- $returnInformation['msg'] = "操作失败,时间类型不能为空";
- return json_encode($returnInformation);
- }
- }
- }else{
- $returnInformation['code'] = 60001;
- $returnInformation['msg'] = "操作失败,api类型不能为空";
- return json_encode($returnInformation);
- }
- }
- }else{
- $returnInformation['code'] = 60001;
- $returnInformation['msg'] = "操作失败,数据范围超出限制";
- return json_encode($returnInformation);
- }
- }else{
- $returnInformation['code'] = 60001;
- $returnInformation['msg'] = "操作失败,数据类型不能为空";
- return json_encode($returnInformation);
- }
- }
- public function ceshiApi()
- {
- header("Access-Control-Allow-Origin:*");
- // 响应类型
- header('Access-Control-Allow-Methods:POST');
- // 响应头设置
- header('Access-Control-Allow-Headers:x-requested-with, content-type');
- $data = input('');
- if (is_array($data)) {
- $getDataJson = json_encode($data, 320);
- $getdata = json_decode($getDataJson, true);//转成数组
- } else {
- $getDataJson = $data;
- $getdata = json_decode($getDataJson, true);//转成数组
- }
- $data1 = array();
- $data2 = array();
- $data3 = array();
- $data4 = array();
- if ($getdata['status']=="getnewslist"){
- $data1['status']=0;
- for ($i=0;$i<2;$i++){
- $data2['id']=$i+1;
- $data2['title']="测试高房价结果回复的合法化觉得很简单的事";
- $data2['add_time']="2021-08-05 16:48:17";
- $data2['zhaiyao']="的就是但是绝大多数公开大量上市价格第四季度睡个好觉了";
- $data2['click']=1;
- $data2['img_url']="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fs10.sinaimg.cn%2Forignal%2F4a8a8049ga9eae999a909&refer=http%3A%2F%2Fs10.sinaimg.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1631010162&t=f95e7303fda34bef3751916ee036b4a9";
- $data3[$i]=$data2;
- }
- $data1['message']=$data3;
- return json_encode($data1);
- }elseif($getdata['status']=="getnew"){
- $data1['status']=0;
- $data2['id']=1;
- $data2['title']="测试高房价结果回复的合法化觉得很简单的事";
- $data2['add_time']="2021-08-05 16:48:17";
- $data2['content']="的就是但是绝大多数公开大量上市价格第四季度睡个好觉了";
- $data2['click']=2;
- $data3[0]=$data2;
- $data1['message']=$data3;
- return json_encode($data1);
- }elseif($getdata['status']=="getimages"){
- $data1['status']=0;
- for ($i=0;$i<2;$i++){
- $data2['id']=$i+1;
- $data2['title']="测试高房价结果回复的合法化觉得很简单的事";
- $data2['zhaiyao']="的就是但是绝大多数公开大量上市价格第四季度睡个好觉了";
- $data2['img_url']="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fn.sinaimg.cn%2Fsinacn08%2F336%2Fw501h635%2F20180630%2F9d76-hespqrx2645109.jpg&refer=http%3A%2F%2Fn.sinaimg.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1631010162&t=384680be0388ea4c8bd06dfed25d9da3";
- $data3[$i]=$data2;
- }
- $data1['message']=$data3;
- return json_encode($data1);
- }elseif($getdata['status']=="getimgcategory"){
- $data1['status']=0;
- for ($i=0;$i<2;$i++){
- $data2['id']=$i+1;
- $data2['title']="测试".$i;
- $data3[$i]=$data2;
- }
- $data1['message']=$data3;
- return json_encode($data1);
- }elseif($getdata['status']=="getthumimages"){
- $data1['status']=0;
- for ($i=0;$i<3;$i++){
- $data2['src']="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.article.pchome.net%2F00%2F40%2F91%2F79%2Fpic_lib%2Fs960x639%2Fcountry_field_landscape_photo_EA52058s960x639.jpg&refer=http%3A%2F%2Fimg.article.pchome.net&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1631010162&t=0fe6c4c3d1a111f5e848695687261303";
- }
- $data1['message']=$data3;
- return json_encode($data1);
- }elseif($getdata['status']=="getimageInfo"){
- $data1['status']=0;
- for ($i=0;$i<1;$i++){
- $data2['id']=$i+1;
- $data2['title']="测试高房价结果回复的合法化觉得很简单的事";
- $data2['add_time']="2021-08-05 16:48:17";
- $data2['click']=3;
- $data2['content']="解释的机会就是进口关税打开撒酒疯还是";
- }
- $data1['message']=$data3;
- return json_encode($data1);
- }elseif($getdata['status']=="getcomments"){
- $data1['status']=0;
- for ($i=0;$i<1;$i++){
- $data2['user_name']="djsjf";
- $data2['add_time']="2021-08-05 16:48:17";
- $data2['content']="快速减肥健身看江户时代";
- }
- $data1['message']=$data3;
- return json_encode($data1);
- }elseif($getdata['status']=="postcomment"){
- $data1['status']=0;
- $data1['message']="啊附加符号方式";
- return json_encode($data1);
- }elseif($getdata['status']=="getgoods"){
- $data1['status']=0;
- for ($i=0;$i<2;$i++){
- $data2['id']=$i+1;
- $data2['title']="测试高房价结果回复的合法化觉得很简单的事";
- $data2['add_time']="2021-08-05 16:48:17";
- $data2['zhaiyao']="的就是但是绝大多数公开大量上市价格第四季度睡个好觉了";
- $data2['click']=0;
- $data2['img_url']="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fup.enterdesk.com%2Fedpic_360_360%2F5b%2F71%2F3b%2F5b713b0d8f5fb4e4f8759c417b42eefb.jpg&refer=http%3A%2F%2Fup.enterdesk.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1631010162&t=699aab395bae994606f72becd4cbb90d";
- $data2['sell_price']=214;
- $data2['market_price']=3446;
- $data2['stock_quantity']=3446;
- }
- $data1['message']=$data3;
- return json_encode($data1);
- }elseif($getdata['status']=="getdesc"){
- $data1['status']=0;
- for ($i=0;$i<2;$i++){
- $data2['title']="测试高房价结果回复的合法化觉得很简单的事";
- $data2['content']="<p>的实际开工的开始</p><p align='center'></p>";
- }
- $data1['message']=$data3;
- return json_encode($data1);
- }
- }
- public function deviceNumber(){
- header("Access-Control-Allow-Origin:*");
- // 响应类型
- header('Access-Control-Allow-Methods:POST');
- // 响应头设置
- header('Access-Control-Allow-Headers:x-requested-with, content-type');
- $data=input('');
- if(is_array($data)){
- $getDataJson= json_encode($data,320);
- $getdata=json_decode($getDataJson,true);//转成数组
- }else{
- $getDataJson=$data;
- $getdata=json_decode($getDataJson,true);//转成数组
- }
- $data6 = array();
- if ($getdata['userName']=="ypywtg"){
- $sql="SELECT COUNT(*) AS waterNumber FROM sp_owner WHERE dwtype = 2 AND company in ('10309', '10308', '10307', '10306', '10305', '10304', '10303', '10302', '10301', '10300', '10299', '10298', '10297', '10296', '10295', '10294', '10293', '10292', '10291', '10290', '10289', '10288', '10287', '10286', '10285', '10284', '10283', '10282', '10281', '10280', '10279', '10278', '10277', '10276', '10275', '10274', '10273', '10272', '10271', '10270', '10269', '10268', '10267', '10266', '10265', '10264', '10263', '10262', '10261', '10260', '10259', '10258', '10257', '10256', '10255', '10254', '10253', '10252', '10251', '10250', '10249', '10248', '10246', '10245', '10244', '10243', '10242', '10241', '10240', '10239', '10238', '10237', '10236', '10234');";
- $res=add($sql);
- $sql1="SELECT COUNT(*) AS levelNumber FROM sp_owner WHERE dwtype = 5 AND company in ('10309', '10308', '10307', '10306', '10305', '10304', '10303', '10302', '10301', '10300', '10299', '10298', '10297', '10296', '10295', '10294', '10293', '10292', '10291', '10290', '10289', '10288', '10287', '10286', '10285', '10284', '10283', '10282', '10281', '10280', '10279', '10278', '10277', '10276', '10275', '10274', '10273', '10272', '10271', '10270', '10269', '10268', '10267', '10266', '10265', '10264', '10263', '10262', '10261', '10260', '10259', '10258', '10257', '10256', '10255', '10254', '10253', '10252', '10251', '10250', '10249', '10248', '10246', '10245', '10244', '10243', '10242', '10241', '10240', '10239', '10238', '10237', '10236', '10234');";
- $res1=add($sql1);
- $sql2="SELECT COUNT(*) AS smokeSensationNumber FROM sp_owner WHERE dwtype = 3 AND company in ('10309', '10308', '10307', '10306', '10305', '10304', '10303', '10302', '10301', '10300', '10299', '10298', '10297', '10296', '10295', '10294', '10293', '10292', '10291', '10290', '10289', '10288', '10287', '10286', '10285', '10284', '10283', '10282', '10281', '10280', '10279', '10278', '10277', '10276', '10275', '10274', '10273', '10272', '10271', '10270', '10269', '10268', '10267', '10266', '10265', '10264', '10263', '10262', '10261', '10260', '10259', '10258', '10257', '10256', '10255', '10254', '10253', '10252', '10251', '10250', '10249', '10248', '10246', '10245', '10244', '10243', '10242', '10241', '10240', '10239', '10238', '10237', '10236', '10234');";
- $res2=add($sql2);
- $sql3="SELECT COUNT(*) AS rtuNumber FROM sp_owner WHERE dwtype = 6 AND company in ('10309', '10308', '10307', '10306', '10305', '10304', '10303', '10302', '10301', '10300', '10299', '10298', '10297', '10296', '10295', '10294', '10293', '10292', '10291', '10290', '10289', '10288', '10287', '10286', '10285', '10284', '10283', '10282', '10281', '10280', '10279', '10278', '10277', '10276', '10275', '10274', '10273', '10272', '10271', '10270', '10269', '10268', '10267', '10266', '10265', '10264', '10263', '10262', '10261', '10260', '10259', '10258', '10257', '10256', '10255', '10254', '10253', '10252', '10251', '10250', '10249', '10248', '10246', '10245', '10244', '10243', '10242', '10241', '10240', '10239', '10238', '10237', '10236', '10234');";
- $res3=add($sql3);
- $sql4="SELECT COUNT(*) AS videoNumber FROM sp_owner WHERE dwtype = 16 AND company in ('10309', '10308', '10307', '10306', '10305', '10304', '10303', '10302', '10301', '10300', '10299', '10298', '10297', '10296', '10295', '10294', '10293', '10292', '10291', '10290', '10289', '10288', '10287', '10286', '10285', '10284', '10283', '10282', '10281', '10280', '10279', '10278', '10277', '10276', '10275', '10274', '10273', '10272', '10271', '10270', '10269', '10268', '10267', '10266', '10265', '10264', '10263', '10262', '10261', '10260', '10259', '10258', '10257', '10256', '10255', '10254', '10253', '10252', '10251', '10250', '10249', '10248', '10246', '10245', '10244', '10243', '10242', '10241', '10240', '10239', '10238', '10237', '10236', '10234');";
- $res4=add($sql4);
- $sql5="SELECT COUNT(*) AS electricalFireNumber FROM sp_owner WHERE dwtype = 7 AND company in ('10309', '10308', '10307', '10306', '10305', '10304', '10303', '10302', '10301', '10300', '10299', '10298', '10297', '10296', '10295', '10294', '10293', '10292', '10291', '10290', '10289', '10288', '10287', '10286', '10285', '10284', '10283', '10282', '10281', '10280', '10279', '10278', '10277', '10276', '10275', '10274', '10273', '10272', '10271', '10270', '10269', '10268', '10267', '10266', '10265', '10264', '10263', '10262', '10261', '10260', '10259', '10258', '10257', '10256', '10255', '10254', '10253', '10252', '10251', '10250', '10249', '10248', '10246', '10245', '10244', '10243', '10242', '10241', '10240', '10239', '10238', '10237', '10236', '10234');";
- $res5=add($sql5);
- $sensorList['waterNumber'] =$res[0]['waterNumber'];
- $sensorList['levelNumber'] =$res1[0]['levelNumber'];
- $sensorList['smokeSensationNumber'] =$res2[0]['smokeSensationNumber'];
- $sensorList['rtuNumber'] =$res3[0]['rtuNumber'];
- $sensorList['videoNumber'] =$res4[0]['videoNumber'];
- $sensorList['electricalFireNumber'] =$res5[0]['electricalFireNumber'];
- $data6 = json_encode($sensorList);
- }
- return $data6;
- }
- public function s_curl($url,$data='',$header="",$method="POST"){
- $ch = curl_init() ;
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
- // curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 4);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
- /* curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');*/
- // curl_setopt($ch, CURLOPT_VERBOSE, 1); //debugģʽ
- curl_setopt($ch, CURLOPT_SSLCERT, "./server.crt"); //client.crt����
- curl_setopt($ch, CURLOPT_SSLCERTPASSWD, "IoM@1234"); //client֤������
- curl_setopt($ch, CURLOPT_SSLKEY, "./server.key");
- if($method=="POST"||$method=="PUT"||$method=="DELETE"){
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
- }
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- $info = curl_exec($ch);
- $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- if (curl_errno($ch)) {
- $infores = curl_error($ch);
- }else{
- $infores = $info;
- }
- curl_close($ch);
- return $infores;
- }
- public function ypxycurl($url,$data=''){
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
- curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
- curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- $info = curl_exec($ch);
- if (curl_errno($ch)) {
- $info = 'ERROR: ' . curl_error($ch);
- }
- curl_close($ch);
- return $info;
- }
- }
|