Server Side/PHP
curl 로 파라미터 전송
Dev. Tool
2017. 3. 30. 22:22
// http API연동 GET방식..
function curl_get($url, $POST_DATA)
{
$url = $url . "?" . http_build_query($POST_DATA);
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_HEADER, false);
if( ! $result = curl_exec($ch))
{
trigger_error(curl_error($ch));
}
curl_close($ch);
$result = str_replace("\r", "", str_replace("\n", "", $result));
return $result;
}
function OrderInsert($order_num, $buy_name, $barcode, $product_code, $buy_date, $buy_hp, $total_price, $opt1, $opt2){
$post_json['order_num'] = $_REQUEST['order_num'];
$post_json['buy_name'] = $_REQUEST['buy_name'];
$post_json['product_code'] = $_REQUEST['product_code']; // 10019(주말) 10018 (주중)
$post_json['mem_id'] = $this->mem_id;
$post_json['buy_date'] = $_REQUEST['buy_date'];
$post_json['buy_hp'] = $this->convert_buy_hp($_REQUEST['buy_hp']);
$post_json['total_price'] = $_REQUEST['total_price'];
$post_json['opt1'] = $_REQUEST['opt1'];
$post_json['opt2'] = $_REQUEST['opt2'];
$post_json['mms'] = $_REQUEST['mms'];
$URI = "http://url/api/order_insert.asp";
$rtnValue = curl_get($URI, $post_json);
return json_decode($rtnValue, true);
}
$gu_api = OrderInsert($order_num, $buy_name, $barcode, $product_code, $buy_date, $buy_hp, $total_price, $opt1, $opt2);
if($gu_api['return_code'] == "0000"){
$return_data['return_code'] = $gu_api['return_code'];
$return_data['return_msg'] = $gu_api['return_msg'];
} else {
$return_data['return_code'] = $gu_api['return_code'];
$return_data['return_msg'] = $gu_api['return_msg'];
}
echo json_encode($return_data, JSON_UNESCAPED_UNICODE);
// json result example
{return_code:0000,return:msg}