123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757 |
- <?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 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;
- }
- }
|