나이스페이 결제 응답 검증 보강

(cherry picked from commit 50c2d6b6cfeaa10bbb65b2537a05c0525528cc63)
This commit is contained in:
thisgun committed 2026-08-24 07:44:22 +00:00
1 parent f7106379b8
commit a21f3103bb
10 files changed
+189 -101

No files matched your search

+12 -4
View File
@@ -117,10 +117,11 @@ if($authResultCode === "0000"){
$ResultCode = nicepay_res('ResultCode', $respArr);
$ResultMsg = nicepay_res('ResultMsg', $respArr);
$tno = nicepay_res('TID', $respArr);
$amount = (int) nicepay_res('Amt', $respArr, 0);
$app_time = nicepay_res('AuthDate', $respArr);
$pay_method = nicepay_res('PayMethod', $respArr);
$od_app_no = $app_no = nicepay_res('AuthCode', $respArr); // 승인 번호 (신용카드, 계좌이체, 휴대폰)
$response_amt = nicepay_res('Amt', $respArr, 0);
$amount = (int) $response_amt;
$app_time = nicepay_res('AuthDate', $respArr);
$pay_method = nicepay_res('PayMethod', $respArr);
$od_app_no = $app_no = nicepay_res('AuthCode', $respArr); // 승인 번호 (신용카드, 계좌이체, 휴대폰)
$pay_type = $NICEPAY_METHOD[$pay_method];
// 승인된 코드가 아니면 결제가 되지 않게 합니다.
@@ -129,6 +130,13 @@ if($authResultCode === "0000"){
die();
}
$responseSignature = nicepay_res('Signature', $respArr);
$responseSignData = bin2hex(hash('sha256', $tno . $mid . $response_amt . $merchantKey, true));
if ($responseSignature != $responseSignData) {
alert("승인 응답 유효성 검증이 틀려서 결제를 진행할수 없습니다.", G5_SHOP_URL);
}
if ($amount != $order_price) {
if($amount > 0) {
$od_id = $moid;
+6 -5
View File
@@ -71,10 +71,11 @@ function nicepay_create_signdata(frm)
var result = true;
$.ajax({
url: g5_url+"/shop/nicepay/createsigndata.php",
type: "POST",
data: {
price : frm.good_mny.value
},
type: "POST",
data: {
price : frm.good_mny.value,
moid : frm.Moid ? frm.Moid.value : ''
},
dataType: "json",
async: false,
cache: false,
@@ -137,4 +138,4 @@ function nicepay_create_signdata(frm)
<input type="hidden" name="comm_vat_mny" value="<?php echo $comm_vat_mny; ?>"> <!-- 부가세 -->
<input type="hidden" name="comm_free_mny" value="<?php echo $comm_free_mny; ?>"> <!-- 비과세 금액 -->
<?php } ?>
</form>
</form>
+24 -13
View File
@@ -3,12 +3,23 @@ include_once('./_common.php');
include_once(G5_MSHOP_PATH.'/settle_nicepay.inc.php');
$authResultCode = isset($_POST['AuthResultCode']) ? clean_xss_tags($_POST['AuthResultCode']) : ''; // authentication result code 0000:success
$authResultMsg = isset($_POST['AuthResultMsg']) ? clean_xss_tags($_POST['AuthResultMsg']) : ''; // authentication result message
$mid = isset($_POST['MID']) ? clean_xss_tags($_POST['MID']) : ''; // merchant id
$moid = isset($_POST['Moid']) ? addslashes(clean_xss_tags(stripslashes($_POST['Moid']))) : ''; // order number
$sql = " select * from {$g5['g5_shop_order_data_table']} where od_id = '$moid' ";
$row = sql_fetch($sql);
$authResultMsg = isset($_POST['AuthResultMsg']) ? clean_xss_tags($_POST['AuthResultMsg']) : ''; // authentication result message
$mid = isset($_POST['MID']) ? clean_xss_tags($_POST['MID']) : ''; // merchant id
$moid = isset($_POST['Moid']) ? addslashes(clean_xss_tags(stripslashes($_POST['Moid']))) : ''; // order number
if ($default['de_nicepay_mid'] != $mid) {
alert("요청한 상점 mid와 설정된 mid가 틀리므로 결제를 진행할수 없습니다.", G5_SHOP_URL);
}
$session_order_id = get_session('ss_order_id');
$session_personalpay_id = get_session('ss_personalpay_id');
if (!$moid || ($session_order_id != $moid && $session_personalpay_id != $moid)) {
alert("요청한 주문번호가 틀려서 결제를 진행할수 없습니다.", G5_SHOP_URL);
}
$sql = " select * from {$g5['g5_shop_order_data_table']} where od_id = '$moid' and dt_pg = 'nicepay' ";
$row = sql_fetch($sql);
if (empty($row)) {
die('');
@@ -19,12 +30,12 @@ $data = unserialize(base64_decode($row['dt_data']));
if(isset($data['pp_id']) && $data['pp_id']) {
$order_action_url = G5_HTTPS_MSHOP_URL.'/personalpayformupdate.php';
$page_return_url = G5_SHOP_URL.'/personalpayform.php?pp_id='.$data['pp_id'];
} else {
$order_action_url = G5_HTTPS_MSHOP_URL.'/orderformupdate.php';
$page_return_url = G5_SHOP_URL.'/orderform.php';
if($_SESSION['ss_direct'])
$page_return_url .= '?sw_direct=1';
}
} else {
$order_action_url = G5_HTTPS_MSHOP_URL.'/orderformupdate.php';
$page_return_url = G5_SHOP_URL.'/orderform.php';
if(isset($_SESSION['ss_direct']) && $_SESSION['ss_direct'])
$page_return_url .= '?sw_direct=1';
}
$params = array();
$var_datas = array();
@@ -84,4 +95,4 @@ if ($authResultCode === '0000') {
// 실패시
alert('오류 : '.$authResultMsg.' 코드 : '.$authResultCode, $page_return_url);
}
}
+4 -3
View File
@@ -1617,9 +1617,6 @@ function pay_approval()
f.TaxFreeAmt.value = pf.comm_free_mny.value;
<?php } ?>
if (! nicepay_create_signdata(f)) {
return false;
}
<?php } ?>
// 주문 정보 임시저장
@@ -1646,6 +1643,10 @@ function pay_approval()
<?php } ?>
<?php if ($default['de_pg_service'] == 'nicepay') { ?>
if (! nicepay_create_signdata(f)) {
return false;
}
nicepayStart(f);
return false;
<?php } ?>
+4 -4
View File
@@ -305,10 +305,6 @@ function pay_approval()
f.TaxFreeAmt.value = pf.comm_free_mny.value;
<?php } ?>
if (! nicepay_create_signdata(f)) {
return false;
}
<?php } ?>
//var new_win = window.open("about:blank", "tar_opener", "scrollbars=yes,resizable=yes");
@@ -338,6 +334,10 @@ function pay_approval()
<?php } ?>
<?php if($default['de_pg_service'] == 'nicepay') { ?>
if (! nicepay_create_signdata(f)) {
return false;
}
nicepayStart(f);
return;