Manage.php.bak.20220111 79 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435
  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. $data1 = array();
  695. $data2 = array();
  696. $data4 = array();
  697. $data5 = array();
  698. $data6 = array();
  699. $data7 = array();
  700. $data8 = array();
  701. $data9 = array();
  702. $data10 = array();
  703. $data11 = array();
  704. $data12 = array();
  705. $data15 = array();
  706. $data16 = array();
  707. $data18 = array();
  708. $data19 = array();
  709. for ($i=0;$i<=14;$i++){
  710. $data1['standard_deviation']=round($this->mt_rand_float(1,5),2);
  711. $data1['variance']=round($data1['standard_deviation']*$data1['standard_deviation'],2);
  712. $data1['average_value']=round($this->mt_rand_float(220,227),2);
  713. $j=$i+1;
  714. if($j>=10){
  715. $data1['data_time']="2021-03-".$j;
  716. }
  717. $data2[$i]=$data1;
  718. $data4['standard_deviation']=round($this->mt_rand_float(3,8),2);
  719. $data4['variance']=round($data4['standard_deviation']*$data4['standard_deviation'],2);
  720. $data4['average_value']=round($this->mt_rand_float(7,15),2);
  721. if($j>=10){
  722. $data4['data_time']="2021-03-".$j;
  723. }
  724. $data5[$i]=$data4;
  725. $data6['standard_deviation']=round($this->mt_rand_float(0,2),2);
  726. $data6['variance']=round($data6['standard_deviation']*$data6['standard_deviation'],2);
  727. $data6['average_value']=round($this->mt_rand_float(17,25),2);
  728. if($j>=10){
  729. $data6['data_time']="2021-03-".$j;
  730. }
  731. $data7[$i]=$data6;
  732. $data8['standard_deviation']=round($this->mt_rand_float(30,70),2);
  733. $data8['variance']=round($data8['standard_deviation']*$data8['standard_deviation'],2);
  734. $data8['average_value']=round($this->mt_rand_float(30,60),2);
  735. if($j>=10){
  736. $data8['data_time']="2021-03-".$j;
  737. }
  738. $data9[$i]=$data8;
  739. $data11['electric_current']=round($this->mt_rand_float(8,18),2);
  740. $data11['voltage']=round($this->mt_rand_float(220,225),2);
  741. $data11['data_time']=$this->randomDate();
  742. $data12[$i]=$data11;
  743. $data15['electric_current']=round($this->mt_rand_float(20,100),2);
  744. $data15['voltage']=round($this->mt_rand_float(220,225),2);
  745. $data15['data_time']=$this->randomDate();
  746. $data16[$i]=$data15;
  747. $data18['ambient_temperature']=round($this->mt_rand_float(20,25),2);
  748. $data18['Cable_temperature']=round($this->mt_rand_float(10,20),2);
  749. $data18['generation_temperature']=round($data18['ambient_temperature']-$data18['Cable_temperature'],2);
  750. $data18['data_time']=$this->randomDate();
  751. $data19[$i]=$data18;
  752. }
  753. $data10['conclusion1']="因数据量未达到暂无法分析";
  754. $data3['voltage']=$data2;
  755. $data3['electric_current']=$data5;
  756. $data3['temperature']=$data7;
  757. $data3['leakage_current']=$data9;
  758. $data3['conclusion']=$data10;
  759. $data14['abnormal_equipment']=$data12;
  760. $data14['leakage_alarm']=$data16;
  761. $data14['conclusion']=$data10;
  762. $data20['visualization']=$data19;
  763. $data20['conclusion']=$data10;
  764. $data13['dispersion_rate']=$data3;
  765. $data13['electrical_aging']=$data14;
  766. $data13['thermal_aging']=$data20;
  767. // $data1['alarm_number']=$this->mt_rand_float(100,500);
  768. // $sensorList['productId'] = round($this->mt_rand_float(3,5),2);
  769. $data17 = json_encode($data13);
  770. return $data17;
  771. }
  772. //水系统电气火灾算法测试API
  773. public function algorithmApi(){
  774. header("Access-Control-Allow-Origin:*");
  775. // 响应类型
  776. header('Access-Control-Allow-Methods:POST');
  777. // 响应头设置
  778. header('Access-Control-Allow-Headers:x-requested-with, content-type');
  779. $data=input('');
  780. if(is_array($data)){
  781. $getDataJson= json_encode($data,320);
  782. $getdata=json_decode($getDataJson,true);//转成数组
  783. }else{
  784. $getDataJson=$data;
  785. $getdata=json_decode($getDataJson,true);//转成数组
  786. }
  787. if(!empty($getdata["dataType"])){
  788. if($getdata["dataType"]==1||$getdata["dataType"]==2){
  789. if($getdata["dataType"]==1){
  790. if (!empty($getdata["apiType"])){
  791. if ($getdata["apiType"]==4){
  792. if(!empty($getdata["timeType"])){
  793. if (!empty($getdata["companyCode"])){
  794. $sql6="select dispersion_rate from sp_water_analysis where company_code ='{$getdata["companyCode"]}' and data_type ={$getdata["timeType"]}";
  795. $longHuOwner = add($sql6);
  796. $returnInformation['code'] = 200;
  797. $returnInformation['msg'] = "success";
  798. $returnInformation['data']=$longHuOwner[0]['dispersion_rate'];
  799. return stripslashes(json_encode($returnInformation));
  800. }else{
  801. $returnInformation['code'] = 60001;
  802. $returnInformation['msg'] = "操作失败,单位编号不能为空";
  803. return json_encode($returnInformation);
  804. }
  805. }else{
  806. $returnInformation['code'] = 60001;
  807. $returnInformation['msg'] = "操作失败,时间类型不能为空";
  808. return json_encode($returnInformation);
  809. }
  810. }elseif ($getdata["apiType"]==5){
  811. if(!empty($getdata["timeType"])){
  812. if (!empty($getdata["companyCode"])){
  813. $sql6="select leakage_investigation from sp_water_analysis where company_code ='{$getdata["companyCode"]}' and data_type ={$getdata["timeType"]}";
  814. $longHuOwner = add($sql6);
  815. $returnInformation['code'] = 200;
  816. $returnInformation['msg'] = "success";
  817. $returnInformation['data']=$longHuOwner[0]['leakage_investigation'];
  818. return stripslashes(json_encode($returnInformation));
  819. }else{
  820. $returnInformation['code'] = 60001;
  821. $returnInformation['msg'] = "操作失败,单位编号不能为空";
  822. return json_encode($returnInformation);
  823. }
  824. }else{
  825. $returnInformation['code'] = 60001;
  826. $returnInformation['msg'] = "操作失败,时间类型不能为空";
  827. return json_encode($returnInformation);
  828. }
  829. }elseif ($getdata["apiType"]==6){
  830. if(!empty($getdata["timeType"])){
  831. if (!empty($getdata["companyCode"])){
  832. $sql6="select device_association from sp_water_analysis where company_code ='{$getdata["companyCode"]}' and data_type ={$getdata["timeType"]}";
  833. $longHuOwner = add($sql6);
  834. $returnInformation['code'] = 200;
  835. $returnInformation['msg'] = "success";
  836. $returnInformation['data']=$longHuOwner[0]['device_association'];
  837. return stripslashes(json_encode($returnInformation));
  838. }else{
  839. $returnInformation['code'] = 60001;
  840. $returnInformation['msg'] = "操作失败,单位编号不能为空";
  841. return json_encode($returnInformation);
  842. }
  843. }else{
  844. $returnInformation['code'] = 60001;
  845. $returnInformation['msg'] = "操作失败,时间类型不能为空";
  846. return json_encode($returnInformation);
  847. }
  848. }elseif ($getdata["apiType"]==7){
  849. if(!empty($getdata["timeType"])){
  850. if (!empty($getdata["companyCode"])){
  851. $sql6="select data_fluctuation from sp_water_analysis where company_code ='{$getdata["companyCode"]}' and data_type ={$getdata["timeType"]}";
  852. $longHuOwner = add($sql6);
  853. $returnInformation['code'] = 200;
  854. $returnInformation['msg'] = "success";
  855. $returnInformation['data']=$longHuOwner[0]['data_fluctuation'];
  856. return stripslashes(json_encode($returnInformation));
  857. }else{
  858. $returnInformation['code'] = 60001;
  859. $returnInformation['msg'] = "操作失败,单位编号不能为空";
  860. return json_encode($returnInformation);
  861. }
  862. }else{
  863. $returnInformation['code'] = 60001;
  864. $returnInformation['msg'] = "操作失败,时间类型不能为空";
  865. return json_encode($returnInformation);
  866. }
  867. }elseif ($getdata["apiType"]==2){
  868. if(!empty($getdata["timeType"])){
  869. if (!empty($getdata["companyCode"])){
  870. $sql6="select data_statistics from sp_water_analysis where company_code ='{$getdata["companyCode"]}' and data_type ={$getdata["timeType"]}";
  871. $longHuOwner = add($sql6);
  872. $returnInformation['code'] = 200;
  873. $returnInformation['msg'] = "success";
  874. $returnInformation['data']=$longHuOwner[0]['data_statistics'];
  875. return stripslashes(json_encode($returnInformation));
  876. }else{
  877. $returnInformation['code'] = 60001;
  878. $returnInformation['msg'] = "操作失败,单位编号不能为空";
  879. return json_encode($returnInformation);
  880. }
  881. }else{
  882. $returnInformation['code'] = 60001;
  883. $returnInformation['msg'] = "操作失败,时间类型不能为空";
  884. return json_encode($returnInformation);
  885. }
  886. }elseif ($getdata["apiType"]==3){
  887. if(!empty($getdata["timeType"])){
  888. if (!empty($getdata["companyCode"])){
  889. if($getdata["timeType"]==1) {
  890. $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'";
  891. $longHuOwner = add($sql6);
  892. $returnInformation['code'] = 200;
  893. $returnInformation['msg'] = "success";
  894. $returnInformation['data'] = $longHuOwner;
  895. return stripslashes(json_encode($returnInformation));
  896. }elseif ($getdata["timeType"]==2){
  897. $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'";
  898. $longHuOwner = add($sql6);
  899. $returnInformation['code'] = 200;
  900. $returnInformation['msg'] = "success";
  901. $returnInformation['data'] = $longHuOwner;
  902. return stripslashes(json_encode($returnInformation));
  903. }elseif ($getdata["timeType"]==3){
  904. $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'";
  905. $longHuOwner = add($sql6);
  906. $returnInformation['code'] = 200;
  907. $returnInformation['msg'] = "success";
  908. $returnInformation['data'] = $longHuOwner;
  909. return stripslashes(json_encode($returnInformation));
  910. }
  911. }else{
  912. $returnInformation['code'] = 60001;
  913. $returnInformation['msg'] = "操作失败,单位编号不能为空";
  914. return json_encode($returnInformation);
  915. }
  916. }else{
  917. $returnInformation['code'] = 60001;
  918. $returnInformation['msg'] = "操作失败,时间类型不能为空";
  919. return json_encode($returnInformation);
  920. }
  921. }
  922. }else{
  923. $returnInformation['code'] = 60001;
  924. $returnInformation['msg'] = "操作失败,api类型不能为空";
  925. return json_encode($returnInformation);
  926. }
  927. }else{
  928. if (!empty($getdata["apiType"])){
  929. if ($getdata["apiType"]==4){
  930. if(!empty($getdata["timeType"])){
  931. if (!empty($getdata["companyCode"])){
  932. $sql6="select dispersion_rate from sp_ef_analysis where company_code ='{$getdata["companyCode"]}' and data_type ={$getdata["timeType"]}";
  933. $longHuOwner = add($sql6);
  934. $returnInformation['code'] = 200;
  935. $returnInformation['msg'] = "success";
  936. $returnInformation['data']=$longHuOwner[0]['dispersion_rate'];
  937. return stripslashes(json_encode($returnInformation));
  938. }else{
  939. $returnInformation['code'] = 60001;
  940. $returnInformation['msg'] = "操作失败,单位编号不能为空";
  941. return json_encode($returnInformation);
  942. }
  943. }else{
  944. $returnInformation['code'] = 60001;
  945. $returnInformation['msg'] = "操作失败,时间类型不能为空";
  946. return json_encode($returnInformation);
  947. }
  948. }elseif ($getdata["apiType"]==5){
  949. if(!empty($getdata["timeType"])){
  950. if (!empty($getdata["companyCode"])){
  951. $sql6="select electrical_aging from sp_ef_analysis where company_code ='{$getdata["companyCode"]}' and data_type ={$getdata["timeType"]}";
  952. $longHuOwner = add($sql6);
  953. $returnInformation['code'] = 200;
  954. $returnInformation['msg'] = "success";
  955. $returnInformation['data']=$longHuOwner[0]['electrical_aging'];
  956. return stripslashes(json_encode($returnInformation));
  957. }else{
  958. $returnInformation['code'] = 60001;
  959. $returnInformation['msg'] = "操作失败,单位编号不能为空";
  960. return json_encode($returnInformation);
  961. }
  962. }else{
  963. $returnInformation['code'] = 60001;
  964. $returnInformation['msg'] = "操作失败,时间类型不能为空";
  965. return json_encode($returnInformation);
  966. }
  967. }elseif ($getdata["apiType"]==6){
  968. if(!empty($getdata["timeType"])){
  969. if (!empty($getdata["companyCode"])){
  970. $sql6="select thermal_aging from sp_ef_analysis where company_code ='{$getdata["companyCode"]}' and data_type ={$getdata["timeType"]}";
  971. $longHuOwner = add($sql6);
  972. $returnInformation['code'] = 200;
  973. $returnInformation['msg'] = "success";
  974. $returnInformation['data']=$longHuOwner[0]['thermal_aging'];
  975. return stripslashes(json_encode($returnInformation));
  976. }else{
  977. $returnInformation['code'] = 60001;
  978. $returnInformation['msg'] = "操作失败,单位编号不能为空";
  979. return json_encode($returnInformation);
  980. }
  981. }else{
  982. $returnInformation['code'] = 60001;
  983. $returnInformation['msg'] = "操作失败,时间类型不能为空";
  984. return json_encode($returnInformation);
  985. }
  986. }elseif ($getdata["apiType"]==7){
  987. if(!empty($getdata["timeType"])){
  988. if (!empty($getdata["companyCode"])){
  989. $sql6="select data_fluctuation from sp_water_analysis where company_code ='{$getdata["companyCode"]}' and data_type ={$getdata["timeType"]}";
  990. $longHuOwner = add($sql6);
  991. $returnInformation['code'] = 200;
  992. $returnInformation['msg'] = "success";
  993. $returnInformation['data']=$longHuOwner[0]['data_fluctuation'];
  994. return stripslashes(json_encode($returnInformation));
  995. }else{
  996. $returnInformation['code'] = 60001;
  997. $returnInformation['msg'] = "操作失败,单位编号不能为空";
  998. return json_encode($returnInformation);
  999. }
  1000. }else{
  1001. $returnInformation['code'] = 60001;
  1002. $returnInformation['msg'] = "操作失败,时间类型不能为空";
  1003. return json_encode($returnInformation);
  1004. }
  1005. }elseif ($getdata["apiType"]==2){
  1006. if(!empty($getdata["timeType"])){
  1007. if (!empty($getdata["companyCode"])){
  1008. $sql6="select data_statistics from sp_water_analysis where company_code ='{$getdata["companyCode"]}' and data_type ={$getdata["timeType"]}";
  1009. $longHuOwner = add($sql6);
  1010. $returnInformation['code'] = 200;
  1011. $returnInformation['msg'] = "success";
  1012. $returnInformation['data']=$longHuOwner[0]['data_statistics'];
  1013. return stripslashes(json_encode($returnInformation));
  1014. }else{
  1015. $returnInformation['code'] = 60001;
  1016. $returnInformation['msg'] = "操作失败,单位编号不能为空";
  1017. return json_encode($returnInformation);
  1018. }
  1019. }else{
  1020. $returnInformation['code'] = 60001;
  1021. $returnInformation['msg'] = "操作失败,时间类型不能为空";
  1022. return json_encode($returnInformation);
  1023. }
  1024. }elseif ($getdata["apiType"]==3){
  1025. if(!empty($getdata["timeType"])){
  1026. if (!empty($getdata["companyCode"])){
  1027. if($getdata["timeType"]==1) {
  1028. $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'";
  1029. $longHuOwner = add($sql6);
  1030. $returnInformation['code'] = 200;
  1031. $returnInformation['msg'] = "success";
  1032. $returnInformation['data'] = $longHuOwner;
  1033. return stripslashes(json_encode($returnInformation));
  1034. }elseif ($getdata["timeType"]==2){
  1035. $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'";
  1036. $longHuOwner = add($sql6);
  1037. $returnInformation['code'] = 200;
  1038. $returnInformation['msg'] = "success";
  1039. $returnInformation['data'] = $longHuOwner;
  1040. return stripslashes(json_encode($returnInformation));
  1041. }elseif ($getdata["timeType"]==3){
  1042. $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'";
  1043. $longHuOwner = add($sql6);
  1044. $returnInformation['code'] = 200;
  1045. $returnInformation['msg'] = "success";
  1046. $returnInformation['data'] = $longHuOwner;
  1047. return stripslashes(json_encode($returnInformation));
  1048. }
  1049. }else{
  1050. $returnInformation['code'] = 60001;
  1051. $returnInformation['msg'] = "操作失败,单位编号不能为空";
  1052. return json_encode($returnInformation);
  1053. }
  1054. }else{
  1055. $returnInformation['code'] = 60001;
  1056. $returnInformation['msg'] = "操作失败,时间类型不能为空";
  1057. return json_encode($returnInformation);
  1058. }
  1059. }
  1060. }else{
  1061. $returnInformation['code'] = 60001;
  1062. $returnInformation['msg'] = "操作失败,api类型不能为空";
  1063. return json_encode($returnInformation);
  1064. }
  1065. }
  1066. }else{
  1067. $returnInformation['code'] = 60001;
  1068. $returnInformation['msg'] = "操作失败,数据范围超出限制";
  1069. return json_encode($returnInformation);
  1070. }
  1071. }else{
  1072. $returnInformation['code'] = 60001;
  1073. $returnInformation['msg'] = "操作失败,数据类型不能为空";
  1074. return json_encode($returnInformation);
  1075. }
  1076. }
  1077. public function ceshiApi()
  1078. {
  1079. header("Access-Control-Allow-Origin:*");
  1080. // 响应类型
  1081. header('Access-Control-Allow-Methods:POST');
  1082. // 响应头设置
  1083. header('Access-Control-Allow-Headers:x-requested-with, content-type');
  1084. $data = input('');
  1085. if (is_array($data)) {
  1086. $getDataJson = json_encode($data, 320);
  1087. $getdata = json_decode($getDataJson, true);//转成数组
  1088. } else {
  1089. $getDataJson = $data;
  1090. $getdata = json_decode($getDataJson, true);//转成数组
  1091. }
  1092. $data1 = array();
  1093. $data2 = array();
  1094. $data3 = array();
  1095. $data4 = array();
  1096. if ($getdata['status']=="getnewslist"){
  1097. $data1['status']=0;
  1098. for ($i=0;$i<2;$i++){
  1099. $data2['id']=$i+1;
  1100. $data2['title']="测试高房价结果回复的合法化觉得很简单的事";
  1101. $data2['add_time']="2021-08-05 16:48:17";
  1102. $data2['zhaiyao']="的就是但是绝大多数公开大量上市价格第四季度睡个好觉了";
  1103. $data2['click']=1;
  1104. $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";
  1105. $data3[$i]=$data2;
  1106. }
  1107. $data1['message']=$data3;
  1108. return json_encode($data1);
  1109. }elseif($getdata['status']=="getnew"){
  1110. $data1['status']=0;
  1111. $data2['id']=1;
  1112. $data2['title']="测试高房价结果回复的合法化觉得很简单的事";
  1113. $data2['add_time']="2021-08-05 16:48:17";
  1114. $data2['content']="的就是但是绝大多数公开大量上市价格第四季度睡个好觉了";
  1115. $data2['click']=2;
  1116. $data3[0]=$data2;
  1117. $data1['message']=$data3;
  1118. return json_encode($data1);
  1119. }elseif($getdata['status']=="getimages"){
  1120. $data1['status']=0;
  1121. for ($i=0;$i<2;$i++){
  1122. $data2['id']=$i+1;
  1123. $data2['title']="测试高房价结果回复的合法化觉得很简单的事";
  1124. $data2['zhaiyao']="的就是但是绝大多数公开大量上市价格第四季度睡个好觉了";
  1125. $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";
  1126. $data3[$i]=$data2;
  1127. }
  1128. $data1['message']=$data3;
  1129. return json_encode($data1);
  1130. }elseif($getdata['status']=="getimgcategory"){
  1131. $data1['status']=0;
  1132. for ($i=0;$i<2;$i++){
  1133. $data2['id']=$i+1;
  1134. $data2['title']="测试".$i;
  1135. $data3[$i]=$data2;
  1136. }
  1137. $data1['message']=$data3;
  1138. return json_encode($data1);
  1139. }elseif($getdata['status']=="getthumimages"){
  1140. $data1['status']=0;
  1141. for ($i=0;$i<3;$i++){
  1142. $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";
  1143. }
  1144. $data1['message']=$data3;
  1145. return json_encode($data1);
  1146. }elseif($getdata['status']=="getimageInfo"){
  1147. $data1['status']=0;
  1148. for ($i=0;$i<1;$i++){
  1149. $data2['id']=$i+1;
  1150. $data2['title']="测试高房价结果回复的合法化觉得很简单的事";
  1151. $data2['add_time']="2021-08-05 16:48:17";
  1152. $data2['click']=3;
  1153. $data2['content']="解释的机会就是进口关税打开撒酒疯还是";
  1154. }
  1155. $data1['message']=$data3;
  1156. return json_encode($data1);
  1157. }elseif($getdata['status']=="getcomments"){
  1158. $data1['status']=0;
  1159. for ($i=0;$i<1;$i++){
  1160. $data2['user_name']="djsjf";
  1161. $data2['add_time']="2021-08-05 16:48:17";
  1162. $data2['content']="快速减肥健身看江户时代";
  1163. }
  1164. $data1['message']=$data3;
  1165. return json_encode($data1);
  1166. }elseif($getdata['status']=="postcomment"){
  1167. $data1['status']=0;
  1168. $data1['message']="啊附加符号方式";
  1169. return json_encode($data1);
  1170. }elseif($getdata['status']=="getgoods"){
  1171. $data1['status']=0;
  1172. for ($i=0;$i<2;$i++){
  1173. $data2['id']=$i+1;
  1174. $data2['title']="测试高房价结果回复的合法化觉得很简单的事";
  1175. $data2['add_time']="2021-08-05 16:48:17";
  1176. $data2['zhaiyao']="的就是但是绝大多数公开大量上市价格第四季度睡个好觉了";
  1177. $data2['click']=0;
  1178. $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";
  1179. $data2['sell_price']=214;
  1180. $data2['market_price']=3446;
  1181. $data2['stock_quantity']=3446;
  1182. }
  1183. $data1['message']=$data3;
  1184. return json_encode($data1);
  1185. }elseif($getdata['status']=="getdesc"){
  1186. $data1['status']=0;
  1187. for ($i=0;$i<2;$i++){
  1188. $data2['title']="测试高房价结果回复的合法化觉得很简单的事";
  1189. $data2['content']="<p>的实际开工的开始</p><p align='center'></p>";
  1190. }
  1191. $data1['message']=$data3;
  1192. return json_encode($data1);
  1193. }
  1194. }
  1195. //杨浦一网通管各类设备数量
  1196. public function deviceNumber(){
  1197. header("Access-Control-Allow-Origin:*");
  1198. // 响应类型
  1199. header('Access-Control-Allow-Methods:POST');
  1200. // 响应头设置
  1201. header('Access-Control-Allow-Headers:x-requested-with, content-type');
  1202. $data=input('');
  1203. if(is_array($data)){
  1204. $getDataJson= json_encode($data,320);
  1205. $getdata=json_decode($getDataJson,true);//转成数组
  1206. }else{
  1207. $getDataJson=$data;
  1208. $getdata=json_decode($getDataJson,true);//转成数组
  1209. }
  1210. $data6 = array();
  1211. if ($getdata['userName']=="ypywtg"){
  1212. $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');";
  1213. $res=add($sql);
  1214. $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');";
  1215. $res1=add($sql1);
  1216. $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');";
  1217. $res2=add($sql2);
  1218. $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');";
  1219. $res3=add($sql3);
  1220. $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');";
  1221. $res4=add($sql4);
  1222. $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');";
  1223. $res5=add($sql5);
  1224. $sensorList['waterNumber'] =$res[0]['waterNumber'];
  1225. $sensorList['levelNumber'] =$res1[0]['levelNumber'];
  1226. $sensorList['smokeSensationNumber'] =$res2[0]['smokeSensationNumber'];
  1227. $sensorList['rtuNumber'] =$res3[0]['rtuNumber'];
  1228. $sensorList['videoNumber'] =$res4[0]['videoNumber'];
  1229. $sensorList['electricalFireNumber'] =$res5[0]['electricalFireNumber'];
  1230. $data6 = json_encode($sensorList);
  1231. }
  1232. return $data6;
  1233. }
  1234. //伍继电力程序校验机制api
  1235. public function wooGiApi(){
  1236. $data=input('');
  1237. if(is_array($data)){
  1238. $getDataJson= json_encode($data,320);
  1239. $getdata=json_decode($getDataJson,true);//转成数组
  1240. }else{
  1241. $getDataJson=$data;
  1242. $getdata=json_decode($getDataJson,true);//转成数组
  1243. }
  1244. $clientIp=$this->ip();
  1245. Log::record('wooGiApi_deviceList' . ':' .'<<<'.$clientIp.'>>>'.$getDataJson);
  1246. $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'];
  1247. if (!in_array($clientIp, $allowIp)){
  1248. $returnInformation['code'] = 60001;
  1249. $returnInformation['msg'] = "操作失败,IP地址不在白名单中";
  1250. $returnInformation['data']=null;
  1251. return json_encode($returnInformation);
  1252. }else{
  1253. $redis = new \Redis();
  1254. $redis->connect('127.0.0.1', 6379);
  1255. $result = $redis->auth("usky2021");
  1256. if ($result == 1) {
  1257. $check =$redis->exists($clientIp);
  1258. if ($check){
  1259. // +1
  1260. // $redis->increment($clientIp);
  1261. // $count =$redis->get($clientIp);
  1262. // // 限制每小时1次
  1263. // if($count > 1){
  1264. // $returnInformation['code'] = 60003;
  1265. // $returnInformation['msg'] = "操作失败,当前ip请求频率过高";
  1266. // $returnInformation['data']=null;
  1267. // return json_encode($returnInformation);
  1268. // }else{
  1269. $publicKey = $getdata['publicKey'];
  1270. $timeStamp = time();
  1271. if (!empty($getdata['requestType'])){
  1272. if($getdata['requestType']==1){
  1273. $publicKey1 = md5("usky".$getdata['timeStamp']."9bcbc5d723cb9bae394d3a097deb6695");
  1274. $publicKey2 = md5("usky".$timeStamp."9bcbc5d723cb9bae394d3a097deb6695");
  1275. }else if ($getdata['requestType']==2){
  1276. $publicKey1 = md5("usky".$getdata['timeStamp']."b9848b4fe4647e380fd1367a4f34ced9");
  1277. $publicKey2 = md5("usky".$timeStamp."b9848b4fe4647e380fd1367a4f34ced9");
  1278. }else if ($getdata['requestType']==3){
  1279. $publicKey1 = md5("usky".$getdata['timeStamp']."056ac8fae059c9c9e700b734922edfc8");
  1280. $publicKey2 = md5("usky".$timeStamp."056ac8fae059c9c9e700b734922edfc8");
  1281. }else{
  1282. $returnInformation['code'] = 60004;
  1283. $returnInformation['msg'] = "操作失败,requestType不在范围内";
  1284. $returnInformation['data']=null;
  1285. return json_encode($returnInformation);
  1286. }
  1287. }else{
  1288. $returnInformation['code'] = 60004;
  1289. $returnInformation['msg'] = "操作失败,requestType不能为空";
  1290. $returnInformation['data']=null;
  1291. return json_encode($returnInformation);
  1292. }
  1293. if ($publicKey==$publicKey1){
  1294. $sensorList['publicKey'] =$publicKey2;
  1295. $sensorList['timeStamp'] =$timeStamp;
  1296. $returnInformation['code'] = 200;
  1297. $returnInformation['msg'] = "操作成功";
  1298. $returnInformation['data']=$sensorList;
  1299. return json_encode($returnInformation);
  1300. }else{
  1301. $returnInformation['code'] = 60002;
  1302. $returnInformation['msg'] = "操作失败,publicKey错误";
  1303. $returnInformation['data']=null;
  1304. return json_encode($returnInformation);
  1305. }
  1306. // }
  1307. } else {
  1308. $redis->set($clientIp, 1,3600);//初始值1
  1309. }
  1310. }
  1311. }
  1312. }
  1313. public function s_curl($url,$data='',$header="",$method="POST"){
  1314. $ch = curl_init() ;
  1315. curl_setopt($ch, CURLOPT_URL, $url);
  1316. curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
  1317. // curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 4);
  1318. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  1319. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  1320. /* curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');*/
  1321. // curl_setopt($ch, CURLOPT_VERBOSE, 1); //debugģʽ
  1322. curl_setopt($ch, CURLOPT_SSLCERT, "./server.crt"); //client.crt����
  1323. curl_setopt($ch, CURLOPT_SSLCERTPASSWD, "IoM@1234"); //client֤������
  1324. curl_setopt($ch, CURLOPT_SSLKEY, "./server.key");
  1325. if($method=="POST"||$method=="PUT"||$method=="DELETE"){
  1326. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
  1327. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  1328. }
  1329. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1330. $info = curl_exec($ch);
  1331. $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  1332. if (curl_errno($ch)) {
  1333. $infores = curl_error($ch);
  1334. }else{
  1335. $infores = $info;
  1336. }
  1337. curl_close($ch);
  1338. return $infores;
  1339. }
  1340. public function ypxycurl($url,$data=''){
  1341. $ch = curl_init();
  1342. curl_setopt($ch, CURLOPT_URL, $url);
  1343. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  1344. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  1345. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  1346. curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
  1347. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  1348. curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
  1349. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  1350. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  1351. $info = curl_exec($ch);
  1352. if (curl_errno($ch)) {
  1353. $info = 'ERROR: ' . curl_error($ch);
  1354. }
  1355. curl_close($ch);
  1356. return $info;
  1357. }
  1358. public function ywManagementCurl($url,$header,$data=''){
  1359. $ch = curl_init();
  1360. curl_setopt($ch, CURLOPT_URL, $url);
  1361. curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
  1362. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  1363. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  1364. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  1365. // curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
  1366. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  1367. curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
  1368. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  1369. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  1370. $info = curl_exec($ch);
  1371. if (curl_errno($ch)) {
  1372. $info = 'ERROR: ' . curl_error($ch);
  1373. }
  1374. curl_close($ch);
  1375. return $info;
  1376. }
  1377. }