Manage.php.bak.20210419 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Controller;
  4. use think\Session;
  5. use think\Db;
  6. use think\Request;
  7. use think\Log;
  8. class Manage extends Controller
  9. {
  10. private $host="https://device.api.ct10649.com:8743/";
  11. private $appId="wvdOfp7JVe0ULwnFKwBF0edfbcAa";
  12. private $secret="Bihoe_rY9vebXMw6sFfpQy0jiRca";
  13. public function index(){
  14. $data_list =Db::table('managelog')->paginate();
  15. $pages = $data_list->render();
  16. $this->assign('data_list', $data_list);
  17. $this->assign('pages', $pages);
  18. //所有的服务类型
  19. $SetType=[
  20. 1=>"读取模块信息",
  21. 2=>"读取参数",
  22. 3=>"设置IOT平台IP地址",
  23. 4=>"设置参数",
  24. 5=>"复位模块",
  25. 6=>"配置下行波特率",
  26. 7=>"读取下行波特率配置",
  27. 8=>"设置DTU自动采集指令",
  28. 9=>"读取DTU自动采集指令",
  29. 10=>"设置APN",
  30. 11=>"读取APN设置",
  31. 12=>"AT指令",
  32. /* [1,"读取模块信息"],[2,"读取参数"],[3,"设置IOT平台IP地址"],[4,"设置参数"],[5,"复位模块"],[6,"配置下行波特率"],
  33. [7,"读取下行波特率配置"],[8,"设置DTU自动采集指令"],[9,"读取DTU自动采集指令"],[10,"设置APN"],[11,"读取APN设置"],
  34. [12,"AT指令"]*/
  35. ];
  36. $this->assign('SetType',$SetType);
  37. return $this->fetch();
  38. }
  39. //下发命令
  40. public function add(){
  41. if ($this->request->isPost()) {
  42. $data=input('');
  43. $list = array();
  44. if (is_array($data)) {
  45. $list['data'] = json_encode($data, 320);
  46. $getdata = json_decode($list['data'], true);//转成数组
  47. $list['type'] = 1;
  48. } else {
  49. $list['data'] = $data;
  50. $getdata = json_decode($list['data'], true);//转成数组
  51. $list['type'] = 2;
  52. }
  53. $json_string = json_encode($getdata, JSON_FORCE_OBJECT);
  54. Log::record('rawData:' .$json_string );
  55. $paras = array();
  56. $upData = array();
  57. if(!empty($getdata["dataType"])){
  58. if($getdata['dataType']=="setting"){
  59. $sql6="select * from sp_owner where id ={$getdata['sensorId']}";
  60. $longHuOwner = add($sql6);
  61. if ($longHuOwner[0]['s_interval']==7){
  62. $imei='&imei='.$longHuOwner[0]['owner_code'];
  63. if($longHuOwner[0]['dwtype']==2){
  64. $deviceType=1;
  65. }elseif ($longHuOwner[0]['dwtype']==5){
  66. $deviceType=2;
  67. }
  68. $sendata['imei']=$longHuOwner[0]['owner_code'];
  69. $sendata['deviceType']=$deviceType;
  70. $sendingGap = '';
  71. if (!empty($getdata["sendTime"])){
  72. if($getdata['sendTime']<1800) {
  73. $sendingGap = '&sendingGap=1800';
  74. $upData['send_time'] = 1800;
  75. $sendata['sendingGap']=1800;
  76. }else{
  77. $sendingGap = '&sendingGap='.$getdata["sendTime"];
  78. $upData['send_time'] = $getdata["sendTime"];
  79. $sendata['sendingGap']=$getdata["sendTime"];
  80. }
  81. }
  82. $unipathThresholdLimit = '';
  83. if (!empty($getdata["lowThreshold"])){
  84. $sendata['unipathThresholdLimit'] = $getdata["lowThreshold"]*1000;
  85. $upData['low_threshold'] = $getdata['lowThreshold'];
  86. }
  87. $unipathThresholdUpper = '';
  88. if (!empty($getdata["highThreshold"])){
  89. $sendata['unipathThresholdUpper'] = $getdata["highThreshold"]*1000;
  90. $upData['high_threshold'] = $getdata['highThreshold'];
  91. }
  92. $header=[
  93. "Content-Type:application/json"
  94. ];
  95. $rescurl=$this->s_curl("https://api.topsailiot.com/dmp/deviceConfig?appkey=3a3e533818a9604dfec0388b2d817dbc2f9f7b05dd4b153c403897cd93a9c04d0edfe3d86ebd3ad0&userid=TS2020120110122980052",json_encode($sendata),$header);
  96. // $rep_url = "https://api.topsailiot.com/dmp/deviceConfig?appkey=3a3e533818a9604dfec0388b2d817dbc2f9f7b05dd4b153c403897cd93a9c04d0edfe3d86ebd3ad0&userid=TS2020120110122980052".$imei.$deviceType.$sendingGap.$unipathThresholdLimit.$unipathThresholdUpper;
  97. // $res = $this->s_curl($rep_url,'');
  98. Log::record('longhulorasend' . ':' . json_encode($sendata));
  99. Log::record('longhuloraresult' . ':' . $rescurl);
  100. // if (is_array($rescurl)) {
  101. //
  102. // }else{}
  103. $resArr = json_decode($rescurl,true);
  104. if ($resArr['code']==0){
  105. $deviceConfigure = Db::name('deviceConfigure')->where('device_code', trim($longHuOwner[0]['owner_code']))->find();
  106. if (!empty($deviceConfigure['device_code'])) {
  107. sleep(1);
  108. $upDataRes = Db::name('deviceConfigure')->where('device_code', trim($longHuOwner[0]['owner_code']))->update($upData);
  109. }else{
  110. sleep(1);
  111. $upData['device_code'] = $longHuOwner[0]['owner_code'];
  112. $insertRes = Db::name('deviceConfigure')->insertGetId($upData);
  113. }
  114. }
  115. return $rescurl;
  116. }else{
  117. $deviceCode = '';
  118. $deviceArr = str_split($longHuOwner[0]['owner_code'],1);
  119. for ($i=0;$i<count($deviceArr);$i++){
  120. $deviceCode.='3'.$deviceArr[$i];
  121. }
  122. $deviceCode = $deviceCode.'30';
  123. $sendingInterval = "";//发送间隔
  124. if (!empty($getdata['sendTime'])) {
  125. if($getdata['sendTime']<1800){
  126. $sendingInterval = "020400000708";
  127. $upData['send_time'] = 1800;
  128. }else{
  129. $liuSendTime1 = dechex($getdata['sendTime']);
  130. $liuSendTime = str_pad($liuSendTime1,8,0,STR_PAD_LEFT);
  131. $sendingInterval = "0204".$liuSendTime;
  132. $upData['send_time'] = $getdata['sendTime'];
  133. }
  134. }
  135. $lowThreshold = "";//告警下限
  136. if (!empty($getdata['lowThreshold'])) {
  137. $shiLowThreshold = $getdata['lowThreshold']*1000;
  138. $liuLowThreshold1 = dechex($shiLowThreshold);
  139. $liuLowThreshold = str_pad($liuLowThreshold1,4,0,STR_PAD_LEFT);
  140. $lowThreshold = "0602".$liuLowThreshold;
  141. $upData['low_threshold'] = $getdata['lowThreshold'];
  142. }
  143. $highThreshold = "";//告警上限
  144. if (!empty($getdata['highThreshold'])) {
  145. $shiHighThreshold = $getdata['highThreshold']*1000;
  146. $liuHighThreshold1 = dechex($shiHighThreshold);
  147. $liuHighThreshold = str_pad($liuHighThreshold1,4,0,STR_PAD_LEFT);
  148. $highThreshold = "0702".$liuHighThreshold;
  149. $upData['high_threshold'] = $getdata['highThreshold'];
  150. }
  151. if($longHuOwner[0]['dwtype']==2){
  152. $dwType = "01";
  153. }elseif ($longHuOwner[0]['dwtype']==5){
  154. $dwType = "02";
  155. }
  156. $shiLength = strlen($dwType.$deviceCode.$sendingInterval.$lowThreshold.$highThreshold)/2;
  157. $liuLength = dechex($shiLength);
  158. $length = str_pad($liuLength,4,0,STR_PAD_LEFT);
  159. //调用电信接口
  160. $token=json_decode(gettoken(),true);
  161. $a = "7470736c04".$length.$dwType.$deviceCode.$sendingInterval.$lowThreshold.$highThreshold;
  162. $s = pack('H*',$a);
  163. $t = crc166($s);
  164. $t = unpack("H*", $s.$t);
  165. $paras['value'] = $t[1]."696f74";
  166. // $t = crc16($paras['value'],0X1021,0Xffff,0X0000,false,false);
  167. $device = Db::name('device')->where('device_id', trim($longHuOwner[0]['owner_code']))->find();
  168. $sendata=[
  169. "appId"=>$this->appId,
  170. "deviceId"=>$device['iot_id'],// c448d5e3-2ec5-4e42-99d7-0ad27668614f 137effbe-4980-4719-a768-0ae301fc5000
  171. "command"=>[
  172. "serviceId"=>"topsailSensorData",
  173. "method"=>"SET_DEVICE_LEVEL",
  174. "paras"=>$paras
  175. ],
  176. "callbackUrl"=>"http://iot.usky.cn:80/ytapi/admin/Manage/status",
  177. ];
  178. $header=[
  179. "Content-Type:application/json",
  180. "app_key:".$this->appId,
  181. "Authorization:Bearer ".$token["accessToken"]
  182. ];
  183. $rescurl=curl($this->host."iocm/app/cmd/v1.4.0/deviceCommands",json_encode($sendata),$header);
  184. // var_dump($rescurl);
  185. Log::record('nbmanage1:' .$rescurl[0].$sendata['command']['paras']['value'] );
  186. if($rescurl[0]==201){//成功
  187. $res1=json_decode($rescurl[1],true);
  188. // var_dump($res1);
  189. }else{//失败
  190. // $res2=json_decode($res1[1],true);
  191. // return $this->error($rescurl[1]);
  192. Log::record('nbmanageerror:' .json_encode($this->error($rescurl[1])));
  193. $returnInformation['code'] = 60001;
  194. $returnInformation['msg'] = "操作失败,请联系管理员";
  195. return json_encode($returnInformation);
  196. }
  197. }
  198. }else if($getdata['dataType']=="bendi"){
  199. $deviceCode = '';
  200. $deviceArr = str_split($getdata['IMEI'],1);
  201. for ($i=0;$i<count($deviceArr);$i++){
  202. $deviceCode.='3'.$deviceArr[$i];
  203. }
  204. $deviceCode = $deviceCode.'30';
  205. //调用电信接口
  206. $collectionInterval = "";//发送间隔
  207. if (!empty($getdata['collectionTime'])) {
  208. $liuCollectionTime1 = dechex($getdata['collectionTime']);
  209. $liuCollectionTime = str_pad($liuCollectionTime1,8,0,STR_PAD_LEFT);
  210. $collectionInterval = "0104".$liuCollectionTime;
  211. }
  212. $sendingInterval = "";//发送间隔
  213. if (!empty($getdata['sendTime'])) {
  214. $liuSendTime1 = dechex($getdata['sendTime']);
  215. $liuSendTime = str_pad($liuSendTime1,8,0,STR_PAD_LEFT);
  216. $sendingInterval = "0204".$liuSendTime;
  217. }
  218. $lowThreshold = "";//告警下限
  219. if (!empty($getdata['alarmLowerLimit'])) {
  220. $shiLowThreshold = $getdata['alarmLowerLimit']*1000;
  221. $liuLowThreshold1 = dechex($shiLowThreshold);
  222. $liuLowThreshold = str_pad($liuLowThreshold1,4,0,STR_PAD_LEFT);
  223. $lowThreshold = "0602".$liuLowThreshold;
  224. }
  225. $highThreshold = "";//告警上限
  226. if (!empty($getdata['alarmUpperLimit'])) {
  227. $shiHighThreshold = $getdata['alarmUpperLimit']*1000;
  228. $liuHighThreshold1 = dechex($shiHighThreshold);
  229. $liuHighThreshold = str_pad($liuHighThreshold1,4,0,STR_PAD_LEFT);
  230. $highThreshold = "0702".$liuHighThreshold;
  231. }
  232. if($getdata['deviceType']==2){
  233. $dwType = "01";
  234. }elseif ($getdata['deviceType']==5){
  235. $dwType = "02";
  236. }
  237. $shiLength = strlen($dwType.$deviceCode.$collectionInterval.$sendingInterval.$lowThreshold.$highThreshold)/2;
  238. $liuLength = dechex($shiLength);
  239. $length = str_pad($liuLength,4,0,STR_PAD_LEFT);
  240. //调用电信接口
  241. $token=json_decode(gettoken(),true);
  242. $a = "7470736c04".$length.$dwType.$deviceCode.$collectionInterval.$sendingInterval.$lowThreshold.$highThreshold;
  243. $s = pack('H*',$a);
  244. $t = crc166($s);
  245. $t = unpack("H*", $s.$t);
  246. $paras['value'] = $t[1]."696f74";
  247. $sendata=[
  248. "appId"=>$this->appId,
  249. "deviceId"=>$getdata['deviceId'],// c448d5e3-2ec5-4e42-99d7-0ad27668614f 137effbe-4980-4719-a768-0ae301fc5000
  250. "command"=>[
  251. "serviceId"=>"topsailSensorData",
  252. "method"=>"SET_DEVICE_LEVEL",
  253. "paras"=>$paras
  254. ],
  255. "callbackUrl"=>"http://iot.usky.cn:80/ytapi/admin/Manage/status",
  256. ];
  257. $header=[
  258. "Content-Type:application/json",
  259. "app_key:".$this->appId,
  260. "Authorization:Bearer ".$token["accessToken"]
  261. ];
  262. $rescurl=curl($this->host."iocm/app/cmd/v1.4.0/deviceCommands",json_encode($sendata),$header);
  263. var_dump($rescurl);
  264. Log::record('nbmanage1:' .$rescurl[0].$sendata['command']['paras']['value'] );
  265. if($rescurl[0]==201){//成功
  266. $res1=json_decode($rescurl[1],true);
  267. // var_dump($res1);
  268. }else{//失败
  269. // $res2=json_decode($res1[1],true);
  270. return $this->error($rescurl[1]);
  271. }
  272. }else{
  273. $returnInformation['code'] = 60001;
  274. $returnInformation['msg'] = "操作失败,请联系管理员";
  275. return json_encode($returnInformation);
  276. }
  277. }else{
  278. $returnInformation['code'] = 60001;
  279. $returnInformation['msg'] = "操作失败,请联系管理员";
  280. return json_encode($returnInformation);
  281. }
  282. //将请求的结果存入managelog中
  283. $list=array();
  284. $list['commandId']=$res1['commandId'];
  285. $list['deviceId']=$res1['deviceId'];
  286. $list['status']=$res1['status'];
  287. $list['command']= json_encode($res1['command'],320) ;
  288. if($getdata['dataType']=="setting"){
  289. $list['IMEI']=$longHuOwner[0]['owner_code'];
  290. }else{
  291. $list['IMEI']=$getdata['IMEI'];
  292. }
  293. $list['HexStr']=json_encode($upData,320) ;;
  294. $list['settype']="";
  295. $list['addtime']= date('Y-m-d H:i:s');
  296. $res = Db::name('managelog')->insertGetId($list);//将推送的数据存入总表
  297. if($res) {
  298. $returnInformation['code'] = 200;
  299. $returnInformation['msg'] = "操作成功";
  300. if($getdata['dataType']=="setting"){
  301. return json_encode($returnInformation);
  302. }else{
  303. return $this->success('添加成功','index');
  304. }
  305. }else{
  306. $returnInformation['code'] = 60001;
  307. $returnInformation['msg'] = "操作失败,请联系管理员";
  308. if($getdata['dataType']=="setting"){
  309. return json_encode($returnInformation);
  310. }else{
  311. return $this->error("添加失败,请稍后再试");
  312. }
  313. }
  314. }
  315. if($this->request->isGet()){
  316. $deviceId=input('deviceId');
  317. $IMEI=input('IMEI');
  318. //所有的服务类型
  319. $SetType=[
  320. [1,"读取模块信息"],[2,"读取参数"],[3,"设置IOT平台IP地址"],[4,"设置参数"],[5,"复位模块"],[6,"配置下行波特率"],
  321. [7,"读取下行波特率配置"],[8,"设置DTU自动采集指令"],[9,"读取DTU自动采集指令"],[10,"设置APN"],[11,"读取APN设置"],
  322. [12,"AT指令"]
  323. ];
  324. $this->assign('SetType',$SetType);
  325. $this->assign('deviceId',$deviceId);
  326. $this->assign('IMEI', $IMEI);
  327. return $this->fetch();
  328. }
  329. }
  330. public function status(){
  331. $data=input('');
  332. if(is_array($data)){
  333. $getdata= json_encode($data,320);
  334. $getdata=json_decode($getdata,true);//转成数组
  335. $list['type']=1;
  336. }else{
  337. $getdata=$data;
  338. $getdata=json_decode($getdata,true);//转成数组
  339. $list['type']=2;
  340. }
  341. $list=array();
  342. $list['deviceId']=$getdata['deviceId'];
  343. $list['commandId']=$getdata['commandId'];
  344. $list['resultCode']=$getdata['result']['resultCode'];
  345. $list['result']= json_encode($getdata['result'],320) ;
  346. $list['addtime']= date('Y-m-d H:i:s');
  347. $res = Db::name('managedata')->insertGetId($list);//将推送的数据存入总表
  348. if($getdata['result']['resultCode']=='SENT'||$getdata['result']['resultCode']=='TIMEOUT'||$getdata['result']['resultCode']=='DELIVERED'||$getdata['result']['resultCode']=='SUCCESSFUL'){
  349. $device = Db::name('device')->where('iot_id', trim($getdata['deviceId']))->find();
  350. $deviceConfigure = Db::name('deviceConfigure')->where('device_code', trim($device['device_id']))->find();
  351. $managelog = Db::name('managelog')->where('commandId', trim($getdata['commandId']))->find();
  352. $upData = json_decode($managelog['HexStr'],true);
  353. if (!empty($deviceConfigure['device_code'])) {
  354. sleep(1);
  355. $upDataRes = Db::name('deviceConfigure')->where('device_code', trim($device['device_id']))->update($upData);
  356. }else{
  357. sleep(1);
  358. $upData['device_code'] = $device['device_id'];
  359. $insertRes = Db::name('deviceConfigure')->insertGetId($upData);
  360. }
  361. }
  362. echo 111;
  363. }
  364. public function delete(){
  365. echo 111;
  366. }
  367. public function manualPush(){
  368. $data=input('');
  369. if(is_array($data)){
  370. $getdata= json_encode($data,320);
  371. $getdata=json_decode($getdata,true);//转成数组
  372. $list['type']=1;
  373. }else{
  374. $getdata=$data;
  375. $getdata=json_decode($getdata,true);//转成数组
  376. $list['type']=2;
  377. }
  378. if ($getdata['deviceType']==2){
  379. $sql6="select * from sp_sj2017 where device_code ='{$getdata["deviceCode"]}'";
  380. $longHuOwner = add($sql6);
  381. Log::record('yangpuxiaoyuan12' . ':' . $longHuOwner[0]["id"]);
  382. foreach ($longHuOwner as $row) {
  383. $waterData["SubType"] = 2;
  384. $waterData["DeviceId"] = $getdata["deviceCode"];
  385. $waterData["InsertId"] = $row["id"];
  386. $waterData["Confirmed"] = false;
  387. $data6 = json_encode($waterData);
  388. $rep_url = "http://47.98.201.187:55335/report";
  389. $res = $this->ypxycurl($rep_url, $data6);
  390. Log::record('yangpuxiaoyuan' . ':' . $res);
  391. sleep(1);
  392. }
  393. }
  394. // $list=array();
  395. // $list['deviceId']=$getdata['deviceId'];
  396. // $list['commandId']=$getdata['commandId'];
  397. // $list['resultCode']=$getdata['result']['resultCode'];
  398. // $list['result']= json_encode($getdata['result'],320) ;
  399. // $list['addtime']= date('Y-m-d H:i:s');
  400. // $res = Db::name('managedata')->insertGetId($list);//将推送的数据存入总表
  401. // if($getdata['result']['resultCode']=='SENT'||$getdata['result']['resultCode']=='TIMEOUT'||$getdata['result']['resultCode']=='DELIVERED'||$getdata['result']['resultCode']=='SUCCESSFUL'){
  402. // $device = Db::name('device')->where('iot_id', trim($getdata['deviceId']))->find();
  403. // $deviceConfigure = Db::name('deviceConfigure')->where('device_code', trim($device['device_id']))->find();
  404. // $managelog = Db::name('managelog')->where('commandId', trim($getdata['commandId']))->find();
  405. // $upData = json_decode($managelog['HexStr'],true);
  406. // if (!empty($deviceConfigure['device_code'])) {
  407. // sleep(1);
  408. // $upDataRes = Db::name('deviceConfigure')->where('device_code', trim($device['device_id']))->update($upData);
  409. // }else{
  410. // sleep(1);
  411. // $upData['device_code'] = $device['device_id'];
  412. // $insertRes = Db::name('deviceConfigure')->insertGetId($upData);
  413. // }
  414. // }
  415. echo 111;
  416. }
  417. // public function alarmHandling(){
  418. // $data=input('');
  419. // if(is_array($data)){
  420. // $getDataJson= json_encode($data,320);
  421. // $getdata=json_decode($getDataJson,true);//转成数组
  422. //// $list['type']=1;
  423. //
  424. // }else{
  425. // $getDataJson=$data;
  426. // $getdata=json_decode($getDataJson,true);//转成数组
  427. //// $list['type']=2;
  428. //
  429. // }
  430. // Log::record('yangpuerqi' . ':' .$getDataJson);
  431. // if (!empty($getdata['userName']) && !empty($getdata['userPassword'])){
  432. // if ($getdata["userName"]=="ypsgec" && $getdata["userPassword"]=="ypsgec123"){
  433. // if (empty($getdata['recordId'])){
  434. // $returnInformation['code'] = 60001;
  435. // $returnInformation['msg'] = "操作失败,缺少记录Id";
  436. // return json_encode($returnInformation);
  437. // }elseif (empty($getdata['deviceCode'])){
  438. // $returnInformation['code'] = 60001;
  439. // $returnInformation['msg'] = "操作失败,缺少设备编号";
  440. // return json_encode($returnInformation);
  441. // }elseif (empty($getdata['deviceType'])){
  442. // $returnInformation['code'] = 60001;
  443. // $returnInformation['msg'] = "操作失败,缺少设备类型";
  444. // return json_encode($returnInformation);
  445. // }elseif (is_int($getdata['confirmAll'])==true&&$getdata['confirmAll']!=0&&$getdata['confirmAll']!=1){
  446. // $returnInformation['code'] = 60001;
  447. // $returnInformation['msg'] = "操作失败,缺少是否批量处理类型";
  448. // return json_encode($returnInformation);
  449. // }elseif ($getdata['misinformation']!=0&&$getdata['misinformation']!=1){
  450. // $returnInformation['code'] = 60001;
  451. // $returnInformation['msg'] = "操作失败,缺少是否误报字段";
  452. // return json_encode($returnInformation);
  453. // }elseif (empty($getdata['handlerName'])){
  454. // $returnInformation['code'] = 60001;
  455. // $returnInformation['msg'] = "操作失败,缺少处理人姓名";
  456. // return json_encode($returnInformation);
  457. // }elseif (empty($getdata['handlerPhone'])){
  458. // $returnInformation['code'] = 60001;
  459. // $returnInformation['msg'] = "操作失败,缺少处理人联系方式";
  460. // return json_encode($returnInformation);
  461. // }else{
  462. // $returnInformation['code'] = 0;
  463. // $returnInformation['msg'] = "操作成功";
  464. // return json_encode($returnInformation);
  465. // }
  466. //
  467. //
  468. //
  469. //
  470. //
  471. //
  472. //
  473. // }else{
  474. // $returnInformation['code'] = 60002;
  475. // $returnInformation['msg'] = "操作失败,用户名或密码错误";
  476. // return json_encode($returnInformation);
  477. // }
  478. // }else{
  479. // $returnInformation['code'] = 60002;
  480. // $returnInformation['msg'] = "操作失败,用户名或密码为空";
  481. // return json_encode($returnInformation);
  482. // }
  483. // }
  484. public function deviceList(){
  485. $data=input('');
  486. if(is_array($data)){
  487. $getDataJson= json_encode($data,320);
  488. $getdata=json_decode($getDataJson,true);//转成数组
  489. }else{
  490. $getDataJson=$data;
  491. $getdata=json_decode($getDataJson,true);//转成数组
  492. }
  493. $clientIp=$this->ip();
  494. Log::record('yangpuerqi_deviceList' . ':' .'<<<'.$clientIp.'>>>'.$getDataJson);
  495. $allowIp = ['222.69.153.207','120.253.238.34','114.86.176.11','120.253.238.37'];
  496. if (!in_array($clientIp, $allowIp)){
  497. $returnInformation['code'] = 60001;
  498. $returnInformation['msg'] = "操作失败,IP地址不在白名单中";
  499. $returnInformation['data']=null;
  500. return json_encode($returnInformation);
  501. }else{
  502. if (!empty($getdata['userName']) && !empty($getdata['userPassword'])){
  503. if ($getdata["userName"]=="sgec68" && $getdata["userPassword"]=="sgec68123"){
  504. if(!empty($getdata['commandType'])){
  505. if($getdata['commandType']=="FRONTPAGE"){
  506. $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'";
  507. $res=add($sql);
  508. if (!empty($res)){
  509. $returnInformation['code'] = 0;
  510. $returnInformation['msg'] = "操作成功";
  511. $returnInformation['data']=$res;
  512. return json_encode($returnInformation);
  513. }else{
  514. $returnInformation['code'] = 60001;
  515. $returnInformation['msg'] = "操作失败";
  516. $returnInformation['data']=null;
  517. return json_encode($returnInformation);
  518. }
  519. }else{
  520. $returnInformation['code'] = 60001;
  521. $returnInformation['msg'] = "操作失败,参数错误";
  522. $returnInformation['data']=null;
  523. return json_encode($returnInformation);
  524. }
  525. }else{
  526. $returnInformation['code'] = 60001;
  527. $returnInformation['msg'] = "操作失败,参数为空";
  528. $returnInformation['data']=null;
  529. return json_encode($returnInformation);
  530. }
  531. }else{
  532. $returnInformation['code'] = 60002;
  533. $returnInformation['msg'] = "操作失败,用户名或密码错误";
  534. $returnInformation['data']=null;
  535. return json_encode($returnInformation);
  536. }
  537. }else{
  538. $returnInformation['code'] = 60002;
  539. $returnInformation['msg'] = "操作失败,用户名或密码为空";
  540. $returnInformation['data']=null;
  541. return json_encode($returnInformation);
  542. }
  543. }
  544. }
  545. public function alarmHandling(){
  546. $data=input('');
  547. if(is_array($data)){
  548. $getDataJson= json_encode($data,320);
  549. $getdata=json_decode($getDataJson,true);//转成数组
  550. // $list['type']=1;
  551. }else{
  552. $getDataJson=$data;
  553. $getdata=json_decode($getDataJson,true);//转成数组
  554. // $list['type']=2;
  555. }
  556. Log::record('yangpuerqi_alarmHandling' . ':' .$getDataJson);
  557. if ($getdata['confirmAll']==""){
  558. $getdata['confirmAll']=0;
  559. }
  560. if ($getdata['misinformation']==""){
  561. $getdata['misinformation']=0;
  562. }
  563. if (!empty($getdata['userName']) && !empty($getdata['userPassword'])){
  564. if ($getdata["userName"]=="ypsgec" && $getdata["userPassword"]=="ypsgec123"){
  565. if (empty($getdata['recordId'])){
  566. $returnInformation['code'] = 60001;
  567. $returnInformation['msg'] = "操作失败,缺少记录Id";
  568. return json_encode($returnInformation);
  569. }elseif (empty($getdata['deviceCode'])){
  570. $returnInformation['code'] = 60001;
  571. $returnInformation['msg'] = "操作失败,缺少设备编号";
  572. return json_encode($returnInformation);
  573. }elseif (empty($getdata['deviceType'])){
  574. $returnInformation['code'] = 60001;
  575. $returnInformation['msg'] = "操作失败,缺少设备类型";
  576. return json_encode($returnInformation);
  577. }elseif ($getdata['confirmAll']!=0&&$getdata['confirmAll']!=1){
  578. $returnInformation['code'] = 60001;
  579. $returnInformation['msg'] = "操作失败,缺少是否批量处理类型";
  580. return json_encode($returnInformation);
  581. }elseif ($getdata['misinformation']!=0&&$getdata['misinformation']!=1){
  582. $returnInformation['code'] = 60001;
  583. $returnInformation['msg'] = "操作失败,缺少是否误报字段";
  584. return json_encode($returnInformation);
  585. }elseif (empty($getdata['handlerName'])){
  586. $returnInformation['code'] = 60001;
  587. $returnInformation['msg'] = "操作失败,缺少处理人姓名";
  588. return json_encode($returnInformation);
  589. }elseif (empty($getdata['handlerPhone'])){
  590. $returnInformation['code'] = 60001;
  591. $returnInformation['msg'] = "操作失败,缺少处理人联系方式";
  592. return json_encode($returnInformation);
  593. }
  594. // else{
  595. // $returnInformation['code'] = 0;
  596. // $returnInformation['msg'] = "操作成功";
  597. // return json_encode($returnInformation);
  598. // }
  599. // echo 'aaaaaaa';
  600. // exit();
  601. switch ($getdata['deviceType']) {
  602. case '1':
  603. $tab="sp_hj2017";
  604. break;
  605. case '2':
  606. $tab="sp_sj2017";
  607. break;
  608. case '6':
  609. $tab="sp_rtu2017";
  610. break;
  611. case '7':
  612. $tab="sp_ef2017";
  613. break;
  614. // case '16':
  615. // $tab="sp_video2017";
  616. // break;
  617. default:
  618. $returnInformation['code'] = 60001;
  619. $returnInformation['msg'] = "操作失败,缺少设备类型";
  620. return json_encode($returnInformation);
  621. break;
  622. }
  623. $time = date('Y-m-d h:i:s', time());
  624. if ($getdata['confirmAll']==0){
  625. $where = " where id=".$getdata['recordId']." and device_code='".$getdata['deviceCode']."' and clzt='0'";
  626. }else{
  627. $where = " where device_code='".$getdata['deviceCode']."' and clzt='0'";
  628. }
  629. $sql="UPDATE ".$tab." SET clsj='".$time."',clr='".$getdata['handlerName']."',clnr='".$getdata['processingContent']."',clwb='".$getdata['misinformation']."',cldh='".$getdata['handlerPhone']."',clzt=1 ".$where;
  630. // echo $sql;
  631. // print_r($sql);
  632. // exit();
  633. $res=addDataInfo($sql);
  634. if ($res){
  635. $returnInformation['code'] = 0;
  636. $returnInformation['msg'] = "操作成功";
  637. return json_encode($returnInformation);
  638. }else{
  639. $returnInformation['code'] = 60001;
  640. $returnInformation['msg'] = "操作失败,参数错误";
  641. return json_encode($returnInformation);
  642. }
  643. }else{
  644. $returnInformation['code'] = 60002;
  645. $returnInformation['msg'] = "操作失败,用户名或密码错误";
  646. return json_encode($returnInformation);
  647. }
  648. }else{
  649. $returnInformation['code'] = 60002;
  650. $returnInformation['msg'] = "操作失败,用户名或密码为空";
  651. return json_encode($returnInformation);
  652. }
  653. }
  654. public function ip() {
  655. //strcasecmp 比较两个字符,不区分大小写。返回0,>0,<0。
  656. if (getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
  657. $ip = getenv('HTTP_CLIENT_IP');
  658. } else if (getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
  659. $ip = getenv('HTTP_X_FORWARDED_FOR');
  660. } else if (getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {
  661. $ip = getenv('REMOTE_ADDR');
  662. } else if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
  663. $ip = $_SERVER['REMOTE_ADDR'];
  664. }
  665. $res = preg_match ( '/[\d\.]{7,15}/', $ip, $matches ) ? $matches [0] : '';
  666. return $res;
  667. //dump(phpinfo());//所有PHP配置信息
  668. }
  669. public function s_curl($url,$data='',$header="",$method="POST"){
  670. $ch = curl_init() ;
  671. curl_setopt($ch, CURLOPT_URL, $url);
  672. curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
  673. // curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 4);
  674. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  675. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  676. /* curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');*/
  677. // curl_setopt($ch, CURLOPT_VERBOSE, 1); //debugģʽ
  678. curl_setopt($ch, CURLOPT_SSLCERT, "./server.crt"); //client.crt����
  679. curl_setopt($ch, CURLOPT_SSLCERTPASSWD, "IoM@1234"); //client֤������
  680. curl_setopt($ch, CURLOPT_SSLKEY, "./server.key");
  681. if($method=="POST"||$method=="PUT"||$method=="DELETE"){
  682. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
  683. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  684. }
  685. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  686. $info = curl_exec($ch);
  687. $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  688. if (curl_errno($ch)) {
  689. $infores = curl_error($ch);
  690. }else{
  691. $infores = $info;
  692. }
  693. curl_close($ch);
  694. return $infores;
  695. }
  696. public function ypxycurl($url,$data=''){
  697. $ch = curl_init();
  698. curl_setopt($ch, CURLOPT_URL, $url);
  699. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  700. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  701. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  702. curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
  703. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  704. curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
  705. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  706. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  707. $info = curl_exec($ch);
  708. if (curl_errno($ch)) {
  709. $info = 'ERROR: ' . curl_error($ch);
  710. }
  711. curl_close($ch);
  712. return $info;
  713. }
  714. }