Manage.php 111 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200
  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:' .$list['data'] );
  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. echo 111;
  395. }
  396. public function deviceList(){
  397. $data=input('');
  398. if(is_array($data)){
  399. $getDataJson= json_encode($data,320);
  400. $getdata=json_decode($getDataJson,true);//转成数组
  401. }else{
  402. $getDataJson=$data;
  403. $getdata=json_decode($getDataJson,true);//转成数组
  404. }
  405. $clientIp=$this->ip();
  406. Log::record('yangpuerqi_deviceList' . ':' .'<<<'.$clientIp.'>>>'.$getDataJson);
  407. $allowIp = ['222.69.148.83','120.253.238.34','114.86.176.11','120.253.238.37','218.242.51.14'];
  408. // if (!in_array($clientIp, $allowIp)){
  409. // $returnInformation['code'] = 60001;
  410. // $returnInformation['msg'] = "操作失败,IP地址不在白名单中";
  411. // $returnInformation['data']=null;
  412. // return json_encode($returnInformation);
  413. // }else{
  414. if (!empty($getdata['userName']) && !empty($getdata['userPassword'])){
  415. if ($getdata["userName"]=="sgec68" && $getdata["userPassword"]=="sgec68123"){
  416. if(!empty($getdata['commandType'])){
  417. if($getdata['commandType']=="FRONTPAGE"){
  418. $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";
  419. $res=add($sql);
  420. if (!empty($res)){
  421. $returnInformation['code'] = 0;
  422. $returnInformation['msg'] = "操作成功";
  423. $returnInformation['data']=$res;
  424. return json_encode($returnInformation);
  425. }else{
  426. $returnInformation['code'] = 60001;
  427. $returnInformation['msg'] = "操作失败";
  428. $returnInformation['data']=null;
  429. return json_encode($returnInformation);
  430. }
  431. }else{
  432. $returnInformation['code'] = 60001;
  433. $returnInformation['msg'] = "操作失败,参数错误";
  434. $returnInformation['data']=null;
  435. return json_encode($returnInformation);
  436. }
  437. }else{
  438. $returnInformation['code'] = 60001;
  439. $returnInformation['msg'] = "操作失败,参数为空";
  440. $returnInformation['data']=null;
  441. return json_encode($returnInformation);
  442. }
  443. }else{
  444. $returnInformation['code'] = 60002;
  445. $returnInformation['msg'] = "操作失败,用户名或密码错误";
  446. $returnInformation['data']=null;
  447. return json_encode($returnInformation);
  448. }
  449. }else{
  450. $returnInformation['code'] = 60002;
  451. $returnInformation['msg'] = "操作失败,用户名或密码为空";
  452. $returnInformation['data']=null;
  453. return json_encode($returnInformation);
  454. }
  455. // }
  456. }
  457. //杨浦城运中心设备基础信息注册
  458. public function deviceInfoRegister()
  459. {
  460. $data = input('');
  461. if (is_array($data)) {
  462. $getDataJson = json_encode($data, 320);
  463. $getdata = json_decode($getDataJson, true);//转成数组
  464. } else {
  465. $getDataJson = $data;
  466. $getdata = json_decode($getDataJson, true);//转成数组
  467. }
  468. $data1 = Db::query("select sensorId,sensorType,sensorName,CONCAT(companyName,address) AS address,wsLng,wsLat,dataCode,applyId,cityId,areaId,regionId,projectCode from yp_ywtg_configure where id >{$getdata["id"]}");
  469. // $rep_url = "http://220.196.241.22:8000/api-projectdatamanage/equipmentsync/sync";
  470. // $header=[
  471. // "Content-Type:application/json",
  472. // "Authenticator:eyJhbGciOiJIUzI1NiJ9.eyJyZWFsTmFtZSI6Iumfqeato-S5iSIsInJvbGVJZHMiOiIxMSIsIm9yZ0NvZGUiOiJYIiwibG9naW5OYW1lIjoiaGFuenkiLCJwbGF0Zm9ybUlkIjpudWxsLCJleHAiOjE2Mzc2NjQ1MDMsInVzZXJJZCI6MTAwNiwib3JnSWQiOjF9.H_xzdQ9jdcndOCsYU9z3cZ-oBk4FtdxJk9wxC0AaZvE"
  473. // ];
  474. // $res = $this->ywManagementCurl($rep_url,$header,json_encode($data1));
  475. return json_encode($data1);
  476. }
  477. public function alarmHandling(){
  478. $data=input('');
  479. if(is_array($data)){
  480. $getDataJson= json_encode($data,320);
  481. $getdata=json_decode($getDataJson,true);//转成数组
  482. // $list['type']=1;
  483. }else{
  484. $getDataJson=$data;
  485. $getdata=json_decode($getDataJson,true);//转成数组
  486. // $list['type']=2;
  487. }
  488. Log::record('yangpuerqi_alarmHandling' . ':' .$getDataJson);
  489. if ($getdata['confirmAll']==""){
  490. $getdata['confirmAll']=0;
  491. }
  492. if ($getdata['misinformation']==""){
  493. $getdata['misinformation']=0;
  494. }
  495. if (!empty($getdata['userName']) && !empty($getdata['userPassword'])){
  496. if ($getdata["userName"]=="ypsgec" && $getdata["userPassword"]=="ypsgec123"){
  497. if (empty($getdata['recordId'])){
  498. $returnInformation['code'] = 60001;
  499. $returnInformation['msg'] = "操作失败,缺少记录Id";
  500. return json_encode($returnInformation);
  501. }elseif (empty($getdata['deviceCode'])){
  502. $returnInformation['code'] = 60001;
  503. $returnInformation['msg'] = "操作失败,缺少设备编号";
  504. return json_encode($returnInformation);
  505. }elseif (empty($getdata['deviceType'])){
  506. $returnInformation['code'] = 60001;
  507. $returnInformation['msg'] = "操作失败,缺少设备类型";
  508. return json_encode($returnInformation);
  509. }elseif ($getdata['confirmAll']!=0&&$getdata['confirmAll']!=1){
  510. $returnInformation['code'] = 60001;
  511. $returnInformation['msg'] = "操作失败,缺少是否批量处理类型";
  512. return json_encode($returnInformation);
  513. }elseif ($getdata['misinformation']!=0&&$getdata['misinformation']!=1){
  514. $returnInformation['code'] = 60001;
  515. $returnInformation['msg'] = "操作失败,缺少是否误报字段";
  516. return json_encode($returnInformation);
  517. }elseif (empty($getdata['handlerName'])){
  518. $returnInformation['code'] = 60001;
  519. $returnInformation['msg'] = "操作失败,缺少处理人姓名";
  520. return json_encode($returnInformation);
  521. }elseif (empty($getdata['handlerPhone'])){
  522. $returnInformation['code'] = 60001;
  523. $returnInformation['msg'] = "操作失败,缺少处理人联系方式";
  524. return json_encode($returnInformation);
  525. }
  526. // else{
  527. // $returnInformation['code'] = 0;
  528. // $returnInformation['msg'] = "操作成功";
  529. // return json_encode($returnInformation);
  530. // }
  531. // echo 'aaaaaaa';
  532. // exit();
  533. switch ($getdata['deviceType']) {
  534. case '1':
  535. $tab="sp_hj2017";
  536. break;
  537. case '2':
  538. $tab="sp_sj2017";
  539. break;
  540. case '6':
  541. $tab="sp_rtu2017";
  542. break;
  543. case '7':
  544. $tab="sp_ef2017";
  545. break;
  546. // case '16':
  547. // $tab="sp_video2017";
  548. // break;
  549. default:
  550. $returnInformation['code'] = 60001;
  551. $returnInformation['msg'] = "操作失败,缺少设备类型";
  552. return json_encode($returnInformation);
  553. break;
  554. }
  555. $time = date('Y-m-d h:i:s', time());
  556. if ($getdata['confirmAll']==0){
  557. $where = " where id=".$getdata['recordId']." and device_code='".$getdata['deviceCode']."' and clzt='0'";
  558. }else{
  559. $where = " where device_code='".$getdata['deviceCode']."' and clzt='0'";
  560. }
  561. $sql="UPDATE ".$tab." SET clsj='".$time."',clr='".$getdata['handlerName']."',clnr='".$getdata['processingContent']."',clwb='".$getdata['misinformation']."',cldh='".$getdata['handlerPhone']."',clzt=1 ".$where;
  562. // echo $sql;
  563. // print_r($sql);
  564. // exit();
  565. $res=addDataInfo($sql);
  566. if ($res){
  567. $returnInformation['code'] = 0;
  568. $returnInformation['msg'] = "操作成功";
  569. return json_encode($returnInformation);
  570. }else{
  571. $returnInformation['code'] = 60001;
  572. $returnInformation['msg'] = "操作失败,参数错误";
  573. return json_encode($returnInformation);
  574. }
  575. }else{
  576. $returnInformation['code'] = 60002;
  577. $returnInformation['msg'] = "操作失败,用户名或密码错误";
  578. return json_encode($returnInformation);
  579. }
  580. }else{
  581. $returnInformation['code'] = 60002;
  582. $returnInformation['msg'] = "操作失败,用户名或密码为空";
  583. return json_encode($returnInformation);
  584. }
  585. }
  586. public function ip() {
  587. //strcasecmp 比较两个字符,不区分大小写。返回0,>0,<0。
  588. if (getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
  589. $ip = getenv('HTTP_CLIENT_IP');
  590. } else if (getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
  591. $ip = getenv('HTTP_X_FORWARDED_FOR');
  592. } else if (getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {
  593. $ip = getenv('REMOTE_ADDR');
  594. } else if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
  595. $ip = $_SERVER['REMOTE_ADDR'];
  596. }
  597. $res = preg_match ( '/[\d\.]{7,15}/', $ip, $matches ) ? $matches [0] : '';
  598. return $res;
  599. //dump(phpinfo());//所有PHP配置信息
  600. }
  601. public function http_post_advertise1($url,$data){ //封装curl方法
  602. $header = array(
  603. 'appKey:'.'850404889644236801',
  604. 'Content-Type:'.'application/json'
  605. );
  606. $ch = curl_init(); //初始化
  607. curl_setopt($ch, CURLOPT_URL, $url); //请求地址
  608. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  609. curl_setopt($ch, CURLOPT_POST, true);
  610. //https协议需要以下两行,否则请求不成功
  611. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  612. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  613. //post方法所需要的参数
  614. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  615. curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
  616. $result = curl_exec($ch);
  617. curl_close($ch);
  618. return $result; //返回所获取的方法
  619. }
  620. public function ytapi_query($sql){
  621. $link = mysqli_connect('47.98.201.187', 'root', 'Yt2018IoT', 'jdxf', 3306);
  622. mysqli_query($link,"set character set 'utf8'");
  623. $res1 = mysqli_query($link,$sql);
  624. if($res1==FALSE){
  625. return $list=null;
  626. }
  627. $list=array();
  628. while ($row = $res1->fetch_assoc()) {
  629. $list[]=$row;
  630. }
  631. mysqli_free_result($res1);
  632. mysqli_close($link);
  633. return $list;
  634. }
  635. public function dianQiCeShiUrl(){
  636. $data=input('');
  637. if(is_array($data)){
  638. $getDataJson= json_encode($data,320);
  639. $getdata=json_decode($getDataJson,true);//转成数组
  640. // $list['type']=1;
  641. }else{
  642. $getDataJson=$data;
  643. $getdata=json_decode($getDataJson,true);//转成数组
  644. // $list['type']=2;
  645. }
  646. $number=$getdata['number'];
  647. $start_number=$getdata['start_number'];
  648. $arr=$this->ytapi_query("select * from a_fire_brigade limit ".$start_number.",".$number);
  649. //$arr=ytapi_query("select * from a_yc_point_register limit 200,10");
  650. $array=[];
  651. foreach ($arr as $key=>$value){
  652. $array[$key]['descript']=$arr[$key]['descript'];
  653. $array[$key]['deviceName']=$arr[$key]['device_name'];
  654. // $array[$key]['deviceNo']=$arr[$key]['device_code'].str_replace(',','',$arr[$key]['port']);
  655. $array[$key]['deviceNo']=$arr[$key]['device_code'].str_replace(',','',$arr[$key]['port']).$arr[$key]['data'];
  656. $array[$key]['deviceType']=$arr[$key]['device_type'];
  657. $array[$key]['deviceTypeName']=$arr[$key]['device_type_name'];
  658. $array[$key]['openProjectId']=$arr[$key]['open_project_id'];
  659. }
  660. $url1='http://iot.shxf-119.com/access/device/point/register';//新正式路径
  661. foreach ($array as $key=>$value){
  662. // sleep(2);
  663. $data1=[];
  664. $data1 = $array[$key];
  665. Log::record('fireBrigadeAfferent:' .json_encode($data1));
  666. $output= $this->http_post_advertise1($url1,json_encode($data1));
  667. echo $output."\n";
  668. Log::record('fireBrigadeOutput:' .$output);
  669. }
  670. }
  671. public function mt_rand_float($min, $max){
  672. return $min + abs($max-$min) * mt_rand(0,mt_getrandmax())/mt_getrandmax();
  673. }
  674. public function randomDate() {
  675. $begin = strtotime("now");
  676. $end = strtotime("-1 Month");
  677. $timestamp = rand($begin, $end);
  678. return date("Y-m-d H:i:s", $timestamp);
  679. }
  680. public function ceShiUrl(){
  681. header("Access-Control-Allow-Origin:*");
  682. // 响应类型
  683. header('Access-Control-Allow-Methods:POST');
  684. // 响应头设置
  685. header('Access-Control-Allow-Headers:x-requested-with, content-type');
  686. $data=input('');
  687. if(is_array($data)){
  688. $getDataJson= json_encode($data,320);
  689. $getdata=json_decode($getDataJson,true);//转成数组
  690. }else{
  691. $getDataJson=$data;
  692. $getdata=json_decode($getDataJson,true);//转成数组
  693. }
  694. Log::record('zhanyejunceshi:' .$getDataJson);
  695. return $getDataJson;
  696. // $data1 = array();
  697. // $data2 = array();
  698. // $data4 = array();
  699. // $data5 = array();
  700. // $data6 = array();
  701. // $data7 = array();
  702. // $data8 = array();
  703. // $data9 = array();
  704. // $data10 = array();
  705. // $data11 = array();
  706. // $data12 = array();
  707. // $data15 = array();
  708. // $data16 = array();
  709. // $data18 = array();
  710. // $data19 = array();
  711. // for ($i=0;$i<=14;$i++){
  712. // $data1['standard_deviation']=round($this->mt_rand_float(1,5),2);
  713. // $data1['variance']=round($data1['standard_deviation']*$data1['standard_deviation'],2);
  714. // $data1['average_value']=round($this->mt_rand_float(220,227),2);
  715. // $j=$i+1;
  716. // if($j>=10){
  717. // $data1['data_time']="2021-03-".$j;
  718. // }
  719. // $data2[$i]=$data1;
  720. // $data4['standard_deviation']=round($this->mt_rand_float(3,8),2);
  721. // $data4['variance']=round($data4['standard_deviation']*$data4['standard_deviation'],2);
  722. // $data4['average_value']=round($this->mt_rand_float(7,15),2);
  723. // if($j>=10){
  724. // $data4['data_time']="2021-03-".$j;
  725. // }
  726. // $data5[$i]=$data4;
  727. // $data6['standard_deviation']=round($this->mt_rand_float(0,2),2);
  728. // $data6['variance']=round($data6['standard_deviation']*$data6['standard_deviation'],2);
  729. // $data6['average_value']=round($this->mt_rand_float(17,25),2);
  730. // if($j>=10){
  731. // $data6['data_time']="2021-03-".$j;
  732. // }
  733. // $data7[$i]=$data6;
  734. // $data8['standard_deviation']=round($this->mt_rand_float(30,70),2);
  735. // $data8['variance']=round($data8['standard_deviation']*$data8['standard_deviation'],2);
  736. // $data8['average_value']=round($this->mt_rand_float(30,60),2);
  737. // if($j>=10){
  738. // $data8['data_time']="2021-03-".$j;
  739. // }
  740. // $data9[$i]=$data8;
  741. // $data11['electric_current']=round($this->mt_rand_float(8,18),2);
  742. // $data11['voltage']=round($this->mt_rand_float(220,225),2);
  743. // $data11['data_time']=$this->randomDate();
  744. // $data12[$i]=$data11;
  745. // $data15['electric_current']=round($this->mt_rand_float(20,100),2);
  746. // $data15['voltage']=round($this->mt_rand_float(220,225),2);
  747. // $data15['data_time']=$this->randomDate();
  748. // $data16[$i]=$data15;
  749. // $data18['ambient_temperature']=round($this->mt_rand_float(20,25),2);
  750. // $data18['Cable_temperature']=round($this->mt_rand_float(10,20),2);
  751. // $data18['generation_temperature']=round($data18['ambient_temperature']-$data18['Cable_temperature'],2);
  752. // $data18['data_time']=$this->randomDate();
  753. // $data19[$i]=$data18;
  754. // }
  755. // $data10['conclusion1']="因数据量未达到暂无法分析";
  756. // $data3['voltage']=$data2;
  757. // $data3['electric_current']=$data5;
  758. // $data3['temperature']=$data7;
  759. // $data3['leakage_current']=$data9;
  760. // $data3['conclusion']=$data10;
  761. // $data14['abnormal_equipment']=$data12;
  762. // $data14['leakage_alarm']=$data16;
  763. // $data14['conclusion']=$data10;
  764. // $data20['visualization']=$data19;
  765. // $data20['conclusion']=$data10;
  766. // $data13['dispersion_rate']=$data3;
  767. // $data13['electrical_aging']=$data14;
  768. // $data13['thermal_aging']=$data20;
  769. //// $data1['alarm_number']=$this->mt_rand_float(100,500);
  770. //// $sensorList['productId'] = round($this->mt_rand_float(3,5),2);
  771. // $data17 = json_encode($data13);
  772. // return $data17;
  773. }
  774. //水系统电气火灾算法测试API
  775. public function algorithmApi(){
  776. header("Access-Control-Allow-Origin:*");
  777. // 响应类型
  778. header('Access-Control-Allow-Methods:POST');
  779. // 响应头设置
  780. header('Access-Control-Allow-Headers:x-requested-with, content-type');
  781. $data=input('');
  782. if(is_array($data)){
  783. $getDataJson= json_encode($data,320);
  784. $getdata=json_decode($getDataJson,true);//转成数组
  785. }else{
  786. $getDataJson=$data;
  787. $getdata=json_decode($getDataJson,true);//转成数组
  788. }
  789. if(!empty($getdata["dataType"])){
  790. if($getdata["dataType"]==1||$getdata["dataType"]==2){
  791. if($getdata["dataType"]==1){
  792. if (!empty($getdata["apiType"])){
  793. if ($getdata["apiType"]==4){
  794. if(!empty($getdata["timeType"])){
  795. if (!empty($getdata["companyCode"])){
  796. $sql6="select dispersion_rate from sp_water_analysis where company_code ='{$getdata["companyCode"]}' and data_type ={$getdata["timeType"]}";
  797. $longHuOwner = add($sql6);
  798. $returnInformation['code'] = 200;
  799. $returnInformation['msg'] = "success";
  800. $returnInformation['data']=$longHuOwner[0]['dispersion_rate'];
  801. return stripslashes(json_encode($returnInformation));
  802. }else{
  803. $returnInformation['code'] = 60001;
  804. $returnInformation['msg'] = "操作失败,单位编号不能为空";
  805. return json_encode($returnInformation);
  806. }
  807. }else{
  808. $returnInformation['code'] = 60001;
  809. $returnInformation['msg'] = "操作失败,时间类型不能为空";
  810. return json_encode($returnInformation);
  811. }
  812. }elseif ($getdata["apiType"]==5){
  813. if(!empty($getdata["timeType"])){
  814. if (!empty($getdata["companyCode"])){
  815. $sql6="select leakage_investigation from sp_water_analysis where company_code ='{$getdata["companyCode"]}' and data_type ={$getdata["timeType"]}";
  816. $longHuOwner = add($sql6);
  817. $returnInformation['code'] = 200;
  818. $returnInformation['msg'] = "success";
  819. $returnInformation['data']=$longHuOwner[0]['leakage_investigation'];
  820. return stripslashes(json_encode($returnInformation));
  821. }else{
  822. $returnInformation['code'] = 60001;
  823. $returnInformation['msg'] = "操作失败,单位编号不能为空";
  824. return json_encode($returnInformation);
  825. }
  826. }else{
  827. $returnInformation['code'] = 60001;
  828. $returnInformation['msg'] = "操作失败,时间类型不能为空";
  829. return json_encode($returnInformation);
  830. }
  831. }elseif ($getdata["apiType"]==6){
  832. if(!empty($getdata["timeType"])){
  833. if (!empty($getdata["companyCode"])){
  834. $sql6="select device_association from sp_water_analysis where company_code ='{$getdata["companyCode"]}' and data_type ={$getdata["timeType"]}";
  835. $longHuOwner = add($sql6);
  836. $returnInformation['code'] = 200;
  837. $returnInformation['msg'] = "success";
  838. $returnInformation['data']=$longHuOwner[0]['device_association'];
  839. return stripslashes(json_encode($returnInformation));
  840. }else{
  841. $returnInformation['code'] = 60001;
  842. $returnInformation['msg'] = "操作失败,单位编号不能为空";
  843. return json_encode($returnInformation);
  844. }
  845. }else{
  846. $returnInformation['code'] = 60001;
  847. $returnInformation['msg'] = "操作失败,时间类型不能为空";
  848. return json_encode($returnInformation);
  849. }
  850. }elseif ($getdata["apiType"]==7){
  851. if(!empty($getdata["timeType"])){
  852. if (!empty($getdata["companyCode"])){
  853. $sql6="select data_fluctuation from sp_water_analysis where company_code ='{$getdata["companyCode"]}' and data_type ={$getdata["timeType"]}";
  854. $longHuOwner = add($sql6);
  855. $returnInformation['code'] = 200;
  856. $returnInformation['msg'] = "success";
  857. $returnInformation['data']=$longHuOwner[0]['data_fluctuation'];
  858. return stripslashes(json_encode($returnInformation));
  859. }else{
  860. $returnInformation['code'] = 60001;
  861. $returnInformation['msg'] = "操作失败,单位编号不能为空";
  862. return json_encode($returnInformation);
  863. }
  864. }else{
  865. $returnInformation['code'] = 60001;
  866. $returnInformation['msg'] = "操作失败,时间类型不能为空";
  867. return json_encode($returnInformation);
  868. }
  869. }elseif ($getdata["apiType"]==2){
  870. if(!empty($getdata["timeType"])){
  871. if (!empty($getdata["companyCode"])){
  872. $sql6="select data_statistics from sp_water_analysis where company_code ='{$getdata["companyCode"]}' and data_type ={$getdata["timeType"]}";
  873. $longHuOwner = add($sql6);
  874. $returnInformation['code'] = 200;
  875. $returnInformation['msg'] = "success";
  876. $returnInformation['data']=$longHuOwner[0]['data_statistics'];
  877. return stripslashes(json_encode($returnInformation));
  878. }else{
  879. $returnInformation['code'] = 60001;
  880. $returnInformation['msg'] = "操作失败,单位编号不能为空";
  881. return json_encode($returnInformation);
  882. }
  883. }else{
  884. $returnInformation['code'] = 60001;
  885. $returnInformation['msg'] = "操作失败,时间类型不能为空";
  886. return json_encode($returnInformation);
  887. }
  888. }elseif ($getdata["apiType"]==3){
  889. if(!empty($getdata["timeType"])){
  890. if (!empty($getdata["companyCode"])){
  891. if($getdata["timeType"]==1) {
  892. $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'";
  893. $longHuOwner = add($sql6);
  894. $returnInformation['code'] = 200;
  895. $returnInformation['msg'] = "success";
  896. $returnInformation['data'] = $longHuOwner;
  897. return stripslashes(json_encode($returnInformation));
  898. }elseif ($getdata["timeType"]==2){
  899. $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'";
  900. $longHuOwner = add($sql6);
  901. $returnInformation['code'] = 200;
  902. $returnInformation['msg'] = "success";
  903. $returnInformation['data'] = $longHuOwner;
  904. return stripslashes(json_encode($returnInformation));
  905. }elseif ($getdata["timeType"]==3){
  906. $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'";
  907. $longHuOwner = add($sql6);
  908. $returnInformation['code'] = 200;
  909. $returnInformation['msg'] = "success";
  910. $returnInformation['data'] = $longHuOwner;
  911. return stripslashes(json_encode($returnInformation));
  912. }
  913. }else{
  914. $returnInformation['code'] = 60001;
  915. $returnInformation['msg'] = "操作失败,单位编号不能为空";
  916. return json_encode($returnInformation);
  917. }
  918. }else{
  919. $returnInformation['code'] = 60001;
  920. $returnInformation['msg'] = "操作失败,时间类型不能为空";
  921. return json_encode($returnInformation);
  922. }
  923. }
  924. }else{
  925. $returnInformation['code'] = 60001;
  926. $returnInformation['msg'] = "操作失败,api类型不能为空";
  927. return json_encode($returnInformation);
  928. }
  929. }else{
  930. if (!empty($getdata["apiType"])){
  931. if ($getdata["apiType"]==4){
  932. if(!empty($getdata["timeType"])){
  933. if (!empty($getdata["companyCode"])){
  934. $sql6="select dispersion_rate from sp_ef_analysis where company_code ='{$getdata["companyCode"]}' and data_type ={$getdata["timeType"]}";
  935. $longHuOwner = add($sql6);
  936. $returnInformation['code'] = 200;
  937. $returnInformation['msg'] = "success";
  938. $returnInformation['data']=$longHuOwner[0]['dispersion_rate'];
  939. return stripslashes(json_encode($returnInformation));
  940. }else{
  941. $returnInformation['code'] = 60001;
  942. $returnInformation['msg'] = "操作失败,单位编号不能为空";
  943. return json_encode($returnInformation);
  944. }
  945. }else{
  946. $returnInformation['code'] = 60001;
  947. $returnInformation['msg'] = "操作失败,时间类型不能为空";
  948. return json_encode($returnInformation);
  949. }
  950. }elseif ($getdata["apiType"]==5){
  951. if(!empty($getdata["timeType"])){
  952. if (!empty($getdata["companyCode"])){
  953. $sql6="select electrical_aging from sp_ef_analysis where company_code ='{$getdata["companyCode"]}' and data_type ={$getdata["timeType"]}";
  954. $longHuOwner = add($sql6);
  955. $returnInformation['code'] = 200;
  956. $returnInformation['msg'] = "success";
  957. $returnInformation['data']=$longHuOwner[0]['electrical_aging'];
  958. return stripslashes(json_encode($returnInformation));
  959. }else{
  960. $returnInformation['code'] = 60001;
  961. $returnInformation['msg'] = "操作失败,单位编号不能为空";
  962. return json_encode($returnInformation);
  963. }
  964. }else{
  965. $returnInformation['code'] = 60001;
  966. $returnInformation['msg'] = "操作失败,时间类型不能为空";
  967. return json_encode($returnInformation);
  968. }
  969. }elseif ($getdata["apiType"]==6){
  970. if(!empty($getdata["timeType"])){
  971. if (!empty($getdata["companyCode"])){
  972. $sql6="select thermal_aging from sp_ef_analysis where company_code ='{$getdata["companyCode"]}' and data_type ={$getdata["timeType"]}";
  973. $longHuOwner = add($sql6);
  974. $returnInformation['code'] = 200;
  975. $returnInformation['msg'] = "success";
  976. $returnInformation['data']=$longHuOwner[0]['thermal_aging'];
  977. return stripslashes(json_encode($returnInformation));
  978. }else{
  979. $returnInformation['code'] = 60001;
  980. $returnInformation['msg'] = "操作失败,单位编号不能为空";
  981. return json_encode($returnInformation);
  982. }
  983. }else{
  984. $returnInformation['code'] = 60001;
  985. $returnInformation['msg'] = "操作失败,时间类型不能为空";
  986. return json_encode($returnInformation);
  987. }
  988. }elseif ($getdata["apiType"]==7){
  989. if(!empty($getdata["timeType"])){
  990. if (!empty($getdata["companyCode"])){
  991. $sql6="select data_fluctuation from sp_water_analysis where company_code ='{$getdata["companyCode"]}' and data_type ={$getdata["timeType"]}";
  992. $longHuOwner = add($sql6);
  993. $returnInformation['code'] = 200;
  994. $returnInformation['msg'] = "success";
  995. $returnInformation['data']=$longHuOwner[0]['data_fluctuation'];
  996. return stripslashes(json_encode($returnInformation));
  997. }else{
  998. $returnInformation['code'] = 60001;
  999. $returnInformation['msg'] = "操作失败,单位编号不能为空";
  1000. return json_encode($returnInformation);
  1001. }
  1002. }else{
  1003. $returnInformation['code'] = 60001;
  1004. $returnInformation['msg'] = "操作失败,时间类型不能为空";
  1005. return json_encode($returnInformation);
  1006. }
  1007. }elseif ($getdata["apiType"]==2){
  1008. if(!empty($getdata["timeType"])){
  1009. if (!empty($getdata["companyCode"])){
  1010. $sql6="select data_statistics from sp_water_analysis where company_code ='{$getdata["companyCode"]}' and data_type ={$getdata["timeType"]}";
  1011. $longHuOwner = add($sql6);
  1012. $returnInformation['code'] = 200;
  1013. $returnInformation['msg'] = "success";
  1014. $returnInformation['data']=$longHuOwner[0]['data_statistics'];
  1015. return stripslashes(json_encode($returnInformation));
  1016. }else{
  1017. $returnInformation['code'] = 60001;
  1018. $returnInformation['msg'] = "操作失败,单位编号不能为空";
  1019. return json_encode($returnInformation);
  1020. }
  1021. }else{
  1022. $returnInformation['code'] = 60001;
  1023. $returnInformation['msg'] = "操作失败,时间类型不能为空";
  1024. return json_encode($returnInformation);
  1025. }
  1026. }elseif ($getdata["apiType"]==3){
  1027. if(!empty($getdata["timeType"])){
  1028. if (!empty($getdata["companyCode"])){
  1029. if($getdata["timeType"]==1) {
  1030. $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'";
  1031. $longHuOwner = add($sql6);
  1032. $returnInformation['code'] = 200;
  1033. $returnInformation['msg'] = "success";
  1034. $returnInformation['data'] = $longHuOwner;
  1035. return stripslashes(json_encode($returnInformation));
  1036. }elseif ($getdata["timeType"]==2){
  1037. $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'";
  1038. $longHuOwner = add($sql6);
  1039. $returnInformation['code'] = 200;
  1040. $returnInformation['msg'] = "success";
  1041. $returnInformation['data'] = $longHuOwner;
  1042. return stripslashes(json_encode($returnInformation));
  1043. }elseif ($getdata["timeType"]==3){
  1044. $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'";
  1045. $longHuOwner = add($sql6);
  1046. $returnInformation['code'] = 200;
  1047. $returnInformation['msg'] = "success";
  1048. $returnInformation['data'] = $longHuOwner;
  1049. return stripslashes(json_encode($returnInformation));
  1050. }
  1051. }else{
  1052. $returnInformation['code'] = 60001;
  1053. $returnInformation['msg'] = "操作失败,单位编号不能为空";
  1054. return json_encode($returnInformation);
  1055. }
  1056. }else{
  1057. $returnInformation['code'] = 60001;
  1058. $returnInformation['msg'] = "操作失败,时间类型不能为空";
  1059. return json_encode($returnInformation);
  1060. }
  1061. }
  1062. }else{
  1063. $returnInformation['code'] = 60001;
  1064. $returnInformation['msg'] = "操作失败,api类型不能为空";
  1065. return json_encode($returnInformation);
  1066. }
  1067. }
  1068. }else{
  1069. $returnInformation['code'] = 60001;
  1070. $returnInformation['msg'] = "操作失败,数据范围超出限制";
  1071. return json_encode($returnInformation);
  1072. }
  1073. }else{
  1074. $returnInformation['code'] = 60001;
  1075. $returnInformation['msg'] = "操作失败,数据类型不能为空";
  1076. return json_encode($returnInformation);
  1077. }
  1078. }
  1079. public function ceshiApi()
  1080. {
  1081. header("Access-Control-Allow-Origin:*");
  1082. // 响应类型
  1083. header('Access-Control-Allow-Methods:POST');
  1084. // 响应头设置
  1085. header('Access-Control-Allow-Headers:x-requested-with, content-type');
  1086. $data = input('');
  1087. if (is_array($data)) {
  1088. $getDataJson = json_encode($data, 320);
  1089. $getdata = json_decode($getDataJson, true);//转成数组
  1090. } else {
  1091. $getDataJson = $data;
  1092. $getdata = json_decode($getDataJson, true);//转成数组
  1093. }
  1094. $data1 = array();
  1095. $data2 = array();
  1096. $data3 = array();
  1097. $data4 = array();
  1098. if ($getdata['status']=="getnewslist"){
  1099. $data1['status']=0;
  1100. for ($i=0;$i<2;$i++){
  1101. $data2['id']=$i+1;
  1102. $data2['title']="测试高房价结果回复的合法化觉得很简单的事";
  1103. $data2['add_time']="2021-08-05 16:48:17";
  1104. $data2['zhaiyao']="的就是但是绝大多数公开大量上市价格第四季度睡个好觉了";
  1105. $data2['click']=1;
  1106. $data2['img_url']="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fs10.sinaimg.cn%2Forignal%2F4a8a8049ga9eae999a909&refer=http%3A%2F%2Fs10.sinaimg.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1631010162&t=f95e7303fda34bef3751916ee036b4a9";
  1107. $data3[$i]=$data2;
  1108. }
  1109. $data1['message']=$data3;
  1110. return json_encode($data1);
  1111. }elseif($getdata['status']=="getnew"){
  1112. $data1['status']=0;
  1113. $data2['id']=1;
  1114. $data2['title']="测试高房价结果回复的合法化觉得很简单的事";
  1115. $data2['add_time']="2021-08-05 16:48:17";
  1116. $data2['content']="的就是但是绝大多数公开大量上市价格第四季度睡个好觉了";
  1117. $data2['click']=2;
  1118. $data3[0]=$data2;
  1119. $data1['message']=$data3;
  1120. return json_encode($data1);
  1121. }elseif($getdata['status']=="getimages"){
  1122. $data1['status']=0;
  1123. for ($i=0;$i<2;$i++){
  1124. $data2['id']=$i+1;
  1125. $data2['title']="测试高房价结果回复的合法化觉得很简单的事";
  1126. $data2['zhaiyao']="的就是但是绝大多数公开大量上市价格第四季度睡个好觉了";
  1127. $data2['img_url']="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fn.sinaimg.cn%2Fsinacn08%2F336%2Fw501h635%2F20180630%2F9d76-hespqrx2645109.jpg&refer=http%3A%2F%2Fn.sinaimg.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1631010162&t=384680be0388ea4c8bd06dfed25d9da3";
  1128. $data3[$i]=$data2;
  1129. }
  1130. $data1['message']=$data3;
  1131. return json_encode($data1);
  1132. }elseif($getdata['status']=="getimgcategory"){
  1133. $data1['status']=0;
  1134. for ($i=0;$i<2;$i++){
  1135. $data2['id']=$i+1;
  1136. $data2['title']="测试".$i;
  1137. $data3[$i]=$data2;
  1138. }
  1139. $data1['message']=$data3;
  1140. return json_encode($data1);
  1141. }elseif($getdata['status']=="getthumimages"){
  1142. $data1['status']=0;
  1143. for ($i=0;$i<3;$i++){
  1144. $data2['src']="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.article.pchome.net%2F00%2F40%2F91%2F79%2Fpic_lib%2Fs960x639%2Fcountry_field_landscape_photo_EA52058s960x639.jpg&refer=http%3A%2F%2Fimg.article.pchome.net&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1631010162&t=0fe6c4c3d1a111f5e848695687261303";
  1145. }
  1146. $data1['message']=$data3;
  1147. return json_encode($data1);
  1148. }elseif($getdata['status']=="getimageInfo"){
  1149. $data1['status']=0;
  1150. for ($i=0;$i<1;$i++){
  1151. $data2['id']=$i+1;
  1152. $data2['title']="测试高房价结果回复的合法化觉得很简单的事";
  1153. $data2['add_time']="2021-08-05 16:48:17";
  1154. $data2['click']=3;
  1155. $data2['content']="解释的机会就是进口关税打开撒酒疯还是";
  1156. }
  1157. $data1['message']=$data3;
  1158. return json_encode($data1);
  1159. }elseif($getdata['status']=="getcomments"){
  1160. $data1['status']=0;
  1161. for ($i=0;$i<1;$i++){
  1162. $data2['user_name']="djsjf";
  1163. $data2['add_time']="2021-08-05 16:48:17";
  1164. $data2['content']="快速减肥健身看江户时代";
  1165. }
  1166. $data1['message']=$data3;
  1167. return json_encode($data1);
  1168. }elseif($getdata['status']=="postcomment"){
  1169. $data1['status']=0;
  1170. $data1['message']="啊附加符号方式";
  1171. return json_encode($data1);
  1172. }elseif($getdata['status']=="getgoods"){
  1173. $data1['status']=0;
  1174. for ($i=0;$i<2;$i++){
  1175. $data2['id']=$i+1;
  1176. $data2['title']="测试高房价结果回复的合法化觉得很简单的事";
  1177. $data2['add_time']="2021-08-05 16:48:17";
  1178. $data2['zhaiyao']="的就是但是绝大多数公开大量上市价格第四季度睡个好觉了";
  1179. $data2['click']=0;
  1180. $data2['img_url']="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fup.enterdesk.com%2Fedpic_360_360%2F5b%2F71%2F3b%2F5b713b0d8f5fb4e4f8759c417b42eefb.jpg&refer=http%3A%2F%2Fup.enterdesk.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1631010162&t=699aab395bae994606f72becd4cbb90d";
  1181. $data2['sell_price']=214;
  1182. $data2['market_price']=3446;
  1183. $data2['stock_quantity']=3446;
  1184. }
  1185. $data1['message']=$data3;
  1186. return json_encode($data1);
  1187. }elseif($getdata['status']=="getdesc"){
  1188. $data1['status']=0;
  1189. for ($i=0;$i<2;$i++){
  1190. $data2['title']="测试高房价结果回复的合法化觉得很简单的事";
  1191. $data2['content']="<p>的实际开工的开始</p><p align='center'></p>";
  1192. }
  1193. $data1['message']=$data3;
  1194. return json_encode($data1);
  1195. }
  1196. }
  1197. //杨浦一网通管各类设备数量
  1198. public function deviceNumber(){
  1199. header("Access-Control-Allow-Origin:*");
  1200. // 响应类型
  1201. header('Access-Control-Allow-Methods:POST');
  1202. // 响应头设置
  1203. header('Access-Control-Allow-Headers:x-requested-with, content-type');
  1204. $data=input('');
  1205. if(is_array($data)){
  1206. $getDataJson= json_encode($data,320);
  1207. $getdata=json_decode($getDataJson,true);//转成数组
  1208. }else{
  1209. $getDataJson=$data;
  1210. $getdata=json_decode($getDataJson,true);//转成数组
  1211. }
  1212. $data6 = array();
  1213. if ($getdata['userName']=="ypywtg"){
  1214. $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');";
  1215. $res=add($sql);
  1216. $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');";
  1217. $res1=add($sql1);
  1218. $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');";
  1219. $res2=add($sql2);
  1220. $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');";
  1221. $res3=add($sql3);
  1222. $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');";
  1223. $res4=add($sql4);
  1224. $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');";
  1225. $res5=add($sql5);
  1226. $sensorList['waterNumber'] =$res[0]['waterNumber'];
  1227. $sensorList['levelNumber'] =$res1[0]['levelNumber'];
  1228. $sensorList['smokeSensationNumber'] =$res2[0]['smokeSensationNumber'];
  1229. $sensorList['rtuNumber'] =$res3[0]['rtuNumber'];
  1230. $sensorList['videoNumber'] =$res4[0]['videoNumber'];
  1231. $sensorList['electricalFireNumber'] =$res5[0]['electricalFireNumber'];
  1232. $data6 = json_encode($sensorList);
  1233. }
  1234. return $data6;
  1235. }
  1236. //伍继电力程序校验机制api
  1237. public function wooGiApi(){
  1238. $data=input('');
  1239. if(is_array($data)){
  1240. $getDataJson= json_encode($data,320);
  1241. $getdata=json_decode($getDataJson,true);//转成数组
  1242. }else{
  1243. $getDataJson=$data;
  1244. $getdata=json_decode($getDataJson,true);//转成数组
  1245. }
  1246. $clientIp=$this->ip();
  1247. Log::record('wooGiApi_deviceList' . ':' .'<<<'.$clientIp.'>>>'.$getDataJson);
  1248. $allowIp = ['101.133.214.75','124.71.174.104','124.71.175.91','124.70.160.158','222.69.148.83','114.95.161.247'];
  1249. // if (!in_array($clientIp, $allowIp)){
  1250. // $returnInformation['code'] = 60001;
  1251. // $returnInformation['msg'] = "操作失败,IP地址不在白名单中";
  1252. // $returnInformation['data']=null;
  1253. // return json_encode($returnInformation);
  1254. // }else{
  1255. $redis = new \Redis();
  1256. $redis->connect('127.0.0.1', 6379);
  1257. $result = $redis->auth("usky2021");
  1258. $redis->select(1);
  1259. if ($result == 1) {
  1260. $check =$redis->exists($clientIp);
  1261. if ($check){
  1262. // +1
  1263. $redis->incr($clientIp);
  1264. $count =$redis->get($clientIp);
  1265. // 限制每小时1次
  1266. if($count > 500){
  1267. $returnInformation['code'] = 60003;
  1268. $returnInformation['msg'] = "操作失败,当前ip请求频率过高";
  1269. $returnInformation['data']=null;
  1270. return json_encode($returnInformation);
  1271. }else{
  1272. if (!empty($getdata['publicKey'])){
  1273. $publicKey = $getdata['publicKey'];
  1274. $timeStamp = time();
  1275. if (!empty($getdata['requestType'])){
  1276. if($getdata['requestType']==1){
  1277. $publicKey1 = md5("usky".$getdata['timeStamp']."9bcbc5d723cb9bae394d3a097deb6695");
  1278. $publicKey2 = md5("usky".$timeStamp."9bcbc5d723cb9bae394d3a097deb6695");
  1279. }else if ($getdata['requestType']==2){
  1280. $publicKey1 = md5("usky".$getdata['timeStamp']."b9848b4fe4647e380fd1367a4f34ced9");
  1281. $publicKey2 = md5("usky".$timeStamp."b9848b4fe4647e380fd1367a4f34ced9");
  1282. }else if ($getdata['requestType']==3){
  1283. $publicKey1 = md5("usky".$getdata['timeStamp']."056ac8fae059c9c9e700b734922edfc8");
  1284. $publicKey2 = md5("usky".$timeStamp."056ac8fae059c9c9e700b734922edfc8");
  1285. }else{
  1286. $returnInformation['code'] = 60004;
  1287. $returnInformation['msg'] = "操作失败,requestType不在范围内";
  1288. $returnInformation['data']=null;
  1289. return json_encode($returnInformation);
  1290. }
  1291. }else{
  1292. $returnInformation['code'] = 60004;
  1293. $returnInformation['msg'] = "操作失败,requestType不能为空";
  1294. $returnInformation['data']=null;
  1295. return json_encode($returnInformation);
  1296. }
  1297. if ($publicKey==$publicKey1){
  1298. $sensorList['publicKey'] =$publicKey2;
  1299. $sensorList['timeStamp'] =$timeStamp;
  1300. $returnInformation['code'] = 200;
  1301. $returnInformation['msg'] = "操作成功";
  1302. $returnInformation['data']=$sensorList;
  1303. return json_encode($returnInformation);
  1304. }else{
  1305. $returnInformation['code'] = 60002;
  1306. $returnInformation['msg'] = "操作失败,publicKey错误";
  1307. $returnInformation['data']=null;
  1308. return json_encode($returnInformation);
  1309. }
  1310. }else{
  1311. $returnInformation['code'] = 60004;
  1312. $returnInformation['msg'] = "操作失败,publicKey不能为空";
  1313. $returnInformation['data']=null;
  1314. return json_encode($returnInformation);
  1315. }
  1316. }
  1317. } else {
  1318. $redis->set($clientIp, 1,3300);//初始值1
  1319. if (!empty($getdata['publicKey'])){
  1320. $publicKey = $getdata['publicKey'];
  1321. $timeStamp = time();
  1322. if (!empty($getdata['requestType'])){
  1323. if($getdata['requestType']==1){
  1324. $publicKey1 = md5("usky".$getdata['timeStamp']."9bcbc5d723cb9bae394d3a097deb6695");
  1325. $publicKey2 = md5("usky".$timeStamp."9bcbc5d723cb9bae394d3a097deb6695");
  1326. }else if ($getdata['requestType']==2){
  1327. $publicKey1 = md5("usky".$getdata['timeStamp']."b9848b4fe4647e380fd1367a4f34ced9");
  1328. $publicKey2 = md5("usky".$timeStamp."b9848b4fe4647e380fd1367a4f34ced9");
  1329. }else if ($getdata['requestType']==3){
  1330. $publicKey1 = md5("usky".$getdata['timeStamp']."056ac8fae059c9c9e700b734922edfc8");
  1331. $publicKey2 = md5("usky".$timeStamp."056ac8fae059c9c9e700b734922edfc8");
  1332. }else{
  1333. $returnInformation['code'] = 60004;
  1334. $returnInformation['msg'] = "操作失败,requestType不在范围内";
  1335. $returnInformation['data']=null;
  1336. return json_encode($returnInformation);
  1337. }
  1338. }else{
  1339. $returnInformation['code'] = 60004;
  1340. $returnInformation['msg'] = "操作失败,requestType不能为空";
  1341. $returnInformation['data']=null;
  1342. return json_encode($returnInformation);
  1343. }
  1344. if ($publicKey==$publicKey1){
  1345. $sensorList['publicKey'] =$publicKey2;
  1346. $sensorList['timeStamp'] =$timeStamp;
  1347. $returnInformation['code'] = 200;
  1348. $returnInformation['msg'] = "操作成功";
  1349. $returnInformation['data']=$sensorList;
  1350. return json_encode($returnInformation);
  1351. }else{
  1352. $returnInformation['code'] = 60002;
  1353. $returnInformation['msg'] = "操作失败,publicKey错误";
  1354. $returnInformation['data']=null;
  1355. return json_encode($returnInformation);
  1356. }
  1357. }else{
  1358. $returnInformation['code'] = 60004;
  1359. $returnInformation['msg'] = "操作失败,publicKey不能为空";
  1360. $returnInformation['data']=null;
  1361. return json_encode($returnInformation);
  1362. }
  1363. }
  1364. }
  1365. // }
  1366. }
  1367. //伍继电力java程序校验机制api
  1368. public function wooGiJavaApi(){
  1369. $data=input('');
  1370. if(is_array($data)){
  1371. $getDataJson= json_encode($data,320);
  1372. $getdata=json_decode($getDataJson,true);//转成数组
  1373. }else{
  1374. $getDataJson=$data;
  1375. $getdata=json_decode($getDataJson,true);//转成数组
  1376. }
  1377. $clientIp=$this->ip();
  1378. Log::record('wooGiJavaApi_deviceList' . ':' .'<<<'.$clientIp.'>>>'.$getDataJson);
  1379. $code = 1;
  1380. if ($code==1){
  1381. return 1;
  1382. }else{
  1383. return 0;
  1384. }
  1385. }
  1386. //杨浦学校设备注册api
  1387. public function ypSchoolApi()
  1388. {
  1389. $data = input('');
  1390. if (is_array($data)) {
  1391. $getDataJson = json_encode($data, 320);
  1392. $getdata = json_decode($getDataJson, true);//转成数组
  1393. } else {
  1394. $getDataJson = $data;
  1395. $getdata = json_decode($getDataJson, true);//转成数组
  1396. }
  1397. $sql6="select * from sp_yangpuxy_share where company_code ='{$getdata["deviceCode"]}' and rec_cur=1586416046";
  1398. $ypSchoolOwner = add($sql6);
  1399. if (!empty($ypSchoolOwner)){
  1400. foreach ($ypSchoolOwner as $key=>$value){
  1401. $cs['deviceId'] = $ypSchoolOwner[$key]['object_code'];
  1402. $cs['deviceName'] = $ypSchoolOwner[$key]['object_name'].$ypSchoolOwner[$key]['device_name'];
  1403. if ($ypSchoolOwner[$key]['owner_dwtype']==2){
  1404. $cs['deviceType'] = "1";
  1405. $cs['deviceTypeName'] = "水泵水压检测器";
  1406. }elseif ($ypSchoolOwner[$key]['owner_dwtype']==128){
  1407. $cs['deviceType'] = "4";
  1408. $cs['deviceTypeName'] = "井盖探测器";
  1409. }elseif ($ypSchoolOwner[$key]['owner_dwtype']==3){
  1410. $cs['deviceType'] = "3";
  1411. $cs['deviceTypeName'] = "烟感检测";
  1412. }elseif ($ypSchoolOwner[$key]['owner_dwtype']==7){
  1413. $cs['deviceType'] = "5";
  1414. $cs['deviceTypeName'] = "高低压配电房检测器";
  1415. }elseif ($ypSchoolOwner[$key]['owner_dwtype']==130){
  1416. $cs['deviceType'] = "2";
  1417. $cs['deviceTypeName'] = "消防栓";
  1418. }elseif ($ypSchoolOwner[$key]['owner_dwtype']==1){
  1419. $cs['deviceType'] = "3";
  1420. $cs['deviceTypeName'] = "烟感检测";
  1421. }
  1422. $cs['companyCode'] = $ypSchoolOwner[$key]['company_code'];
  1423. $cs['companyName'] = $ypSchoolOwner[$key]['company_name'];
  1424. $data6 = json_encode($cs);
  1425. $rep_url = "http://ypaqpt.edu.sh.cn/schoolSafe-yp/deviceAdd";
  1426. $res = $this->ypxycurl($rep_url, $data6);
  1427. Log::record('yangpuxiaoyuandevice1' . ':' . $data6);
  1428. Log::record('yangpuxiaoyuandevice2' . ':' . $res);
  1429. print_r('结果'.$res);
  1430. print_r($data6);
  1431. sleep(0.5);
  1432. }
  1433. }
  1434. }
  1435. //消防总队平台主机点位设备注册api
  1436. public function xfzdAddApi()
  1437. {
  1438. $data = input('');
  1439. if (is_array($data)) {
  1440. $getDataJson = json_encode($data, 320);
  1441. $getdata = json_decode($getDataJson, true);//转成数组
  1442. } else {
  1443. $getDataJson = $data;
  1444. $getdata = json_decode($getDataJson, true);//转成数组
  1445. }
  1446. $header=[
  1447. "Content-Type:application/json",
  1448. "appKey:850404889644236801"
  1449. ];
  1450. $sql6="select * from sp_corps_share_ceshi where open_project_id ='{$getdata["companyCode"]}' and `data` ={$getdata["hostCode"]} limit ".$getdata["startNum"].",".$getdata["endNum"];
  1451. $ypSchoolOwner = add($sql6);
  1452. if (!empty($ypSchoolOwner)){
  1453. foreach ($ypSchoolOwner as $key=>$value){
  1454. $cs['descript'] = $ypSchoolOwner[$key]['descript'];
  1455. $cs['deviceName'] = $ypSchoolOwner[$key]['device_name'];
  1456. // if ($ypSchoolOwner[$key]['dwtype']==6){
  1457. $cs['deviceNo'] = $ypSchoolOwner[$key]['device_code'].str_replace(',','',$ypSchoolOwner[$key]['port']).$ypSchoolOwner[$key]['data'];
  1458. // }else{
  1459. // $cs['deviceNo'] = $ypSchoolOwner[$key]['device_code'];
  1460. // }
  1461. $cs['deviceType'] = $ypSchoolOwner[$key]['device_type'];
  1462. $cs['deviceTypeName'] = $ypSchoolOwner[$key]['device_type_name'];
  1463. $cs['openProjectId'] = $ypSchoolOwner[$key]['open_project_id'];
  1464. $cs['floor'] = $ypSchoolOwner[$key]['device_floor'];
  1465. $data6 = json_encode($cs);
  1466. $rep_url = "http://iot.shxf-119.com/access/device/point/register";
  1467. $res = $this->ywManagementCurl($rep_url,$header,$data6);
  1468. Log::record('xiaofangzongduidevice1' . ':' . $data6);
  1469. Log::record('xiaofangzongduidevice2' . ':' . $res);
  1470. print_r('结果'.$res);
  1471. print_r($data6);
  1472. sleep(0.5);
  1473. }
  1474. }
  1475. }
  1476. //消防总队平台主机点位设备注册api
  1477. public function xfzdDeviceAddApi()
  1478. {
  1479. $data = input('');
  1480. if (is_array($data)) {
  1481. $getDataJson = json_encode($data, 320);
  1482. $getdata = json_decode($getDataJson, true);//转成数组
  1483. } else {
  1484. $getDataJson = $data;
  1485. $getdata = json_decode($getDataJson, true);//转成数组
  1486. }
  1487. $header=[
  1488. "Content-Type:application/json",
  1489. "appKey:850404889644236801"
  1490. ];
  1491. $sql6="select * from sp_corps_share where open_project_id ='{$getdata["companyCode"]}' limit ".$getdata["startNum"].",".$getdata["endNum"];
  1492. $ypSchoolOwner = add($sql6);
  1493. if (!empty($ypSchoolOwner)){
  1494. foreach ($ypSchoolOwner as $key=>$value){
  1495. $cs['descript'] = $ypSchoolOwner[$key]['descript'];
  1496. $cs['deviceName'] = $ypSchoolOwner[$key]['device_name'];
  1497. if ($ypSchoolOwner[$key]['dwtype']==6){
  1498. $cs['deviceNo'] = $ypSchoolOwner[$key]['device_code'].$ypSchoolOwner[$key]['port'];
  1499. }else{
  1500. $cs['deviceNo'] = $ypSchoolOwner[$key]['device_code'];
  1501. }
  1502. $cs['deviceType'] = $ypSchoolOwner[$key]['device_type'];
  1503. $cs['deviceTypeName'] = $ypSchoolOwner[$key]['device_type_name'];
  1504. $cs['openProjectId'] = $ypSchoolOwner[$key]['open_project_id'];
  1505. $cs['floor'] = $ypSchoolOwner[$key]['device_floor'];
  1506. $data6 = json_encode($cs);
  1507. $rep_url = "http://iot.shxf-119.com/access/device/point/register";
  1508. $res = $this->ywManagementCurl($rep_url,$header,$data6);
  1509. Log::record('xiaofangzongduidevice1' . ':' . $data6);
  1510. Log::record('xiaofangzongduidevice2' . ':' . $res);
  1511. print_r('结果'.$res);
  1512. print_r($data6);
  1513. sleep(0.5);
  1514. }
  1515. }
  1516. }
  1517. //消防总队平台设备数据推送api
  1518. public function xfzdDeviceInfoAddApi()
  1519. {
  1520. $data = input('');
  1521. if (is_array($data)) {
  1522. $getDataJson = json_encode($data, 320);
  1523. $getdata = json_decode($getDataJson, true);//转成数组
  1524. } else {
  1525. $getDataJson = $data;
  1526. $getdata = json_decode($getDataJson, true);//转成数组
  1527. }
  1528. $header=[
  1529. "Content-Type:application/json",
  1530. "appKey:850404889644236801"
  1531. ];
  1532. $rep_url1 = "http://iot.shxf-119.com/access/devlog/transmission/devicestatus";//用传
  1533. $rep_url2 = "http://iot.shxf-119.com/access/devlog/sprinkler/endpressure";//喷淋末端压力
  1534. $rep_url3 = "http://iot.shxf-119.com/access/devlog/sprinkler/pipepressunusual";//喷淋主管压力
  1535. $rep_url4 = "http://iot.shxf-119.com/access/devlog/sprinkler/spraypump";//喷淋泵状态
  1536. $rep_url5 = "http://iot.shxf-119.com/access/devlog/hydrant/endpressure";//消火栓末端压力
  1537. $rep_url6 = "http://iot.shxf-119.com/access/devlog/hydrant/pipepress";//消火栓主管压力
  1538. $rep_url7 = "http://iot.shxf-119.com/access/devlog/hydrant/tanklevel";//水箱液位
  1539. $rep_url8 = "http://iot.shxf-119.com/access/devlog/hydrant/pumpstatus";//消防泵状态
  1540. $sql6="select * from sp_corps_share where open_project_id ='{$getdata["companyCode"]}'";
  1541. $ypSchoolOwner = add($sql6);
  1542. if (!empty($ypSchoolOwner)){
  1543. foreach ($ypSchoolOwner as $key=>$value){
  1544. $sql7="select * from sp_owner_status where device_id ='{$ypSchoolOwner[$key]['device_code']}'";
  1545. $companyOwner = add($sql7);
  1546. $cs['descript'] = $ypSchoolOwner[$key]['descript'];
  1547. $cs['deviceName'] = $ypSchoolOwner[$key]['device_name'];
  1548. if ($ypSchoolOwner[$key]['dwtype']==6){
  1549. $cs['deviceNo'] = $ypSchoolOwner[$key]['device_code'].$ypSchoolOwner[$key]['port'];
  1550. }else{
  1551. $cs['deviceNo'] = $ypSchoolOwner[$key]['device_code'];
  1552. }
  1553. $cs['deviceType'] = $ypSchoolOwner[$key]['device_type'];
  1554. $cs['deviceTypeName'] = $ypSchoolOwner[$key]['device_type_name'];
  1555. $cs['openProjectId'] = $ypSchoolOwner[$key]['open_project_id'];
  1556. $cs['floor'] = $ypSchoolOwner[$key]['device_floor'];
  1557. if ($ypSchoolOwner[$key]['dwtype']==1){
  1558. foreach ($companyOwner as $key1=>$value1){
  1559. if ($companyOwner[$key1]['point_code']==1){
  1560. if(strstr($companyOwner[$key1]['content'],'监测连线故障') !== false) {
  1561. $cs['connectStatus'] = "1";
  1562. }else{
  1563. $cs['connectStatus'] = "0";
  1564. }
  1565. $cs['workStatus'] = "0";
  1566. $cs['mainPower'] = "0";
  1567. $cs['logTime'] = date('Y-m-d H:i:s');
  1568. $data6 = json_encode($cs);
  1569. $res = $this->ywManagementCurl($rep_url1,$header,$data6);
  1570. print_r('结果'.$res);
  1571. }
  1572. }
  1573. }elseif ($ypSchoolOwner[$key]['dwtype']==2){
  1574. foreach ($companyOwner as $key1=>$value1){
  1575. if ($companyOwner[$key1]['point_code']==4){
  1576. $cs['logTime'] = date('Y-m-d H:i:s');
  1577. $cs['pressure'] = $companyOwner[$key1]['point_data'];
  1578. }elseif ($companyOwner[$key1]['point_code']==1){
  1579. if(strstr($companyOwner[$key1]['content'],'正常') !== false) {
  1580. $cs['alarmStatus'] = "0";
  1581. }elseif (strstr($companyOwner[$key1]['content'],'低压') !== false){
  1582. $cs['alarmStatus'] = "1";
  1583. }elseif (strstr($companyOwner[$key1]['content'],'高压') !== false){
  1584. $cs['alarmStatus'] = "2";
  1585. }else{
  1586. $cs['alarmStatus'] = "0";
  1587. }
  1588. }
  1589. }
  1590. if($ypSchoolOwner[$key]['device_type']==304){
  1591. $data6 = json_encode($cs);
  1592. $res = $this->ywManagementCurl($rep_url2,$header,$data6);
  1593. print_r('结果'.$res);
  1594. }elseif ($ypSchoolOwner[$key]['device_type']==301){
  1595. $data6 = json_encode($cs);
  1596. $res = $this->ywManagementCurl($rep_url3,$header,$data6);
  1597. print_r('结果'.$res);
  1598. }elseif ($ypSchoolOwner[$key]['device_type']==305){
  1599. $data6 = json_encode($cs);
  1600. $res = $this->ywManagementCurl($rep_url5,$header,$data6);
  1601. print_r('结果'.$res);
  1602. }elseif ($ypSchoolOwner[$key]['device_type']==302){
  1603. $data6 = json_encode($cs);
  1604. $res = $this->ywManagementCurl($rep_url6,$header,$data6);
  1605. print_r('结果'.$res);
  1606. }
  1607. }elseif ($ypSchoolOwner[$key]['dwtype']==5){
  1608. foreach ($companyOwner as $key1=>$value1){
  1609. if ($companyOwner[$key1]['point_code']==4){
  1610. $cs['logTime'] = date('Y-m-d H:i:s');
  1611. $cs['level'] = $companyOwner[$key1]['point_data'];
  1612. }elseif ($companyOwner[$key1]['point_code']==1){
  1613. if(strstr($companyOwner[$key1]['content'],'正常') !== false) {
  1614. $cs['alarmStatus'] = "0";
  1615. }elseif (strstr($companyOwner[$key1]['content'],'低液位') !== false){
  1616. $cs['alarmStatus'] = "1";
  1617. }elseif (strstr($companyOwner[$key1]['content'],'高液位') !== false){
  1618. $cs['alarmStatus'] = "2";
  1619. }else{
  1620. $cs['alarmStatus'] = "0";
  1621. }
  1622. }
  1623. }
  1624. if($ypSchoolOwner[$key]['device_type']==402){
  1625. $data6 = json_encode($cs);
  1626. $res = $this->ywManagementCurl($rep_url7,$header,$data6);
  1627. print_r('结果'.$res);
  1628. }else{
  1629. $data6 = json_encode($cs);
  1630. $res = $this->ywManagementCurl($rep_url7,$header,$data6);
  1631. print_r('结果'.$res);
  1632. }
  1633. }elseif ($ypSchoolOwner[$key]['dwtype']==6){
  1634. if($ypSchoolOwner[$key]['device_type']==258 || $ypSchoolOwner[$key]['device_type']==256 || $ypSchoolOwner[$key]['device_type']==452){
  1635. $cs['logTime'] = date('Y-m-d H:i:s');
  1636. $companyOwner1 = $ypSchoolOwner[$key]['data'];
  1637. foreach ($companyOwner1 as $key1=>$value1){
  1638. if ($companyOwner1[$key1]['port']==-1){
  1639. if(strstr($companyOwner1[$key1]['name'],'powerStatus') !== false) {
  1640. $cs['powerState'] = "0";
  1641. }elseif (strstr($companyOwner1[$key1]['name'],'runStatus') !== false){
  1642. $cs['manualAutomaticState'] = "0";
  1643. }elseif (strstr($companyOwner1[$key1]['name'],'startStatus') !== false){
  1644. $cs['startStopStatus'] = "0";
  1645. }elseif (strstr($companyOwner1[$key1]['name'],'faultStatus') !== false){
  1646. $cs['faultStatus'] = "0";
  1647. }
  1648. }
  1649. }
  1650. foreach ($companyOwner as $key3=>$value3){
  1651. foreach ($companyOwner1 as $key2=>$value2){
  1652. if ($companyOwner1[$key2]['port']==$companyOwner[$key3]['point_code'] && $companyOwner[$key3]['point_code']!=0){
  1653. if(strstr($companyOwner[$key3]['content'],'正常') !== false || strstr($companyOwner[$key3]['content'],'自动') !== false || strstr($companyOwner[$key3]['content'],'停止') !== false) {
  1654. if(strstr($companyOwner1[$key2]['name'],'powerStatus') !== false) {
  1655. $cs['powerState'] = "0";
  1656. }elseif (strstr($companyOwner1[$key2]['name'],'runStatus') !== false){
  1657. $cs['manualAutomaticState'] = "0";
  1658. }elseif (strstr($companyOwner1[$key2]['name'],'startStatus') !== false){
  1659. $cs['startStopStatus'] = "0";
  1660. }elseif (strstr($companyOwner1[$key2]['name'],'faultStatus') !== false){
  1661. $cs['faultStatus'] = "0";
  1662. }
  1663. }elseif (strstr($companyOwner[$key3]['content'],'关闭') !== false || strstr($companyOwner[$key3]['content'],'手动') !== false || strstr($companyOwner[$key3]['content'],'运行') !== false || strstr($companyOwner[$key3]['content'],'故障') !== false){
  1664. if(strstr($companyOwner1[$key2]['name'],'powerStatus') !== false) {
  1665. $cs['powerState'] = "1";
  1666. }elseif (strstr($companyOwner1[$key2]['name'],'runStatus') !== false){
  1667. $cs['manualAutomaticState'] = "1";
  1668. }elseif (strstr($companyOwner1[$key2]['name'],'startStatus') !== false){
  1669. $cs['startStopStatus'] = "1";
  1670. }elseif (strstr($companyOwner1[$key2]['name'],'faultStatus') !== false){
  1671. $cs['faultStatus'] = "1";
  1672. }
  1673. }else{
  1674. if(strstr($companyOwner1[$key2]['name'],'powerStatus') !== false) {
  1675. $cs['powerState'] = "0";
  1676. }elseif (strstr($companyOwner1[$key2]['name'],'runStatus') !== false){
  1677. $cs['manualAutomaticState'] = "0";
  1678. }elseif (strstr($companyOwner1[$key2]['name'],'startStatus') !== false){
  1679. $cs['startStopStatus'] = "0";
  1680. }elseif (strstr($companyOwner1[$key2]['name'],'faultStatus') !== false){
  1681. $cs['faultStatus'] = "0";
  1682. }
  1683. }
  1684. break;
  1685. }
  1686. }
  1687. }
  1688. if ($ypSchoolOwner[$key]['device_type']==258){
  1689. $data6 = json_encode($cs);
  1690. $res = $this->ywManagementCurl($rep_url8,$header,$data6);
  1691. print_r('结果'.$res);
  1692. }elseif ($ypSchoolOwner[$key]['device_type']==256){
  1693. $data6 = json_encode($cs);
  1694. $res = $this->ywManagementCurl($rep_url4,$header,$data6);
  1695. print_r('结果'.$res);
  1696. }elseif ($ypSchoolOwner[$key]['device_type']==452){
  1697. $data6 = json_encode($cs);
  1698. $res = $this->ywManagementCurl($rep_url4,$header,$data6);
  1699. print_r('结果'.$res);
  1700. }
  1701. }else{
  1702. $cs['logTime'] = date('Y-m-d H:i:s');
  1703. $companyOwner1 = $ypSchoolOwner[$key]['data'];
  1704. foreach ($companyOwner as $key2=>$value2) {
  1705. foreach ($companyOwner1 as $key3 => $value3) {
  1706. if (strstr($companyOwner1[$key3]['name'],'value') !== false){
  1707. if ($companyOwner1[$key3]['port']==$companyOwner[$key2]['point_code'] && $companyOwner[$key2]['point_code']!=0){
  1708. $cs['pressure'] = $companyOwner[$key2]['point_data'];
  1709. if(strstr($companyOwner[$key2]['content'],'正常') !== false) {
  1710. $cs['alarmStatus'] = "0";
  1711. }elseif (strstr($companyOwner[$key2]['content'],'低压') !== false){
  1712. $cs['alarmStatus'] = "1";
  1713. }elseif (strstr($companyOwner[$key2]['content'],'高压') !== false){
  1714. $cs['alarmStatus'] = "2";
  1715. }else{
  1716. $cs['alarmStatus'] = "0";
  1717. }
  1718. break;
  1719. }
  1720. }
  1721. }
  1722. }
  1723. if($ypSchoolOwner[$key]['device_type']==304){
  1724. $data6 = json_encode($cs);
  1725. $res = $this->ywManagementCurl($rep_url2,$header,$data6);
  1726. print_r('结果'.$res);
  1727. }elseif ($ypSchoolOwner[$key]['device_type']==301){
  1728. $data6 = json_encode($cs);
  1729. $res = $this->ywManagementCurl($rep_url3,$header,$data6);
  1730. print_r('结果'.$res);
  1731. }elseif ($ypSchoolOwner[$key]['device_type']==305){
  1732. $data6 = json_encode($cs);
  1733. $res = $this->ywManagementCurl($rep_url5,$header,$data6);
  1734. print_r('结果'.$res);
  1735. }elseif ($ypSchoolOwner[$key]['device_type']==302){
  1736. $data6 = json_encode($cs);
  1737. $res = $this->ywManagementCurl($rep_url6,$header,$data6);
  1738. print_r('结果'.$res);
  1739. }
  1740. }
  1741. }
  1742. }
  1743. }
  1744. }
  1745. //消防物联网api
  1746. public function mhMobileLogin()
  1747. {
  1748. // 制定允许其他域名访问
  1749. header('Access-Control-Allow-Origin:*');
  1750. // 响应类型
  1751. header('Access-Control-Allow-Methods:*');
  1752. //请求头
  1753. header('Access-Control-Allow-Headers:*');
  1754. // 响应头设置
  1755. header('Access-Control-Allow-Credentials:false');
  1756. $data=input('');
  1757. if(is_array($data)){
  1758. $getDataJson= json_encode($data,320);
  1759. $getdata=json_decode($getDataJson,true);//转成数组
  1760. }else{
  1761. $getDataJson=$data;
  1762. $getdata=json_decode($getDataJson,true);//转成数组
  1763. }
  1764. $sendata['V_LOGINNAME'] = "afzzh";
  1765. $sendata['V_PASSWORD'] = "f67832d9943f7a68b80c05c411a6485e";
  1766. $sendata['V_COMMAND'] = "FRONTPAGE";
  1767. $sendata['COMMSTATUS'] = "NO";
  1768. if($getdata['api_type']==1){
  1769. $header=[
  1770. "Content-Type:application/json",
  1771. ];
  1772. $rescurl=curl("https://fire.usky.cn:8443/YtIoT/cgi-bin/WebAction.cgi",json_encode($sendata),$header);
  1773. }
  1774. return $rescurl[1];
  1775. }
  1776. //积木测试api
  1777. public function mhCompanyData()
  1778. {
  1779. $data=input('');
  1780. if(is_array($data)){
  1781. $getDataJson= json_encode($data,320);
  1782. $getdata=json_decode($getDataJson,true);//转成数组
  1783. }else{
  1784. $getDataJson=$data;
  1785. $getdata=json_decode($getDataJson,true);//转成数组
  1786. }
  1787. $allowKey = ['31cdd6a7766d24820156e5304a3f7107'];
  1788. // if (!in_array($clientIp, $allowIp)){
  1789. if (!empty($getdata['app_key']) && in_array($getdata['app_key'], $allowKey)){
  1790. if (!empty($getdata['app_key'])){
  1791. }
  1792. }else{
  1793. $sensorList=[];
  1794. $returnInformation['code'] = 10001;
  1795. $returnInformation['msg'] = "app_key参数错误";
  1796. $returnInformation['data']=$sensorList;
  1797. return json_encode($returnInformation);
  1798. }
  1799. }
  1800. //积木测试api
  1801. public function IOTData()
  1802. {
  1803. $data=input('');
  1804. if(is_array($data)){
  1805. $getDataJson= json_encode($data,320);
  1806. $getdata=json_decode($getDataJson,true);//转成数组
  1807. }else{
  1808. $getDataJson=$data;
  1809. $getdata=json_decode($getDataJson,true);//转成数组
  1810. }
  1811. $sql6="select COUNT(*) AS deviceNumber from sp_owner";
  1812. $device = add($sql6);
  1813. $sensorList['deviceNumber'] =$device[0]['deviceNumber'];
  1814. $sql7="SELECT COUNT(*) AS onDeviceNumber FROM Online_v_state WHERE `差值(小时)` < 24";
  1815. $onDevice = $this->temSelect($sql7);
  1816. $sensorList['onDeviceNumber'] =$onDevice[0]['onDeviceNumber'];
  1817. $sql8="select COUNT(*) AS pointNumber from sp_corps_share_ceshi";
  1818. $point1 = add($sql8);
  1819. $sql9="select COUNT(*) AS pointNumber from sp_corps_share_yf";
  1820. $point2 = add($sql9);
  1821. $sensorList['pointNumber'] =$point1[0]['pointNumber']+$point2[0]['pointNumber'];
  1822. $sql10="select COUNT(*) AS companyNumber from sp_owner_company";
  1823. $company = add($sql10);
  1824. $sensorList['companyNumber'] =$company[0]['companyNumber'];
  1825. $sql11="select COUNT(*) AS corpsDeviceNumber FROM sp_corps_share GROUP BY device_code";
  1826. $corpsDevice = add($sql11);
  1827. $sensorList['corpsDeviceNumber'] =count($corpsDevice);
  1828. $sql12="SELECT COUNT(*) AS corpsOffWaterDeviceNumber FROM Online_v_state WHERE `类型` = '水系统' AND `差值(小时)` > 48 AND `单位编号` in ('10357',
  1829. '10356',
  1830. '10354',
  1831. '10352',
  1832. '10349',
  1833. '10350',
  1834. '10347',
  1835. '10346',
  1836. '10334',
  1837. '10188',
  1838. '10343',
  1839. '10348',
  1840. '10331',
  1841. '10320',
  1842. '10320',
  1843. '10164',
  1844. '10071',
  1845. '10345',
  1846. '10144',
  1847. '10064',
  1848. '10336',
  1849. '10131',
  1850. '10205',
  1851. '10340',
  1852. '10339',
  1853. '10225',
  1854. '10323',
  1855. '10320',
  1856. '10134',
  1857. '10235',
  1858. '10337',
  1859. '10226',
  1860. '10214',
  1861. '10160',
  1862. '10076',
  1863. '10079',
  1864. '10078',
  1865. '10215',
  1866. '10324',
  1867. '10324',
  1868. '10154',
  1869. '10106',
  1870. '10121',
  1871. '10067',
  1872. '10310',
  1873. '10325',
  1874. '10323',
  1875. '10322',
  1876. '10320',
  1877. '10128',
  1878. '10314',
  1879. '10315',
  1880. '10312',
  1881. '10222',
  1882. '10077',
  1883. '10146',
  1884. '10151',
  1885. '10232',
  1886. '10150',
  1887. '10116',
  1888. '10114',
  1889. '10122',
  1890. '10166',
  1891. '10353',
  1892. '10358',
  1893. '10359',
  1894. '10361',
  1895. '10360',
  1896. '10140',
  1897. '10362',
  1898. '10206',
  1899. '10355')";
  1900. $corpsOffWaterDevice = $this->temSelect($sql12);
  1901. $sensorList['corpsOffWaterDeviceNumber'] =$corpsOffWaterDevice[0]['corpsOffWaterDeviceNumber'];
  1902. $sql13="SELECT COUNT(*) AS corpsOffLevelDeviceNumber FROM Online_v_state WHERE `类型` = '液位' AND `差值(小时)` > 48 AND `单位编号` in ('10357',
  1903. '10356',
  1904. '10354',
  1905. '10352',
  1906. '10349',
  1907. '10350',
  1908. '10347',
  1909. '10346',
  1910. '10334',
  1911. '10188',
  1912. '10343',
  1913. '10348',
  1914. '10331',
  1915. '10320',
  1916. '10320',
  1917. '10164',
  1918. '10071',
  1919. '10345',
  1920. '10144',
  1921. '10064',
  1922. '10336',
  1923. '10131',
  1924. '10205',
  1925. '10340',
  1926. '10339',
  1927. '10225',
  1928. '10323',
  1929. '10320',
  1930. '10134',
  1931. '10235',
  1932. '10337',
  1933. '10226',
  1934. '10214',
  1935. '10160',
  1936. '10076',
  1937. '10079',
  1938. '10078',
  1939. '10215',
  1940. '10324',
  1941. '10324',
  1942. '10154',
  1943. '10106',
  1944. '10121',
  1945. '10067',
  1946. '10310',
  1947. '10325',
  1948. '10323',
  1949. '10322',
  1950. '10320',
  1951. '10128',
  1952. '10314',
  1953. '10315',
  1954. '10312',
  1955. '10222',
  1956. '10077',
  1957. '10146',
  1958. '10151',
  1959. '10232',
  1960. '10150',
  1961. '10116',
  1962. '10114',
  1963. '10122',
  1964. '10166',
  1965. '10353',
  1966. '10358',
  1967. '10359',
  1968. '10361',
  1969. '10360',
  1970. '10140',
  1971. '10362',
  1972. '10206',
  1973. '10355')";
  1974. $corpsOffLevelDevice = $this->temSelect($sql13);
  1975. $sensorList['corpsOffLevelDeviceNumber'] =$corpsOffLevelDevice[0]['corpsOffLevelDeviceNumber'];
  1976. $sql14="SELECT COUNT(*) AS corpsOffRtuDeviceNumber FROM Online_v_state WHERE `类型` = 'rtu' AND `差值(小时)` > 48 AND `单位编号` in ('10357',
  1977. '10356',
  1978. '10354',
  1979. '10352',
  1980. '10349',
  1981. '10350',
  1982. '10347',
  1983. '10346',
  1984. '10334',
  1985. '10188',
  1986. '10343',
  1987. '10348',
  1988. '10331',
  1989. '10320',
  1990. '10320',
  1991. '10164',
  1992. '10071',
  1993. '10345',
  1994. '10144',
  1995. '10064',
  1996. '10336',
  1997. '10131',
  1998. '10205',
  1999. '10340',
  2000. '10339',
  2001. '10225',
  2002. '10323',
  2003. '10320',
  2004. '10134',
  2005. '10235',
  2006. '10337',
  2007. '10226',
  2008. '10214',
  2009. '10160',
  2010. '10076',
  2011. '10079',
  2012. '10078',
  2013. '10215',
  2014. '10324',
  2015. '10324',
  2016. '10154',
  2017. '10106',
  2018. '10121',
  2019. '10067',
  2020. '10310',
  2021. '10325',
  2022. '10323',
  2023. '10322',
  2024. '10320',
  2025. '10128',
  2026. '10314',
  2027. '10315',
  2028. '10312',
  2029. '10222',
  2030. '10077',
  2031. '10146',
  2032. '10151',
  2033. '10232',
  2034. '10150',
  2035. '10116',
  2036. '10114',
  2037. '10122',
  2038. '10166',
  2039. '10353',
  2040. '10358',
  2041. '10359',
  2042. '10361',
  2043. '10360',
  2044. '10140',
  2045. '10362',
  2046. '10206',
  2047. '10355')";
  2048. $corpsOffRtuDevice = $this->temSelect($sql14);
  2049. $sensorList['corpsOffRtuDeviceNumber'] =$corpsOffRtuDevice[0]['corpsOffRtuDeviceNumber'];
  2050. return json_encode($sensorList);
  2051. }
  2052. public function s_curl($url,$data='',$header="",$method="POST"){
  2053. $ch = curl_init() ;
  2054. curl_setopt($ch, CURLOPT_URL, $url);
  2055. curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
  2056. // curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 4);
  2057. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  2058. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  2059. /* curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');*/
  2060. // curl_setopt($ch, CURLOPT_VERBOSE, 1); //debugģʽ
  2061. curl_setopt($ch, CURLOPT_SSLCERT, "./server.crt"); //client.crt����
  2062. curl_setopt($ch, CURLOPT_SSLCERTPASSWD, "IoM@1234"); //client֤������
  2063. curl_setopt($ch, CURLOPT_SSLKEY, "./server.key");
  2064. if($method=="POST"||$method=="PUT"||$method=="DELETE"){
  2065. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
  2066. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  2067. }
  2068. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  2069. $info = curl_exec($ch);
  2070. $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  2071. if (curl_errno($ch)) {
  2072. $infores = curl_error($ch);
  2073. }else{
  2074. $infores = $info;
  2075. }
  2076. curl_close($ch);
  2077. return $infores;
  2078. }
  2079. public function ypxycurl($url,$data=''){
  2080. $ch = curl_init();
  2081. curl_setopt($ch, CURLOPT_URL, $url);
  2082. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  2083. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  2084. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  2085. curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
  2086. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  2087. curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
  2088. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  2089. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  2090. $info = curl_exec($ch);
  2091. if (curl_errno($ch)) {
  2092. $info = 'ERROR: ' . curl_error($ch);
  2093. }
  2094. curl_close($ch);
  2095. return $info;
  2096. }
  2097. public function ywManagementCurl($url,$header,$data=''){
  2098. $ch = curl_init();
  2099. curl_setopt($ch, CURLOPT_URL, $url);
  2100. curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
  2101. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  2102. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  2103. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  2104. // curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
  2105. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  2106. curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
  2107. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  2108. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  2109. $info = curl_exec($ch);
  2110. if (curl_errno($ch)) {
  2111. $info = 'ERROR: ' . curl_error($ch);
  2112. }
  2113. curl_close($ch);
  2114. return $info;
  2115. }
  2116. public function temSelect($sql)
  2117. {
  2118. $link = mysqli_connect('47.98.201.187', 'root', 'Yt2018IoT', 'Temporary data', 3306);
  2119. mysqli_query($link,"set character set 'utf8'");
  2120. $res1 = mysqli_query($link,$sql);
  2121. // Log::record('res'.':'.$res1);
  2122. $list=array();
  2123. while ($row = $res1->fetch_assoc()) {
  2124. $list[]=$row;
  2125. //print_r($row);
  2126. }
  2127. mysqli_free_result($res1);
  2128. mysqli_close($link);
  2129. return $list;
  2130. }
  2131. }