123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- <?php
- namespace app\admin\controller;
- use think\Controller;
- use think\Session;
- use think\Db;
- use think\Request;
- use think\Log;
- class Onenet extends Controller
- {
-
-
- public function index(){
- }
- //下发命令
- public function add(){
-
-
- }
- public function status(){
- }
- public function delete(){
-
- }
- public function OneNetCeShi(){
- // if ($this->request->isPost()) {
- $data = input('');
- /* $rand=rand(0,2);
- $header=["Content-Type:application/json"];
- //将数据分配给不同的服务
- $httpserver=["http://47.98.153.212:1101","http://47.98.153.212:1102","http://47.98.153.212:1103"];
- $server=$httpserver[$rand];
- //将数据随机转发到别的平台做处理
- $res=curltest($server,$data,$header);
- */
- $list = array();
- if (is_array($data)) {
- $list['data'] = json_encode($data, 320);
- $getdata = json_decode($list['data'], true);//转成数组
- } else {
- $list['data'] = $data;
- $getdata = json_decode($list['data'], true);//转成数组
- }
- // $list['data']=11;
- // $list['response'] = "111";
- //
- // $list['notifyType'] = $getdata["notifyType"];
- // $list['deviceId'] = $getdata["deviceId"];
- // $list['addtime'] = date('Y-m-d H:i:s');
- $res = Db::name('one_net_data')->insertGetId($list);//将推送的数据存入总表
- $returnInformation['code'] = 200;
- $returnInformation['msg'] = "操作成功";
- Log::record('onenet:' .$getdata['msg'] );
- return $getdata['msg'];
- // }
- }
- //山东党校api
- public function sdSchoolApi()
- {
- header("Access-Control-Allow-Origin:*");
- // 响应类型
- header('Access-Control-Allow-Methods:POST');
- // 响应头设置
- header('Access-Control-Allow-Headers:x-requested-with, content-type');
- $data = input('');
- if (is_array($data)) {
- $getDataJson = json_encode($data, 320);
- $getdata = json_decode($getDataJson, true);//转成数组
- } else {
- $getDataJson = $data;
- $getdata = json_decode($getDataJson, true);//转成数组
- }
- $cs['V_LOGINNAME'] = "sddx";
- $cs['V_PASSWORD'] = "sddx123";
- $cs['COMPANY_CODE'] = "10321";
- $cs['COMMSTATUS'] = "NO";
- $data6 = json_encode($cs);
- $data = "queryJson=".$data6;
- $rep_url = "https://fire.usky.cn:8443/YtIoT/iot/frontpage/getCurrentObjectListByCompanyId";
- $res = $this->ypxycurl($rep_url, $data);
- // if (!empty($ypSchoolOwner)){
- // foreach ($ypSchoolOwner as $key=>$value){
- // $cs['deviceId'] = $ypSchoolOwner[$key]['object_code'];
- // $cs['deviceName'] = $ypSchoolOwner[$key]['object_name'].$ypSchoolOwner[$key]['device_name'];
- // if ($ypSchoolOwner[$key]['owner_dwtype']==2){
- // $cs['deviceType'] = "1";
- // $cs['deviceTypeName'] = "水泵水压检测器";
- // }elseif ($ypSchoolOwner[$key]['owner_dwtype']==128){
- // $cs['deviceType'] = "4";
- // $cs['deviceTypeName'] = "井盖探测器";
- // }elseif ($ypSchoolOwner[$key]['owner_dwtype']==3){
- // $cs['deviceType'] = "3";
- // $cs['deviceTypeName'] = "烟感检测";
- // }elseif ($ypSchoolOwner[$key]['owner_dwtype']==7){
- // $cs['deviceType'] = "5";
- // $cs['deviceTypeName'] = "高低压配电房检测器";
- // }elseif ($ypSchoolOwner[$key]['owner_dwtype']==130){
- // $cs['deviceType'] = "2";
- // $cs['deviceTypeName'] = "消防栓";
- // }elseif ($ypSchoolOwner[$key]['owner_dwtype']==1){
- // $cs['deviceType'] = "3";
- // $cs['deviceTypeName'] = "烟感检测";
- // }
- // $cs['companyCode'] = $ypSchoolOwner[$key]['company_code'];
- // $cs['companyName'] = $ypSchoolOwner[$key]['company_name'];
- // $data6 = json_encode($cs);
- // $rep_url = "http://ypaqpt.edu.sh.cn/schoolSafe-yp/deviceAdd";
- // $res = $this->ypxycurl($rep_url, $data6);
- // Log::record('yangpuxiaoyuandevice1' . ':' . $data6);
- // Log::record('yangpuxiaoyuandevice2' . ':' . $res);
- // print_r('结果'.$res);
- // print_r($data6);
- // sleep(0.5);
- // }
- // }
- return $res;
- }
- public function ypxycurl($url,$data=''){
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_HEADER, FALSE);//不抓取头部信息。只返回数据
- curl_setopt($ch, CURLOPT_TIMEOUT,1000);//超时设置
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);//1表示不返回bool值
- curl_setopt($ch, CURLOPT_POST, TRUE);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));//重点
- curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
- $info = curl_exec($ch);
- if (curl_errno($ch)) {
- $info = 'ERROR: ' . curl_error($ch);
- }
- curl_close($ch);
- return $info;
- }
-
- }
|