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;$iwhere('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$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 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; } }