语言 : PHP
系统: CENTOS LINUX+APACHE
首先使用print_r($_REQUEST); 获取上传数据及格式
/* * Array ( [device_id] => DC4F22D1BE38 [device_key] => 51d6b20a //id+ “2018doit”,md5 取前8个字节 [device_time] => 2018-11-13#20:05:34 //通过postion_mac位置mac,调用如下接口可以定位设备所在的位置: // //http://dingwei.doit.am/d.php?mac=BC:D1:77:55:17:FA // //返回: // //{"location":{"address":{"region":"广东省","county":"南山区","street":"学苑大道(西段)","street_number":"沙埔仔","city":"深圳市","country":"中国"},"addressDescription":"广东省深圳市南山区丽山路桃源街道沙埔仔,众冠·红花岭工业北区北189米,学苑大道(西段)西北1米","longitude":113.9612082,"latitude":22.5849447,"accuracy":"189米"},"access_token":null,"ErrCode":"0"} // // [postion_mac] => 78:EB:14:D6:19:7A|Fast-802,2C:95:7F:12:60:18|ChinaNet-TK,6C:59:40:F8:1C:E0|大鸡炖粉条 //第一列表示手机MAC,第二列表示路由mac,第三列表示路由名称(如果为空表示没有名称),第四列表示采集设备与手机的距离,第5列表示是否已经连接路由 [message] => 70:20:84:2E:A9:56,FC:D7:33:00:48:B4,mataiping,7.50,0 84:21:F1:5D:3D:BF,D0:C7:C0:5E:CD:A4,tktep321,3.65,1 F0:C8:50:93:BA:82,6C:E8:73:58:1D:F6,1107,11.55,0 A0:4E:A7:31:8B:26,D0:C7:C0:5E:CD:A4,tktep321,3.92,0 00:26:C7:06:B7:18,A4:93:3F:DA:E1:9A,sbt,0.60,1 B4:0B:44:A7:E7:19,A4:93:3F:DA:E1:9A,sbt,2.05,1 )
可以看出是标准的FORM表单POST上传数据,
解析就简单了
$message = explode("\r\n",$_REQUEST['message']); $time =strtime(); foreach($message as $m) { $info = explode(",",$m); $o = ORM::for_table('wifitz')->create(); $o->device_id = $_REQUEST['device_id']; $o->device_time =str_replace('#',' ', $_REQUEST['device_time']); $o->postion_mac = $_REQUEST['postion_mac']; $o->phone_mac =$info[0]; $o->router_mac =$info[1]; $o->router_name =$info[2]; $o->distance =$info[3]; $o->connectroute =$info[4]; $o->ctime = $time; $o->save(); }
硬件用的这一款:
https://item.taobao.com/item.htm?spm=a1z10.3-c.w4002-951511554.36.4eb91349J6wiE2&id=582039558477