/**
* key1、key2 ダミーキー 空だとエラー
* format レスポンス形式 (json/xml)
* charset 文字コードのエンコード (jis/sjis/eucjp/utf8)
* ipadr IPだけ書替え
* mode plain
* pref 1~47
* prefCF、cityCF 0~100
*/
extract( $_GET );
$rest_data = array( "IP" => "210.251.250.30", "CountryCode" => "JP" , "CountryAName" => "japan" , "CountryJName" => "日本" ,
"PrefCode" => "22" , "PrefAName" => "shizuoka" , "PrefJName" => "静岡" , "PrefLatitude" => "34.97682" ,
"PrefLongtude" => "138.38315" , "PrefCF" => "95" , "CityCode" => "22206" , "CityAName" => "mishima-shi" ,
"CityJName" => "三島市" , "CityLatitude" => "35.11772" , "CityLongtude" => "138.91868" , "CityCF" => "85" ,
"BCFlag" => "b" , "OrgCode" => "100002637" , "OrgOfficeCode" => "0" , "OrgIndependentCode" => "0" ,
"OrgName" => "サイバーエリアリサーチ株式会社", "OrgPrefCode" => "22" , "OrgCityCode" => "22206" ,
"OrgZipCode" => "411-0036" , "OrgAddress" => "静岡県三島市一番町18-22 アーサーファーストビル4F",
"OrgTel" => "055-991-5544" , "OrgFax" => "055-991-5540", "OrgIpoType" => "9" , "OrgDate" => "200002" ,
"OrgCapitalCode" => "4" , "OrgEmployeesCode" => "3" , "OrgGrossCode" => "2" , "OrgPresident" => "山本 敬介" ,
"OrgIndustrialCategoryL" => "G" , "OrgIndustrialCategoryM" => "37,39,40", "OrgIndustrialCategoryS" => "373,391,392,401",
"OrgIndustrialCategoryT" => "3731,3911,3921,3929,4013" , "OrgDomainName" => "arearesearch.co.jp",
"OrgUrl" => "http://www.arearesearch.co.jp/" , "OrgLatitude" => "35.1246742" , "OrgLongitude" => "138.9101771" ,
"LineCode" => "f" , "LineJName" => "フレッツISDN", "LineCF" => "95" , "ProxyFlag" => "0" ,
"TelCode" => "059" , "DomainName" => "arearesearch.co.jp"
);
if ( !$key1 || !$key2 ) { $status = "401"; }
switch( $charset ) {
case "sjis": $charset = "shift_jis"; break;
case "jis": $charset = "iso-2022-jp"; break;
case "eucjp": $charset = "euc-jp"; break;
default: $charset = "utf-8";
}
if ( preg_match( "/^[A-Z]{2}$/", $country ) && $country != "JP" ) {
/*
foreach ( $rest_data as $key => &$value ) {
if ( preg_match( "/^(Pref|City|Line)CF|(Pref|Tel)Code$/", $key )) { $value = "00"; }
else if ( preg_match( "/^(Pref|City|Line)JName$/", $key )) { $value = "判定不明"; }
else if ( preg_match( "/^(PrefA|CityA|Domain)Name$/", $key )) { $value = "unknown"; }
else { $value = ""; }
}
*/
foreach ( $rest_data as $key => $value ) {
if ( preg_match( "/^(Pref|City|Line)CF|(Pref|Tel)Code$/", $key )) { $rest_data[$key] = "00"; }
else if ( preg_match( "/^(Pref|City|Line)JName$/", $key )) { $rest_data[$key] = "判定不明"; }
else if ( preg_match( "/^(PrefA|CityA|Domain)Name$/", $key )) { $rest_data[$key] = "unknown"; }
else { $rest_data[$key] = ""; }
}
$rest_data["IP"] = rand( 0, 255 ).'.'.rand( 0, 255 ).'.'.rand( 0, 255 ).'.'.rand( 0, 255 );
$rest_data["CityCode"] = "00000";
$rest_data["LineCode"] = "z";
include_once( "globe_data.php" );
if ( $globe_data[$country] ) {
$rest_data["CountryCode"] = $country;
$rest_data["CountryAName"] = $globe_data[$country]["countryAname"];
$rest_data["CountryJName"] = $globe_data[$country]["countryJname"];
}
else {
$rest_data["CountryCode"] = "00";
$rest_data["CountryAName"] = "unknown";
$rest_data["CountryJName"] = "判定不明";
}
}
else {
if ( $ipadr && preg_match( "/^([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})$/", $ipadr, $match )) {
$rest_data["IP"] = $match[0];
if ( !$pref ) { $pref = rand( 1, 47 ); }
}
if ( preg_match( "/^0?[1-9]|1[0-9]|2[0-9]|3[0-9]|4[0-7]$/", $pref )) {
$pref--;
include( "pref_data.php" );
$rest_data["PrefCode"] = $pref_data[$pref]["prefCode"];
$rest_data["PrefAName"] = $pref_data[$pref]["aname"];
$rest_data["PrefJName"] = $pref_data[$pref]["jname"];
$rest_data["PrefLatitude"] = $pref_data[$pref]["lat"];
$rest_data["PrefLongtude"] = $pref_data[$pref]["lng"];
$rest_data["CityCode"] = $pref_data[$pref]["cityCode"];
$rest_data["CityAName"] = $pref_data[$pref]["cityAname"];
$rest_data["CityJName"] = $pref_data[$pref]["cityJname"];
$rest_data["CityLatitude"] = $pref_data[$pref]["cityLat"];
$rest_data["CityLongtude"] = $pref_data[$pref]["cityLat"];
}
if ( preg_match( "/^\d{0,3}$/", $prefCF ) && $prefCF <= 100 ) { $rest_data["PrefCF"] = sprintf( "%02d", $prefCF ); }
if ( preg_match( "/^\d{0,3}$/", $cityCF ) && $cityCF <= 100 ) { $rest_data["CityCF"] = sprintf( "%02d", $cityCF ); }
}
if ( $format == "json" ) {
switch ( $status ) {
case "401":
header( "Content-type: application/xml" );
$body = '';
$body .= "401Unauthorized";
$body .= "";
break;
default:
header( "Content-type: text/plain; charset=\"UTF-8\"" );
foreach ( $rest_data as $key => $value ) {
if ( $ipadr == "hoge" ) {
$body .= '"'.$key.'":"hoge",';
}
else {
$body .= '"'.$key.'":"'.$value.'",';
}
}
$body = "{".rtrim( $body, "," )."}";
}
}
else {
header( "Content-type: application/xml" );
$body = '';
switch ( $status ) {
case "401":
$body .= "401Unauthorized";
break;
default:
foreach ( $rest_data as $key => $value ) {
if ( $ipadr == "hoge" ) {
$body .= "<".$key.">hoge".$key.">";
}
else {
$body .= "<".$key.">".$value."".$key.">";
}
}
}
$body .= "";
}
if ( $mode == "plain" ) {
header( "Content-type: text/plain; charset=\"UTF-8\"" );
$body = str_replace( "", "\n\n", $body );
$body = preg_replace( "|(<[^>]*>.*[^>]*>)|U", "\t$1\n", $body );
$body = preg_replace( "/{(.*)}/", "{\n$1}", $body );
$body = preg_replace( '/("[^:]*:"[^"]*",?)/', "\t$1\n", $body );
}
echo mb_convert_encoding( $body, $charset, "UTF-8" );
?>