Manage.php.bak.20220227 83 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509
  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. public function s_curl($url,$data='',$header="",$method="POST"){
  1387. $ch = curl_init() ;
  1388. curl_setopt($ch, CURLOPT_URL, $url);
  1389. curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
  1390. // curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 4);
  1391. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  1392. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  1393. /* curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');*/
  1394. // curl_setopt($ch, CURLOPT_VERBOSE, 1); //debugģʽ
  1395. curl_setopt($ch, CURLOPT_SSLCERT, "./server.crt"); //client.crt����
  1396. curl_setopt($ch, CURLOPT_SSLCERTPASSWD, "IoM@1234"); //client֤������
  1397. curl_setopt($ch, CURLOPT_SSLKEY, "./server.key");
  1398. if($method=="POST"||$method=="PUT"||$method=="DELETE"){
  1399. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
  1400. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  1401. }
  1402. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1403. $info = curl_exec($ch);
  1404. $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  1405. if (curl_errno($ch)) {
  1406. $infores = curl_error($ch);
  1407. }else{
  1408. $infores = $info;
  1409. }
  1410. curl_close($ch);
  1411. return $infores;
  1412. }
  1413. public function ypxycurl($url,$data=''){
  1414. $ch = curl_init();
  1415. curl_setopt($ch, CURLOPT_URL, $url);
  1416. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  1417. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  1418. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  1419. curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
  1420. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  1421. curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
  1422. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  1423. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  1424. $info = curl_exec($ch);
  1425. if (curl_errno($ch)) {
  1426. $info = 'ERROR: ' . curl_error($ch);
  1427. }
  1428. curl_close($ch);
  1429. return $info;
  1430. }
  1431. public function ywManagementCurl($url,$header,$data=''){
  1432. $ch = curl_init();
  1433. curl_setopt($ch, CURLOPT_URL, $url);
  1434. curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
  1435. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  1436. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  1437. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  1438. // curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
  1439. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  1440. curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
  1441. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  1442. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  1443. $info = curl_exec($ch);
  1444. if (curl_errno($ch)) {
  1445. $info = 'ERROR: ' . curl_error($ch);
  1446. }
  1447. curl_close($ch);
  1448. return $info;
  1449. }
  1450. }