Onenet.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 Onenet extends Controller
  9. {
  10. public function index(){
  11. }
  12. //下发命令
  13. public function add(){
  14. }
  15. public function status(){
  16. }
  17. public function delete(){
  18. }
  19. public function OneNetCeShi(){
  20. // if ($this->request->isPost()) {
  21. $data = input('');
  22. /* $rand=rand(0,2);
  23. $header=["Content-Type:application/json"];
  24. //将数据分配给不同的服务
  25. $httpserver=["http://47.98.153.212:1101","http://47.98.153.212:1102","http://47.98.153.212:1103"];
  26. $server=$httpserver[$rand];
  27. //将数据随机转发到别的平台做处理
  28. $res=curltest($server,$data,$header);
  29. */
  30. $list = array();
  31. if (is_array($data)) {
  32. $list['data'] = json_encode($data, 320);
  33. $getdata = json_decode($list['data'], true);//转成数组
  34. } else {
  35. $list['data'] = $data;
  36. $getdata = json_decode($list['data'], true);//转成数组
  37. }
  38. // $list['data']=11;
  39. // $list['response'] = "111";
  40. //
  41. // $list['notifyType'] = $getdata["notifyType"];
  42. // $list['deviceId'] = $getdata["deviceId"];
  43. // $list['addtime'] = date('Y-m-d H:i:s');
  44. $res = Db::name('one_net_data')->insertGetId($list);//将推送的数据存入总表
  45. $returnInformation['code'] = 200;
  46. $returnInformation['msg'] = "操作成功";
  47. Log::record('onenet:' .$getdata['msg'] );
  48. return $getdata['msg'];
  49. // }
  50. }
  51. //山东党校api
  52. public function sdSchoolApi()
  53. {
  54. header("Access-Control-Allow-Origin:*");
  55. // 响应类型
  56. header('Access-Control-Allow-Methods:POST');
  57. // 响应头设置
  58. header('Access-Control-Allow-Headers:x-requested-with, content-type');
  59. $data = input('');
  60. if (is_array($data)) {
  61. $getDataJson = json_encode($data, 320);
  62. $getdata = json_decode($getDataJson, true);//转成数组
  63. } else {
  64. $getDataJson = $data;
  65. $getdata = json_decode($getDataJson, true);//转成数组
  66. }
  67. $cs['V_LOGINNAME'] = "sddx";
  68. $cs['V_PASSWORD'] = "sddx123";
  69. $cs['COMPANY_CODE'] = "10321";
  70. $cs['COMMSTATUS'] = "NO";
  71. $data6 = json_encode($cs);
  72. $data = "queryJson=".$data6;
  73. $rep_url = "https://fire.usky.cn:8443/YtIoT/iot/frontpage/getCurrentObjectListByCompanyId";
  74. $res = $this->ypxycurl($rep_url, $data);
  75. // if (!empty($ypSchoolOwner)){
  76. // foreach ($ypSchoolOwner as $key=>$value){
  77. // $cs['deviceId'] = $ypSchoolOwner[$key]['object_code'];
  78. // $cs['deviceName'] = $ypSchoolOwner[$key]['object_name'].$ypSchoolOwner[$key]['device_name'];
  79. // if ($ypSchoolOwner[$key]['owner_dwtype']==2){
  80. // $cs['deviceType'] = "1";
  81. // $cs['deviceTypeName'] = "水泵水压检测器";
  82. // }elseif ($ypSchoolOwner[$key]['owner_dwtype']==128){
  83. // $cs['deviceType'] = "4";
  84. // $cs['deviceTypeName'] = "井盖探测器";
  85. // }elseif ($ypSchoolOwner[$key]['owner_dwtype']==3){
  86. // $cs['deviceType'] = "3";
  87. // $cs['deviceTypeName'] = "烟感检测";
  88. // }elseif ($ypSchoolOwner[$key]['owner_dwtype']==7){
  89. // $cs['deviceType'] = "5";
  90. // $cs['deviceTypeName'] = "高低压配电房检测器";
  91. // }elseif ($ypSchoolOwner[$key]['owner_dwtype']==130){
  92. // $cs['deviceType'] = "2";
  93. // $cs['deviceTypeName'] = "消防栓";
  94. // }elseif ($ypSchoolOwner[$key]['owner_dwtype']==1){
  95. // $cs['deviceType'] = "3";
  96. // $cs['deviceTypeName'] = "烟感检测";
  97. // }
  98. // $cs['companyCode'] = $ypSchoolOwner[$key]['company_code'];
  99. // $cs['companyName'] = $ypSchoolOwner[$key]['company_name'];
  100. // $data6 = json_encode($cs);
  101. // $rep_url = "http://ypaqpt.edu.sh.cn/schoolSafe-yp/deviceAdd";
  102. // $res = $this->ypxycurl($rep_url, $data6);
  103. // Log::record('yangpuxiaoyuandevice1' . ':' . $data6);
  104. // Log::record('yangpuxiaoyuandevice2' . ':' . $res);
  105. // print_r('结果'.$res);
  106. // print_r($data6);
  107. // sleep(0.5);
  108. // }
  109. // }
  110. return $res;
  111. }
  112. public function ypxycurl($url,$data=''){
  113. $ch = curl_init();
  114. curl_setopt($ch, CURLOPT_URL, $url);
  115. curl_setopt($ch, CURLOPT_HEADER, FALSE);//不抓取头部信息。只返回数据
  116. curl_setopt($ch, CURLOPT_TIMEOUT,1000);//超时设置
  117. curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);//1表示不返回bool值
  118. curl_setopt($ch, CURLOPT_POST, TRUE);
  119. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  120. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  121. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));//重点
  122. curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
  123. $info = curl_exec($ch);
  124. if (curl_errno($ch)) {
  125. $info = 'ERROR: ' . curl_error($ch);
  126. }
  127. curl_close($ch);
  128. return $info;
  129. }
  130. }