Tryag File Manager
Home
||
Turbo Force
||
B-F Config_Cpanel
Current Path :
/
home
/
ltman.eemo.co.kr
/
public_html
/
www
/
Or
Select Your Path :
Upload File :
New :
File
Dir
/home/ltman.eemo.co.kr/public_html/www/api_call_brif.php
<? session_cache_limiter('no-cache, must-revalidate'); session_start(); header("Pragma: no-cache"); header("Cache-Control: no-cache,must-revalidate"); header("Content-Type: text/html; charset=utf-8"); include_once("dbconn.php"); include_once("lib.php"); foreach($_GET as $key => $value) { ${$key}=mysql_real_escape_string(trim($value)); } foreach($_POST as $key => $value) { ${$key}=mysql_real_escape_string(trim($value)); } $arr_rst=array(); $tts_cont="농장 브리핑입니다."; $title="농장 브리핑"; $vv_time=time()-120; $result_dong=mysql_query("select * from farm_dong_info where farm_no='$farm_no' order by CAST(dong_name AS DECIMAL(10,2)) asc ") or die(mysql_error()); while($rs_dong=mysql_fetch_array($result_dong)) { $rs_avg_temp=RS("select avg(now_temper_value) as cnt, no from farm_sensor where farm_no='$farm_no' and dong_no='{$rs_dong[no]}' and unix_timestamp(sens_uptime) >= '$vv_time' "); $rs_avg_humi=RS("select avg(now_humi_value) as cnt, no from farm_sensor where farm_no='$farm_no' and dong_no='{$rs_dong[no]}' and unix_timestamp(sens_uptime) >= '$vv_time' "); $tts_cont.=$rs_dong[dong_name]." 브리핑입니다 "; if($rs_avg_temp[no]) { $tts_cont.=$rs_dong[dong_name]." 평균 온도는 ".sprintf("%.1f",$rs_avg_temp[cnt])."도 입니다 "; $tts_cont.=$rs_dong[dong_name]." 평균 습도는 ".sprintf("%.1f",$rs_avg_humi[cnt])."퍼센트입니다 "; } else { $tts_cont.=$rs_dong[dong_name]." 평균 온도 / 습도가 측정되지 않습니다 "; } $tts_cont.=" "; } $cont=$tts_cont; $rs_mem=RS("select * from member where no='$vmem_no' and fcm_token is not null "); if($rs_mem[fcm_token]) { $tokens = array(); $tokens[]=$rs_mem[fcm_token]; $istts="1"; $is_sound="0"; $isvib="1"; $ispopup=0; $message = array("message" => $cont,"title" => $title,"mode" => $mode,"sound" => $is_sound=="1"?"1":'-1',"tts" => $tts_cont,"istts" => $istts=="1"?"1":'-1',"isvib" => $isvib=="1"?"1":'-1',"ispopup" => $ispopup=="1"?"1":'-1'); $rst=send_notification($tokens, $message); if($rst=="success") { $str_val=implode("&",$tokens); mysql_query("insert into brif_log set farm_no='$farm_no', ment='$tts_cont', regdate=now() ") or die(mysql_error()); } else { } } function send_notification($tokens, $message) { $url = 'https://fcm.googleapis.com/fcm/send'; $fields = array( 'registration_ids' => $tokens, 'data' => $message ); $key = "AIzaSyCG6QsJex8nT-CVCMaDQL7vKxclJl3_XwI"; $headers = array( 'Authorization:key =' . $key, 'Content-Type: application/json' ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields)); $response = curl_exec($ch); curl_close($ch); $json=json_decode($response,true); //NotRegistered = 앱삭제 if($json["success"]) { return "success"; } else { return $response; } } $arr_rst['rst']='1'; echo json_encode($arr_rst); ?>