php curl post 获取数据接口 同步局域网 人脸识别设备数据

从服务器调取数据数去---同步到局域网服务器 上传到某台设备上
<?phpheader("Content-type: text/html;charset=utf-8");$url = "http://www.hdyun.com//api/index.php?type=iot&m=face&a=sync"; //读取海大云数据的一个接口//请求参数$data = array("client_id" =>2); //请求接口 并接收数据 返回JSON格式//请求接口$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_POSTFIELDS, $data);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);$res = curl_exec($ch);curl_close($ch);$human = json_decode($res, true);$url = "http://192.168.1.180:8080/addDeviceWhiteList";foreach ($human[data][faces] as $v) { $img = base64_encode(file_get_contents($v[picpath])); $res = array( "usertype" => "white", "name" => $v[name], "sex" => $v[gender] == 1 ? "" : "", "peoplestartdate"=>date("Y-m-d H:i:s"), "peopleenddate"=>"2025-01-01 12:12:12", "idno" => $v[idcard]==‘‘?rand("100000000", "99999999").time() :$v[idcard], //身份证号 "icno" => date("Ymd"), "picData1" =>$img, ); } $param = array( "totalnum" => 1, "currentnum" => 1, "pass" => "888888", "data" => $res ); print_r($param);die; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($param)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $r = curl_exec($ch); //print_r($r);die; curl_close($ch); $rs = json_decode($r, true); if ($rs[result] == 0) { echo "ok"; } else { echo "NO"; }

类似一样的还以还有一种
<?phpset_time_limit(0);$url = "http://www.hdyun.com//api/index.php?type=iot&m=face&a=sync";$succ = 0;$err = 0;//物流接口的参数定义$sl_data = array( client_id => 2,);$handle = fopen("log.txt", "r");if ($handle) { $text = fread($handle, 1024); $sl_data[lastdate] = $text;}fclose($handle);$ch = curl_init();curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);curl_setopt($ch, CURLOPT_TIMEOUT, 500);curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($sl_data));$output = curl_exec($ch); //执行并获取数据curl_close($ch);$outputArr = json_decode($output, true);$txt = "";if ($outputArr[data][faces]) { foreach ($outputArr[data][faces] as $k => $val) { $file = $val[picpath]; if (!file_get_contents($file)) { $image_data = "1"; } else { $image_data = base64_encode(file_get_contents($file)); } $item = array( "usertype" => "white", "idno" => $val[idcard] ?: time() . mt_rand(10000000, 99999999), "picData1" => $image_data, "name" => $val[name], ); $wurl = "http://192.168.1.180:8080/addDeviceWhiteList"; //物流接口的参数定义 $s_data = array( totalnum => count($outputArr[data][faces]), currentnum => 1, data => $item ); $chs = curl_init(); curl_setopt($chs, CURLOPT_RETURNTRANSFER, true); curl_setopt($chs, CURLOPT_TIMEOUT, 500); curl_setopt($chs, CURLOPT_URL, $wurl); curl_setopt($chs, CURLOPT_POSTFIELDS, json_encode($s_data)); $xml = curl_exec($chs); //执行并获取数据 curl_close($chs); echo "index " . $k . "\r\n"; $result = json_decode($xml, true); if ($result[result] == 0) { $succ++; } else { $err++; } $txt = $val[lastdate]; } $myfile = fopen("log.txt", "w"); fwrite($myfile, $txt); fclose($myfile);}die("传输完成,成功" . $succ . "条,失败" . $err . "");

 

 

 

相关文章