Manage.php.bak.20210808 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321
  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 dianQiCeShiUrl(){
  670. $file_in = file_get_contents("php://input"); //接收post数据
  671. $xml = simplexml_load_string($file_in);//转换post数据为simplexml对象
  672. $json_string=array();
  673. foreach($xml->children() as $child) //遍历所有节点数据
  674. {
  675. $json_string[$child->getName()]=$child;
  676. // echo $child->getName() . ": " . $child . "<br />"; //打印节点名称和节点值
  677. //if($child->getName()=="from") //捡取要操作的节点
  678. //{
  679. //echo "i say ". ": get you!" . "<br />"; //操作节点数据
  680. //}
  681. }
  682. $getDataJson= json_encode($json_string,320);
  683. Log::record('dianQiCeShiData:' .$getDataJson );
  684. // $data5 = array();
  685. // $sensorList = array();
  686. // $sensorList1 = array();
  687. // $sensorListArray = array();
  688. // $data5['status'] = "0";
  689. // $sensorList['productId'] = "10001";
  690. // $sensorList['productName'] = "小米6";
  691. // $sensorList['productPrice'] = "2499";
  692. // $sensorList['productImg'] = "http://47.103.74.123/VideoAlarmPics/pic_1569859775_JYDL_XAQ_0.jpg";
  693. // $sensorListArray[0] = $sensorList;
  694. // $sensorList1['productId'] = "10002";
  695. // $sensorList1['productName'] = "小米笔记本";
  696. // $sensorList1['productPrice'] = "3999";
  697. // $sensorList1['productImg'] = "http://47.103.74.123/VideoAlarmPics/pic_1569859775_JYDL_XAQ_0.jpg";
  698. // $sensorListArray[1] = $sensorList1;
  699. // $data5['result'] = $sensorListArray;
  700. // $data6 = json_encode($data5);
  701. // return $getDataJson;
  702. }
  703. public function mt_rand_float($min, $max){
  704. return $min + abs($max-$min) * mt_rand(0,mt_getrandmax())/mt_getrandmax();
  705. }
  706. public function randomDate() {
  707. $begin = strtotime("now");
  708. $end = strtotime("-1 Month");
  709. $timestamp = rand($begin, $end);
  710. return date("Y-m-d H:i:s", $timestamp);
  711. }
  712. public function ceShiUrl(){
  713. header("Access-Control-Allow-Origin:*");
  714. // 响应类型
  715. header('Access-Control-Allow-Methods:POST');
  716. // 响应头设置
  717. header('Access-Control-Allow-Headers:x-requested-with, content-type');
  718. $data=input('');
  719. if(is_array($data)){
  720. $getDataJson= json_encode($data,320);
  721. $getdata=json_decode($getDataJson,true);//转成数组
  722. }else{
  723. $getDataJson=$data;
  724. $getdata=json_decode($getDataJson,true);//转成数组
  725. }
  726. $data1 = array();
  727. $data2 = array();
  728. $data4 = array();
  729. $data5 = array();
  730. $data6 = array();
  731. $data7 = array();
  732. $data8 = array();
  733. $data9 = array();
  734. $data10 = array();
  735. $data11 = array();
  736. $data12 = array();
  737. $data15 = array();
  738. $data16 = array();
  739. $data18 = array();
  740. $data19 = array();
  741. for ($i=0;$i<=14;$i++){
  742. $data1['standard_deviation']=round($this->mt_rand_float(1,5),2);
  743. $data1['variance']=round($data1['standard_deviation']*$data1['standard_deviation'],2);
  744. $data1['average_value']=round($this->mt_rand_float(220,227),2);
  745. $j=$i+1;
  746. if($j>=10){
  747. $data1['data_time']="2021-03-".$j;
  748. }
  749. $data2[$i]=$data1;
  750. $data4['standard_deviation']=round($this->mt_rand_float(3,8),2);
  751. $data4['variance']=round($data4['standard_deviation']*$data4['standard_deviation'],2);
  752. $data4['average_value']=round($this->mt_rand_float(7,15),2);
  753. if($j>=10){
  754. $data4['data_time']="2021-03-".$j;
  755. }
  756. $data5[$i]=$data4;
  757. $data6['standard_deviation']=round($this->mt_rand_float(0,2),2);
  758. $data6['variance']=round($data6['standard_deviation']*$data6['standard_deviation'],2);
  759. $data6['average_value']=round($this->mt_rand_float(17,25),2);
  760. if($j>=10){
  761. $data6['data_time']="2021-03-".$j;
  762. }
  763. $data7[$i]=$data6;
  764. $data8['standard_deviation']=round($this->mt_rand_float(30,70),2);
  765. $data8['variance']=round($data8['standard_deviation']*$data8['standard_deviation'],2);
  766. $data8['average_value']=round($this->mt_rand_float(30,60),2);
  767. if($j>=10){
  768. $data8['data_time']="2021-03-".$j;
  769. }
  770. $data9[$i]=$data8;
  771. $data11['electric_current']=round($this->mt_rand_float(8,18),2);
  772. $data11['voltage']=round($this->mt_rand_float(220,225),2);
  773. $data11['data_time']=$this->randomDate();
  774. $data12[$i]=$data11;
  775. $data15['electric_current']=round($this->mt_rand_float(20,100),2);
  776. $data15['voltage']=round($this->mt_rand_float(220,225),2);
  777. $data15['data_time']=$this->randomDate();
  778. $data16[$i]=$data15;
  779. $data18['ambient_temperature']=round($this->mt_rand_float(20,25),2);
  780. $data18['Cable_temperature']=round($this->mt_rand_float(10,20),2);
  781. $data18['generation_temperature']=round($data18['ambient_temperature']-$data18['Cable_temperature'],2);
  782. $data18['data_time']=$this->randomDate();
  783. $data19[$i]=$data18;
  784. }
  785. $data10['conclusion1']="因数据量未达到暂无法分析";
  786. $data3['voltage']=$data2;
  787. $data3['electric_current']=$data5;
  788. $data3['temperature']=$data7;
  789. $data3['leakage_current']=$data9;
  790. $data3['conclusion']=$data10;
  791. $data14['abnormal_equipment']=$data12;
  792. $data14['leakage_alarm']=$data16;
  793. $data14['conclusion']=$data10;
  794. $data20['visualization']=$data19;
  795. $data20['conclusion']=$data10;
  796. $data13['dispersion_rate']=$data3;
  797. $data13['electrical_aging']=$data14;
  798. $data13['thermal_aging']=$data20;
  799. // $data1['alarm_number']=$this->mt_rand_float(100,500);
  800. // $sensorList['productId'] = round($this->mt_rand_float(3,5),2);
  801. $data17 = json_encode($data13);
  802. return $data17;
  803. }
  804. public function algorithmApi(){
  805. header("Access-Control-Allow-Origin:*");
  806. // 响应类型
  807. header('Access-Control-Allow-Methods:POST');
  808. // 响应头设置
  809. header('Access-Control-Allow-Headers:x-requested-with, content-type');
  810. $data=input('');
  811. if(is_array($data)){
  812. $getDataJson= json_encode($data,320);
  813. $getdata=json_decode($getDataJson,true);//转成数组
  814. }else{
  815. $getDataJson=$data;
  816. $getdata=json_decode($getDataJson,true);//转成数组
  817. }
  818. if(!empty($getdata["dataType"])){
  819. if($getdata["dataType"]==1||$getdata["dataType"]==2){
  820. if($getdata["dataType"]==1){
  821. if (!empty($getdata["apiType"])){
  822. if ($getdata["apiType"]==4){
  823. if(!empty($getdata["timeType"])){
  824. if (!empty($getdata["companyCode"])){
  825. $sql6="select dispersion_rate from sp_water_analysis where company_code ='{$getdata["companyCode"]}' and data_type ={$getdata["timeType"]}";
  826. $longHuOwner = add($sql6);
  827. $returnInformation['code'] = 200;
  828. $returnInformation['msg'] = "success";
  829. $returnInformation['data']=$longHuOwner[0]['dispersion_rate'];
  830. return stripslashes(json_encode($returnInformation));
  831. }else{
  832. $returnInformation['code'] = 60001;
  833. $returnInformation['msg'] = "操作失败,单位编号不能为空";
  834. return json_encode($returnInformation);
  835. }
  836. }else{
  837. $returnInformation['code'] = 60001;
  838. $returnInformation['msg'] = "操作失败,时间类型不能为空";
  839. return json_encode($returnInformation);
  840. }
  841. }elseif ($getdata["apiType"]==5){
  842. if(!empty($getdata["timeType"])){
  843. if (!empty($getdata["companyCode"])){
  844. $sql6="select leakage_investigation from sp_water_analysis where company_code ='{$getdata["companyCode"]}' and data_type ={$getdata["timeType"]}";
  845. $longHuOwner = add($sql6);
  846. $returnInformation['code'] = 200;
  847. $returnInformation['msg'] = "success";
  848. $returnInformation['data']=$longHuOwner[0]['leakage_investigation'];
  849. return stripslashes(json_encode($returnInformation));
  850. }else{
  851. $returnInformation['code'] = 60001;
  852. $returnInformation['msg'] = "操作失败,单位编号不能为空";
  853. return json_encode($returnInformation);
  854. }
  855. }else{
  856. $returnInformation['code'] = 60001;
  857. $returnInformation['msg'] = "操作失败,时间类型不能为空";
  858. return json_encode($returnInformation);
  859. }
  860. }elseif ($getdata["apiType"]==6){
  861. if(!empty($getdata["timeType"])){
  862. if (!empty($getdata["companyCode"])){
  863. $sql6="select device_association from sp_water_analysis where company_code ='{$getdata["companyCode"]}' and data_type ={$getdata["timeType"]}";
  864. $longHuOwner = add($sql6);
  865. $returnInformation['code'] = 200;
  866. $returnInformation['msg'] = "success";
  867. $returnInformation['data']=$longHuOwner[0]['device_association'];
  868. return stripslashes(json_encode($returnInformation));
  869. }else{
  870. $returnInformation['code'] = 60001;
  871. $returnInformation['msg'] = "操作失败,单位编号不能为空";
  872. return json_encode($returnInformation);
  873. }
  874. }else{
  875. $returnInformation['code'] = 60001;
  876. $returnInformation['msg'] = "操作失败,时间类型不能为空";
  877. return json_encode($returnInformation);
  878. }
  879. }elseif ($getdata["apiType"]==7){
  880. if(!empty($getdata["timeType"])){
  881. if (!empty($getdata["companyCode"])){
  882. $sql6="select data_fluctuation from sp_water_analysis where company_code ='{$getdata["companyCode"]}' and data_type ={$getdata["timeType"]}";
  883. $longHuOwner = add($sql6);
  884. $returnInformation['code'] = 200;
  885. $returnInformation['msg'] = "success";
  886. $returnInformation['data']=$longHuOwner[0]['data_fluctuation'];
  887. return stripslashes(json_encode($returnInformation));
  888. }else{
  889. $returnInformation['code'] = 60001;
  890. $returnInformation['msg'] = "操作失败,单位编号不能为空";
  891. return json_encode($returnInformation);
  892. }
  893. }else{
  894. $returnInformation['code'] = 60001;
  895. $returnInformation['msg'] = "操作失败,时间类型不能为空";
  896. return json_encode($returnInformation);
  897. }
  898. }elseif ($getdata["apiType"]==2){
  899. if(!empty($getdata["timeType"])){
  900. if (!empty($getdata["companyCode"])){
  901. $sql6="select data_statistics from sp_water_analysis where company_code ='{$getdata["companyCode"]}' and data_type ={$getdata["timeType"]}";
  902. $longHuOwner = add($sql6);
  903. $returnInformation['code'] = 200;
  904. $returnInformation['msg'] = "success";
  905. $returnInformation['data']=$longHuOwner[0]['data_statistics'];
  906. return stripslashes(json_encode($returnInformation));
  907. }else{
  908. $returnInformation['code'] = 60001;
  909. $returnInformation['msg'] = "操作失败,单位编号不能为空";
  910. return json_encode($returnInformation);
  911. }
  912. }else{
  913. $returnInformation['code'] = 60001;
  914. $returnInformation['msg'] = "操作失败,时间类型不能为空";
  915. return json_encode($returnInformation);
  916. }
  917. }elseif ($getdata["apiType"]==3){
  918. if(!empty($getdata["timeType"])){
  919. if (!empty($getdata["companyCode"])){
  920. if($getdata["timeType"]==1) {
  921. $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'";
  922. $longHuOwner = add($sql6);
  923. $returnInformation['code'] = 200;
  924. $returnInformation['msg'] = "success";
  925. $returnInformation['data'] = $longHuOwner;
  926. return stripslashes(json_encode($returnInformation));
  927. }elseif ($getdata["timeType"]==2){
  928. $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'";
  929. $longHuOwner = add($sql6);
  930. $returnInformation['code'] = 200;
  931. $returnInformation['msg'] = "success";
  932. $returnInformation['data'] = $longHuOwner;
  933. return stripslashes(json_encode($returnInformation));
  934. }elseif ($getdata["timeType"]==3){
  935. $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'";
  936. $longHuOwner = add($sql6);
  937. $returnInformation['code'] = 200;
  938. $returnInformation['msg'] = "success";
  939. $returnInformation['data'] = $longHuOwner;
  940. return stripslashes(json_encode($returnInformation));
  941. }
  942. }else{
  943. $returnInformation['code'] = 60001;
  944. $returnInformation['msg'] = "操作失败,单位编号不能为空";
  945. return json_encode($returnInformation);
  946. }
  947. }else{
  948. $returnInformation['code'] = 60001;
  949. $returnInformation['msg'] = "操作失败,时间类型不能为空";
  950. return json_encode($returnInformation);
  951. }
  952. }
  953. }else{
  954. $returnInformation['code'] = 60001;
  955. $returnInformation['msg'] = "操作失败,api类型不能为空";
  956. return json_encode($returnInformation);
  957. }
  958. }else{
  959. if (!empty($getdata["apiType"])){
  960. if ($getdata["apiType"]==4){
  961. if(!empty($getdata["timeType"])){
  962. if (!empty($getdata["companyCode"])){
  963. $sql6="select dispersion_rate from sp_ef_analysis where company_code ='{$getdata["companyCode"]}' and data_type ={$getdata["timeType"]}";
  964. $longHuOwner = add($sql6);
  965. $returnInformation['code'] = 200;
  966. $returnInformation['msg'] = "success";
  967. $returnInformation['data']=$longHuOwner[0]['dispersion_rate'];
  968. return stripslashes(json_encode($returnInformation));
  969. }else{
  970. $returnInformation['code'] = 60001;
  971. $returnInformation['msg'] = "操作失败,单位编号不能为空";
  972. return json_encode($returnInformation);
  973. }
  974. }else{
  975. $returnInformation['code'] = 60001;
  976. $returnInformation['msg'] = "操作失败,时间类型不能为空";
  977. return json_encode($returnInformation);
  978. }
  979. }elseif ($getdata["apiType"]==5){
  980. if(!empty($getdata["timeType"])){
  981. if (!empty($getdata["companyCode"])){
  982. $sql6="select electrical_aging from sp_ef_analysis where company_code ='{$getdata["companyCode"]}' and data_type ={$getdata["timeType"]}";
  983. $longHuOwner = add($sql6);
  984. $returnInformation['code'] = 200;
  985. $returnInformation['msg'] = "success";
  986. $returnInformation['data']=$longHuOwner[0]['electrical_aging'];
  987. return stripslashes(json_encode($returnInformation));
  988. }else{
  989. $returnInformation['code'] = 60001;
  990. $returnInformation['msg'] = "操作失败,单位编号不能为空";
  991. return json_encode($returnInformation);
  992. }
  993. }else{
  994. $returnInformation['code'] = 60001;
  995. $returnInformation['msg'] = "操作失败,时间类型不能为空";
  996. return json_encode($returnInformation);
  997. }
  998. }elseif ($getdata["apiType"]==6){
  999. if(!empty($getdata["timeType"])){
  1000. if (!empty($getdata["companyCode"])){
  1001. $sql6="select thermal_aging from sp_ef_analysis where company_code ='{$getdata["companyCode"]}' and data_type ={$getdata["timeType"]}";
  1002. $longHuOwner = add($sql6);
  1003. $returnInformation['code'] = 200;
  1004. $returnInformation['msg'] = "success";
  1005. $returnInformation['data']=$longHuOwner[0]['thermal_aging'];
  1006. return stripslashes(json_encode($returnInformation));
  1007. }else{
  1008. $returnInformation['code'] = 60001;
  1009. $returnInformation['msg'] = "操作失败,单位编号不能为空";
  1010. return json_encode($returnInformation);
  1011. }
  1012. }else{
  1013. $returnInformation['code'] = 60001;
  1014. $returnInformation['msg'] = "操作失败,时间类型不能为空";
  1015. return json_encode($returnInformation);
  1016. }
  1017. }elseif ($getdata["apiType"]==7){
  1018. if(!empty($getdata["timeType"])){
  1019. if (!empty($getdata["companyCode"])){
  1020. $sql6="select data_fluctuation from sp_water_analysis where company_code ='{$getdata["companyCode"]}' and data_type ={$getdata["timeType"]}";
  1021. $longHuOwner = add($sql6);
  1022. $returnInformation['code'] = 200;
  1023. $returnInformation['msg'] = "success";
  1024. $returnInformation['data']=$longHuOwner[0]['data_fluctuation'];
  1025. return stripslashes(json_encode($returnInformation));
  1026. }else{
  1027. $returnInformation['code'] = 60001;
  1028. $returnInformation['msg'] = "操作失败,单位编号不能为空";
  1029. return json_encode($returnInformation);
  1030. }
  1031. }else{
  1032. $returnInformation['code'] = 60001;
  1033. $returnInformation['msg'] = "操作失败,时间类型不能为空";
  1034. return json_encode($returnInformation);
  1035. }
  1036. }elseif ($getdata["apiType"]==2){
  1037. if(!empty($getdata["timeType"])){
  1038. if (!empty($getdata["companyCode"])){
  1039. $sql6="select data_statistics from sp_water_analysis where company_code ='{$getdata["companyCode"]}' and data_type ={$getdata["timeType"]}";
  1040. $longHuOwner = add($sql6);
  1041. $returnInformation['code'] = 200;
  1042. $returnInformation['msg'] = "success";
  1043. $returnInformation['data']=$longHuOwner[0]['data_statistics'];
  1044. return stripslashes(json_encode($returnInformation));
  1045. }else{
  1046. $returnInformation['code'] = 60001;
  1047. $returnInformation['msg'] = "操作失败,单位编号不能为空";
  1048. return json_encode($returnInformation);
  1049. }
  1050. }else{
  1051. $returnInformation['code'] = 60001;
  1052. $returnInformation['msg'] = "操作失败,时间类型不能为空";
  1053. return json_encode($returnInformation);
  1054. }
  1055. }elseif ($getdata["apiType"]==3){
  1056. if(!empty($getdata["timeType"])){
  1057. if (!empty($getdata["companyCode"])){
  1058. if($getdata["timeType"]==1) {
  1059. $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'";
  1060. $longHuOwner = add($sql6);
  1061. $returnInformation['code'] = 200;
  1062. $returnInformation['msg'] = "success";
  1063. $returnInformation['data'] = $longHuOwner;
  1064. return stripslashes(json_encode($returnInformation));
  1065. }elseif ($getdata["timeType"]==2){
  1066. $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'";
  1067. $longHuOwner = add($sql6);
  1068. $returnInformation['code'] = 200;
  1069. $returnInformation['msg'] = "success";
  1070. $returnInformation['data'] = $longHuOwner;
  1071. return stripslashes(json_encode($returnInformation));
  1072. }elseif ($getdata["timeType"]==3){
  1073. $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'";
  1074. $longHuOwner = add($sql6);
  1075. $returnInformation['code'] = 200;
  1076. $returnInformation['msg'] = "success";
  1077. $returnInformation['data'] = $longHuOwner;
  1078. return stripslashes(json_encode($returnInformation));
  1079. }
  1080. }else{
  1081. $returnInformation['code'] = 60001;
  1082. $returnInformation['msg'] = "操作失败,单位编号不能为空";
  1083. return json_encode($returnInformation);
  1084. }
  1085. }else{
  1086. $returnInformation['code'] = 60001;
  1087. $returnInformation['msg'] = "操作失败,时间类型不能为空";
  1088. return json_encode($returnInformation);
  1089. }
  1090. }
  1091. }else{
  1092. $returnInformation['code'] = 60001;
  1093. $returnInformation['msg'] = "操作失败,api类型不能为空";
  1094. return json_encode($returnInformation);
  1095. }
  1096. }
  1097. }else{
  1098. $returnInformation['code'] = 60001;
  1099. $returnInformation['msg'] = "操作失败,数据范围超出限制";
  1100. return json_encode($returnInformation);
  1101. }
  1102. }else{
  1103. $returnInformation['code'] = 60001;
  1104. $returnInformation['msg'] = "操作失败,数据类型不能为空";
  1105. return json_encode($returnInformation);
  1106. }
  1107. // $data1 = array();
  1108. // $data2 = array();
  1109. // $data4 = array();
  1110. // $data5 = array();
  1111. // $data6 = array();
  1112. // $data7 = array();
  1113. // $data8 = array();
  1114. // $data9 = array();
  1115. // $data10 = array();
  1116. // $data11 = array();
  1117. // $data12 = array();
  1118. // $data15 = array();
  1119. // $data16 = array();
  1120. // $data18 = array();
  1121. // $data19 = array();
  1122. // for ($i=0;$i<=14;$i++){
  1123. // $data1['standard_deviation']=round($this->mt_rand_float(1,5),2);
  1124. // $data1['variance']=round($data1['standard_deviation']*$data1['standard_deviation'],2);
  1125. // $data1['average_value']=round($this->mt_rand_float(220,227),2);
  1126. // $j=$i+1;
  1127. // if($j>=10){
  1128. // $data1['data_time']="2021-03-".$j;
  1129. // }
  1130. // $data2[$i]=$data1;
  1131. // $data4['standard_deviation']=round($this->mt_rand_float(3,8),2);
  1132. // $data4['variance']=round($data4['standard_deviation']*$data4['standard_deviation'],2);
  1133. // $data4['average_value']=round($this->mt_rand_float(7,15),2);
  1134. // if($j>=10){
  1135. // $data4['data_time']="2021-03-".$j;
  1136. // }
  1137. // $data5[$i]=$data4;
  1138. // $data6['standard_deviation']=round($this->mt_rand_float(0,2),2);
  1139. // $data6['variance']=round($data6['standard_deviation']*$data6['standard_deviation'],2);
  1140. // $data6['average_value']=round($this->mt_rand_float(17,25),2);
  1141. // if($j>=10){
  1142. // $data6['data_time']="2021-03-".$j;
  1143. // }
  1144. // $data7[$i]=$data6;
  1145. // $data8['standard_deviation']=round($this->mt_rand_float(30,70),2);
  1146. // $data8['variance']=round($data8['standard_deviation']*$data8['standard_deviation'],2);
  1147. // $data8['average_value']=round($this->mt_rand_float(30,60),2);
  1148. // if($j>=10){
  1149. // $data8['data_time']="2021-03-".$j;
  1150. // }
  1151. // $data9[$i]=$data8;
  1152. // $data11['electric_current']=round($this->mt_rand_float(8,18),2);
  1153. // $data11['voltage']=round($this->mt_rand_float(220,225),2);
  1154. // $data11['data_time']=$this->randomDate();
  1155. // $data12[$i]=$data11;
  1156. // $data15['electric_current']=round($this->mt_rand_float(20,100),2);
  1157. // $data15['voltage']=round($this->mt_rand_float(220,225),2);
  1158. // $data15['data_time']=$this->randomDate();
  1159. // $data16[$i]=$data15;
  1160. // $data18['ambient_temperature']=round($this->mt_rand_float(20,25),2);
  1161. // $data18['Cable_temperature']=round($this->mt_rand_float(10,20),2);
  1162. // $data18['generation_temperature']=round($data18['ambient_temperature']-$data18['Cable_temperature'],2);
  1163. // $data18['data_time']=$this->randomDate();
  1164. // $data19[$i]=$data18;
  1165. // }
  1166. // $data10['conclusion1']="因数据量未达到暂无法分析";
  1167. // $data3['voltage']=$data2;
  1168. // $data3['electric_current']=$data5;
  1169. // $data3['temperature']=$data7;
  1170. // $data3['leakage_current']=$data9;
  1171. // $data3['conclusion']=$data10;
  1172. // $data14['abnormal_equipment']=$data12;
  1173. // $data14['leakage_alarm']=$data16;
  1174. // $data14['conclusion']=$data10;
  1175. // $data20['visualization']=$data19;
  1176. // $data20['conclusion']=$data10;
  1177. // $data13['dispersion_rate']=$data3;
  1178. // $data13['electrical_aging']=$data14;
  1179. // $data13['thermal_aging']=$data20;
  1180. //// $data1['alarm_number']=$this->mt_rand_float(100,500);
  1181. //// $sensorList['productId'] = round($this->mt_rand_float(3,5),2);
  1182. // $data17 = json_encode($data13);
  1183. // return $data17;
  1184. }
  1185. public function deviceNumber(){
  1186. header("Access-Control-Allow-Origin:*");
  1187. // 响应类型
  1188. header('Access-Control-Allow-Methods:POST');
  1189. // 响应头设置
  1190. header('Access-Control-Allow-Headers:x-requested-with, content-type');
  1191. $data=input('');
  1192. if(is_array($data)){
  1193. $getDataJson= json_encode($data,320);
  1194. $getdata=json_decode($getDataJson,true);//转成数组
  1195. }else{
  1196. $getDataJson=$data;
  1197. $getdata=json_decode($getDataJson,true);//转成数组
  1198. }
  1199. $data6 = array();
  1200. if ($getdata['userName']=="ypywtg"){
  1201. $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');";
  1202. $res=add($sql);
  1203. $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');";
  1204. $res1=add($sql1);
  1205. $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');";
  1206. $res2=add($sql2);
  1207. $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');";
  1208. $res3=add($sql3);
  1209. $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');";
  1210. $res4=add($sql4);
  1211. $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');";
  1212. $res5=add($sql5);
  1213. $sensorList['waterNumber'] =$res[0]['waterNumber'];
  1214. $sensorList['levelNumber'] =$res1[0]['levelNumber'];
  1215. $sensorList['smokeSensationNumber'] =$res2[0]['smokeSensationNumber'];
  1216. $sensorList['rtuNumber'] =$res3[0]['rtuNumber'];
  1217. $sensorList['videoNumber'] =$res4[0]['videoNumber'];
  1218. $sensorList['electricalFireNumber'] =$res5[0]['electricalFireNumber'];
  1219. $data6 = json_encode($sensorList);
  1220. }
  1221. return $data6;
  1222. }
  1223. public function s_curl($url,$data='',$header="",$method="POST"){
  1224. $ch = curl_init() ;
  1225. curl_setopt($ch, CURLOPT_URL, $url);
  1226. curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
  1227. // curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 4);
  1228. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  1229. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  1230. /* curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');*/
  1231. // curl_setopt($ch, CURLOPT_VERBOSE, 1); //debugģʽ
  1232. curl_setopt($ch, CURLOPT_SSLCERT, "./server.crt"); //client.crt����
  1233. curl_setopt($ch, CURLOPT_SSLCERTPASSWD, "IoM@1234"); //client֤������
  1234. curl_setopt($ch, CURLOPT_SSLKEY, "./server.key");
  1235. if($method=="POST"||$method=="PUT"||$method=="DELETE"){
  1236. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
  1237. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  1238. }
  1239. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1240. $info = curl_exec($ch);
  1241. $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  1242. if (curl_errno($ch)) {
  1243. $infores = curl_error($ch);
  1244. }else{
  1245. $infores = $info;
  1246. }
  1247. curl_close($ch);
  1248. return $infores;
  1249. }
  1250. public function ypxycurl($url,$data=''){
  1251. $ch = curl_init();
  1252. curl_setopt($ch, CURLOPT_URL, $url);
  1253. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  1254. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  1255. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  1256. curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
  1257. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  1258. curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
  1259. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  1260. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  1261. $info = curl_exec($ch);
  1262. if (curl_errno($ch)) {
  1263. $info = 'ERROR: ' . curl_error($ch);
  1264. }
  1265. curl_close($ch);
  1266. return $info;
  1267. }
  1268. }