Onenet.php.bak.20220301 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. }