<?
$search = "°¡»ê ¿¡À̽º";
$url = "http://post.phpschool.com/phps.kr";
$data = array("addr"=>"$search", "ipkey"=>"ÀÎÁõ¸ÞÀÏ¿¡¼¾È³»", "charset"=>"EUC-KR", "type"=>"new");
// charsetÀÌ UTF-8ÀÏ°æ¿ì "UTF-8" ·Î ±âÀç
// ipkey´Â ÀÎÁõ¸ÞÀÏ¿¡¼ ¾È³»ÇÕ´Ï´Ù.
// Áö¹øÁÖ¼Ò·Î µµ·Î¸íÁÖ¼Ò¸¦ ã±âÀ§ÇÑ °Ë»ö "type"=>"newdong" /* "°¡»êµ¿ 371-50" ½ÄÀ¸·Î µ¿/¹øÁöÀÔ·Â */
// Áö¹øÁּҷΠã±âÀÇ °æ¿ì http://post.phpschool.com/post.html ¿¹¸¦ ÂüÁ¶¹Ù¶ø´Ï´Ù.
// ±¸ÁÖ¼Ò°Ë»öÀÏ°æ¿ì(±¸ ¿ìÆí¹øÈ£·Î¸¸ ã±â) "type"=>"old"
$output = (HTTP_Post($url, $data));
$output = substr($output, strpos($output,"\r\n\r\n")+4);
$output = unserialize($output);
$result = $output['result'];
if ($result > 0) {
$post_data = unserialize($output['post']);
echo "°Ë»ö°Ç¼ö : {$output[result]}\n";
echo "°Ë»ö½Ã°£ : {$output[time]}\n";
echo "Á¶È¸È½¼ö : {$output[cnt]}\n";
echo "Á¶È¸Çѵµ : {$output[maxcnt]}\n";
for ($i=0; $i<$result; $i++) {
//$post_data[$i]['postnew']; // »õ¿ìÆí¹øÈ£ (5ÀÚ¸®)
//$post_data[$i]['post']; // ¿ìÆí¹øÈ£ (6ÀÚ¸®)
//$post_data[$i]['addr_1']; // ½Ã/µµ
//$post_data[$i]['addr_2']; // ±¸
//$post_data[$i]['addr_3']; // µµ·Î¸í
//$post_data[$i]['addr_4']; // µ¿/°Ç¹°
//$post_data[$i]['addr_5']; // ±¸ÁÖ¼Ò (µµ·Î¸íÁÖ¼Ò1:1¸ÅĪ) µµ·Î¸íÁÖ¼Ò°Ë»öÀÏ°æ¿ì¸¸ ¸®ÅÏ
//$post_data[$i]['addr_eng']; // ¿µ¹®ÁÖ¼Ò / µµ·ÎÁÖ¼Ò°Ë»öÀÏ°æ¿ì¸¸ ¸®ÅÏ
print_r($post_data[$i]);
}
} else if ($result == 0) {
echo "°Ë»ö°á°ú°¡ ¾ø½À´Ï´Ù.";
} else if ($result == -1) {
echo "°Ë»ö°á°ú°¡ ³Ê¹« ¸¹½À´Ï´Ù. ÀÔ·ÂÇϽŠ°Ë»ö¾î $search µÚ¿¡ ´Ü¾î¸¦ Ãß°¡Çؼ °Ë»öÇغ¸¼¼¿ä.";
} else if ($result < 0) {
echo "°Ë»ö½ÇÆÐ : ".$output['message'];
}
// $result "-1" ÀÏ°æ¿ì : ³Ê¹«¸¹Àº°Ë»ö°á°ú 1000°ÇÀÌ»ó
// $result "-2" ÀÏ°æ¿ì : ¼¹ö IP ¹ÌÀÎÁõ
// $result "-3" ÀÏ°æ¿ì : Á¶È¸È½¼öÃÊ°ú
// $result "-4" ÀÏ°æ¿ì : ¹ÌÀÎÁõ »ç¿ëÀÚ
// ½ÇÁ¦ ±¸Çö ¼Ò½º´Â À§¿¡±îÁöÀÔ´Ï´Ù. ¾Æ·¡´Â ¼ÒÄÏÇÔ¼ö(curl·Î ±¸Çö°¡´É)
function HTTP_Post($URL,$data) {
$URL_Info=parse_url($URL);
if(!empty($data)) foreach($data AS $k => $v) $str .= urlencode($k).'='.urlencode($v).'&';
$path = $URL_Info["path"];
$host = $URL_Info["host"];
$port = $URL_Info["port"];
if (empty($port)) $port=80;
$result = "";
$fp = fsockopen($host, $port, $errno, $errstr, 30);
$http = "POST $path HTTP/1.0\r\n";
$http .= "Host: $host\r\n";
$http .= "Content-Type: application/x-www-form-urlencoded\r\n";
$http .= "Content-length: " . strlen($str) . "\r\n";
$http .= "Connection: close\r\n\r\n";
$http .= $str . "\r\n\r\n";
fwrite($fp, $http);
while (!feof($fp)) { $result .= fgets($fp, 4096); }
fclose($fp);
return $result;
}
?>
|
PHP json ¿¹Á¦
<?
$search = "°¡»ê ¿¡À̽º"; // jsonÀº UTF-8¸¸ Áö¿øÇÕ´Ï´Ù. (°á°ú°ªµµ UTF-8·Î ¸®ÅÏ)
$url = "http://post.phpschool.com/json.phps.kr";
$data = array("addr"=>$search, "ipkey"=>"ÀÎÁõ¸ÞÀÏ¿¡¼¾È³»", "type"=>"new");
// ipkey´Â ÀÎÁõ¸ÞÀÏ¿¡¼ ¾È³»ÇÕ´Ï´Ù.
// ±¸ÁÖ¼Ò°Ë»öÀÏ°æ¿ì array("addr"=>$search, "ipkey"=>"XXX", "type"=>"old");
// Áö¹øÁÖ¼Ò·Î µµ·Î¸íÁÖ¼Ò¸¦ ã±âÀ§ÇÑ °Ë»ö "type"=>"newdong" /* "°¡»êµ¿ 371-50" ½ÄÀ¸·Î µ¿/¹øÁöÀÔ·Â */
// Áö¹øÁּҷΠã±âÀÇ °æ¿ì http://post.phpschool.com/post.html ¿¹¸¦ ÂüÁ¶¹Ù¶ø´Ï´Ù.
// ±¸ÁÖ¼Ò°Ë»öÀÏ°æ¿ì(±¸ ¿ìÆí¹øÈ£·Î¸¸ ã±â) "type"=>"old"
$output = (HTTP_Post($url, $data));
$output = substr($output, strpos($output,"\r\n\r\n")+4);
$json = json_decode($output);
if ($json->result > 0) {
echo "°Ë»ö°Ç¼ö : {$json->result}\n";
echo "°Ë»ö½Ã°£ : {$json->time}\n";
echo "Á¶È¸È½¼ö : {$json->cnt}\n";
echo "Á¶È¸Çѵµ : {$json->maxcnt}\n";
foreach ($json->post as $key=>$value) {
//$value->postnew; // »õ¿ìÆí¹øÈ£ (5ÀÚ¸®)
//$value->post; // ¿ìÆí¹øÈ£ (6ÀÚ¸®)
//$value->addr_1; // ½Ã/µµ
//$value->addr_2; // ±¸
//$value->addr_3; // µµ·Î¸í
//$value->addr_4; // µ¿/°Ç¹°
//$value->addr_5; // ±¸ÁÖ¼Ò (µµ·Î¸íÁÖ¼Ò1:1¸ÅĪ) // µµ·Î¸íÁÖ¼Ò°Ë»öÀÏ°æ¿ì¸¸ ¸®ÅÏ
//$value->addr_eng; // ¿µ¹®ÁÖ¼Ò // µµ·Î¸íÁÖ¼Ò°Ë»öÀÏ°æ¿ì¸¸ ¸®ÅÏ
print_r($value);
}
} else if ($json->result == 0) {
echo "°Ë»ö°á°ú°¡ ¾ø½À´Ï´Ù.";
} else if ($json->result == -1) {
echo "°Ë»ö°á°ú°¡ ³Ê¹« ¸¹½À´Ï´Ù. ÀÔ·ÂÇϽŠ°Ë»ö¾î $search µÚ¿¡ ´Ü¾î¸¦ Ãß°¡Çؼ °Ë»öÇغ¸¼¼¿ä.";
} else if ($json->result < 0) {
echo "°Ë»ö½ÇÆÐ : ".$json->message;
}
// $result "-1" ÀÏ°æ¿ì : ³Ê¹«¸¹Àº°Ë»ö°á°ú 1000°ÇÀÌ»ó
// $result "-2" ÀÏ°æ¿ì : ¼¹ö IP ¹ÌÀÎÁõ
// $result "-3" ÀÏ°æ¿ì : Á¶È¸È½¼öÃÊ°ú
// $result "-4" ÀÏ°æ¿ì : ¹ÌÀÎÁõ »ç¿ëÀÚ
// ½ÇÁ¦ ±¸Çö ¼Ò½º´Â À§¿¡±îÁöÀÔ´Ï´Ù. ¾Æ·¡´Â ¼ÒÄÏÇÔ¼ö(curl·Î ±¸Çö°¡´É)
function HTTP_Post($URL,$data) {
$URL_Info=parse_url($URL);
if(!empty($data)) foreach($data AS $k => $v) $str .= urlencode($k).'='.urlencode($v).'&';
$path = $URL_Info["path"];
$host = $URL_Info["host"];
$port = $URL_Info["port"];
if (empty($port)) $port=80;
$result = "";
$fp = fsockopen($host, $port, $errno, $errstr, 30);
$http = "POST $path HTTP/1.0\r\n";
$http .= "Host: $host\r\n";
$http .= "Content-Type: application/x-www-form-urlencoded\r\n";
$http .= "Content-length: " . strlen($str) . "\r\n";
$http .= "Connection: close\r\n\r\n";
$http .= $str . "\r\n\r\n";
fwrite($fp, $http);
while (!feof($fp)) { $result .= fgets($fp, 4096); }
fclose($fp);
return $result;
}
?>
|
|
* °Ë»ö¾î °¡À̵å *
1. ¿ìÆí¹øÈ£ °Ë»ö°¡´É : "153787" ¶Ç´Â "153-787"
2. ¿©·¯´Ü¾î °Ë»ö°¡´É : "°¡»êµðÁöÅÐ ¿¡À̽ºÇÏÀÌ¿£µå" ¶Ç´Â "¼¿ï ±Ýõ °¡»ê ¿¡À̽º"
3. µµ·Î¸íÁÖ¼Ò¿Í 1:1 ¸ÅÄ¡µÇ´Â ±¸ÁÖ¼ÒÁ¦°ø(µµ·Î¸íÁÖ¼Ò ¹Ø¿¡ ±¸ÁÖ¼ÒÇ¥½Ã¶§ »ç¿ë)
4. °Ë»ö°á°ú°¡ 1000°ÇÀÌ»óÀÇ °æ¿ì -1°ª ¸®ÅÏ (¼Ò½ºÂüÁ¶)
5. ±¸ÁÖ¼Ò·Î µµ·Î¸íÁÖ¼Ò Ã£±â( type=newdong)
TESTÆäÀÌÁöó·³ µ¿°ú ¹øÁö¸¦ ºÐ¸® ÀԷ¹ްí, °Ë»ö¾î°ªÀº "°¡»êµ¿ 371-50" ó·³
API¿¡ »ç¿ëÇÏ½Ã¸é µË´Ï´Ù!
µµ·Î¸íÁÖ¼Ò¿¡ ¸ÅÄ¡µÇ´Â ±¸ÁÖ¼ÒÀÇ °æ¿ì DB¿¡ "°íô1µ¿/°íô2µ¿ => °íôµ¿" À¸·Î ÅëÀϵǼ
Á¦°øµÇ±â¶§¹®¿¡ ÀÚµ¿À¸·Î "°íôµ¿"À¸·Î ġȯÁ¦°øÇÕ´Ï´Ù.
"°íô2µ¿ 339" "°íôµ¿ 339¹øÁö" "°íô 339" "°íô2µ¿ 339"
=> °Ë»ö°á°ú °°À½
=> ¹øÁö¾Õ¸¸ ÀÔ·ÂÇصµ °á°ú°ªÀ» ¹ÞÀ» ¼ö ÀÖ´Ï´Ù.
(Áö¸¶ÄÏÀÇ °æ¿ì µ¿/¹øÁö°¡ ÀÏÄ¡ÇØ¾ß °á°úÁ¦°ø, "°íô2µ¿" °Ë»ö¾ÈµÊ)
- ÆäÀÌ¡À» Á¦°ø¾ÈÇÏ´Â ÀÌÀ¯
°Ë»ö°á°ú°¡ ¸¹À»°æ¿ì ¼öõ°ÇÀ» ¼ö½ÊÆäÀÌÁö¸¦ ´·¯°¡¸ç ã´Â°Íº¸´Ù °Ë»ö´Ü¾î¸¦ Çѹø´õ
ÀÔ·ÂÇÏ´Â°Ô ´õ È¿À²ÀûÀ̱⠶§¹®ÀÔ´Ï´Ù.
- ¼¿ï/ºÎ»êµî Áö¿ª ¼±ÅÃÀÌ ¾ø´Â ÀÌÀ¯
µµ·Î¸íÀÌ Áߺ¹µÇ´Â °æ¿ì°¡ ¸¹Áö ¾Ê½À´Ï´Ù. µû·Î ¼±ÅÃÇϴ°ÍÀÌ Àǹ̰¡ ¾ø½À´Ï´Ù.
Áö¸¶Äϵ¼ ½ÇÁ¦ °Ë»öÇغ¸¼¼¿ä.¤¾ ³Ê¹«³ª ºÒÆíÇÕ´Ï´Ù.
µµ·Î¸íÁÖ¼ÒÀÇ °æ¿ì 700¸¸°Ç¿¡ À̸£´Â µ¥ÀÌÅÍ¿¡¼ °Ë»öÇϱ⶧¹®¿¡ ÃæºÐÇÑ ¾È³»°¡ ÇÊ¿äÇÕ´Ï´Ù.
ex) °Ë»ö°á°ú°¡ ³Ê¹« ¸¹½À´Ï´Ù. ÀÔ·ÂÇϽŠ°Ë»ö¾î "°¡»ê" µÚ¿¡ ¹øÁö³ª °Ç¹°¸íÀ» Ãß°¡ÀÔ·ÂÇØÁÖ¼¼¿ä.
|
|