Order.php.bak.20211202 92 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713
  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 Order 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::name('order')->paginate();
  15. $pages = $data_list->render();
  16. $this->assign('data_list', $data_list);
  17. $this->assign('pages', $pages);
  18. return $this->fetch();
  19. }
  20. public function add(){
  21. $res=Db::name('order')->where('notifyType',input('notifyType'))->find();
  22. if(!$res){
  23. if ($this->request->isPost()) {
  24. $data=$_POST;
  25. //验证数据
  26. if(empty($data['notifyType'])||empty($data['callbackUrl'])){
  27. return $this->error("请填写好必要内容");
  28. }
  29. $token=json_decode(gettoken(),true);
  30. $sendata=[
  31. "notifyType"=>$data['notifyType'],
  32. "callbackUrl"=>$data['callbackUrl'],
  33. "appId"=>$this->appId,
  34. ];
  35. $header=[
  36. "Content-Type:application/json",
  37. "app_key:".$this->appId,
  38. "Authorization:Bearer ".$token["accessToken"]
  39. ];
  40. //https://server:port/iocm/app/sub/v1.2.0/subscriptions?ownerFlag={ownerFlag}
  41. $rescurl=curl($this->host."iocm/app/sub/v1.2.0/subscriptions",json_encode($sendata),$header);
  42. dump($rescurl);
  43. if($rescurl[0]==201){//成功
  44. $res1=json_decode($rescurl[1],true);
  45. }else{//失败
  46. // $res2=json_decode($res1[1],true);
  47. return $this->error($rescurl[1]);
  48. }
  49. //添加
  50. $list=array();
  51. $list['notifyType']= $data['notifyType'];
  52. $list['callbackUrl']= $data['callbackUrl'];
  53. $list['subscriptionId']= $res1['subscriptionId'];
  54. $list['addtime']= date('Y-m-d H:i:s');
  55. $list['updatetime']= date('Y-m-d H:i:s');
  56. $res = Db::name('order')->insertGetId($list);
  57. if($res) {
  58. return $this->success('添加成功','index');
  59. }else{
  60. return $this->error("添加失败,请稍后再试");
  61. }
  62. }
  63. }else{
  64. return $this->error("该订阅类型已经填写");
  65. }
  66. $notifyType=Db::table('notifyType')->select();
  67. $this->assign('notifyType', $notifyType);
  68. return $this->fetch();
  69. }
  70. /* public function edit(){
  71. if ($this->request->isPost()) {
  72. $data=$_POST;
  73. //验证数据
  74. if(empty($data['callbackUrl'])){
  75. return $this->error("请填写好必要内容");
  76. }
  77. $token=json_decode(gettoken(),true);
  78. $sendata=[
  79. "notifyType"=>$data['notifyType'],
  80. "callbackUrl"=>$data['callbackUrl'],
  81. "appId"=>$this->appId,
  82. ];
  83. $header=[
  84. "Content-Type:application/json",
  85. "app_key:".$this->appId,
  86. "Authorization:Bearer ".$token["accessToken"]
  87. ];
  88. //https://server:port/iocm/app/sub/v1.2.0/subscriptions?ownerFlag={ownerFlag}
  89. $res1=curl($this->host."iocm/app/sub/v1.2.0/subscriptions",json_encode($sendata),$header);
  90. $res1=json_decode($res1,true);
  91. $list=array();
  92. $list['notifyType']= $data['notifyType'];
  93. $list['callbackUrl']= $data['callbackUrl'];
  94. $list['subscriptionId']= $res1['subscriptionId'];
  95. $list['updatetime']= date('Y-m-d H:i:s');
  96. $res = Db::name('order')->where('id',$data['id'])->update($list);
  97. if($res) {
  98. return $this->success('编辑成功','index');
  99. }else{
  100. return $this->error("编辑失败,请稍后再试");
  101. }
  102. }
  103. $notifyType=Db::table('notifyType')->select();
  104. $this->assign('notifyType', $notifyType);
  105. $res=Db::name('order')->where('id',input('id'))->find();
  106. $this->assign('data', $res);
  107. return $this->fetch();
  108. }*/
  109. //删除订阅
  110. public function delete(){
  111. if ($this->request->isPost()) {
  112. $data=$_POST;
  113. $token=json_decode(gettoken(),true);
  114. $header=[
  115. "Content-Type:application/json",
  116. "app_key:".$this->appId,
  117. "Authorization:Bearer ".$token["accessToken"]
  118. ];
  119. //https://server:port/iocm/app/sub/v1.2.0/subscriptions/{subscriptionId}
  120. $rescurl=curl($this->host."iocm/app/sub/v1.2.0/subscriptions/".$data['subscriptionId'],"",$header,"DELETE");
  121. if($rescurl[0]==204){//成功
  122. Db::name('order')->where('subscriptionId',$data['subscriptionId'])->delete();
  123. return "1111";
  124. //将数据库的订阅数据也删掉
  125. }else{//失败
  126. return $this->error($rescurl[1]);//
  127. }
  128. }
  129. }
  130. public function adddata(){
  131. if ($this->request->isPost()) {
  132. $data = input('');
  133. /* $rand=rand(0,2);
  134. $header=["Content-Type:application/json"];
  135. //将数据分配给不同的服务
  136. $httpserver=["http://47.98.153.212:1101","http://47.98.153.212:1102","http://47.98.153.212:1103"];
  137. $server=$httpserver[$rand];
  138. //将数据随机转发到别的平台做处理
  139. $res=curltest($server,$data,$header);
  140. */
  141. $list = array();
  142. if (is_array($data)) {
  143. $list['data'] = json_encode($data, 320);
  144. $getdata = json_decode($list['data'], true);//转成数组
  145. $list['type'] = 1;
  146. } else {
  147. $list['data'] = $data;
  148. $getdata = json_decode($list['data'], true);//转成数组
  149. $list['type'] = 2;
  150. }
  151. // $list['data']=11;
  152. $list['response'] = "111";
  153. $list['notifyType'] = $getdata["notifyType"];
  154. $list['deviceId'] = $getdata["deviceId"];
  155. $list['addtime'] = date('Y-m-d H:i:s');
  156. $res = Db::name('noticedata')->insertGetId($list);//将推送的数据存入总表
  157. Log::record('deviceId' . ':' . $getdata["service"]["eventTime"]);
  158. //在详细表里插入数据
  159. //根据设备id查找到device里的device_id
  160. if (trim($getdata["notifyType"]) == "deviceDataChanged") {
  161. $device = Db::name('device')->where('iot_id', trim($getdata["deviceId"]))->find();
  162. $datainfo = array();
  163. $datainfo['notifyType'] = $getdata["notifyType"];
  164. $datainfo['device_id'] = $device["device_id"];
  165. $datainfo['iot_id'] = $getdata["deviceId"];
  166. $datainfo['service'] = json_encode($getdata["service"]);
  167. $datainfo['addtime'] = date('Y-m-d H:i:s');
  168. $res1 = Db::table('dev_' . $device["device_id"])->insertGetId($datainfo);
  169. $data2=array();
  170. $data2['devicestatus'] = 0;
  171. $data2['true_status'] = '0';
  172. $data2['lastcommtime'] = date('Y-m-d H:i:s');
  173. $sql2="UPDATE sp_devices_status SET statustime = {$data2['lastcommtime']} devicestatus = {$data2['devicestatus']},true_status={$data2['true_status']},lastcommtime='{$data2['lastcommtime']}' WHERE deviceid='{$device['device_id']}'";
  174. $res2 = addDataInfo($sql2);
  175. if ($device['deviceType']=='Smoke') {
  176. $data3 = array();
  177. $data3['device_id'] = $device["device_id"];
  178. $data3['RSRQ'] = $getdata["service"]['data']['RSRQ'];
  179. $data3['CSQ'] = $getdata["service"]['data']["CSQ"];
  180. $data3['DeviceType'] = $getdata["service"]['data']["DeviceType"];
  181. $data3['DeviceStatus'] = $getdata["service"]['data']["DeviceStatus"];
  182. $data3['BatteryLevel'] = $getdata["service"]['data']["BatteryLevel"];
  183. $data3['SensorLevel'] = $getdata["service"]['data']["SensorLevel"];
  184. $data3['eventTime'] = $getdata["service"]["eventTime"];
  185. $data3['storeTime'] = date('Y-m-d H:i:s');
  186. $sql = "INSERT INTO sp_y{$data3['device_id']} VALUES ('','{$data3['device_id']}',
  187. '{$data3['RSRQ']}', '{$data3['CSQ']}', '{$data3['DeviceType']}','{$data3['DeviceStatus']}','{$data3['BatteryLevel']}','{$data3['SensorLevel']}','{$data3['eventTime']}','{$data3['storeTime']}')";
  188. $res3 = addDataInfo($sql);
  189. } elseif($device['deviceType']=='MultiSensor') {
  190. $data3 = array();
  191. $data3['device_id'] = $device["device_id"];
  192. $data3['port'] = 'tp_water_pressure';
  193. $data3['storeTime'] = date('Y-m-d H:i:s');
  194. $data3['unit'] =$getdata["service"]['data']["unit"];
  195. // $data3['messageId'] = $getdata["service"]['data']["messageId"];
  196. $data3['batteyValue'] = $getdata["service"]['data']["batteyValue"];
  197. $data3['alarmBoolean'] = $getdata["service"]['data']["alarmBoolean"];
  198. $unit=dechex($getdata["service"]['data']["unit"]);
  199. Log::record('sql1234'.':'.$unit);
  200. $sql11="SELECT dwtype FROM sp_owner WHERE owner_code ='{$device["device_id"]}'";
  201. $dwtype = add($sql11);
  202. $arr_y=array('10','11','20','21','22');
  203. if ($dwtype[0]['dwtype'] == 5){
  204. if ($data3['unit']== 1){
  205. $data3['data1']='LL2';
  206. }elseif($data3['unit']== 2){
  207. $data3['data1']='LL1';
  208. }else{
  209. $data3['data1']='LL0';
  210. }
  211. }else {
  212. if ($data3['unit']== 1){
  213. $data3['data1']='WP2';
  214. }elseif($data3['unit']== 2){
  215. $data3['data1']='WP1';
  216. }else{
  217. $data3['data1']='WP0';
  218. }
  219. }
  220. switch ($unit){
  221. case '10':
  222. $data3['data4'] = $getdata["service"]['data']["data"]*0.0001;
  223. break;
  224. case '11':
  225. $data3['data4'] = $getdata["service"]['data']["data"]*0.001;
  226. break;
  227. case '20':
  228. $data3['data4'] = $getdata["service"]['data']["data"]*0.01;
  229. break;
  230. case '21':
  231. $data3['data4'] = $getdata["service"]['data']["data"]*0.1;
  232. break;
  233. case '22':
  234. $data3['data4'] = $getdata["service"]['data']["data"];
  235. break;
  236. case '30':
  237. $data3['data4'] = $getdata["service"]['data']["data"]*0.0000001;
  238. break;
  239. case '31':
  240. $data3['data4'] = $getdata["service"]['data']["data"]*0.000001;
  241. break;
  242. case '40':
  243. $data3['data4'] = $getdata["service"]['data']["data"]*0.00001;
  244. break;
  245. case '41':
  246. $data3['data4'] = $getdata["service"]['data']["data"]*0.0001;
  247. break;
  248. case '42':
  249. $data3['data4'] = $getdata["service"]['data']["data"]*0.001;
  250. break;
  251. case '50':
  252. $data3['data4'] = $getdata["service"]['data']["data"]*0.01;
  253. break;
  254. case '51':
  255. $data3['data4'] = $getdata["service"]['data']["data"]*0.1;
  256. break;
  257. case '52':
  258. $data3['data4'] = $getdata["service"]['data']["data"];
  259. break;
  260. case '2':
  261. $data3['data4'] = $getdata["service"]['data']["data"]*0.001;
  262. break;
  263. case '1':
  264. $data3['data4'] = $getdata["service"]['data']["data"]*0.001;
  265. break;
  266. }
  267. $data3['data'] = $getdata["service"]['data']["data"];
  268. $sql = "INSERT INTO sp_d{$data3['device_id']} VALUES ('','{$data3['device_id']}','{$data3['port']}','{$data3['storeTime']}',
  269. '','','','{$data3['data1']}','{$data3['batteyValue']}','5','{$data3['data4']}','11111111111')";
  270. // Log::record('sql1234'.':'.$sql);
  271. $res4 = addDataInfo($sql);
  272. }elseif ($device['deviceType']=='WaterMeter'){
  273. //宇洁容情
  274. Log::record('xinshuibiaozhi'.':'.$getdata["service"]['data']['data']);
  275. $data3 = array();
  276. $data3['device_id'] = $device["device_id"];
  277. $data3['port'] = 'tp_water_pressure';
  278. $data3['storeTime'] = date('Y-m-d H:i:s');
  279. $data3['batteyValue'] = dechex($getdata["service"]['data']["battery"]);
  280. $data3['unit'] =dechex($getdata["service"]['data']['data']);
  281. $data3['device_type'] =dechex($getdata["service"]['data']['device_type']);
  282. $data3['address'] = '180.101.147.89';
  283. $data3['alarmBoolean'] = $getdata["service"]['data']["alarm"];
  284. $alarm=dechex($data3['alarmBoolean']);
  285. $data3['sign'] = round($getdata["service"]['data']["signal"]/6);
  286. $data3['coeffice'] = dechex($getdata["service"]['data']["coeffice"]);
  287. if ($data3['alarmBoolean']!== 0){
  288. if ($data3['alarmBoolean']== 161){
  289. $data3['data1']='WP1';
  290. }else{
  291. $data3['data1']='WP2';
  292. }
  293. }else {
  294. $data3['data1'] = 'WP0';
  295. }
  296. if ($data3['device_type']=='ae'){
  297. switch ($data3['coeffice']){
  298. case 'd3':
  299. $data3['data4'] = $data3['unit']*0.001;
  300. break;
  301. case 'd2':
  302. $data3['data4'] = $data3['unit']*0.01;
  303. break;
  304. case 'd1':
  305. $data3['data4'] = $data3['unit']*0.1;
  306. break;
  307. case 'e0':
  308. $data3['data4'] = $data3['unit'];
  309. break;
  310. case 'e1':
  311. $data3['data4'] = $data3['unit']*10;
  312. break;
  313. case 'e2':
  314. $data3['data4'] = $data3['unit']*100;
  315. break;
  316. }
  317. $sql = "INSERT INTO sp_d{$data3['device_id']} VALUES ('','{$data3['device_id']}','{$data3['port']}','{$data3['storeTime']}',
  318. '','','','{$data3['data1']}','{$data3['batteyValue']}','{$data3['sign']}','{$data3['data4']}','11111111111')";
  319. $res5 = addDataInfo($sql);
  320. if ($data3['alarmBoolean']!== 0){
  321. $sql = "INSERT INTO sp_sj2017 VALUES ('','tp_water_pressure','{$data3['device_id']}','{$data3['storeTime']}','$alarm','{$data3['address']}', ''
  322. ,'{$data3['data1']}','{$data3['batteyValue']}','{$data3['sign']}','{$data3['data4']}','','','','','','','','','','')";
  323. $insert_id = addDataInfo($sql);
  324. // $sql66="update sp_devices_status set statustime=".$data3['storeTime'];
  325. Log::record('yujie'.':'.$insert_id);
  326. // $update_id = addDataInfo($sql66);
  327. $insert_id_sql="select id from sp_sj2017 where device_code='".$data3['device_id']."' and time='".$data3['storeTime']."'";
  328. Log::record('sql987'.':'.$insert_id_sql);
  329. $insert_id66=add($insert_id_sql);
  330. Log::record('sql253232'.':'.$insert_id66[0]['id']);
  331. if ($data3['alarmBoolean']== 161){
  332. $msg['evt'] = "WP1";
  333. $msg['msg'] = "低压";
  334. }else{ // high
  335. $msg['evt'] = "WP2";
  336. $msg['msg'] = "高压";
  337. }
  338. if ( $msg['evt']=='WP1' || $msg['evt']=='WP2' ) {
  339. $sql3="select s.owner_name,s.unitinfo,s.company,c.owner_address from sp_owner s ,sp_owner_company c where s.company=c.owner_id and s.owner_code ='{$device["device_id"]}'";
  340. $company = add($sql3);
  341. $sql4="select phone from sp_owner_phone WHERE owner_code='".$company[0]['company']."' AND data2 like '%3%' union select phone from sp_owner_phone WHERE owner_code in (select other_code from sp_owner_fujin where owner_code='".$company[0]['company']."') AND data2 like '%3%'";
  342. $union_sql=add($sql4);
  343. // Log::record('sql12345'.':'.$sql4);
  344. $openids=$this->array_column1($union_sql,"phone");
  345. if (empty($openids))
  346. {
  347. echo 'open is null';
  348. exit;
  349. }
  350. // Log::record('data666_phone'.':'.$openids);
  351. $sql5="SELECT openid FROM sp_wx_customuser WHERE type='wx' and idphone in($openids)";
  352. $op=add($sql5);
  353. $access_token=GetAccess_Token();
  354. $address='警报地址:'.$company[0]['owner_address'].$company[0]['unitinfo'];
  355. $deviceid=$device["device_id"];
  356. $type=$msg['msg'];
  357. $time=$data3['storeTime'];
  358. $remark='设备名称:'.$company[0]['owner_name'];
  359. $url_wx_push2 = "https://iot.usky.cn/jdxf/wxapp2.php/Home/Waterwarn/message_water";
  360. Log::record('data666_url_wx_push2'.':'. $url_wx_push2);
  361. $data666['IMEI']=$device["device_id"];
  362. Log::record('data666_IMET'.':'.$data666['IMEI']);
  363. $data666['phone']=$openids;
  364. Log::record('data666_phone'.':'.$data666['phone']);
  365. $data666['evt']=$data3['data1'];
  366. Log::record('data666_evt'.':'.$data666['evt']);
  367. $data666['insert_id']=$insert_id66[0]['id'];
  368. Log::record('data666_insert_id'.':'.$data666['insert_id']);
  369. $data666['time']=$data3['storeTime'];
  370. // Log::record('data666'.':'.$data666);
  371. $sql88="UPDATE sp_devices_status SET statustime ='".$data3['storeTime']."' where deviceid='".$data666['IMEI']."'";
  372. addDataInfo($sql88);
  373. $this->curl($url_wx_push2,$data666);
  374. $waterData["SubType"] = 2;
  375. $waterData["DeviceId"] = $data666['IMEI'];
  376. $waterData["InsertId"] = $insert_id66[0]['id'];
  377. $waterData["Confirmed"] = false;
  378. $data6 = json_encode($waterData);
  379. $rep_url = "http://47.98.201.187:55335/report";
  380. $res = $this->curl($rep_url, $data6);
  381. // $url_wx_push2 = "http://www.jd-ioe.com/jdxf/wxapp2.php/Home/Waterwarn/bj";
  382. foreach($op as $key => $o){
  383. if (!empty($o['openid']))
  384. {
  385. // $data88['openid']=$o['openid'];
  386. // $data88['address']=$address;
  387. // $data88['deviceid']=$deviceid;
  388. // $data88['type']=$type;
  389. // $data88['time']=$time;
  390. // $data88['remark']=$remark;
  391. //token,微信id,地址,设备号,类型,时间,设备名称(或者其他内容)
  392. //{{first.DATA}}$address
  393. //设备号:{{keyword1.DATA}}$deviceid
  394. //报警类型:{{keyword2.DATA}}$type
  395. //时间:{{keyword3.DATA}}$time
  396. //{{remark.DATA}}$remark
  397. $Message=$this->SendDeviceAlarm($access_token,$o['openid'],$address,$deviceid,$type,$time,$remark,$url='');
  398. // s_curl($url_wx_push2,$data88);
  399. $Message['openid']=$o['openid'];
  400. $arr[$key]=$Message;
  401. }
  402. }
  403. }
  404. }
  405. }
  406. }elseif ($device['deviceType']=='topsailSensor'){
  407. //拓普索尔
  408. Log::record('tuopusuoershuibiao'.':'.$getdata["service"]['data']['Imei']);
  409. $data3 = array();
  410. $data4 = array();
  411. $data5 = array();
  412. $sensorList = array();
  413. $sensorListArray = array();
  414. $data4['provider'] = 'Usky';
  415. $data3['device_id'] = $device["device_id"];
  416. $data3['port'] = 'TuoPuSuoEr-TSM-04P';
  417. $data3['storeTime'] = date('Y-m-d H:i:s');
  418. $data3['batteyValue'] = $getdata["service"]['data']["batteryLevel"];
  419. $data3['data'] =substr($getdata["service"]['data']["sampleData"],-5);
  420. $data3['unit'] =substr($getdata["service"]['data']["sampleData"],0,1);
  421. $data3['device_type'] =$getdata["service"]['data']['deviceType'];
  422. $data3['sendTime'] =$getdata["service"]['data']['sendTime'];
  423. $data3['address'] = '180.101.147.89';
  424. $data3['alarmBoolean'] = $getdata["service"]['data']["alarmType"];
  425. $data3['sign'] = round($getdata["service"]['data']["signalStrength"]/6);
  426. $sql6="select * from sp_owner where owner_code ='{$device["device_id"]}'";
  427. $longHuCompany = add($sql6);
  428. $sensorList['sensorId'] = (int)$longHuCompany[0]['id'];
  429. if($data3['device_type']==1 || $data3['device_type']==4){
  430. if ($data3['alarmBoolean']!== '0'){
  431. if ($data3['alarmBoolean']== '1'){
  432. $data3['data1']='WP1';
  433. $sensorList['status'] = 3;
  434. $sensorList['desc'] = $longHuCompany[0]['unitinfo'].'-'.$longHuCompany[0]['owner_name'].'-压力低于下限';
  435. $topic = 'mh/water/alert';
  436. $ytTMhwater = Db::name('yt_t_mhwater')->where('device_code', trim($device["device_id"]))->find();
  437. if (!empty($ytTMhwater)) {
  438. $mhMqtt['deviceCode']=$ytTMhwater['mh_device_code'];
  439. $mhMqtt['addr']='上海市';
  440. $mhMqtt['eventCode1']='02';
  441. $mhMqtt['eventName1']='预警事件';
  442. $mhMqtt['eventCode2']='02008';
  443. $mhMqtt['eventName2']='水压报警';
  444. $mhMqtt['description']='低压';
  445. $mhMqtt['lon']=(double)$ytTMhwater['longitude'];
  446. $mhMqtt['lat']=(double)$ytTMhwater['latitude'];
  447. $mhMqtt['createdTime']=time();
  448. $param = ["platform_cy"=>$ytTMhwater['platform_cy'],"scenetype_cy"=>$ytTMhwater['scenetype_cy']];
  449. $mhMqtt['param']=$param;
  450. $mhMqttJson = json_encode($mhMqtt);
  451. $this->message_push_mh($topic,$mhMqttJson,0);
  452. }
  453. }elseif ($data3['alarmBoolean']== '2'){
  454. $data3['data1']='WP2';
  455. $sensorList['status'] = 4;
  456. $sensorList['desc'] = $longHuCompany[0]['unitinfo'].'-'.$longHuCompany[0]['owner_name'].'-压力超过上限';
  457. $topic = 'mh/water/alert';
  458. $ytTMhwater = Db::name('yt_t_mhwater')->where('device_code', trim($device["device_id"]))->find();
  459. if (!empty($ytTMhwater)) {
  460. $mhMqtt['deviceCode']=$ytTMhwater['mh_device_code'];
  461. $mhMqtt['addr']='上海市';
  462. $mhMqtt['eventCode1']='02';
  463. $mhMqtt['eventName1']='预警事件';
  464. $mhMqtt['eventCode2']='02008';
  465. $mhMqtt['eventName2']='水压报警';
  466. $mhMqtt['description']='高压';
  467. $mhMqtt['lon']=(double)$ytTMhwater['longitude'];
  468. $mhMqtt['lat']=(double)$ytTMhwater['latitude'];
  469. $mhMqtt['createdTime']=time();
  470. $param = ["platform_cy"=>$ytTMhwater['platform_cy'],"scenetype_cy"=>$ytTMhwater['scenetype_cy']];
  471. $mhMqtt['param']=$param;
  472. $mhMqttJson = json_encode($mhMqtt);
  473. $this->message_push_mh($topic,$mhMqttJson,0);
  474. }
  475. }
  476. }else {
  477. $topic = 'mh/water/info';
  478. $ytTMhwater = Db::name('yt_t_mhwater')->where('device_code', trim($device["device_id"]))->find();
  479. if (!empty($ytTMhwater)) {
  480. $mhMqtt['deviceCode']=$ytTMhwater['mh_device_code'];
  481. $mhMqtt['signalLevel']=(int)$data3['sign']*20;
  482. $mhMqtt['volt']=(int)$data3['batteyValue'];
  483. $mhMqtt['lon']=(double)$ytTMhwater['longitude'];
  484. $mhMqtt['lat']=(double)$ytTMhwater['latitude'];
  485. $mhMqtt['createdTime']=time();
  486. $param = ["platform_cy"=>$ytTMhwater['platform_cy'],"scenetype_cy"=>$ytTMhwater['scenetype_cy']];
  487. $mhMqtt['param']=$param;
  488. $mhMqttJson = json_encode($mhMqtt);
  489. $this->message_push_mh($topic,$mhMqttJson,0);
  490. }
  491. $data3['data1'] = 'WP0';
  492. $sensorList['status'] = 0;
  493. $sensorList['desc'] = $longHuCompany[0]['unitinfo'].'-'.$longHuCompany[0]['owner_name'].'-压力正常';
  494. }
  495. $data4['deviceType'] = 'XiaoFangShuiYa';
  496. $sensorList['unit'] = 'MPa';
  497. }elseif ($data3['device_type']==2){
  498. if ($data3['alarmBoolean']!== '0'){
  499. if ($data3['alarmBoolean']== '1'){
  500. $data3['data1']='LL1';
  501. $sensorList['status'] = 3;
  502. $sensorList['desc'] = $longHuCompany[0]['unitinfo'].'-'.$longHuCompany[0]['owner_name'].'-液位低于下限';
  503. }elseif ($data3['alarmBoolean']== '2'){
  504. $data3['data1']='LL2';
  505. $sensorList['status'] = 4;
  506. $sensorList['desc'] = $longHuCompany[0]['unitinfo'].'-'.$longHuCompany[0]['owner_name'].'-液位超过上限';
  507. }
  508. }else {
  509. $data3['data1'] = 'LL0';
  510. $sensorList['status'] = 0;
  511. $sensorList['desc'] = $longHuCompany[0]['unitinfo'].'-'.$longHuCompany[0]['owner_name'].'-液位正常';
  512. }
  513. $data4['deviceType'] = 'YeWei';
  514. $sensorList['unit'] = 'm-米';
  515. }
  516. if (!empty($data3['sendTime'])) {
  517. switch ($data3['unit']) {
  518. case '0':
  519. $data3['data4'] = $data3['data'] * 1;
  520. break;
  521. case '1':
  522. $data3['data4'] = $data3['data'] * 0.1;
  523. break;
  524. case '2':
  525. $data3['data4'] = $data3['data'] * 0.01;
  526. break;
  527. case '3':
  528. $data3['data4'] = $data3['data'] * 0.001;
  529. break;
  530. case '4':
  531. $data3['data4'] = $data3['data'] * 0.0001;
  532. break;
  533. }
  534. $sql = "INSERT INTO sp_d{$data3['device_id']} VALUES ('','{$data3['device_id']}','{$data3['port']}','{$data3['storeTime']}',
  535. '','','','{$data3['data1']}','{$data3['batteyValue']}','{$data3['sign']}','{$data3['data4']}','11111111111')";
  536. $res5 = addDataInfo($sql);
  537. if ($longHuCompany[0]['company']=='10232'|| $longHuCompany[0]['company']=='10318'){
  538. $data4['dataType'] = 'deviceInfo';
  539. $data4['softVersion'] = '1.00.00';
  540. $data4['hardVersion'] = '0.1';
  541. $sensorList['pointValue'] = $data3['data4'];
  542. $deviceConfigure = Db::name('deviceConfigure')->where('device_code', trim($device["device_id"]))->find();
  543. if(!empty($deviceConfigure)){
  544. $sensorList['lowThreshold'] = (double)$deviceConfigure['low_threshold'];
  545. $sensorList['highThreshold'] = (double)$deviceConfigure['high_threshold'];
  546. $sensorList['sendTime'] = (int)$deviceConfigure['send_time'];
  547. }else{
  548. $sensorList['lowThreshold'] = 0;
  549. $sensorList['highThreshold'] = 0;
  550. $sensorList['sendTime'] = 1800;
  551. }
  552. $sensorListArray[0] = $sensorList;
  553. $data4['sensorList'] = $sensorListArray;
  554. if ($longHuCompany[0]['company']=='10232'){
  555. $data5['mqttId'] = 'a71c40bb-5b02-4741-881b-24449f699db5';
  556. }else{
  557. $data5['mqttId'] = 'a71c40bb-5b02-4741-881b-24449f699db6';
  558. }
  559. $data5['action'] = 'transpush';
  560. $data5['data'] = $data4;
  561. $data6 = json_encode($data5);
  562. $rep_url = "http://47.98.201.73:55126/report";
  563. $res = $this->curl($rep_url,$data6);
  564. Log::record('minhanglonghuduijie'.':'.$res);
  565. }
  566. if ($data3['alarmBoolean']!== '0'){
  567. $sql = "INSERT INTO sp_sj2017 VALUES ('','TuoPuSuoEr-TSM-04P','{$data3['device_id']}','{$data3['storeTime']}','{$data3['alarmBoolean']}','{$data3['address']}', ''
  568. ,'{$data3['data1']}','{$data3['batteyValue']}','{$data3['sign']}','{$data3['data4']}','','','','','','','','','','')";
  569. $insert_id = addDataInfo($sql);
  570. // $sql66="update sp_devices_status set statustime=".$data3['storeTime'];
  571. // Log::record('sql66'.':'.$sql66);
  572. // $update_id = addDataInfo($sql66);
  573. $insert_id_sql="select id from sp_sj2017 where device_code='".$data3['device_id']."' and time='".$data3['storeTime']."'";
  574. Log::record('sql98725'.':'.$insert_id_sql);
  575. $insert_id66=add($insert_id_sql);
  576. if($data3['device_type']==1 || $data3['device_type']==4){
  577. if ($data3['alarmBoolean']== '1'){
  578. $msg['evt'] = "WP1";
  579. $msg['msg'] = "低压";
  580. }elseif ($data3['alarmBoolean']== '2'){ // high
  581. $msg['evt'] = "WP2";
  582. $msg['msg'] = "高压";
  583. }
  584. }elseif ($data3['device_type']==2){
  585. if ($data3['alarmBoolean']== '1'){
  586. $msg['evt'] = "LL1";
  587. $msg['msg'] = "低水位";
  588. }elseif ($data3['alarmBoolean']== '2'){ // high
  589. $msg['evt'] = "LL2";
  590. $msg['msg'] = "高水位";
  591. }
  592. }
  593. if ( $msg['evt']=='WP1' || $msg['evt']=='WP2' || $msg['evt']=='LL2' || $msg['evt']=='LL1') {
  594. $sql3="select s.owner_name,s.unitinfo,s.company,c.owner_address from sp_owner s ,sp_owner_company c where s.company=c.owner_id and s.owner_code ='{$device["device_id"]}'";
  595. $company = add($sql3);
  596. $sql4="select phone from sp_owner_phone WHERE owner_code='".$company[0]['company']."' AND data2 like '%3%' union select phone from sp_owner_phone WHERE owner_code in (select other_code from sp_owner_fujin where owner_code='".$company[0]['company']."') AND data2 like '%3%'";
  597. $union_sql=add($sql4);
  598. // Log::record('sql12345'.':'.$sql4);
  599. $openids=$this->array_column1($union_sql,"phone");
  600. if (empty($openids))
  601. {
  602. echo 'open is null';
  603. exit;
  604. }
  605. // Log::record('data666_phone'.':'.$openids);
  606. $sql5="SELECT openid FROM sp_wx_customuser WHERE type='wx' and idphone in($openids)";
  607. $op=add($sql5);
  608. $access_token=GetAccess_Token();
  609. $address='警报地址:'.$company[0]['owner_address'].$company[0]['unitinfo'];
  610. $deviceid=$device["device_id"];
  611. $type=$msg['msg'];
  612. $time=$data3['storeTime'];
  613. $remark='设备名称:'.$company[0]['owner_name'];
  614. $url_wx_push2 = "https://iot.usky.cn/jdxf/wxapp2.php/Home/Waterwarn/message_water";
  615. Log::record('data666_url_wx_push2'.':'. $url_wx_push2);
  616. $data666['IMEI']=$device["device_id"];
  617. Log::record('data666_IMET'.':'.$data666['IMEI']);
  618. $data666['phone']=$openids;
  619. Log::record('data666_phone'.':'.$data666['phone']);
  620. $data666['evt']=$data3['data1'];
  621. Log::record('data666_evt'.':'.$data666['evt']);
  622. $data666['insert_id']=$insert_id66[0]['id'];
  623. Log::record('data666_insert_id'.':'.$data666['insert_id']);
  624. $data666['time']=$data3['storeTime'];
  625. // Log::record('data666'.':'.$data666);
  626. $sql88="UPDATE sp_devices_status SET statustime ='".$data3['storeTime']."' where deviceid='".$data666['IMEI']."'";
  627. addDataInfo($sql88);
  628. $this->curl($url_wx_push2,$data666);
  629. $rep['SubType']=2;
  630. $rep['DeviceId']=$device["device_id"];
  631. $rep['InsertId']=$insert_id66[0]['id'];
  632. $rep['Confirmed']=0;
  633. $rep['CompanyCode']=$company[0]['company'];
  634. $rep['evt_name']=$data3['data1'];
  635. $rep['evt']=0;
  636. $rep['alarm_time']=$data3['storeTime'];
  637. $rep2 = json_encode($rep);
  638. $rep_url = "http://47.98.201.73:55125/report";
  639. $res = $this->curl($rep_url,$rep2);
  640. Log::record('TuoPuSuoEr-TSM-04P'.':'.$res);
  641. // $url_wx_push2 = "http://www.jd-ioe.com/jdxf/wxapp2.php/Home/Waterwarn/bj";
  642. foreach($op as $key => $o){
  643. if (!empty($o['openid']))
  644. {
  645. $Message=$this->SendDeviceAlarm($access_token,$o['openid'],$address,$deviceid,$type,$time,$remark,$url='');
  646. // s_curl($url_wx_push2,$data88);
  647. $Message['openid']=$o['openid'];
  648. $arr[$key]=$Message;
  649. }
  650. }
  651. }
  652. }
  653. }
  654. }
  655. if ($device['deviceType']=='Smoke') {
  656. if ($getdata["service"]['data']["DeviceStatus"]!== 7){
  657. $arr_bit = array(
  658. "","报警","报警静音","保留","低压","故障","保留"
  659. );
  660. $deviceStatus=$getdata["service"]['data']["DeviceStatus"];
  661. $data3 = array();
  662. $data3['device_code'] = $device["device_id"];
  663. $data3['time'] = date('Y-m-d H:i:s');
  664. $data3['status'] = 'y'.'0'.$deviceStatus;
  665. $data3['address'] = '180.101.147.89';
  666. $data3['compartment'] = '';
  667. $data3['fireprocess'] = '';
  668. $data3['flowendtime'] = '0000-00-00 00:00:00';
  669. $data3['ncmd'] = 'y'.'0'.$deviceStatus;
  670. $data3['data1'] = 'y'.'0'.$deviceStatus;
  671. $data3['data2'] = $arr_bit["{$deviceStatus}"];
  672. $data3['data3'] = '';
  673. $data3['data4'] = '烟雾'.$arr_bit["{$deviceStatus}"];
  674. $data3['data5'] = '';
  675. $sql = "INSERT INTO sp_hj2017 VALUES ('','','{$data3['device_code']}','{$data3['time']}','{$data3['status']}','{$data3['address']}','{$data3['compartment']}',
  676. '{$data3['fireprocess']}', '{$data3['flowendtime']}', '{$data3['ncmd']}','{$data3['data1']}','{$data3['data2']}','{$data3['data3']}','{$data3['data4']}','{$data3['data5']}','','',''
  677. ,'','','','','','')";
  678. $res5 = addDataInfo($sql);
  679. $insert_id_sql="select id from sp_hj2017 where device_code='".$data3['device_code']."' and time='".$data3['time']."'";
  680. Log::record('sql66886688'.':'.$insert_id_sql);
  681. $insert_id66=add($insert_id_sql);
  682. // $sql66="update sp_devices_status set statustime=".$data3['time'];
  683. // Log::record('sql66'.':'.$sql66);
  684. // $update_id = addDataInfo($sql66);
  685. }
  686. $arr_h=array(1,2);
  687. if (in_array($getdata["service"]['data']["DeviceStatus"],$arr_h)){
  688. $sql3="select s.owner_name,s.unitinfo,s.company,c.owner_address from sp_owner s ,sp_owner_company c where s.company=c.owner_id and s.owner_code ='{$device["device_id"]}'";
  689. Log::record('sql3'.':'.$sql3);
  690. $company = add($sql3);
  691. Log::record('company'.':'.$company[0]['company']);
  692. $sql4="select phone from sp_owner_phone WHERE owner_code='".$company[0]['company']."' AND data2 like '%6%' union select phone from sp_owner_phone WHERE owner_code in (select other_code from sp_owner_fujin where owner_code='".$company[0]['company']."') AND data2 like '%6%'";
  693. Log::record('sql4'.':'.$sql4);
  694. $union_sql=add($sql4);
  695. $openids=$this->array_column1($union_sql,"phone");
  696. if (empty($openids))
  697. {
  698. echo 'open is null';
  699. exit;
  700. }
  701. $sql5="SELECT openid FROM sp_wx_customuser WHERE type='wx' and idphone in($openids)";
  702. $op=add($sql5);
  703. $access_token=GetAccess_Token();
  704. $address='警报地址:'.$company[0]['owner_address'].$company[0]['unitinfo'];
  705. $deviceid=$device["device_id"];
  706. $type='烟雾';
  707. $time=$data3['time'];
  708. $remark='设备名称:'.$company[0]['owner_name'];
  709. $url_wx_push2 = "https://iot.usky.cn/jdxf/wxapp2.php/Home/Waterwarn/bj";
  710. Log::record('data666_url_wx_push2'.':'.$url_wx_push2);
  711. $data666['phone']=$openids;
  712. Log::record('data666_phone'.':'.$data666['phone']);
  713. $data666['IMEI']=$device["device_id"];
  714. Log::record('data666_IMEI'.':'.$data666['IMEI']);
  715. $data666['time']=$data3['time'];
  716. Log::record('data666_time'.':'.$data666['time']);
  717. $data666['evt']=$data3['data1'];
  718. Log::record('data666_evt'.':'.$data666['evt']);
  719. $data666['insert_id']=$insert_id66[0]['id'];
  720. Log::record('data666_insert_id'.':'.$data666['insert_id']);
  721. $this->curl($url_wx_push2,$data666);
  722. foreach($op as $key => $o){
  723. if (!empty($o['openid']))
  724. {
  725. $Message=$this->SendDeviceAlarm($access_token,$o['openid'],$address,$deviceid,$type,$time,$remark,$url='');
  726. // s_curl($url_wx_push2,$data88);
  727. $Message['openid']=$o['openid'];
  728. $arr[$key]=$Message;
  729. }
  730. }
  731. }
  732. } elseif($device['deviceType']=='MultiSensor') {
  733. if($getdata["service"]['data']["alarmBoolean"]== 17){
  734. // $sql1="SELECT * from 'dev_' . {$device["device_id"]} where addtime=(select max(addtime) from 'dev_' . {$device["device_id"]})";
  735. // $Model = M();
  736. // $result = $Model->query($sql1);
  737. // $service=json_decode($result['']['service']);
  738. $unit=dechex($getdata["service"]['data']["unit"]);
  739. $data3 = array();
  740. $data3['device_code'] = $device["device_id"];
  741. $data3['time'] = date('Y-m-d H:i:s');
  742. $data3['status'] = $getdata["service"]['data']["alarmBoolean"];
  743. $data3['address'] = '180.101.147.89';
  744. $data3['ncmd'] = '';
  745. $data3['unit'] =$getdata["service"]['data']["unit"];
  746. $arr_y=array('10','11','20','21','22');
  747. $sql11="SELECT dwtype FROM sp_owner WHERE owner_code ='{$device["device_id"]}'";
  748. $dwtype = add($sql11);
  749. if ($dwtype[0]['dwtype'] == 5){
  750. if ($data3['unit']== 1){
  751. $data3['data1']='LL2';
  752. }elseif($data3['unit']== 2){
  753. $data3['data1']='LL1';
  754. }else{
  755. $data3['data1']='LL0';
  756. }
  757. }else {
  758. if ($data3['unit']== 1){
  759. $data3['data1']='WP2';
  760. }elseif($data3['unit']== 2){
  761. $data3['data1']='WP1';
  762. }else{
  763. $data3['data1']='WP0';
  764. }
  765. }
  766. $data3['data2'] = $getdata["service"]['data']["batteyValue"];
  767. $data3['data3'] = '';
  768. switch ($unit){
  769. case '10':
  770. $data3['data4'] = $getdata["service"]['data']["data"]*0.0001;
  771. break;
  772. case '11':
  773. $data3['data4'] = $getdata["service"]['data']["data"]*0.001;
  774. break;
  775. case '20':
  776. $data3['data4'] = $getdata["service"]['data']["data"]*0.01;
  777. break;
  778. case '21':
  779. $data3['data4'] = $getdata["service"]['data']["data"]*0.1;
  780. break;
  781. case '22':
  782. $data3['data4'] = $getdata["service"]['data']["data"];
  783. break;
  784. case '30':
  785. $data3['data4'] = $getdata["service"]['data']["data"]*0.0000001;
  786. break;
  787. case '31':
  788. $data3['data4'] = $getdata["service"]['data']["data"]*0.000001;
  789. break;
  790. case '40':
  791. $data3['data4'] = $getdata["service"]['data']["data"]*0.00001;
  792. break;
  793. case '41':
  794. $data3['data4'] = $getdata["service"]['data']["data"]*0.0001;
  795. break;
  796. case '42':
  797. $data3['data4'] = $getdata["service"]['data']["data"]*0.001;
  798. break;
  799. case '50':
  800. $data3['data4'] = $getdata["service"]['data']["data"]*0.01;
  801. break;
  802. case '51':
  803. $data3['data4'] = $getdata["service"]['data']["data"]*0.1;
  804. break;
  805. case '52':
  806. $data3['data4'] = $getdata["service"]['data']["data"];
  807. break;
  808. case '2':
  809. $data3['data4'] = $getdata["service"]['data']["data"]*0.001;
  810. break;
  811. case '1':
  812. $data3['data4'] = $getdata["service"]['data']["data"]*0.001;
  813. break;
  814. }
  815. $data3['data5'] = '';
  816. $sql = "INSERT INTO sp_sj2017 VALUES ('','tp_water_pressure','{$data3['device_code']}','{$data3['time']}','{$data3['status']}','{$data3['address']}', '{$data3['ncmd']}'
  817. ,'{$data3['data1']}','{$data3['data2']}','{$data3['data3']}','{$data3['data4']}','{$data3['data5']}','','','','','','','','','')";
  818. // Log::record('sql123'.':'.$sql);
  819. $insert_id = addDataInfo($sql);
  820. $insert_id_sql="select id from sp_sj2017 where device_code='".$data3['device_id']."' and time='".$data3['time']."'";
  821. Log::record('sql987253232'.':'.$insert_id_sql);
  822. $insert_id66=add($insert_id_sql);
  823. if ($dwtype[0]['dwtype'] == 5) {
  824. if ($getdata["service"]['data']["unit"] == '1') {
  825. $msg['evt'] = "WP2";
  826. $msg['msg'] = "高水位";
  827. } elseif ($getdata["service"]['data']["unit"] == '2') { // high
  828. $msg['evt'] = "WP1";
  829. $msg['msg'] = "低水位";
  830. }
  831. }else{
  832. if ($getdata["service"]['data']["unit"] == '1') {
  833. $msg['evt'] = "WP2";
  834. $msg['msg'] = "高压";
  835. } elseif ($getdata["service"]['data']["unit"] == '2') { // high
  836. $msg['evt'] = "WP1";
  837. $msg['msg'] = "低压";
  838. }
  839. }
  840. if ( $msg['evt']=='WP1' || $msg['evt']=='WP2' ) {
  841. $sql3="select s.owner_name,s.unitinfo,s.company,c.owner_address from sp_owner s ,sp_owner_company c where s.company=c.owner_id and s.owner_code ='{$device["device_id"]}'";
  842. $company = add($sql3);
  843. $sql4="select phone from sp_owner_phone WHERE owner_code='".$company[0]['company']."' AND data2 like '%3%' union select phone from sp_owner_phone WHERE owner_code in (select other_code from sp_owner_fujin where owner_code='".$company[0]['company']."') AND data2 like '%3%'";
  844. $union_sql=add($sql4);
  845. Log::record('sql12345'.':'.$sql4);
  846. $openids=$this->array_column1($union_sql,"phone");
  847. if (empty($openids))
  848. {
  849. echo 'open is null';
  850. exit;
  851. }
  852. Log::record('data666_phone'.':'.$openids);
  853. $sql5="SELECT openid FROM sp_wx_customuser WHERE type='wx' and idphone in($openids)";
  854. $op=add($sql5);
  855. $access_token=GetAccess_Token();
  856. $address='警报地址:'.$company[0]['owner_address'].$company[0]['unitinfo'];
  857. $deviceid=$device["device_id"];
  858. $type=$msg['msg'];
  859. $time=$data3['time'];
  860. $remark='设备名称:'.$company[0]['owner_name'];
  861. //
  862. $url_wx_push2 = "https://iot.usky.cn/jdxf/wxapp2.php/Home/Waterwarn/message_water";
  863. Log::record('data666_url_wx_push2'.':'. $url_wx_push2);
  864. $data666['IMEI']=$device["device_id"];
  865. Log::record('data666_IMET'.':'.$data666['IMEI']);
  866. $data666['phone']=$openids;
  867. Log::record('data666_phone'.':'.$data666['phone']);
  868. $data666['evt']=$data3['data1'];
  869. Log::record('data666_evt'.':'.$data666['evt']);
  870. $data666['insert_id']=$insert_id66[0]['id'];
  871. Log::record('data666_insert_id'.':'.$data666['insert_id']);
  872. $data666['time']=$data3['time'];
  873. // Log::record('data666'.':'.$data666);
  874. $sql88="UPDATE sp_devices_status SET statustime ='".$data3['time']."' where deviceid='".$data666['IMEI']."'";
  875. addDataInfo($sql88);
  876. $this->curl($url_wx_push2,$data666);
  877. // $url_wx_push2 = "http://www.jd-ioe.com/jdxf/wxapp2.php/Home/Waterwarn/bj";
  878. foreach($op as $key => $o){
  879. if (!empty($o['openid']))
  880. {
  881. // $data88['openid']=$o['openid'];
  882. // $data88['address']=$address;
  883. // $data88['deviceid']=$deviceid;
  884. // $data88['type']=$type;
  885. // $data88['time']=$time;
  886. // $data88['remark']=$remark;
  887. //token,微信id,地址,设备号,类型,时间,设备名称(或者其他内容)
  888. //{{first.DATA}}$address
  889. //设备号:{{keyword1.DATA}}$deviceid
  890. //报警类型:{{keyword2.DATA}}$type
  891. //时间:{{keyword3.DATA}}$time
  892. //{{remark.DATA}}$remark
  893. $Message=$this->SendDeviceAlarm($access_token,$o['openid'],$address,$deviceid,$type,$time,$remark,$url='');
  894. // s_curl($url_wx_push2,$data88);
  895. $Message['openid']=$o['openid'];
  896. $arr[$key]=$Message;
  897. }
  898. }
  899. }
  900. }
  901. }
  902. }
  903. return json_encode($data, 320);
  904. }
  905. }
  906. public function addtuobaodata(){
  907. if ($this->request->isPost()) {
  908. $data = input('');
  909. $list = array();
  910. if (is_array($data)) {
  911. $list['data'] = json_encode($data, 320);
  912. $getdata = json_decode($list['data'], true);//转成数组
  913. $list['type'] = 1;
  914. } else {
  915. $list['data'] = $data;
  916. $getdata = json_decode($list['data'], true);//转成数组
  917. $list['type'] = 2;
  918. }
  919. // $list['data']=11;
  920. $list['response'] = "222";
  921. $list['notifyType'] = $getdata["notifyType"];
  922. $list['deviceId'] = $getdata["deviceId"];
  923. $list['addtime'] = date('Y-m-d H:i:s');
  924. $res = Db::name('noticedata')->insertGetId($list);//将推送的数据存入总表
  925. if (trim($getdata["notifyType"]) == "deviceDataChanged") {
  926. $device = Db::name('device')->where('iot_id', trim($getdata["deviceId"]))->find();
  927. Log::record('tuobaoceshi123' . ':' . $device["device_id"]);
  928. $datainfo = array();
  929. $datainfo['notifyType'] = $getdata["notifyType"];
  930. $datainfo['device_id'] = $device["device_id"];
  931. $datainfo['iot_id'] = $getdata["deviceId"];
  932. $datainfo['service'] = json_encode($getdata["service"]);
  933. $datainfo['addtime'] = date('Y-m-d H:i:s');
  934. $res1 = Db::table('dev_' . $device["device_id"])->insertGetId($datainfo);
  935. if ($device['deviceType']=='SaiTeSmoke') {
  936. $data3 = array();
  937. $data3['device_id'] = $device["device_id"];
  938. $data3['RSRQ'] = $getdata["service"]['data']['RSRP'];
  939. $data3['CSQ'] = $getdata["service"]['data']["CSQ"];
  940. $data3['DeviceType'] = 1;
  941. if ($getdata["service"]['data']["Alarm_Status"]!== 7) {
  942. $data3['DeviceStatus'] = 1;
  943. }else{
  944. $data3['DeviceStatus'] = 7;
  945. }
  946. $data3['BatteryLevel'] = $getdata["service"]['data']["Battery_Level"];
  947. $data3['SensorLevel'] = $getdata["service"]['data']["AlarmLevel"];
  948. $data3['TData'] = $getdata["service"]['data']["TData"];
  949. $data3['eventTime'] = $getdata["service"]["eventTime"];
  950. $data3['storeTime'] = date('Y-m-d H:i:s');
  951. $sql = "INSERT INTO sp_y{$data3['device_id']} VALUES ('','{$data3['device_id']}',
  952. '{$data3['RSRQ']}', '{$data3['CSQ']}', '{$data3['DeviceType']}','{$data3['DeviceStatus']}','{$data3['BatteryLevel']}','{$data3['SensorLevel']}','{$data3['eventTime']}','{$data3['storeTime']}','{$data3['TData']}')";
  953. $res3 = addDataInfo($sql);
  954. if ($getdata["service"]['data']["Alarm_Status"]!== 7){
  955. $arr_bit = array(
  956. "","报警","静音","保留","低压","故障","数据异常","","设备收到单次静音指令","设备收到连续静音指令","拆卸报警","拆卸恢复","","","模拟报警"
  957. );
  958. $deviceStatus=$getdata["service"]['data']["Alarm_Status"];
  959. $data3 = array();
  960. $data3['device_code'] = $device["device_id"];
  961. $data3['time'] = date('Y-m-d H:i:s');
  962. $data3['status'] = 'y'.'0'.$deviceStatus;
  963. $data3['address'] = '180.101.147.89';
  964. $data3['compartment'] = '';
  965. $data3['fireprocess'] = '';
  966. $data3['flowendtime'] = '0000-00-00 00:00:00';
  967. $data3['ncmd'] = 'y'.'01';
  968. $data3['data1'] = 'y'.'01';
  969. $data3['data2'] = $arr_bit["{$deviceStatus}"];
  970. $data3['data3'] = '';
  971. $data3['data4'] = '烟雾'.$arr_bit["{$deviceStatus}"];
  972. $data3['data5'] = '';
  973. $sql = "INSERT INTO sp_hj2017 VALUES ('','','{$data3['device_code']}','{$data3['time']}','{$data3['status']}','{$data3['address']}','{$data3['compartment']}',
  974. '{$data3['fireprocess']}', '{$data3['flowendtime']}', '{$data3['ncmd']}','{$data3['data1']}','{$data3['data2']}','{$data3['data3']}','{$data3['data4']}','{$data3['data5']}','','',''
  975. ,'','','','','','')";
  976. $res5 = addDataInfo($sql);
  977. $insert_id_sql="select id from sp_hj2017 where device_code='".$data3['device_code']."' and time='".$data3['time']."'";
  978. Log::record('sql6688668866'.':'.$insert_id_sql);
  979. $insert_id66=add($insert_id_sql);
  980. $arr_h=array(1,2,6,8,9,10,11,14);
  981. if (in_array($getdata["service"]['data']["Alarm_Status"],$arr_h)){
  982. $sql3="select s.owner_name,s.unitinfo,s.company,c.owner_address from sp_owner s ,sp_owner_company c where s.company=c.owner_id and s.owner_code ='{$device["device_id"]}'";
  983. Log::record('sql3'.':'.$sql3);
  984. $company = add($sql3);
  985. Log::record('company'.':'.$company[0]['company']);
  986. $sql4="select phone from sp_owner_phone WHERE owner_code='".$company[0]['company']."' AND data2 like '%6%' union select phone from sp_owner_phone WHERE owner_code in (select other_code from sp_owner_fujin where owner_code='".$company[0]['company']."') AND data2 like '%6%'";
  987. Log::record('sql4'.':'.$sql4);
  988. $union_sql=add($sql4);
  989. $openids=$this->array_column1($union_sql,"phone");
  990. if (empty($openids))
  991. {
  992. echo 'open is null';
  993. exit;
  994. }
  995. $sql5="SELECT openid FROM sp_wx_customuser WHERE type='wx' and idphone in($openids)";
  996. $op=add($sql5);
  997. $access_token=GetAccess_Token();
  998. $address='警报地址:'.$company[0]['owner_address'].$company[0]['unitinfo'];
  999. $deviceid=$device["device_id"];
  1000. $type='烟雾';
  1001. $time=$data3['time'];
  1002. $remark='设备名称:'.$company[0]['owner_name'];
  1003. if($getdata["service"]['data']["Alarm_Status"]==5){
  1004. $deviceStatus1='y05';
  1005. }elseif ($getdata["service"]['data']["Alarm_Status"]==1){
  1006. $deviceStatus1='y01';
  1007. }elseif ($getdata["service"]['data']["Alarm_Status"]==10){
  1008. $deviceStatus1='y10';
  1009. }elseif ($getdata["service"]['data']["Alarm_Status"]==14){
  1010. $deviceStatus1='y12';
  1011. }
  1012. $url_wx_push2 = "https://iot.usky.cn/jdxf/wxapp2.php/Home/Waterwarn/bj";
  1013. Log::record('data666_url_wx_push2'.':'.$url_wx_push2);
  1014. $data666['phone']=$openids;
  1015. Log::record('data666_phone'.':'.$data666['phone']);
  1016. $data666['IMEI']=$device["device_id"];
  1017. Log::record('data666_IMEI'.':'.$data666['IMEI']);
  1018. $data666['time']=$data3['time'];
  1019. Log::record('data666_time'.':'.$data666['time']);
  1020. $data666['evt']=$deviceStatus1;
  1021. Log::record('data666_evt'.':'.$data666['evt']);
  1022. $data666['insert_id']=$insert_id66[0]['id'];
  1023. Log::record('data666_insert_id'.':'.$data666['insert_id']);
  1024. $this->curl($url_wx_push2,$data666);
  1025. foreach($op as $key => $o){
  1026. if (!empty($o['openid']))
  1027. {
  1028. $Message=$this->SendDeviceAlarm($access_token,$o['openid'],$address,$deviceid,$type,$time,$remark,$url='');
  1029. // s_curl($url_wx_push2,$data88);
  1030. $Message['openid']=$o['openid'];
  1031. $arr[$key]=$Message;
  1032. }
  1033. }
  1034. }
  1035. }
  1036. }
  1037. }
  1038. }
  1039. }
  1040. public function jingan(){
  1041. if ($this->request->isPost()) {
  1042. Log::record('jinganxiaofang' . ':ceshi');
  1043. $data = input('');
  1044. /* $rand=rand(0,2);
  1045. $header=["Content-Type:application/json"];
  1046. //将数据分配给不同的服务
  1047. $httpserver=["http://47.98.153.212:1101","http://47.98.153.212:1102","http://47.98.153.212:1103"];
  1048. $server=$httpserver[$rand];
  1049. //将数据随机转发到别的平台做处理
  1050. $res=curltest($server,$data,$header);
  1051. */
  1052. $list = array();
  1053. if (is_array($data)) {
  1054. $list['data'] = json_encode($data, 320);
  1055. $getdata = json_decode($list['data'], true);//转成数组
  1056. } else {
  1057. $list['data'] = $data;
  1058. $getdata = json_decode($list['data'], true);//转成数组
  1059. }
  1060. // $list['data']=11;
  1061. // $list['response'] = "111";
  1062. //
  1063. // $list['notifyType'] = $getdata["notifyType"];
  1064. // $list['deviceId'] = $getdata["deviceId"];
  1065. // $list['addtime'] = date('Y-m-d H:i:s');
  1066. $res = Db::name('jingandata')->insertGetId($list);//将推送的数据存入总表
  1067. Log::record('jinganxiaofang' . ':' . $res);
  1068. $Data = array();
  1069. $Data['app_key'] = $getdata["app_key"];
  1070. $Data['timestamp'] = date('Y-m-d H:i:s',$getdata["timestamp"]);
  1071. $Data['format'] = $getdata["format"];
  1072. $Data['v'] = $getdata["v"];
  1073. $Data['sign_method'] = $getdata["sign_method"];
  1074. $Data['pid'] = $getdata["pid"];
  1075. $Data['bid'] = $getdata["bid"];
  1076. $Data['fid'] = $getdata["fid"];
  1077. $Data['supervise_id'] = $getdata["supervise_id"];
  1078. if (empty($getdata["supervise_code"])){
  1079. $Data['supervise_code']="";
  1080. }else{
  1081. $Data['supervise_code'] = $getdata["supervise_code"];
  1082. }
  1083. $Data['status'] = $getdata["status"];
  1084. $Data['content'] = $getdata["content"];
  1085. $Data['type'] = $getdata["type"];
  1086. if (empty($getdata["device_id"])){
  1087. $Data['device_id']="";
  1088. }else{
  1089. $Data['device_id'] = $getdata["device_id"];
  1090. }
  1091. if (empty($getdata["aid"])){
  1092. $Data['aid']="";
  1093. }else{
  1094. $Data['aid'] = $getdata["aid"];
  1095. }
  1096. if (empty($getdata["loop_number"])){
  1097. $Data['loop_number']="";
  1098. }else{
  1099. $Data['loop_number'] = $getdata["loop_number"];
  1100. }
  1101. if (empty($getdata["position_number"])){
  1102. $Data['position_number']="";
  1103. }else{
  1104. $Data['position_number'] = $getdata["position_number"];
  1105. }
  1106. if (empty($getdata["mainframe_id"])){
  1107. $Data['mainframe_id']="";
  1108. }else{
  1109. $Data['mainframe_id'] = $getdata["mainframe_id"];
  1110. }
  1111. $Data['sign'] = $getdata["sign"];
  1112. if ($Data['app_key']=="f8bdea7926bcc7cb827d2eccf67fa559"){
  1113. $sql3="select device_name,company_code from sp_huangpu_share where pid='{$getdata["pid"]}' GROUP BY company_code";
  1114. }else if ($Data['app_key']=="9e555b8b2244ebc1f59695824b86c5a0"){
  1115. $sql3="select device_name,company_code from sp_jingan_share where pid='{$getdata["pid"]}' and bid='{$getdata["bid"]}' and fid='{$getdata["fid"]}' GROUP BY company_code";
  1116. }
  1117. $company = add($sql3);
  1118. $Data['company_code'] = $company[0]['company_code'];
  1119. $res1 = Db::name('jinganAnalysisData')->insertGetId($Data);
  1120. $url_wx_data = "https://iot.usky.cn/jdxf/wxapp2.php/Home/WorkOrderNotice/message_workordernotice";
  1121. $data_wx['company_code'] = $company[0]['company_code'];
  1122. $data_wx['time']=$Data['timestamp'];
  1123. $data_wx['title']=$Data['content'];
  1124. $data_wx['id']=$res1;
  1125. $data_wx['types']=2;
  1126. if($getdata["status"]==0){
  1127. $this->s_curl($url_wx_data,$data_wx);
  1128. }
  1129. return "success";
  1130. }
  1131. }
  1132. public function jinganPerson(){
  1133. if ($this->request->isPost()) {
  1134. Log::record('jinganxiaofangren' . ':ceshi');
  1135. $data = input('');
  1136. $list = array();
  1137. $data_list = array();
  1138. if (is_array($data)) {
  1139. $list['data'] = json_encode($data, 320);
  1140. $getdata = json_decode($list['data'], true);//转成数组
  1141. } else {
  1142. $list['data'] = $data;
  1143. $getdata = json_decode($list['data'], true);//转成数组
  1144. }
  1145. // $list['data']=11;
  1146. // $list['response'] = "111";
  1147. $res = Db::name('jinganperson')->insertGetId($list);//将推送的数据存入总表
  1148. Log::record('jinganxiaofangren' . ':' . $res);
  1149. $data_list['app_key'] = $getdata["app_key"];
  1150. $data_list['timestamp'] = date('Y-m-d H:i:s',$getdata["timestamp"]);
  1151. $data_list['format'] = $getdata["format"];
  1152. $data_list['version'] = $getdata["v"];
  1153. $data_list['sign_method'] = $getdata["sign_method"];
  1154. $data_list['artificial_id'] = $getdata["artificial_id"];
  1155. $data_list['pid'] = $getdata["pid"];
  1156. $data_list['artificial_code'] = $getdata["artificial_code"];
  1157. $data_list['company_id'] = $getdata["company_id"];
  1158. $data_list['content'] = $getdata["content"];
  1159. $data_list['status'] = $getdata["status"];
  1160. $data_list['sign'] = $getdata["sign"];
  1161. $device = Db::name('person_data')->where('artificial_id', trim( $data_list['artificial_id']))->find();
  1162. if($device){
  1163. return "success";
  1164. }else{
  1165. if ($data_list['app_key']=="f8bdea7926bcc7cb827d2eccf67fa559"){
  1166. $sql3="select device_name,company_code from sp_huangpu_share where pid='{$getdata["pid"]}' GROUP BY company_code";
  1167. }else if ($data_list['app_key']=="9e555b8b2244ebc1f59695824b86c5a0"){
  1168. $sql3="select device_name,company_code from sp_jingan_share where pid='{$getdata["pid"]}' GROUP BY company_code";
  1169. }
  1170. $company = add($sql3);
  1171. $data_list['company_code'] = $company[0]['company_code'];
  1172. $res1 = Db::name('person_data')->insertGetId($data_list);//将推送的数据存入解析表
  1173. Log::record('person_data_list'.':'.$getdata["content"]);
  1174. $url_wx_data = "https://iot.usky.cn/jdxf/wxapp2.php/Home/WorkOrderNotice/message_workordernotice";
  1175. $data_wx['company_code']=$company[0]['company_code'];
  1176. $data_wx['time']=$data_list['timestamp'];
  1177. $data_wx['title']=$data_list['content'];
  1178. $data_wx['id']=$res1;
  1179. $data_wx['types']=1;
  1180. $this->s_curl($url_wx_data,$data_wx);
  1181. return "success";
  1182. }
  1183. }
  1184. }
  1185. public function aepceshi(){
  1186. if ($this->request->isPost()) {
  1187. Log::record('aep' . ':ceshi');
  1188. $data = input('');
  1189. /* $rand=rand(0,2);
  1190. $header=["Content-Type:application/json"];
  1191. //将数据分配给不同的服务
  1192. $httpserver=["http://47.98.153.212:1101","http://47.98.153.212:1102","http://47.98.153.212:1103"];
  1193. $server=$httpserver[$rand];
  1194. //将数据随机转发到别的平台做处理
  1195. $res=curltest($server,$data,$header);
  1196. */
  1197. $list = array();
  1198. if (is_array($data)) {
  1199. $list['data'] = json_encode($data, 320);
  1200. $getdata = json_decode($list['data'], true);//转成数组
  1201. } else {
  1202. $list['data'] = $data;
  1203. $getdata = json_decode($list['data'], true);//转成数组
  1204. }
  1205. // $list['data']=11;
  1206. // $list['response'] = "111";
  1207. //
  1208. // $list['notifyType'] = $getdata["notifyType"];
  1209. // $list['deviceId'] = $getdata["deviceId"];
  1210. // $list['addtime'] = date('Y-m-d H:i:s');
  1211. $res = Db::name('nb_aep')->insertGetId($list);//将推送的数据存入总表
  1212. Log::record('aep' . ':' . $res);
  1213. return json_encode($data, 320);
  1214. }
  1215. }
  1216. public function longHuConfigure(){
  1217. if ($this->request->isPost()) {
  1218. $data = input('');
  1219. $list = array();
  1220. $set_data = array();
  1221. if (is_array($data)) {
  1222. $list['data'] = json_encode($data, 320);
  1223. $getdata = json_decode($list['data'], true);//转成数组
  1224. } else {
  1225. $list['data'] = $data;
  1226. $getdata = json_decode($list['data'], true);//转成数组
  1227. }
  1228. if ($getdata["dataType"]=="setting"){
  1229. $sql="SELECT owner_code FROM sp_owner WHERE id ={$getdata["sensorId"]}";
  1230. $owner_code = add($sql);
  1231. $imei='&imei='.$owner_code[0]['owner_code'];
  1232. if ($getdata["deviceType"]=="XiaoFangShuiYa"){
  1233. $deviceType='&deviceType='.'1';
  1234. }elseif ($getdata["deviceType"]=="YeWei"){
  1235. $deviceType='&deviceType='.'2';
  1236. }
  1237. $sendingGap = '';
  1238. if (!empty($getdata["sendTime"])){
  1239. $sendingGap = '&sendingGap='.$getdata["sendTime"];
  1240. }
  1241. $unipathThresholdLimit = '';
  1242. if (!empty($getdata["lowThreshold"])){
  1243. $unipathThresholdLimit = '&unipathThresholdLimit='.$getdata["lowThreshold"]*1000;
  1244. }
  1245. $unipathThresholdUpper = '';
  1246. if (!empty($getdata["highThreshold"])){
  1247. $unipathThresholdUpper = '&unipathThresholdUpper='.$getdata["highThreshold"]*1000;
  1248. }
  1249. $data6 = json_encode($set_data);
  1250. $rep_url = "https://api.topsailiot.com/dmp/deviceConfig?appkey=3a3e533818a9604dfec0388b2d817dbc2f9f7b05dd4b153c403897cd93a9c04d0edfe3d86ebd3ad0&userid=TS2020120110122980052".$imei.$deviceType.$sendingGap.$unipathThresholdLimit.$unipathThresholdUpper;
  1251. $res = $this->s_curl($rep_url,'');
  1252. Log::record('longhu' . ':' . $rep_url);
  1253. return $res;
  1254. }else{
  1255. $res_arr = array();
  1256. $res_arr['code'] = 60001;
  1257. $res_arr['msg'] = "dataType参数有误";
  1258. $res_arr['data'] = "";
  1259. $res = json_encode($res_arr);
  1260. Log::record('longhuerror' . ':' . $res);
  1261. return $res;
  1262. }
  1263. }
  1264. }
  1265. public function longhudata(){
  1266. if ($this->request->isPost()) {
  1267. $data = input('');
  1268. $list = array();
  1269. $set_data = array();
  1270. if (is_array($data)) {
  1271. $list['data'] = json_encode($data, 320);
  1272. $getdata = json_decode($list['data'], true);//转成数组
  1273. } else {
  1274. $list['data'] = $data;
  1275. $getdata = json_decode($list['data'], true);//转成数组
  1276. }
  1277. if ($getdata["user_from"]=="longHuWater"){
  1278. $sql6="select * from sp_owner where owner_code ='{$getdata["device_code"]}'";
  1279. $longHuCompany = add($sql6);
  1280. $sensorList['sensorId'] = (int)$longHuCompany[0]['id'];
  1281. $sensorList['status'] = 0;
  1282. $sensorList['desc'] = $longHuCompany[0]['unitinfo'].'-'.$longHuCompany[0]['owner_name'].'-压力正常';
  1283. $data4['deviceType'] = 'XiaoFangShuiYa';
  1284. $sensorList['unit'] = 'MPa';
  1285. $data4['dataType'] = 'deviceInfo';
  1286. $data4['provider'] = 'Usky';
  1287. $data4['softVersion'] = '1.00.00';
  1288. $data4['hardVersion'] = '0.1';
  1289. $sensorList['pointValue'] = (double)$getdata['device_value'];
  1290. $deviceConfigure = Db::name('deviceConfigure')->where('device_code', trim($getdata["device_code"]))->find();
  1291. if (!empty($deviceConfigure)) {
  1292. $sensorList['lowThreshold'] = (double)$deviceConfigure['low_threshold'];
  1293. $sensorList['highThreshold'] = (double)$deviceConfigure['high_threshold'];
  1294. $sensorList['sendTime'] = (int)$deviceConfigure['send_time'];
  1295. } else {
  1296. $sensorList['lowThreshold'] = 0;
  1297. $sensorList['highThreshold'] = 0;
  1298. $sensorList['sendTime'] = 1800;
  1299. }
  1300. $sensorListArray[0] = $sensorList;
  1301. $data4['sensorList'] = $sensorListArray;
  1302. if ($longHuCompany[0]['company']=='10232'){
  1303. $data5['mqttId'] = 'a71c40bb-5b02-4741-881b-24449f699db5';
  1304. }else{
  1305. $data5['mqttId'] = 'a71c40bb-5b02-4741-881b-24449f699db6';
  1306. }
  1307. $data5['action'] = 'transpush';
  1308. $data5['data'] = $data4;
  1309. $data6 = json_encode($data5);
  1310. $rep_url = "http://47.98.201.73:55126/report";
  1311. $res = $this->curl($rep_url, $data6);
  1312. Log::record('minhanglonghuduijie' . ':' . $res);
  1313. $res_arr = array();
  1314. $res_arr['code'] = 200;
  1315. $res_arr['msg'] = "操作成功";
  1316. $res_arr['data'] = "";
  1317. $res1 = json_encode($res_arr);
  1318. return $res1;
  1319. }else if ($getdata["user_from"]=="longHuWaterAlarm"){
  1320. $sql6="select * from sp_owner where owner_code ='{$getdata["device_code"]}'";
  1321. $longHuCompany = add($sql6);
  1322. $sensorList['sensorId'] = (int)$longHuCompany[0]['id'];
  1323. $sql7="select * from sp_sj2017 where id ={$getdata['device_value']}";
  1324. $longHuAlarm = add($sql7);
  1325. if ($longHuAlarm[0]['data1']=='WP1'){
  1326. $sensorList['status'] = 3;
  1327. $sensorList['desc'] = $longHuCompany[0]['unitinfo'].'-'.$longHuCompany[0]['owner_name'].'-压力低于下限';
  1328. }elseif ($longHuAlarm[0]['data1']=='WP2'){
  1329. $sensorList['status'] = 4;
  1330. $sensorList['desc'] = $longHuCompany[0]['unitinfo'].'-'.$longHuCompany[0]['owner_name'].'-压力超过上限';
  1331. }elseif ($longHuAlarm[0]['data1']=='WP3'){
  1332. $sensorList['status'] = 1;
  1333. $sensorList['desc'] = $longHuCompany[0]['unitinfo'].'-'.$longHuCompany[0]['owner_name'].'-设备故障';
  1334. }
  1335. $data4['deviceType'] = 'XiaoFangShuiYa';
  1336. $sensorList['unit'] = 'MPa';
  1337. $data4['dataType'] = 'deviceInfo';
  1338. $data4['softVersion'] = '1.00.00';
  1339. $data4['hardVersion'] = '0.1';
  1340. $sensorList['pointValue'] = (double)$longHuAlarm[0]['data4'];
  1341. $deviceConfigure = Db::name('deviceConfigure')->where('device_code', trim($getdata["device_code"]))->find();
  1342. if (!empty($deviceConfigure)) {
  1343. $sensorList['lowThreshold'] = (double)$deviceConfigure['low_threshold'];
  1344. $sensorList['highThreshold'] = (double)$deviceConfigure['high_threshold'];
  1345. $sensorList['sendTime'] = (int)$deviceConfigure['send_time'];
  1346. } else {
  1347. $sensorList['lowThreshold'] = 0;
  1348. $sensorList['highThreshold'] = 0;
  1349. $sensorList['sendTime'] = 1800;
  1350. }
  1351. $sensorListArray[0] = $sensorList;
  1352. $data4['sensorList'] = $sensorListArray;
  1353. $data5['mqttId'] = 'a71c40bb-5b02-4741-881b-24449f699db5';
  1354. $data5['action'] = 'transpush';
  1355. $data5['data'] = $data4;
  1356. $data6 = json_encode($data5);
  1357. $rep_url = "http://47.98.201.73:55126/report";
  1358. $res = $this->curl($rep_url, $data6);
  1359. Log::record('minhanglonghuduijie' . ':' . $res);
  1360. $res_arr = array();
  1361. $res_arr['code'] = 200;
  1362. $res_arr['msg'] = "操作成功";
  1363. $res_arr['data'] = "";
  1364. $res1 = json_encode($res_arr);
  1365. return $res1;
  1366. }else if ($getdata["user_from"]=="xingYueHuiRtuWater"){
  1367. Log::record('xingyuehui' . ':' . $getdata["device_code"]);
  1368. $sql6="select * from sp_owner where owner_code ='{$getdata["device_code"]}'";
  1369. $longHuCompany = add($sql6);
  1370. $sensorList['sensorId'] = (int)$longHuCompany[0]['id'].(int)$getdata["port"];
  1371. $sensorList['status'] = 0;
  1372. $sensorList['desc'] = $longHuCompany[0]['unitinfo'].'-'.$getdata["port_name"].'-压力正常';
  1373. $data4['deviceType'] = 'XiaoFangShuiYa';
  1374. $sensorList['unit'] = 'MPa';
  1375. $data4['dataType'] = 'deviceInfo';
  1376. $data4['provider'] = 'Usky';
  1377. $data4['softVersion'] = '1.00.00';
  1378. $data4['hardVersion'] = '0.1';
  1379. $sensorList['pointValue'] = (double)$getdata['device_value'];
  1380. $deviceConfigure = Db::name('deviceConfigure')->where('device_code', trim($getdata["device_code"]))->find();
  1381. if (!empty($deviceConfigure)) {
  1382. $sensorList['lowThreshold'] = (double)$deviceConfigure['low_threshold'];
  1383. $sensorList['highThreshold'] = (double)$deviceConfigure['high_threshold'];
  1384. $sensorList['sendTime'] = (int)$deviceConfigure['send_time'];
  1385. } else {
  1386. $sensorList['lowThreshold'] = 0;
  1387. $sensorList['highThreshold'] = 0;
  1388. $sensorList['sendTime'] = 1800;
  1389. }
  1390. $sensorListArray[0] = $sensorList;
  1391. $data4['sensorList'] = $sensorListArray;
  1392. if ($longHuCompany[0]['company']=='10232'){
  1393. $data5['mqttId'] = 'a71c40bb-5b02-4741-881b-24449f699db5';
  1394. }else{
  1395. $data5['mqttId'] = 'a71c40bb-5b02-4741-881b-24449f699db6';
  1396. }
  1397. $data5['action'] = 'transpush';
  1398. $data5['data'] = $data4;
  1399. $data6 = json_encode($data5);
  1400. $rep_url = "http://47.98.201.73:55126/report";
  1401. $res = $this->curl($rep_url, $data6);
  1402. Log::record('minhanglonghuduijie' . ':' . $res);
  1403. $res_arr = array();
  1404. $res_arr['code'] = 200;
  1405. $res_arr['msg'] = "操作成功";
  1406. $res_arr['data'] = "";
  1407. $res1 = json_encode($res_arr);
  1408. return $res1;
  1409. }else{
  1410. $res_arr = array();
  1411. $res_arr['code'] = 60001;
  1412. $res_arr['msg'] = "user_from参数有误";
  1413. $res_arr['data'] = "";
  1414. $res = json_encode($res_arr);
  1415. Log::record('longhuerror' . ':' . $res);
  1416. return $res;
  1417. }
  1418. }
  1419. }
  1420. public function testdata1(){
  1421. $rand=rand(0,2);
  1422. $data=[
  1423. '{"notifyType":"deviceDataChanged","deviceId":"a1d88da9-5156-4507-995a-bb20af09001a","gatewayId":"a1d88da9-5156-4507-995a-bb20af09001a","requestId":null,"service":{"serviceId":"hxkcnbdtu","serviceType":"hxkcnbdtu","data":{"deviceAddress":"868744030057305","framenumber":0,"framenum":0,"frameser":0,"voltage":3.6,"rsrp":-99.9,"snr":67,"ecl":0,"csq":11,"cellid":"0125145939","reportway":0,"cycle":1600,"setmode":3,"settime":"3-00","freezday":"28-02","nbtime":"18-09-21 10:30:15","pressure":0.7455,"alarm_en":0,"alarm_time":60,"down_alarm_pre":0,"up_alarm_pre":0,"pre_status":0,"log":"7E64E7834300000011395914250100064003030028021809211030151811112222011F1D0000003C00000000000000000000000000","eventTime":"2018-09-21 10:30:17"},"eventTime":"20180921T023017Z"}}',
  1424. '{"notifyType":"deviceDataChanged","deviceId":"a1d88da9-5156-4507-995a-bb20af09001a","gatewayId":"a1d88da9-5156-4507-995a-bb20af09001a","requestId":null,"service":{"serviceId":"hxkcnbdtu","serviceType":"hxkcnbdtu","data":{"deviceAddress":"868744030057305","framenumber":0,"framenum":0,"frameser":0,"voltage":3.6,"rsrp":-99.9,"snr":67,"ecl":0,"csq":11,"cellid":"0125145939","reportway":0,"cycle":1600,"setmode":3,"settime":"3-00","freezday":"28-02","nbtime":"18-09-21 10:30:15","pressure":0.7455,"alarm_en":0,"alarm_time":60,"down_alarm_pre":0,"up_alarm_pre":0,"pre_status":0,"log":"7E64E7834300000011395914250100064003030028021809211030151811112222011F1D0000003C00000000000000000000000000","eventTime":"2018-09-21 10:30:17"},"eventTime":"20180921T023017Z"}}',
  1425. '{"notifyType":"deviceDataChanged","deviceId":"a1d88da9-5156-4507-995a-bb20af09001a","gatewayId":"a1d88da9-5156-4507-995a-bb20af09001a","requestId":null,"service":{"serviceId":"hxkcnbdtu","serviceType":"hxkcnbdtu","data":{"deviceAddress":"868744030057305","framenumber":0,"framenum":0,"frameser":0,"voltage":3.6,"rsrp":-99.9,"snr":67,"ecl":0,"csq":11,"cellid":"0125145939","reportway":0,"cycle":1600,"setmode":3,"settime":"3-00","freezday":"28-02","nbtime":"18-09-21 10:30:15","pressure":0.7455,"alarm_en":0,"alarm_time":60,"down_alarm_pre":0,"up_alarm_pre":0,"pre_status":0,"log":"7E64E7834300000011395914250100064003030028021809211030151811112222011F1D0000003C00000000000000000000000000","eventTime":"2018-09-21 10:30:17"},"eventTime":"20180921T023017Z"}}',
  1426. ];
  1427. $header=["Content-Type:application/json"];
  1428. //将数据分配给不同的服务
  1429. $httpserver=["http://47.98.153.212:1101","http://47.98.153.212:1102","http://47.98.153.212:1103"];
  1430. $senddata=$data[$rand];
  1431. $server=$httpserver[$rand];
  1432. $res=curltest($server,$senddata,$header);
  1433. dump($res);
  1434. /* //设备所属公司
  1435. $owner=Db::name('device')->field("owner_id")->where('iot_id',$iot_id)->find();
  1436. $ownerhost=Db::name('owner')->where('id',$owner["owner_id"])->find();
  1437. $ipaddr=$ownerhost['host'].":".$ownerhost['port'];
  1438. $res=curltest($ipaddr,$senddata);
  1439. dump($res);*/
  1440. //将数据转发到不同的接口中
  1441. /* $sendapi="senddata".$rand;
  1442. echo $this->$sendapi($data[$rand],$devies[$rand]);*/
  1443. }
  1444. public function tuoBaoUrl(){
  1445. if ($this->request->isPost()) {
  1446. $data = input('');
  1447. $list = array();
  1448. if (is_array($data)) {
  1449. $list['data'] = json_encode($data, 320);
  1450. $getdata = json_decode($list['data'], true);//转成数组
  1451. } else {
  1452. $list['data'] = $data;
  1453. $getdata = json_decode($list['data'], true);//转成数组
  1454. }
  1455. $res = Db::name('tuobao_data')->insertGetId($list);//将推送的数据存入总表
  1456. Log::record('tuoBaoLora' . ':' . $res);
  1457. $tuoBaoData['deviceId'] = $getdata['deviceId'];
  1458. if(!empty($getdata['parseMsg'])){
  1459. Log::record('tuoBaoLoraParseMsg' . ':' . $getdata['parseMsg'][0]['method']);
  1460. }
  1461. $tuoBaoData['deviceId'] = $getdata['deviceId'];
  1462. return json_encode($data, 320);
  1463. }else{
  1464. $msg = input('msg');
  1465. return $msg;
  1466. }
  1467. }
  1468. public function senddata0($data){
  1469. //将数据存到总表
  1470. //将数据存到设备详细表
  1471. //查看当前设备属于哪家业主
  1472. //查找业主的服务器
  1473. //给服务器发数据
  1474. }
  1475. public function senddata1($data){
  1476. echo "m2".$data;
  1477. }
  1478. public function senddata2($data){
  1479. echo "m3".$data;
  1480. }
  1481. public function array_column1($rows, $column_key, $index_key = null) {
  1482. $data = array();
  1483. if (empty($index_key)) {
  1484. foreach ($rows as $row) {
  1485. $data[] = $row[$column_key];
  1486. }
  1487. $data=implode(",",$data);
  1488. } else {
  1489. foreach ($rows as $row) {
  1490. $data[$row[$index_key]] = $row[$column_key];
  1491. }
  1492. }
  1493. return $data;
  1494. }
  1495. public function SendDeviceAlarm($access_token,$openid,$address,$deviceid,$type,$time,$remark,$url){
  1496. $data = array(
  1497. "touser"=> $openid,
  1498. "template_id"=>"JkQYUiScfIuH9O4vvUgtgYxPIOBOY7Zh9w2DcWTgm50",
  1499. //"url" =>"http://zt-iot.com/ztxf/weixin.php/Home/Fire/water",
  1500. "data"=> array(
  1501. "first"=> array(
  1502. "value"=> $address,
  1503. "color"=>"#44b549"
  1504. ),
  1505. "keyword1"=>array(
  1506. "value"=> $deviceid,
  1507. "color"=>"#173177"
  1508. ),
  1509. "keyword2"=> array(
  1510. "value"=> $type,
  1511. "color"=>"#173177"
  1512. ),
  1513. "keyword3"=> array(
  1514. "value"=> $time,
  1515. "color"=>"#173177"
  1516. ),
  1517. "remark"=>array(
  1518. "value"=> $remark,
  1519. "color"=>"#aaaaaa"
  1520. )
  1521. )
  1522. );
  1523. //{{first.DATA}}
  1524. //设备号:{{keyword1.DATA}}
  1525. //报警类型:{{keyword2.DATA}}
  1526. //时间:{{keyword3.DATA}}
  1527. //{{remark.DATA}}
  1528. $data = json_encode($data);
  1529. $QUEST_URL = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".$access_token;
  1530. $res = $this->curl($QUEST_URL,$data);
  1531. return json_decode($res,true);
  1532. }
  1533. public function curl($url,$data=''){
  1534. $ch = curl_init();
  1535. curl_setopt($ch, CURLOPT_URL, $url);
  1536. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  1537. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  1538. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  1539. curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
  1540. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  1541. curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
  1542. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  1543. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  1544. $info = curl_exec($ch);
  1545. if (curl_errno($ch)) {
  1546. $info = 'ERROR: ' . curl_error($ch);
  1547. }
  1548. curl_close($ch);
  1549. return $info;
  1550. }
  1551. public function s_curl($url, $data = '')
  1552. {
  1553. $ch = curl_init();
  1554. curl_setopt($ch, CURLOPT_URL, $url);
  1555. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  1556. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  1557. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  1558. curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
  1559. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  1560. curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
  1561. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  1562. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  1563. $info = curl_exec($ch);
  1564. if (curl_errno($ch)) {
  1565. $info = 'ERROR: ' . curl_error($ch);
  1566. }
  1567. curl_close($ch);
  1568. return $info;
  1569. }
  1570. public function get_curl($url, $data = '')
  1571. {
  1572. $ch = curl_init();
  1573. curl_setopt($ch, CURLOPT_URL, $url);
  1574. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
  1575. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  1576. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  1577. curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
  1578. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  1579. curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
  1580. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  1581. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  1582. $info = curl_exec($ch);
  1583. if (curl_errno($ch)) {
  1584. $info = 'ERROR: ' . curl_error($ch);
  1585. }
  1586. curl_close($ch);
  1587. return $info;
  1588. }
  1589. public function message_push_mh($topic,$msg,$qos){
  1590. vendor('phpMQTT.phpMQTT');
  1591. $server = '47.98.201.73'; // 服务器IP
  1592. $port = 1883; // 服务器端口
  1593. $username = 'usky'; // 用户名
  1594. $password = 'usky'; // 密码
  1595. $client_id = 'pub_' . uniqid();
  1596. $mqtt = new \phpMQTT($server, $port, $client_id);
  1597. if ($mqtt->connect(true, NULL, $username, $password)) {
  1598. $mqtt->publish($topic, $msg, $qos);
  1599. usleep(100000);
  1600. $mqtt->close();
  1601. Log::record('MH—NB-MQTT-Push success!('.$topic.')['.date('Y-m-d H:i:s').']:'.json_encode($msg));
  1602. } else {
  1603. Log::record('MH—NB-MQTT-Time out!('.$topic.')['.date('Y-m-d H:i:s').']:'.json_encode($msg));
  1604. }
  1605. }
  1606. }