먼저 질문한 것이 어렵기도 하고 국내 기상청자료여서 좀 쉽게 해볼 수 있고 전세계 지역을 대상을 할 수 잇는 것으로 할 수 있는 방법을 찾아보고자 합니다.
if($called_position == 'after_module_proc' && Context::getResponseMethod() == 'HTML' && Context::get('module') != 'admin') {
//적용대상이 아닐시 리턴
$logged_info = Context::get('logged_info');
if(($addon_info->use_target == 'user' && !$logged_info) || ($addon_info->use_target == 'customer' && $logged_info)) return;
//해당act는 리턴 (필요시 계속추가)
$act = Context::get('act');
if($act == 'dispCommunicationSendMessage') return;
//날씨연동시 기상청 날씨정보 파싱 및 캐시저장
if($addon_info->weather_kma == 'yes'){
//캐싱설정
$cache_path = './files/cache/snow_falling_addon/';
FileHandler::makeDir($cache_path);
$cache_name = 'snow_falling_addon';
$cache_time = 60*60; //캐시할 시간 (60분)
$cache_file = sprintf('%s%s.cache', $cache_path, $cache_name);
//캐시파일 있으면
if(file_exists($cache_file)){
//캐싱시간확인
$filemtime = filemtime($cache_file)+$cache_time;
$servertime = $_SERVER['REQUEST_TIME'];
//캐싱시간인경우 캐시파일로드
if($filemtime > $servertime){
$cache_body = FileHandler::readFile($cache_file);
}else{
//캐싱시간 지난경우 캐시파일삭제
FileHandler::removeFile($cache_file);
}
}
//캐시파일 없으면 데이터 생성 및 캐시파일로 저장
if(!file_exists($cache_file)){
//날씨정보가공
ini_set("allow_url_fopen","1"); //서버 fopen 허용
$kma_url = "http://www.kma.go.kr/wid/queryDFS.jsp?gridx=67&gridy=108"; //어디기준 날씨정보인지 확실하지않음 ㅡㅡ;
$xml = simplexml_load_file($kma_url);
//날짜데이터 시간
$weather = sprintf('%d',$xml->header->tm);
//가장 최근의 정보를 기준으로 정보저장
if(count($xml->body->data) > 1){
$weather .= sprintf(',%s',$xml->body->data[0]->wfKor); //결과) 시간,날씨상태(맑음,구름조금,구름많음,흐림,비,눈/비,눈)
}
//가공된 정보 캐시정보에 넣음
$cache_content = $weather;
//캐시생성
FileHandler::writeFile($cache_file, $cache_content);
//캐시파일로드
$cache_body = FileHandler::readFile($cache_file);
}
//눈이라는 단어있을경우 snowly 변수에 true 값 세팅
if(preg_match('/눈/',$cache_body)) $snowly = true;
}
//기상청 날씨연동일경우 눈이 안올때 리턴
if($addon_info->weather_kma == 'yes' && $snowly != true) return;
현재 애드온 코드입니다.
국내 어느 한지역의 기상상황을 기준으로 눈내리는 효과를 컨트롤 합니다.
이를 접속자의 위치기반으로 현지 날씨를 기준으로 해보려고 합니다.
* api 절약을 위해 쿠키를 사용해서 같은 브라우저에서는 30분 간격으로 IP로 위경도 확인 / 해당 위경도 값으로 날씨 확인
http://ip-api.com/
http://ip-api.com/json/아이피주소
ip 주소로 현위치 위경도를 파악 할 수 있습니다.
http://openweathermap.org/current
현재 날씨를 구하는 방법 중 위.경도 값으로 현재 날씨를 구할 수 있습니다.
By geographic coordinates
API call:
api.openweathermap.org/data/2.5/weather?lat={lat}&lon={lon}
Parameters:
lat, lon coordinates of the location of your interest
Examples of API calls:
api.openweathermap.org/data/2.5/weather?lat=35&lon=139
API respond:
{"coord":{"lon":139,"lat":35}, "sys":{"country":"JP","sunrise":1369769524,"sunset":1369821049}, "weather":[{"id":804,"main":"clouds","description":"overcast clouds","icon":"04n"}], "main":{"temp":289.5,"humidity":89,"pressure":1013,"temp_min":287.04,"temp_max":292.04}, "wind":{"speed":7.31,"deg":187.002}, "rain":{"3h":0}, "clouds":{"all":92}, "dt":1369824698, "id":1851632, "name":"Shuzenji", "cod":200}
위 내용으로 애드온에 코드를 만들어주세요... ㅡㅡ;
클라이언트 ip주소 수집
쿠키를 적용하는것
api를 통해 값을 가져오는 것....
이값을 사용하는 것....
전혀 해본적도 없어서....