12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898 |
- <?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:' .$list['data'] );
- $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);
- }
- }
- echo 111;
- }
- 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.148.83','120.253.238.34','114.86.176.11','120.253.238.37','218.242.51.14'];
- // 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";
- $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 deviceInfoRegister()
- {
- $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 = Db::query("select sensorId,sensorType,sensorName,CONCAT(companyName,address) AS address,wsLng,wsLat,dataCode,applyId,cityId,areaId,regionId,projectCode from yp_ywtg_configure where id >{$getdata["id"]}");
- // $rep_url = "http://220.196.241.22:8000/api-projectdatamanage/equipmentsync/sync";
- // $header=[
- // "Content-Type:application/json",
- // "Authenticator:eyJhbGciOiJIUzI1NiJ9.eyJyZWFsTmFtZSI6Iumfqeato-S5iSIsInJvbGVJZHMiOiIxMSIsIm9yZ0NvZGUiOiJYIiwibG9naW5OYW1lIjoiaGFuenkiLCJwbGF0Zm9ybUlkIjpudWxsLCJleHAiOjE2Mzc2NjQ1MDMsInVzZXJJZCI6MTAwNiwib3JnSWQiOjF9.H_xzdQ9jdcndOCsYU9z3cZ-oBk4FtdxJk9wxC0AaZvE"
- // ];
- // $res = $this->ywManagementCurl($rep_url,$header,json_encode($data1));
- return json_encode($data1);
- }
- 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 http_post_advertise1($url,$data){ //封装curl方法
- $header = array(
- 'appKey:'.'850404889644236801',
- 'Content-Type:'.'application/json'
- );
- $ch = curl_init(); //初始化
- curl_setopt($ch, CURLOPT_URL, $url); //请求地址
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_POST, true);
- //https协议需要以下两行,否则请求不成功
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
- //post方法所需要的参数
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
- curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
- $result = curl_exec($ch);
- curl_close($ch);
- return $result; //返回所获取的方法
- }
- public function ytapi_query($sql){
- $link = mysqli_connect('47.98.201.187', 'root', 'Yt2018IoT', 'jdxf', 3306);
- mysqli_query($link,"set character set 'utf8'");
- $res1 = mysqli_query($link,$sql);
- if($res1==FALSE){
- return $list=null;
- }
- $list=array();
- while ($row = $res1->fetch_assoc()) {
- $list[]=$row;
- }
- mysqli_free_result($res1);
- mysqli_close($link);
- return $list;
- }
- public function dianQiCeShiUrl(){
- $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;
- }
- $number=$getdata['number'];
- $start_number=$getdata['start_number'];
- $arr=$this->ytapi_query("select * from a_fire_brigade limit ".$start_number.",".$number);
- //$arr=ytapi_query("select * from a_yc_point_register limit 200,10");
- $array=[];
- foreach ($arr as $key=>$value){
- $array[$key]['descript']=$arr[$key]['descript'];
- $array[$key]['deviceName']=$arr[$key]['device_name'];
- // $array[$key]['deviceNo']=$arr[$key]['device_code'].str_replace(',','',$arr[$key]['port']);
- $array[$key]['deviceNo']=$arr[$key]['device_code'].str_replace(',','',$arr[$key]['port']).$arr[$key]['data'];
- $array[$key]['deviceType']=$arr[$key]['device_type'];
- $array[$key]['deviceTypeName']=$arr[$key]['device_type_name'];
- $array[$key]['openProjectId']=$arr[$key]['open_project_id'];
- }
- $url1='http://iot.shxf-119.com/access/device/point/register';//新正式路径
- foreach ($array as $key=>$value){
- // sleep(2);
- $data1=[];
- $data1 = $array[$key];
- Log::record('fireBrigadeAfferent:' .json_encode($data1));
- $output= $this->http_post_advertise1($url1,json_encode($data1));
- echo $output."\n";
- Log::record('fireBrigadeOutput:' .$output);
- }
- }
- 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);//转成数组
- }
- Log::record('zhanyejunceshi:' .$getDataJson);
- return $getDataJson;
- // $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;
- }
- //水系统电气火灾算法测试API
- 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;
- }
- //伍继电力程序校验机制api
- public function wooGiApi(){
- $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('wooGiApi_deviceList' . ':' .'<<<'.$clientIp.'>>>'.$getDataJson);
- $allowIp = ['101.133.214.75','124.71.174.104','124.71.175.91','124.70.160.158','222.69.148.83','114.95.161.247'];
- // if (!in_array($clientIp, $allowIp)){
- // $returnInformation['code'] = 60001;
- // $returnInformation['msg'] = "操作失败,IP地址不在白名单中";
- // $returnInformation['data']=null;
- // return json_encode($returnInformation);
- // }else{
- $redis = new \Redis();
- $redis->connect('127.0.0.1', 6379);
- $result = $redis->auth("usky2021");
- $redis->select(1);
- if ($result == 1) {
- $check =$redis->exists($clientIp);
- if ($check){
- // +1
- $redis->incr($clientIp);
- $count =$redis->get($clientIp);
- // 限制每小时1次
- if($count > 500){
- $returnInformation['code'] = 60003;
- $returnInformation['msg'] = "操作失败,当前ip请求频率过高";
- $returnInformation['data']=null;
- return json_encode($returnInformation);
- }else{
- if (!empty($getdata['publicKey'])){
- $publicKey = $getdata['publicKey'];
- $timeStamp = time();
- if (!empty($getdata['requestType'])){
- if($getdata['requestType']==1){
- $publicKey1 = md5("usky".$getdata['timeStamp']."9bcbc5d723cb9bae394d3a097deb6695");
- $publicKey2 = md5("usky".$timeStamp."9bcbc5d723cb9bae394d3a097deb6695");
- }else if ($getdata['requestType']==2){
- $publicKey1 = md5("usky".$getdata['timeStamp']."b9848b4fe4647e380fd1367a4f34ced9");
- $publicKey2 = md5("usky".$timeStamp."b9848b4fe4647e380fd1367a4f34ced9");
- }else if ($getdata['requestType']==3){
- $publicKey1 = md5("usky".$getdata['timeStamp']."056ac8fae059c9c9e700b734922edfc8");
- $publicKey2 = md5("usky".$timeStamp."056ac8fae059c9c9e700b734922edfc8");
- }else{
- $returnInformation['code'] = 60004;
- $returnInformation['msg'] = "操作失败,requestType不在范围内";
- $returnInformation['data']=null;
- return json_encode($returnInformation);
- }
- }else{
- $returnInformation['code'] = 60004;
- $returnInformation['msg'] = "操作失败,requestType不能为空";
- $returnInformation['data']=null;
- return json_encode($returnInformation);
- }
- if ($publicKey==$publicKey1){
- $sensorList['publicKey'] =$publicKey2;
- $sensorList['timeStamp'] =$timeStamp;
- $returnInformation['code'] = 200;
- $returnInformation['msg'] = "操作成功";
- $returnInformation['data']=$sensorList;
- return json_encode($returnInformation);
- }else{
- $returnInformation['code'] = 60002;
- $returnInformation['msg'] = "操作失败,publicKey错误";
- $returnInformation['data']=null;
- return json_encode($returnInformation);
- }
- }else{
- $returnInformation['code'] = 60004;
- $returnInformation['msg'] = "操作失败,publicKey不能为空";
- $returnInformation['data']=null;
- return json_encode($returnInformation);
- }
- }
- } else {
- $redis->set($clientIp, 1,3300);//初始值1
- if (!empty($getdata['publicKey'])){
- $publicKey = $getdata['publicKey'];
- $timeStamp = time();
- if (!empty($getdata['requestType'])){
- if($getdata['requestType']==1){
- $publicKey1 = md5("usky".$getdata['timeStamp']."9bcbc5d723cb9bae394d3a097deb6695");
- $publicKey2 = md5("usky".$timeStamp."9bcbc5d723cb9bae394d3a097deb6695");
- }else if ($getdata['requestType']==2){
- $publicKey1 = md5("usky".$getdata['timeStamp']."b9848b4fe4647e380fd1367a4f34ced9");
- $publicKey2 = md5("usky".$timeStamp."b9848b4fe4647e380fd1367a4f34ced9");
- }else if ($getdata['requestType']==3){
- $publicKey1 = md5("usky".$getdata['timeStamp']."056ac8fae059c9c9e700b734922edfc8");
- $publicKey2 = md5("usky".$timeStamp."056ac8fae059c9c9e700b734922edfc8");
- }else{
- $returnInformation['code'] = 60004;
- $returnInformation['msg'] = "操作失败,requestType不在范围内";
- $returnInformation['data']=null;
- return json_encode($returnInformation);
- }
- }else{
- $returnInformation['code'] = 60004;
- $returnInformation['msg'] = "操作失败,requestType不能为空";
- $returnInformation['data']=null;
- return json_encode($returnInformation);
- }
- if ($publicKey==$publicKey1){
- $sensorList['publicKey'] =$publicKey2;
- $sensorList['timeStamp'] =$timeStamp;
- $returnInformation['code'] = 200;
- $returnInformation['msg'] = "操作成功";
- $returnInformation['data']=$sensorList;
- return json_encode($returnInformation);
- }else{
- $returnInformation['code'] = 60002;
- $returnInformation['msg'] = "操作失败,publicKey错误";
- $returnInformation['data']=null;
- return json_encode($returnInformation);
- }
- }else{
- $returnInformation['code'] = 60004;
- $returnInformation['msg'] = "操作失败,publicKey不能为空";
- $returnInformation['data']=null;
- return json_encode($returnInformation);
- }
- }
- }
- // }
- }
- //伍继电力java程序校验机制api
- public function wooGiJavaApi(){
- $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('wooGiJavaApi_deviceList' . ':' .'<<<'.$clientIp.'>>>'.$getDataJson);
- $code = 1;
- if ($code==1){
- return 1;
- }else{
- return 0;
- }
- }
- //杨浦学校设备注册api
- public function ypSchoolApi()
- {
- $data = input('');
- if (is_array($data)) {
- $getDataJson = json_encode($data, 320);
- $getdata = json_decode($getDataJson, true);//转成数组
- } else {
- $getDataJson = $data;
- $getdata = json_decode($getDataJson, true);//转成数组
- }
- $sql6="select * from sp_yangpuxy_share where company_code ='{$getdata["deviceCode"]}' and rec_cur=1586416046";
- $ypSchoolOwner = add($sql6);
- if (!empty($ypSchoolOwner)){
- foreach ($ypSchoolOwner as $key=>$value){
- $cs['deviceId'] = $ypSchoolOwner[$key]['object_code'];
- $cs['deviceName'] = $ypSchoolOwner[$key]['object_name'].$ypSchoolOwner[$key]['device_name'];
- if ($ypSchoolOwner[$key]['owner_dwtype']==2){
- $cs['deviceType'] = "1";
- $cs['deviceTypeName'] = "水泵水压检测器";
- }elseif ($ypSchoolOwner[$key]['owner_dwtype']==128){
- $cs['deviceType'] = "4";
- $cs['deviceTypeName'] = "井盖探测器";
- }elseif ($ypSchoolOwner[$key]['owner_dwtype']==3){
- $cs['deviceType'] = "3";
- $cs['deviceTypeName'] = "烟感检测";
- }elseif ($ypSchoolOwner[$key]['owner_dwtype']==7){
- $cs['deviceType'] = "5";
- $cs['deviceTypeName'] = "高低压配电房检测器";
- }elseif ($ypSchoolOwner[$key]['owner_dwtype']==130){
- $cs['deviceType'] = "2";
- $cs['deviceTypeName'] = "消防栓";
- }elseif ($ypSchoolOwner[$key]['owner_dwtype']==1){
- $cs['deviceType'] = "3";
- $cs['deviceTypeName'] = "烟感检测";
- }
- $cs['companyCode'] = $ypSchoolOwner[$key]['company_code'];
- $cs['companyName'] = $ypSchoolOwner[$key]['company_name'];
- $data6 = json_encode($cs);
- $rep_url = "http://ypaqpt.edu.sh.cn/schoolSafe-yp/deviceAdd";
- $res = $this->ypxycurl($rep_url, $data6);
- Log::record('yangpuxiaoyuandevice1' . ':' . $data6);
- Log::record('yangpuxiaoyuandevice2' . ':' . $res);
- print_r('结果'.$res);
- print_r($data6);
- sleep(0.5);
- }
- }
- }
- //消防总队平台主机点位设备注册api
- public function xfzdAddApi()
- {
- $data = input('');
- if (is_array($data)) {
- $getDataJson = json_encode($data, 320);
- $getdata = json_decode($getDataJson, true);//转成数组
- } else {
- $getDataJson = $data;
- $getdata = json_decode($getDataJson, true);//转成数组
- }
- $header=[
- "Content-Type:application/json",
- "appKey:850404889644236801"
- ];
- $sql6="select * from sp_corps_share_ceshi where open_project_id ='{$getdata["companyCode"]}' and `data` ={$getdata["hostCode"]} limit ".$getdata["startNum"].",".$getdata["endNum"];
- $ypSchoolOwner = add($sql6);
- if (!empty($ypSchoolOwner)){
- foreach ($ypSchoolOwner as $key=>$value){
- $cs['descript'] = $ypSchoolOwner[$key]['descript'];
- $cs['deviceName'] = $ypSchoolOwner[$key]['device_name'];
- // if ($ypSchoolOwner[$key]['dwtype']==6){
- $cs['deviceNo'] = $ypSchoolOwner[$key]['device_code'].str_replace(',','',$ypSchoolOwner[$key]['port']).$ypSchoolOwner[$key]['data'];
- // }else{
- // $cs['deviceNo'] = $ypSchoolOwner[$key]['device_code'];
- // }
- $cs['deviceType'] = $ypSchoolOwner[$key]['device_type'];
- $cs['deviceTypeName'] = $ypSchoolOwner[$key]['device_type_name'];
- $cs['openProjectId'] = $ypSchoolOwner[$key]['open_project_id'];
- $cs['floor'] = $ypSchoolOwner[$key]['device_floor'];
- $data6 = json_encode($cs);
- $rep_url = "http://iot.shxf-119.com/access/device/point/register";
- $res = $this->ywManagementCurl($rep_url,$header,$data6);
- Log::record('xiaofangzongduidevice1' . ':' . $data6);
- Log::record('xiaofangzongduidevice2' . ':' . $res);
- print_r('结果'.$res);
- print_r($data6);
- sleep(0.5);
- }
- }
- }
- //消防总队平台主机点位设备注册api
- public function xfzdDeviceAddApi()
- {
- $data = input('');
- if (is_array($data)) {
- $getDataJson = json_encode($data, 320);
- $getdata = json_decode($getDataJson, true);//转成数组
- } else {
- $getDataJson = $data;
- $getdata = json_decode($getDataJson, true);//转成数组
- }
- $header=[
- "Content-Type:application/json",
- "appKey:850404889644236801"
- ];
- $sql6="select * from sp_corps_share where open_project_id ='{$getdata["companyCode"]}' limit ".$getdata["startNum"].",".$getdata["endNum"];
- $ypSchoolOwner = add($sql6);
- if (!empty($ypSchoolOwner)){
- foreach ($ypSchoolOwner as $key=>$value){
- $cs['descript'] = $ypSchoolOwner[$key]['descript'];
- $cs['deviceName'] = $ypSchoolOwner[$key]['device_name'];
- if ($ypSchoolOwner[$key]['dwtype']==6){
- $cs['deviceNo'] = $ypSchoolOwner[$key]['device_code'].$ypSchoolOwner[$key]['port'];
- }else{
- $cs['deviceNo'] = $ypSchoolOwner[$key]['device_code'];
- }
- $cs['deviceType'] = $ypSchoolOwner[$key]['device_type'];
- $cs['deviceTypeName'] = $ypSchoolOwner[$key]['device_type_name'];
- $cs['openProjectId'] = $ypSchoolOwner[$key]['open_project_id'];
- $cs['floor'] = $ypSchoolOwner[$key]['device_floor'];
- $data6 = json_encode($cs);
- $rep_url = "http://iot.shxf-119.com/access/device/point/register";
- $res = $this->ywManagementCurl($rep_url,$header,$data6);
- Log::record('xiaofangzongduidevice1' . ':' . $data6);
- Log::record('xiaofangzongduidevice2' . ':' . $res);
- print_r('结果'.$res);
- print_r($data6);
- sleep(0.5);
- }
- }
- }
- //消防总队平台设备数据推送api
- public function xfzdDeviceInfoAddApi()
- {
- $data = input('');
- if (is_array($data)) {
- $getDataJson = json_encode($data, 320);
- $getdata = json_decode($getDataJson, true);//转成数组
- } else {
- $getDataJson = $data;
- $getdata = json_decode($getDataJson, true);//转成数组
- }
- $header=[
- "Content-Type:application/json",
- "appKey:850404889644236801"
- ];
- $rep_url1 = "http://iot.shxf-119.com/access/devlog/transmission/devicestatus";//用传
- $rep_url2 = "http://iot.shxf-119.com/access/devlog/sprinkler/endpressure";//喷淋末端压力
- $rep_url3 = "http://iot.shxf-119.com/access/devlog/sprinkler/pipepressunusual";//喷淋主管压力
- $rep_url4 = "http://iot.shxf-119.com/access/devlog/sprinkler/spraypump";//喷淋泵状态
- $rep_url5 = "http://iot.shxf-119.com/access/devlog/hydrant/endpressure";//消火栓末端压力
- $rep_url6 = "http://iot.shxf-119.com/access/devlog/hydrant/pipepress";//消火栓主管压力
- $rep_url7 = "http://iot.shxf-119.com/access/devlog/hydrant/tanklevel";//水箱液位
- $rep_url8 = "http://iot.shxf-119.com/access/devlog/hydrant/pumpstatus";//消防泵状态
- $sql6="select * from sp_corps_share where open_project_id ='{$getdata["companyCode"]}'";
- $ypSchoolOwner = add($sql6);
- if (!empty($ypSchoolOwner)){
- foreach ($ypSchoolOwner as $key=>$value){
- $sql7="select * from sp_owner_status where device_id ='{$ypSchoolOwner[$key]['device_code']}'";
- $companyOwner = add($sql7);
- $cs['descript'] = $ypSchoolOwner[$key]['descript'];
- $cs['deviceName'] = $ypSchoolOwner[$key]['device_name'];
- if ($ypSchoolOwner[$key]['dwtype']==6){
- $cs['deviceNo'] = $ypSchoolOwner[$key]['device_code'].$ypSchoolOwner[$key]['port'];
- }else{
- $cs['deviceNo'] = $ypSchoolOwner[$key]['device_code'];
- }
- $cs['deviceType'] = $ypSchoolOwner[$key]['device_type'];
- $cs['deviceTypeName'] = $ypSchoolOwner[$key]['device_type_name'];
- $cs['openProjectId'] = $ypSchoolOwner[$key]['open_project_id'];
- $cs['floor'] = $ypSchoolOwner[$key]['device_floor'];
- if ($ypSchoolOwner[$key]['dwtype']==1){
- foreach ($companyOwner as $key1=>$value1){
- if ($companyOwner[$key1]['point_code']==1){
- if(strstr($companyOwner[$key1]['content'],'监测连线故障') !== false) {
- $cs['connectStatus'] = "1";
- }else{
- $cs['connectStatus'] = "0";
- }
- $cs['workStatus'] = "0";
- $cs['mainPower'] = "0";
- $cs['logTime'] = date('Y-m-d H:i:s');
- $data6 = json_encode($cs);
- $res = $this->ywManagementCurl($rep_url1,$header,$data6);
- print_r('结果'.$res);
- }
- }
- }elseif ($ypSchoolOwner[$key]['dwtype']==2){
- foreach ($companyOwner as $key1=>$value1){
- if ($companyOwner[$key1]['point_code']==4){
- $cs['logTime'] = date('Y-m-d H:i:s');
- $cs['pressure'] = $companyOwner[$key1]['point_data'];
- }elseif ($companyOwner[$key1]['point_code']==1){
- if(strstr($companyOwner[$key1]['content'],'正常') !== false) {
- $cs['alarmStatus'] = "0";
- }elseif (strstr($companyOwner[$key1]['content'],'低压') !== false){
- $cs['alarmStatus'] = "1";
- }elseif (strstr($companyOwner[$key1]['content'],'高压') !== false){
- $cs['alarmStatus'] = "2";
- }else{
- $cs['alarmStatus'] = "0";
- }
- }
- }
- if($ypSchoolOwner[$key]['device_type']==304){
- $data6 = json_encode($cs);
- $res = $this->ywManagementCurl($rep_url2,$header,$data6);
- print_r('结果'.$res);
- }elseif ($ypSchoolOwner[$key]['device_type']==301){
- $data6 = json_encode($cs);
- $res = $this->ywManagementCurl($rep_url3,$header,$data6);
- print_r('结果'.$res);
- }elseif ($ypSchoolOwner[$key]['device_type']==305){
- $data6 = json_encode($cs);
- $res = $this->ywManagementCurl($rep_url5,$header,$data6);
- print_r('结果'.$res);
- }elseif ($ypSchoolOwner[$key]['device_type']==302){
- $data6 = json_encode($cs);
- $res = $this->ywManagementCurl($rep_url6,$header,$data6);
- print_r('结果'.$res);
- }
- }elseif ($ypSchoolOwner[$key]['dwtype']==5){
- foreach ($companyOwner as $key1=>$value1){
- if ($companyOwner[$key1]['point_code']==4){
- $cs['logTime'] = date('Y-m-d H:i:s');
- $cs['level'] = $companyOwner[$key1]['point_data'];
- }elseif ($companyOwner[$key1]['point_code']==1){
- if(strstr($companyOwner[$key1]['content'],'正常') !== false) {
- $cs['alarmStatus'] = "0";
- }elseif (strstr($companyOwner[$key1]['content'],'低液位') !== false){
- $cs['alarmStatus'] = "1";
- }elseif (strstr($companyOwner[$key1]['content'],'高液位') !== false){
- $cs['alarmStatus'] = "2";
- }else{
- $cs['alarmStatus'] = "0";
- }
- }
- }
- if($ypSchoolOwner[$key]['device_type']==402){
- $data6 = json_encode($cs);
- $res = $this->ywManagementCurl($rep_url7,$header,$data6);
- print_r('结果'.$res);
- }else{
- $data6 = json_encode($cs);
- $res = $this->ywManagementCurl($rep_url7,$header,$data6);
- print_r('结果'.$res);
- }
- }elseif ($ypSchoolOwner[$key]['dwtype']==6){
- if($ypSchoolOwner[$key]['device_type']==258 || $ypSchoolOwner[$key]['device_type']==256 || $ypSchoolOwner[$key]['device_type']==452){
- $cs['logTime'] = date('Y-m-d H:i:s');
- $companyOwner1 = $ypSchoolOwner[$key]['data'];
- foreach ($companyOwner1 as $key1=>$value1){
- if ($companyOwner1[$key1]['port']==-1){
- if(strstr($companyOwner1[$key1]['name'],'powerStatus') !== false) {
- $cs['powerState'] = "0";
- }elseif (strstr($companyOwner1[$key1]['name'],'runStatus') !== false){
- $cs['manualAutomaticState'] = "0";
- }elseif (strstr($companyOwner1[$key1]['name'],'startStatus') !== false){
- $cs['startStopStatus'] = "0";
- }elseif (strstr($companyOwner1[$key1]['name'],'faultStatus') !== false){
- $cs['faultStatus'] = "0";
- }
- }
- }
- foreach ($companyOwner as $key3=>$value3){
- foreach ($companyOwner1 as $key2=>$value2){
- if ($companyOwner1[$key2]['port']==$companyOwner[$key3]['point_code'] && $companyOwner[$key3]['point_code']!=0){
- if(strstr($companyOwner[$key3]['content'],'正常') !== false || strstr($companyOwner[$key3]['content'],'自动') !== false || strstr($companyOwner[$key3]['content'],'停止') !== false) {
- if(strstr($companyOwner1[$key2]['name'],'powerStatus') !== false) {
- $cs['powerState'] = "0";
- }elseif (strstr($companyOwner1[$key2]['name'],'runStatus') !== false){
- $cs['manualAutomaticState'] = "0";
- }elseif (strstr($companyOwner1[$key2]['name'],'startStatus') !== false){
- $cs['startStopStatus'] = "0";
- }elseif (strstr($companyOwner1[$key2]['name'],'faultStatus') !== false){
- $cs['faultStatus'] = "0";
- }
- }elseif (strstr($companyOwner[$key3]['content'],'关闭') !== false || strstr($companyOwner[$key3]['content'],'手动') !== false || strstr($companyOwner[$key3]['content'],'运行') !== false || strstr($companyOwner[$key3]['content'],'故障') !== false){
- if(strstr($companyOwner1[$key2]['name'],'powerStatus') !== false) {
- $cs['powerState'] = "1";
- }elseif (strstr($companyOwner1[$key2]['name'],'runStatus') !== false){
- $cs['manualAutomaticState'] = "1";
- }elseif (strstr($companyOwner1[$key2]['name'],'startStatus') !== false){
- $cs['startStopStatus'] = "1";
- }elseif (strstr($companyOwner1[$key2]['name'],'faultStatus') !== false){
- $cs['faultStatus'] = "1";
- }
- }else{
- if(strstr($companyOwner1[$key2]['name'],'powerStatus') !== false) {
- $cs['powerState'] = "0";
- }elseif (strstr($companyOwner1[$key2]['name'],'runStatus') !== false){
- $cs['manualAutomaticState'] = "0";
- }elseif (strstr($companyOwner1[$key2]['name'],'startStatus') !== false){
- $cs['startStopStatus'] = "0";
- }elseif (strstr($companyOwner1[$key2]['name'],'faultStatus') !== false){
- $cs['faultStatus'] = "0";
- }
- }
- break;
- }
- }
- }
- if ($ypSchoolOwner[$key]['device_type']==258){
- $data6 = json_encode($cs);
- $res = $this->ywManagementCurl($rep_url8,$header,$data6);
- print_r('结果'.$res);
- }elseif ($ypSchoolOwner[$key]['device_type']==256){
- $data6 = json_encode($cs);
- $res = $this->ywManagementCurl($rep_url4,$header,$data6);
- print_r('结果'.$res);
- }elseif ($ypSchoolOwner[$key]['device_type']==452){
- $data6 = json_encode($cs);
- $res = $this->ywManagementCurl($rep_url4,$header,$data6);
- print_r('结果'.$res);
- }
- }else{
- $cs['logTime'] = date('Y-m-d H:i:s');
- $companyOwner1 = $ypSchoolOwner[$key]['data'];
- foreach ($companyOwner as $key2=>$value2) {
- foreach ($companyOwner1 as $key3 => $value3) {
- if (strstr($companyOwner1[$key3]['name'],'value') !== false){
- if ($companyOwner1[$key3]['port']==$companyOwner[$key2]['point_code'] && $companyOwner[$key2]['point_code']!=0){
- $cs['pressure'] = $companyOwner[$key2]['point_data'];
- if(strstr($companyOwner[$key2]['content'],'正常') !== false) {
- $cs['alarmStatus'] = "0";
- }elseif (strstr($companyOwner[$key2]['content'],'低压') !== false){
- $cs['alarmStatus'] = "1";
- }elseif (strstr($companyOwner[$key2]['content'],'高压') !== false){
- $cs['alarmStatus'] = "2";
- }else{
- $cs['alarmStatus'] = "0";
- }
- break;
- }
- }
- }
- }
- if($ypSchoolOwner[$key]['device_type']==304){
- $data6 = json_encode($cs);
- $res = $this->ywManagementCurl($rep_url2,$header,$data6);
- print_r('结果'.$res);
- }elseif ($ypSchoolOwner[$key]['device_type']==301){
- $data6 = json_encode($cs);
- $res = $this->ywManagementCurl($rep_url3,$header,$data6);
- print_r('结果'.$res);
- }elseif ($ypSchoolOwner[$key]['device_type']==305){
- $data6 = json_encode($cs);
- $res = $this->ywManagementCurl($rep_url5,$header,$data6);
- print_r('结果'.$res);
- }elseif ($ypSchoolOwner[$key]['device_type']==302){
- $data6 = json_encode($cs);
- $res = $this->ywManagementCurl($rep_url6,$header,$data6);
- print_r('结果'.$res);
- }
- }
- }
- }
- }
- }
- //积木测试api
- public function mhCompanyData()
- {
- $data=input('');
- if(is_array($data)){
- $getDataJson= json_encode($data,320);
- $getdata=json_decode($getDataJson,true);//转成数组
- }else{
- $getDataJson=$data;
- $getdata=json_decode($getDataJson,true);//转成数组
- }
- $allowKey = ['31cdd6a7766d24820156e5304a3f7107'];
- // if (!in_array($clientIp, $allowIp)){
- if (!empty($getdata['app_key']) && in_array($getdata['app_key'], $allowKey)){
- if (!empty($getdata['app_key'])){
- }
- }else{
- $sensorList=[];
- $returnInformation['code'] = 10001;
- $returnInformation['msg'] = "app_key参数错误";
- $returnInformation['data']=$sensorList;
- return json_encode($returnInformation);
- }
- }
- 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;
- }
- public function ywManagementCurl($url,$header,$data=''){
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
- 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;
- }
- }
|