diff --git a/adm/shop_admin/configform.php b/adm/shop_admin/configform.php
index dea227d3d..27ef34840 100644
--- a/adm/shop_admin/configform.php
+++ b/adm/shop_admin/configform.php
@@ -13,8 +13,6 @@ if ($config['cf_sms_use'] && $config['cf_icode_id'] && $config['cf_icode_pw']) {
$userinfo = get_icode_userinfo($config['cf_icode_id'], $config['cf_icode_pw']);
}
-check_log_folder(G5_SHOP_PATH.'/inicis/key', false);
-
$g5['title'] = '쇼핑몰설정';
include_once (G5_ADMIN_PATH.'/admin.head.php');
@@ -68,8 +66,7 @@ if(!isset($default['de_pg_service'])) {
// inicis 필드 추가
if(!isset($default['de_inicis_mid'])) {
sql_query(" ALTER TABLE `{$g5['g5_shop_default_table']}`
- ADD `de_inicis_mid` varchar(255) NOT NULL DEFAULT '' AFTER `de_kcp_site_key`,
- ADD `de_inicis_admin_key` varchar(255) NOT NULL DEFAULT '' AFTER `de_inicis_mid` ", true);
+ ADD `de_inicis_mid` varchar(255) NOT NULL DEFAULT '' AFTER `de_kcp_site_key` ", true);
}
// 모바일 초기화면 이미지 줄 수 필드 추가
@@ -137,7 +134,7 @@ if(!isset($default['de_kakaopay_mid'])) {
// 이니시스 웹결제 사인키 필드 추가
if(!isset($default['de_inicis_sign_key'])) {
sql_query(" ALTER TABLE `{$g5['g5_shop_default_table']}`
- ADD `de_inicis_sign_key` varchar(255) NOT NULL DEFAULT '' AFTER `de_inicis_admin_key` ", true);
+ ADD `de_inicis_sign_key` varchar(255) NOT NULL DEFAULT '' ", true);
}
// 네이버페이 필드추가
@@ -202,6 +199,14 @@ if( ! isset($default['de_easy_pay_services']) ){
sql_query($sql, false);
}
+// KG 이니시스 iniapi_key 추가
+if( ! isset($default['de_inicis_iniapi_key']) ){
+ $sql = "ALTER TABLE `{$g5['g5_shop_default_table']}`
+ ADD COLUMN `de_inicis_iniapi_key` VARCHAR(30) NOT NULL DEFAULT '' AFTER `de_inicis_sign_key`,
+ ADD COLUMN `de_inicis_iniapi_iv` VARCHAR(30) NOT NULL DEFAULT '' AFTER `de_inicis_iniapi_key`; ";
+ sql_query($sql, false);
+}
+
if( function_exists('pg_setting_check') ){
pg_setting_check(true);
}
@@ -830,17 +835,24 @@ if(!$default['de_kakaopay_cancelpwd']){
- |
+ |
-
-
+ KG이니시스 가맹점관리자 > 상점정보 > 계약정보 > 부가정보의 웹결제 signkey생성 조회 버튼 클릭, 팝업창에서 생성 버튼 클릭 후 해당 값을 입력합니다."); ?>
+
|
- |
+ |
- 상점정보 > 계약정보 > 부가정보의 웹결제 signkey생성 조회 버튼 클릭, 팝업창에서 생성 버튼 클릭 후 해당 값을 입력합니다."); ?>
-
+ KG이니시스 가맹점관리자 > 상점정보 > 계약정보 > 부가정보 > INIAPI key 생성 조회 하여 KEY를 여기에 입력합니다.\n이 항목은 영카트 주문에서 kg이니시스 PG 결제 취소, 부분취소, 에스크로 배송등록, 현금영수증 발급에 필요합니다."); ?>
+
+ |
+
+
+ |
+
+ KG이니시스 가맹점관리자 > 상점정보 > 계약정보 > 부가정보 > INIAPI IV 생성 조회 하여 KEY를 여기에 입력합니다.\n이 항목은 영카트 주문에서 kg이니시스 현금영수증 발급에 필요합니다."); ?>
+
|
@@ -849,7 +861,7 @@ if(!$default['de_kakaopay_cancelpwd']){
삼성페이 서비스신청하기
- 삼성페이 사용 계약을 하신 경우에만 체크해주세요. (모바일 주문서 결제수단에 삼성페이가 노출됩니다.) 실결제시 반드시 결제대행사 KG이니시스 항목에 상점 아이디와 키패스워드를 입력해 주세요.", 50); ?>
+ 삼성페이 사용 계약을 하신 경우에만 체크해주세요. (모바일 주문서 결제수단에 삼성페이가 노출됩니다.) 실결제시 반드시 결제대행사 KG이니시스 항목에 상점 아이디와 웹결제 사인키를 입력해 주세요.", 50); ?>
>
|
@@ -858,7 +870,7 @@ if(!$default['de_kakaopay_cancelpwd']){
- 실결제시 반드시 결제대행사 KG이니시스 항목의 상점 정보( 아이디, 키패스워드, 웹결제 사인키 )를 입력해 주세요.", 50); ?>
+ 실결제시 반드시 결제대행사 KG이니시스 항목의 상점 정보( 아이디, 웹결제 사인키 )를 입력해 주세요.", 50); ?>
>
|
@@ -867,7 +879,7 @@ if(!$default['de_kakaopay_cancelpwd']){
- 실결제시 반드시 결제대행사 KG이니시스 항목의 상점 정보( 아이디, 키패스워드, 웹결제 사인키 )를 입력해 주세요.", 50); ?>
+ 실결제시 반드시 결제대행사 KG이니시스 항목의 상점 정보( 아이디, 웹결제 사인키 )를 입력해 주세요.", 50); ?>
>
|
@@ -2012,20 +2024,8 @@ if($default['de_iche_use'] || $default['de_vbank_use'] || $default['de_hp_use']
} catch(Exception $e) {
}
- if(!is_dir($log_path)) {
- echo ''.PHP_EOL;
- } else {
- if(!is_writable($log_path)) {
- echo ''.PHP_EOL;
- } else {
- if( function_exists('check_log_folder') && is_writable($log_path) ){
- check_log_folder($log_path);
- }
- }
+ if( function_exists('check_log_folder') && is_writable($log_path) ){
+ check_log_folder($log_path);
}
}
diff --git a/adm/shop_admin/configformupdate.php b/adm/shop_admin/configformupdate.php
index 96e13d9e4..72359169a 100644
--- a/adm/shop_admin/configformupdate.php
+++ b/adm/shop_admin/configformupdate.php
@@ -160,7 +160,8 @@ $check_sanitize_keys = array(
'cf_lg_mid', //LG유플러스 상점아이디
'cf_lg_mert_key', //LG유플러스 MERT KEY
'de_inicis_mid', //KG이니시스 상점아이디
-'de_inicis_admin_key', //KG이니시스 키패스워드
+'de_inicis_iniapi_key', //KG이니시스 INIAPI KEY
+'de_inicis_iniapi_iv', //KG이니시스 INIAPI IV
'de_inicis_sign_key', //KG이니시스 웹결제 사인키
'de_samsung_pay_use', //KG이니시스 삼성페이 사용
'de_inicis_lpay_use', //KG이니시스 Lpay 사용
@@ -399,7 +400,8 @@ $sql = " update {$g5['g5_shop_default_table']}
de_kcp_mid = '{$de_kcp_mid}',
de_kcp_site_key = '{$de_kcp_site_key}',
de_inicis_mid = '{$de_inicis_mid}',
- de_inicis_admin_key = '{$de_inicis_admin_key}',
+ de_inicis_iniapi_key = '{$de_inicis_iniapi_key}',
+ de_inicis_iniapi_iv = '{$de_inicis_iniapi_iv}',
de_inicis_sign_key = '{$de_inicis_sign_key}',
de_iche_use = '{$de_iche_use}',
de_sms_cont1 = '{$_POST['de_sms_cont1']}',
diff --git a/adm/shop_admin/orderformcartupdate.php b/adm/shop_admin/orderformcartupdate.php
index 8384ce849..43454803a 100644
--- a/adm/shop_admin/orderformcartupdate.php
+++ b/adm/shop_admin/orderformcartupdate.php
@@ -222,46 +222,27 @@ if (in_array($_POST['ct_status'], $status_cancel)) {
break;
case 'inicis':
include_once(G5_SHOP_PATH.'/settle_inicis.inc.php');
- $cancel_msg = iconv_euckr('쇼핑몰 운영자 승인 취소');
+ $cancel_msg = '쇼핑몰 운영자 승인 취소';
+
+ $args = array(
+ 'paymethod' => get_type_inicis_paymethod($od['od_settle_case']),
+ 'tid' => $od['od_tno'],
+ 'msg' => $cancel_msg
+ );
- /*********************
- * 3. 취소 정보 설정 *
- *********************/
- $inipay->SetField("type", "cancel"); // 고정 (절대 수정 불가)
- $inipay->SetField("mid", $default['de_inicis_mid']); // 상점아이디
- /**************************************************************************************************
- * admin 은 키패스워드 변수명입니다. 수정하시면 안됩니다. 1111의 부분만 수정해서 사용하시기 바랍니다.
- * 키패스워드는 상점관리자 페이지(https://iniweb.inicis.com)의 비밀번호가 아닙니다. 주의해 주시기 바랍니다.
- * 키패스워드는 숫자 4자리로만 구성됩니다. 이 값은 키파일 발급시 결정됩니다.
- * 키패스워드 값을 확인하시려면 상점측에 발급된 키파일 안의 readme.txt 파일을 참조해 주십시오.
- **************************************************************************************************/
- $inipay->SetField("admin", $default['de_inicis_admin_key']); //비대칭 사용키 키패스워드
- $inipay->SetField("tid", $od['od_tno']); // 취소할 거래의 거래아이디
- $inipay->SetField("cancelmsg", $cancel_msg); // 취소사유
+ $response = inicis_tid_cancel($args);
+ $result = json_decode($response, true);
- /****************
- * 4. 취소 요청 *
- ****************/
- $inipay->startAction();
-
- /****************************************************************
- * 5. 취소 결과 *
- * *
- * 결과코드 : $inipay->getResult('ResultCode') ("00"이면 취소 성공) *
- * 결과내용 : $inipay->getResult('ResultMsg') (취소결과에 대한 설명) *
- * 취소날짜 : $inipay->getResult('CancelDate') (YYYYMMDD) *
- * 취소시각 : $inipay->getResult('CancelTime') (HHMMSS) *
- * 현금영수증 취소 승인번호 : $inipay->getResult('CSHR_CancelNum') *
- * (현금영수증 발급 취소시에만 리턴됨) *
- ****************************************************************/
-
- $res_cd = $inipay->getResult('ResultCode');
- $res_msg = $inipay->getResult('ResultMsg');
-
- if($res_cd != '00') {
- $pg_res_cd = $res_cd;
- $pg_res_msg = iconv_utf8($res_msg);
+ if (isset($result['resultCode'])) {
+ if ($result['resultCode'] != '00') {
+ $pg_res_cd = $result['resultCode'];
+ $pg_res_msg = $result['resultMsg'];
+ }
+ } else {
+ $pg_res_cd = '';
+ $pg_res_msg = 'curl 로 데이터를 받지 못했습니다.';
}
+
break;
case 'KAKAOPAY':
include_once(G5_SHOP_PATH.'/settle_kakaopay.inc.php');
diff --git a/install/gnuboard5shop.sql b/install/gnuboard5shop.sql
index 74b2d23f8..dd8410e6b 100644
--- a/install/gnuboard5shop.sql
+++ b/install/gnuboard5shop.sql
@@ -349,7 +349,8 @@ CREATE TABLE IF NOT EXISTS `g5_shop_default` (
`de_kcp_mid` varchar(255) NOT NULL DEFAULT '',
`de_kcp_site_key` varchar(255) NOT NULL DEFAULT '',
`de_inicis_mid` varchar(255) NOT NULL DEFAULT '',
- `de_inicis_admin_key` varchar(255) NOT NULL DEFAULT '',
+ `de_inicis_iniapi_key` varchar(30) NOT NULL DEFAULT '',
+ `de_inicis_iniapi_iv` varchar(30) NOT NULL DEFAULT '',
`de_inicis_sign_key` varchar(255) NOT NULL DEFAULT '',
`de_iche_use` tinyint(4) NOT NULL DEFAULT '0',
`de_easy_pay_use` tinyint(4) NOT NULL DEFAULT '0',
diff --git a/mobile/shop/settle_inicis.inc.php b/mobile/shop/settle_inicis.inc.php
index 503e165c7..d8d7e0459 100644
--- a/mobile/shop/settle_inicis.inc.php
+++ b/mobile/shop/settle_inicis.inc.php
@@ -14,12 +14,10 @@ if ($default['de_card_test']) {
if ($default['de_escrow_use'] == 1) {
// 에스크로결제 테스트
$default['de_inicis_mid'] = 'iniescrow0';
- $default['de_inicis_admin_key'] = '1111';
}
else {
// 일반결제 테스트
$default['de_inicis_mid'] = 'INIpayTest';
- $default['de_inicis_admin_key'] = '1111';
}
}
else {
@@ -109,6 +107,8 @@ $inicis_cardpoint = $default['de_inicis_cartpoint_use'] ? '&cp_yn=Y' : '';
// 예) BC 2,3,6개월, 국민 3,6개월, 삼성 6,9개월 무이자 : 11-2:3:6^06-3:6^12-3:6:4
//$inicis_cardpoint .= ''; // &merc_noint=Y&noint_quota=카드사코드-개월:개월^추가카드사코드-개월:개월:개월 형식으로 설정
+require_once(G5_SHOP_PATH.'/inicis/libs/inicis_youngcart_fn.php');
+
$noti_url = G5_MSHOP_URL.'/inicis/settle_common.php';
$next_url = G5_MSHOP_URL.'/inicis/pay_approval.php';
$return_url = G5_MSHOP_URL.'/inicis/pay_return.php?oid=';
\ No newline at end of file
diff --git a/shop/inicis/escrow.register.php b/shop/inicis/escrow.register.php
index 33c1ae801..18420f9fb 100644
--- a/shop/inicis/escrow.register.php
+++ b/shop/inicis/escrow.register.php
@@ -5,27 +5,12 @@ if($od['od_pg'] != 'inicis') return;
include_once(G5_SHOP_PATH.'/settle_inicis.inc.php');
-$oid = $od['od_id'];
-$EscrowType = 'I';
-$invoice = $escrow_numb;
-$dlv_charge = 'SH'; // 배송비 지급형태 (SH : 판매자부담, BH : 구매자부담)
-$sendName = iconv_euckr($od['od_name']);
-$sendPost = $od['od_zip1'].$od['od_zip2'];
-$sendAddr1 = iconv_euckr($od['od_addr1']);
-$sendAddr2 = iconv_euckr($od['od_addr2']);
-$sendTel = $od['od_tel'];
-$recvName = iconv_euckr($od['od_b_name']);
-$recvPost = $od['od_b_zip1'].$od['od_b_zip2'];
-$recvAddr = iconv_euckr($od['od_b_addr1'].($od['od_b_addr2'] ? ' ' : '').$od['od_b_addr2']);
-$recvTel = $od['od_b_tel'];
-$price = $od['od_receipt_price'];
-
-// 택배회사 코드
+// 택배회사 코드, https://manual.inicis.com/iniweb/code.html 에서 조회
$exCode = array(
'대한통운' => 'korex',
'아주택배' => 'ajutb',
'KT로지스' => 'ktlogistics',
- '현대택배' => 'hyundai',
+ '롯데택배(구.현대)' => 'hyundai',
'CJ대한통운' => 'cjgls',
'한진택배' => 'hanjin',
'트라넷' => 'tranet',
@@ -39,76 +24,109 @@ $exCode = array(
'동부택배' => 'dongbu',
'우체국' => 'EPOST',
'우편등기' => 'registpost',
+ '경동택배' => 'kdexp',
+ '천일택배' => 'chunil',
+ '대신택배' => 'daesin',
+ '일양로지스' => 'ilyang',
+ '호남택배' => 'honam',
+ '편의점택배' => 'cvsnet',
+ '합동택배' => 'hdexp',
'기타택배' => '9999'
);
-$dlv_exName = $escrow_corp;
-$dlv_exCode = $exCode[$dlv_exName];
-if(!$dlv_exCode)
- $dlv_exCode = '9999';
+//step1. 요청을 위한 파라미터 설정
+// 가맹점관리자 > 상점정보 > 계약정보 > 부가정보 > INIAPI key 생성조회
+if (function_exists('get_inicis_iniapi_key')) {
+ $key = get_inicis_iniapi_key();
+} else {
+ $key = ! $default['de_card_test'] ? $default['de_inicis_iniapi_key'] : "ItEQKi3rY7uvDS8l";
+}
-/*********************
- * 3. 지불 정보 설정 *
- *********************/
-$inipay->SetField("tid", $escrow_tno); // 거래아이디
-$inipay->SetField("mid", $default['de_inicis_mid']); // 상점아이디
-/**************************************************************************************************
- * admin 은 키패스워드 변수명입니다. 수정하시면 안됩니다. 1111의 부분만 수정해서 사용하시기 바랍니다.
- * 키패스워드는 상점관리자 페이지(https://iniweb.inicis.com)의 비밀번호가 아닙니다. 주의해 주시기 바랍니다.
- * 키패스워드는 숫자 4자리로만 구성됩니다. 이 값은 키파일 발급시 결정됩니다.
- * 키패스워드 값을 확인하시려면 상점측에 발급된 키파일 안의 readme.txt 파일을 참조해 주십시오.
- **************************************************************************************************/
-$inipay->SetField("admin", $default['de_inicis_admin_key']); // 키패스워드(상점아이디에 따라 변경)
-$inipay->SetField("type", "escrow"); // 고정 (절대 수정 불가)
-$inipay->SetField("escrowtype", "dlv"); // 고정 (절대 수정 불가)
-$inipay->SetField("dlv_ip", getenv("REMOTE_ADDR")); // 고정
+$dlv_exName = $escrow_corp;
+$type = "Dlv"; //"Dlv" 고정
+$mid = $default['de_inicis_mid'];
+$clientIp = $_SERVER['SERVER_ADDR']; // 가맹점 요청 서버IP, 상점 임의 설정 가능 (상점측 서버 구분을 위함)
+$timestamp = date("YmdHis");
+$tid = $escrow_tno; //에스크로 결제 승인TID
+$oid = $od['od_id'];
+$price = $od['od_receipt_price'];
+$report = "I"; //에스크로 등록형태 ["I":등록, "U":변경]
+$invoice = $escrow_numb; //운송장번호
+$registName = $member['mb_id'];
+$exCode = isset($exCode[$dlv_exName]) ? $exCode[$dlv_exName] : ''; //택배사코드 참고(https://manual.inicis.com/code/#gls)
+$exName = $dlv_exName;
+$charge = "SH"; //배송비 지급형태 ("SH":판매자부담, "BH":구매자부담)
+$invoiceDay = G5_TIME_YMDHIS; //배송등록 확인일자 (String 으로 timestamp 사용 가능)
+$sendName = $od['od_name'];
+$sendTel = $od['od_tel'];
+$sendPost = $od['od_zip1'].$od['od_zip2'];
+$sendAddr1 = $od['od_addr1'].' '.$od['od_addr2'];
+$recvName = $od['od_b_name'];
+$recvTel = $od['od_b_tel'];
+$recvPost = $od['od_b_zip1'].$od['od_b_zip2'];
+$recvAddr = $od['od_b_addr1'].($od['od_b_addr2'] ? ' ' : '').$od['od_b_addr2'];
-$inipay->SetField("oid", $oid);
-$inipay->SetField("soid", "1");
-//$inipay->SetField("dlv_date", $dlv_date);
-//$inipay->SetField("dlv_time", $dlv_time);
-$inipay->SetField("dlv_report", $EscrowType);
-$inipay->SetField("dlv_invoice", $invoice);
-$inipay->SetField("dlv_name", $member['mb_id']);
+if(!$exCode)
+ $exCode = '9999';
-$inipay->SetField("dlv_excode", $dlv_exCode);
-$inipay->SetField("dlv_exname", $dlv_exName);
-$inipay->SetField("dlv_charge", $dlv_charge);
+// hash => INIAPIKey + type + timestamp + clientIp + mid + oid + tid + price
+$plainText = (string)$key.(string)$type.(string)$timestamp.(string)$clientIp.(string)$mid.(string)$oid.(string)$tid.(string)$price;
-$inipay->SetField("dlv_invoiceday", G5_TIME_YMDHIS);
-$inipay->SetField("dlv_sendname", $sendName);
-$inipay->SetField("dlv_sendpost", $sendPost);
-$inipay->SetField("dlv_sendaddr1", $sendAddr1);
-$inipay->SetField("dlv_sendaddr2", $sendAddr2);
-$inipay->SetField("dlv_sendtel", $sendTel);
+// hash 암호화
+$hashData = hash("sha512", $plainText);
-$inipay->SetField("dlv_recvname", $recvName);
-$inipay->SetField("dlv_recvpost", $recvPost);
-$inipay->SetField("dlv_recvaddr", $recvAddr);
-$inipay->SetField("dlv_recvtel", $recvTel);
+//step2. key=value 로 post 요청
-$inipay->SetField("dlv_goodscode", $goodsCode);
-$inipay->SetField("dlv_goods", $goods);
-$inipay->SetField("dlv_goodscnt", $goodCnt);
-$inipay->SetField("price", $price);
-$inipay->SetField("dlv_reserved1", $reserved1);
-$inipay->SetField("dlv_reserved2", $reserved2);
-$inipay->SetField("dlv_reserved3", $reserved3);
+$data = array(
+ 'type' => $type,
+ 'mid' => $mid,
+ 'clientIp' => $clientIp,
+ 'timestamp' => $timestamp,
+ 'tid' => $tid,
+ 'oid' => $oid,
+ 'price' => $price,
+ 'report' => $report,
+ 'invoice' => $invoice,
+ 'registName' => $registName,
+ 'exCode' => $exCode,
+ 'exName' => $exName,
+ 'charge' => $charge,
+ 'invoiceDay' => $invoiceDay,
+ 'sendName' => $sendName,
+ 'sendTel' => $sendTel,
+ 'sendPost' => $sendPost,
+ 'sendAddr1' => $sendAddr1,
+ 'recvName' => $recvName,
+ 'recvTel' => $recvTel,
+ 'recvPost' => $recvPost,
+ 'recvAddr' => $recvAddr,
+ 'hashData'=> $hashData
+);
-$inipay->SetField("pgn", $pgn);
+// Request URL
+$url = "https://iniapi.inicis.com/api/v1/escrow";
-/*********************
- * 3. 배송 등록 요청 *
- *********************/
-$inipay->startAction();
+$ch = curl_init(); // curl 초기화
+curl_setopt($ch, CURLOPT_URL, $url); // 전송 URL 지정하기
+curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 요청 결과를 문자열로 반환
+curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); // connection timeout 10초
+curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); // POST data
+curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // (※ 로컬 테스트에서만 사용) 원격 서버의 인증서가 유효한지 검사 안함
+curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded; charset=utf-8')); // 전송헤더 설정
+curl_setopt($ch, CURLOPT_POST, 1); // post 전송
+
+$response = curl_exec($ch);
+curl_close($ch);
+//step3. 요청 결과
+$ini_result = json_decode($response, true);
+
/**********************
* 4. 배송 등록 결과 *
**********************/
- $tid = $inipay->GetResult("tid"); // 거래번호
- $resultCode = $inipay->GetResult("ResultCode"); // 결과코드 ("00"이면 지불 성공)
- $resultMsg = $inipay->GetResult("ResultMsg"); // 결과내용 (지불결과에 대한 설명)
- $dlv_date = $inipay->GetResult("DLV_Date");
- $dlv_time = $inipay->GetResult("DLV_Time");
\ No newline at end of file
+$resultCode = $ini_result['resultCode']; // 결과코드 ("00"이면 지불 성공)
+$resultMsg = $ini_result['resultMsg']; // 결과내용 (지불결과에 대한 설명)
+$dlv_date = $ini_result['resultDate'];
+$dlv_time = $ini_result['resultTime'];
\ No newline at end of file
diff --git a/shop/inicis/inipay_cancel.php b/shop/inicis/inipay_cancel.php
index 094fcc538..4c4849362 100644
--- a/shop/inicis/inipay_cancel.php
+++ b/shop/inicis/inipay_cancel.php
@@ -46,18 +46,16 @@ if($cancelFlag == "true")
sql_query($sql, false);
}
+
+ $ini_paymethod = get_type_inicis_paymethod($od_settle_case);
- $TID = $tno;
- $inipay->SetField("type", "cancel"); // 고정
- if( $default['de_inicis_admin_key'] ){
- $inipay->SetField("mid", $mid);
- $inipay->SetField("admin", $default['de_inicis_admin_key']);
- }
- $inipay->SetField("tid", $TID); // 고정
- $inipay->SetField("cancelmsg", "DB FAIL"); // 취소사유
- $inipay->startAction();
- if($inipay->GetResult('ResultCode') == "00")
- {
- $inipay->MakeTXErrMsg(MERCHANT_DB_ERR,"Merchant DB FAIL");
+ if ($ini_paymethod){
+ $args = array(
+ 'paymethod' => $ini_paymethod,
+ 'tid' => $tno,
+ 'msg' => 'DB FAIL' // 취소사유
+ );
+
+ $response = inicis_tid_cancel($args);
}
}
\ No newline at end of file
diff --git a/shop/inicis/key/.htaccess b/shop/inicis/key/.htaccess
deleted file mode 100644
index e42f31a18..000000000
--- a/shop/inicis/key/.htaccess
+++ /dev/null
@@ -1,2 +0,0 @@
-Order deny,allow
-Deny from all
\ No newline at end of file
diff --git a/shop/inicis/key/INIpayTest/keypass.enc b/shop/inicis/key/INIpayTest/keypass.enc
deleted file mode 100644
index d6583cb9a..000000000
--- a/shop/inicis/key/INIpayTest/keypass.enc
+++ /dev/null
@@ -1 +0,0 @@
-pm/4rSNJdLw=
diff --git a/shop/inicis/key/INIpayTest/mcert.pem b/shop/inicis/key/INIpayTest/mcert.pem
deleted file mode 100644
index 00ce5d78a..000000000
--- a/shop/inicis/key/INIpayTest/mcert.pem
+++ /dev/null
@@ -1,16 +0,0 @@
------BEGIN CERTIFICATE-----
-MIICmzCCAgQCAQAwDQYJKoZIhvcNAQEEBQAwgZUxCzAJBgNVBAYTAktSMRUwEwYD
-VQQIDAzrjIDtlZzrr7zqta0xDTALBgNVBAcTBG51bGwxGjAYBgNVBAoMESjso7wp
-7J2064uI7Iuc7IqkMQswCQYDVQQLEwJFQzETMBEGA1UEAxMKSU5JcGF5VGVzdDEi
-MCAGCgmSJomT8ixkAQMUEmx5dGFrNzFAaW5pY2lzLmNvbTAeFw0wNDAzMTUxMDAx
-MjNaFw0wNTAzMTUxMDAxMjNaMIGVMQswCQYDVQQGEwJLUjEVMBMGA1UECAwM64yA
-7ZWc66+86rWtMQ0wCwYDVQQHEwRudWxsMRowGAYDVQQKDBEo7KO8KeydtOuLiOyL
-nOyKpDELMAkGA1UECxMCRUMxEzARBgNVBAMTCklOSXBheVRlc3QxIjAgBgoJkiaJ
-k/IsZAEDFBJseXRhazcxQGluaWNpcy5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0A
-MIGJAoGBAP6a/WaRyDMxHDgKHtahbZTnv+cayR0b052y2sCAGdgMc6CK0GxyvudV
-KR7mltKhexur/ikaPKXXApK+SlXUvwNS7pdQ13BTNCeLlEg0WLjGoVi9n96AcjR/
-QqlmkFaVAQQe9X95uwAcCoIrkErrpFJNPhppTXfsPH8YpzegogPnAgMBAAEwDQYJ
-KoZIhvcNAQEEBQADgYEAvmKuNAD7oPxOfRxj1EyBrKt2YdrhzMTvZXz7IIGCeKf0
-tsAKiuxuh20i6zWbD4N+twZvDYG23DFBsLb5Iw3pft5RK9OOVZJ8+ChAaDFHBa4a
-RzLDmsdD9NsF7UfYb0KXFUnZMTW5ZKirWUq21MdQiqVNhuLs0zy2hAqABBwhICk=
------END CERTIFICATE-----
diff --git a/shop/inicis/key/INIpayTest/mpriv.pem b/shop/inicis/key/INIpayTest/mpriv.pem
deleted file mode 100644
index 39f960a71..000000000
--- a/shop/inicis/key/INIpayTest/mpriv.pem
+++ /dev/null
@@ -1,18 +0,0 @@
------BEGIN RSA PRIVATE KEY-----
-Proc-Type: 4,ENCRYPTED
-DEK-Info: DES-EDE3-CBC,1E6B60D94624128F
-
-+9VjCYsbhvQIrQVWRmTV1dBc3HpHbjDrnwEu8znuxO9dgN7ZKKahSOo/iZv9tzWr
-SpEnbaGiRivO7/jTfJxgcy7wqjV+jYiwpBzL640JdOditUMoIxx3Rzxq+Dheuz13
-1dwt6f3d11zzXjIA5eQQXf1dBTjNCrxhAHqtHccWc5eP1QScQA+KdDAT+vQ6qTVq
-aZOI+7BkfWt5YMYBienXwEZSK5ZJ0GU91xSwDApIwsq7E7JGBExPIXGJeZ/RDAVN
-sKuO5Ny0JBNJN2Lym39Nb9lF0sKAedMiQNfaEnRqG37fh4H1ONo9NTYilENCIrg6
-tgYw/G9FrY8UvNLBsdUEUSV3bSqlRXZxP2TcPPrpYVbYZ1CQAH3fhVjAo9dpSNeI
-KuGv3x+JAkuJ+SjhANUU+ChOm27tF7scUxDTfwzTGfyB3P1UFHDwf0nWMU5cuJRY
-1+DLxEVL9FaZmonf5SZdf14Ln8a0cVdm+5rujFpFecSaw9K6gNFUvu6qF6CLx9/O
-UgcL90Ga+EvMG1iWyCFGvbr53r4i776JG+rVergIcgT5winvYpKiOS9AOV5NXPPI
-ev5PCXmDbnalmK6IrgrV0bAJD3d+NcN9JGFSx+GYKlw4OTrz/hxxuojPW6em4cfi
-mEIl5JIiLoC2BqM+Jcs8UMq0TOS8Pcki4O05H9Juws5nh6+d5d2p2BcvkXc+SWF7
-ClfjMZDaniMzPZr1dQj5XFZwptN6jATYL/4u1CpXYKi3N6TwHbOtQD/2l4e+DNPR
-JsSAW8ftyLAK0QJUTLhvA9Np9pzmO4hE7LfeRKBKpoU2PwKyXoO+PA==
------END RSA PRIVATE KEY-----
diff --git a/shop/inicis/key/INIpayTest/readme.txt b/shop/inicis/key/INIpayTest/readme.txt
deleted file mode 100644
index d7174692a..000000000
--- a/shop/inicis/key/INIpayTest/readme.txt
+++ /dev/null
@@ -1,10 +0,0 @@
-Ű ÆÄÀÏ 3°³ - mcert.pem, mpriv.pem, keypass.enc - ¸¦
-"key/{»óÁ¡¾ÆÀ̵ð}/" ·Î º¹»çÇϽÅ ÈÄ ÇÁ·α¥ ¼ҽºÀÇ ¼öÁ¤
-»çÇ×À» ¹ݿµÇϽʽÿÀ(¸º¾ó ÂüÁ¶).
-
-»óÁ¡¾ÆÀ̵ð : INIpayTest
-ŰÆнº¿öµå : 1111
-»óÁ¡ °ü¸® ½ÎÀÌƮ Æнº¿öµå : 1111
-
-»óÁ¡ °ü¸® ½ÎÀÌƮ´Â https://iniweb.inicis.comÀ̸ç,
-·α×ÀÎ ¾ÆÀ̵ð´Â »óÁ¡¾ÆÀ̵ðÀԴϴÙ.
diff --git a/shop/inicis/key/index.php b/shop/inicis/key/index.php
deleted file mode 100644
index e69de29bb..000000000
diff --git a/shop/inicis/key/iniescrow0/keypass.enc b/shop/inicis/key/iniescrow0/keypass.enc
deleted file mode 100644
index e4205d8ef..000000000
--- a/shop/inicis/key/iniescrow0/keypass.enc
+++ /dev/null
@@ -1 +0,0 @@
-pm/4rSNJdLw=
diff --git a/shop/inicis/key/iniescrow0/mcert.pem b/shop/inicis/key/iniescrow0/mcert.pem
deleted file mode 100644
index 77304aebd..000000000
--- a/shop/inicis/key/iniescrow0/mcert.pem
+++ /dev/null
@@ -1,17 +0,0 @@
------BEGIN CERTIFICATE-----
-MIICnTCCAgYCAQAwDQYJKoZIhvcNAQEEBQAwgZYxCzAJBgNVBAYTAktSMRUwEwYD
-VQQIDAzrjIDtlZzrr7zqta0xDTALBgNVBAcTBG51bGwxGjAYBgNVBAoMESjso7wp
-7J2064uI7Iuc7IqkMQswCQYDVQQLEwJFQzETMBEGA1UEAxMKaW5pZXNjcm93MDEj
-MCEGCgmSJomT8ixkAQMUE2RkYWVtaXJpQGluaWNpcy5jb20wHhcNMDgwMTE2MDQ0
-MTU1WhcNMDkwMTE1MDQ0MTU1WjCBljELMAkGA1UEBhMCS1IxFTATBgNVBAgMDOuM
-gO2VnOuvvOq1rTENMAsGA1UEBxMEbnVsbDEaMBgGA1UECgwRKOyjvCnsnbTri4js
-i5zsiqQxCzAJBgNVBAsTAkVDMRMwEQYDVQQDEwppbmllc2Nyb3cwMSMwIQYKCZIm
-iZPyLGQBAxQTZGRhZW1pcmlAaW5pY2lzLmNvbTCBnzANBgkqhkiG9w0BAQEFAAOB
-jQAwgYkCgYEAxElWzHNgDFZpwNvPGbWtA0PKTDPfeP1r7xE/k2n2XMzBFQFxbjSC
-EBKbQzFRVbNJv4Jyon/OzlywSR3A1DYMm5Oy9Vh3OOrH2FiYxMXClp7MynnmFEug
-ysHuYOHlMnoEfI5k8h9hIXlYbRFDLdY7IxVzqkaYJ37HX01Apuxo8sUCAwEAATAN
-BgkqhkiG9w0BAQQFAAOBgQCPrVeBW8+anq3CORMYU5TX1tfrYeCzLFH2hkDJF0Rr
-1xWxgjhdFZxtBtYSbxr3UKFe6/EWrlv7k37LoM8ORYcNZun+Rd1jz5xwTOjLBTsd
-UGwgUpgBLB1z9GoZgaeJJOm7BFUE0Jp7laI0zWkpWeova2RUT1PODnQMvRNi2d88
-vQ==
------END CERTIFICATE-----
diff --git a/shop/inicis/key/iniescrow0/mpriv.pem b/shop/inicis/key/iniescrow0/mpriv.pem
deleted file mode 100644
index ba54f77b2..000000000
--- a/shop/inicis/key/iniescrow0/mpriv.pem
+++ /dev/null
@@ -1,18 +0,0 @@
------BEGIN RSA PRIVATE KEY-----
-Proc-Type: 4,ENCRYPTED
-DEK-Info: DES-EDE3-CBC,FBB268FC75417BD4
-
-G4/3WRZg/9peL3ym0S2LsTWvFkSCT/Co+qcCeKBunQ1UPH/pVyQjW0oxtmjBpBfp
-YFNJmc5mEhwV30uKXLEYP6bhpHKlLDQWv926+UBIkSZ4cOkm9JNZUETlb+tlSgIN
-i5l5KLaX198rGlQAEYX+TxTaxlfXxoBiXkoqxs64Jn0RApy1SPTXKjLffXHP2Yk5
-q3jOZ4z4REdnmkH5NYuRHz6cyRr4XdmvPFMwBpzOL08go6yToYfYRvyO4hf2T1Kl
-ug1ws6e1HNSm1t3PrZP2kj1oIQef80/DQf9eu1mOP0VQD1GlQSydt2+kAdEBba4d
-FIlpO3oGCbCB1UhBOBCllFlXvd4sqj1inZhHS/g9R0vAwAPVpsssXYnWL2qnb+zj
-gfSyk+ao56sOBIwhyFXX9IdLcFKMGVQDrxZhDxVieStwk9iVK4zGZW+clS+TzFY7
-8qPDP53vXenumSnVq11Mj5gKwJzy40wGm61bQR1B5ldJJW7978Njahh0T0ZCxu48
-n5H0FbVu9wrILehWxEI5IrXAAGbRYDlurSSvHtOX1qL0WvJa4EQD9De3u8kqD3Yx
-soKJqII277UQBpPuyyE+eP1F+7i4cQdfCU31sK1LMz/wiJxRrG1CiOpV1FH22ABy
-vxAh1gpTRgYHvNVWG37P9rYbrW2UcM4cjhbgOzTLhrThxteAgosaXWowc/lcobSB
-G444RQXVPZEetqt2In2kBr7UmE2WuvM0CrC6sD336K2t0q/5HLPLntGozdadZ4F5
-OS8Oi8I9Ygiqwz95JSUaOfETGZ6RpGRJXL9ysimBeEDuQmQ2lxtkZA==
------END RSA PRIVATE KEY-----
diff --git a/shop/inicis/key/iniescrow0/readme.txt b/shop/inicis/key/iniescrow0/readme.txt
deleted file mode 100644
index f4b770416..000000000
--- a/shop/inicis/key/iniescrow0/readme.txt
+++ /dev/null
@@ -1,19 +0,0 @@
-
-please read this README.TXT file
-
-ZIP file contains following 3 files.
- - mcert.pem
- - mpriv.pem
- - keypass.enc
-
-Copy these 3 files to directory [key/iniescrow0].
-
-Merchant ID : iniescrow0
-Key Password : 1111
-Admin Password: 1111
-
-please visit https://iniweb.inicis.com
-for your Merchant Administration.
-This site provides your payment transaction details and account details by calculation period.
-
-You can also log on this site using your Merchant ID(iniescrow0).
diff --git a/shop/inicis/key/keypass.enc b/shop/inicis/key/keypass.enc
deleted file mode 100644
index e4205d8ef..000000000
--- a/shop/inicis/key/keypass.enc
+++ /dev/null
@@ -1 +0,0 @@
-pm/4rSNJdLw=
diff --git a/shop/inicis/key/mcert.pem b/shop/inicis/key/mcert.pem
deleted file mode 100644
index 70baf94e5..000000000
--- a/shop/inicis/key/mcert.pem
+++ /dev/null
@@ -1,17 +0,0 @@
------BEGIN CERTIFICATE-----
-MIICtDCCAhwCAQAwDQYJKoZIhvcNAQEEBQAwgaExCzAJBgNVBAYTAktSMRUwEwYD
-VQQIDAzrjIDtlZzrr7zqta0xDTALBgNVBAcTBG51bGwxJTAjBgNVBAoMHFNL7Luk
-666k64uI7LyA7J207IWY7KaIKOyjvCkxCzAJBgNVBAsTAkVDMRMwEQYDVQQDEwpD
-eXdvcmxkMDE0MSMwIQYKCZImiZPyLGQBAxQTc3VuZ21vY2tAaW5pY2lzLmNvbTAe
-Fw0wNzExMTIwNjExMzBaFw0wODExMTEwNjExMzBaMIGhMQswCQYDVQQGEwJLUjEV
-MBMGA1UECAwM64yA7ZWc66+86rWtMQ0wCwYDVQQHEwRudWxsMSUwIwYDVQQKDBxT
-S+y7pOuupOuLiOy8gOydtOyFmOymiCjso7wpMQswCQYDVQQLEwJFQzETMBEGA1UE
-AxMKQ3l3b3JsZDAxNDEjMCEGCgmSJomT8ixkAQMUE3N1bmdtb2NrQGluaWNpcy5j
-b20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAV0zuTBHq1SZWArRHCNz1jlU
-WUyTK3Gv6BGq3J6Tly/o6g51Nbjcu2TYMXLIhMgsqDPeJzOnXbSvnh3FWgAMcFm/
-EZEs9oKw+jkiPfIEeSc7KZThqDm1oG4FgJZrXim6Y3jlLLaW1h0WyapCV2u60759
-LX8YzmmFmUuXGZOb5s7DAgMBAAEwDQYJKoZIhvcNAQEEBQADgYIAAN4AumokztkK
-z5UBScG4Ccvu3nwcuFlCqzDUm9xnZyfy96RIjTJjVelkLwk6NFPqbDEyDLmHm6fe
-Zus+fvZBKQAyHigfuS/RVitcup52OkWCZerbcWsziX8Pzqb/MHu19Elt+y/QYe5x
-ysyIsZn47Bp+7kbQtlMjJecXGEFfmoi1
------END CERTIFICATE-----
diff --git a/shop/inicis/key/mpriv.pem b/shop/inicis/key/mpriv.pem
deleted file mode 100644
index 3d30395f3..000000000
--- a/shop/inicis/key/mpriv.pem
+++ /dev/null
@@ -1,18 +0,0 @@
------BEGIN RSA PRIVATE KEY-----
-Proc-Type: 4,ENCRYPTED
-DEK-Info: DES-EDE3-CBC,6B92FB59B7AB8A00
-
-NSplji6yUKrk1LXAid9TcBIOSkA+oE+5b52s7GaebioGsGSMIW7RrK8VHWlTOpxs
-GnFkTNg3ALZucdhYiAdm6vzaGmmJogoPnmpevs2JIDl3rkgcQH0AVU6nkKg9EcuP
-QP/2DknfqzNO46fTMjUIRSrJ7AauDz6836Mm3GVNl7cA42ecM7xHSVK3ZvCvpTrJ
-A9ik1zWZbzCIKg/mgMJkHu8xO8K9GKQAY1OM0KxK+oqS/Txmi6RplCHlrTAR+Ahb
-J3W8vG3tCu6orlczvPYEnB0a1E/dycDPziBFm6nVAk8cb+yPbZnl/Nqfu6nvPsSx
-iJYJR9YZ6L5i/IIhBc8tjNWeDB1KLsXZY41B//D/pjr9nfFUcJex8uPpOA0+GnGz
-EhDT8j/WMylgAxKKIYjFqE7HnMQ+n+ZZqLKO6JLdu3HHNz0QC7nz/SZtEMw/of4e
-1DlFHDTLTg0vJxwuLSBHVQN3H7SiFbxc/U5UmZEEVPprwbS9m0ok9JmBdfCv8iqu
-vuJiYc3HCdJaTRu0U3fJM33yr//BrZxXw0RjABePprcQDf590Vws8tygc/L5voF6
-lw8JYXuWKuRn4soNKwhrLL9YvQ0FNy1ITS2MpKGNYRPp5l3YCKO19y1dLMwrA33k
-SL1laFxrXLDaaE7MJZ8VD9hIymnn0aivtJHelW9DNoWJdI/DgTNKRhgT2TWBqR09
-VVCCKF3RLAQMvOFq/49A68px8/xHKxd6pYis/l8BONlZBMYRyIgjZ0IU81pmvHm+
-8UphsgRGx1ZvNtP0ApnTMF9DdpPN6vkxmpDWTe93HWJTp3TV1wyZPA==
------END RSA PRIVATE KEY-----
diff --git a/shop/inicis/key/pgcert.pem b/shop/inicis/key/pgcert.pem
deleted file mode 100644
index 745cd7c38..000000000
--- a/shop/inicis/key/pgcert.pem
+++ /dev/null
@@ -1,21 +0,0 @@
------BEGIN CERTIFICATE-----
-MIIDcTCCAtqgAwIBAgIBHjANBgkqhkiG9w0BAQQFADCBiDELMAkGA1UEBhMCS1Ix
-DjAMBgNVBAgTBVNlb3VsMRgwFgYDVQQKEw9JbmljaXMgQ28sIEx0ZC4xDzANBgNV
-BAsTBklOSXBheTEfMB0GA1UEAxMWSU5JcGF5IFBheW1lbnQgR2F0ZXdheTEdMBsG
-CSqGSIb3DQEJARYOZGV2QGluaWNpcy5jb20wHhcNMDcwOTA2MDYxNTI0WhcNMTcw
-OTAzMDYxNTI0WjCBiDELMAkGA1UEBhMCS1IxDjAMBgNVBAgTBVNlb3VsMRgwFgYD
-VQQKEw9JbmljaXMgQ28sIEx0ZC4xDzANBgNVBAsTBklOSXBheTEfMB0GA1UEAxMW
-SU5JcGF5IFBheW1lbnQgR2F0ZXdheTEdMBsGCSqGSIb3DQEJARYOZGV2QGluaWNp
-cy5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAOC8v1rxqoo7tonq7t4d
-c3FVfIlLyA9ku+l9+d5pUQrbiUXDe8NoJZnoSyud4WhOUrN2ZpzNmjGxuPquYrT/
-LkXoR+ib9OAhFBp7izstjHEA+oUNTVO24MRRvOHWWaLrCeTNX9PeaZl9ploojyHc
-Uxm5/gIlPEojiaWNc3HVnb55AgMBAAGjgegwgeUwHQYDVR0OBBYEFGgqMfJUMSUQ
-pjyGnurepI+NUf6JMIG1BgNVHSMEga0wgaqAFGgqMfJUMSUQpjyGnurepI+NUf6J
-oYGOpIGLMIGIMQswCQYDVQQGEwJLUjEOMAwGA1UECBMFU2VvdWwxGDAWBgNVBAoT
-D0luaWNpcyBDbywgTHRkLjEPMA0GA1UECxMGSU5JcGF5MR8wHQYDVQQDExZJTklw
-YXkgUGF5bWVudCBHYXRld2F5MR0wGwYJKoZIhvcNAQkBFg5kZXZAaW5pY2lzLmNv
-bYIBHjAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBAUAA4GBANUj8vYzU2Q9pebQ
-yX+6U9e36DeO/+15iDgU2PRK63uPaEa6vMqN2ibI8twolZB2t2oqIRgO44Hf3Nyf
-1XKNzCP1eRF1XreGOnrPZtJ5UeUs3RNBqvQkIAdSW80jkXw0i/7i95BYxRIJWSIE
-2fLjemy6r8gAQgWRAPv32F0xwRRT
------END CERTIFICATE-----
\ No newline at end of file
diff --git a/shop/inicis/key/readme.txt b/shop/inicis/key/readme.txt
deleted file mode 100644
index d8d53d59f..000000000
--- a/shop/inicis/key/readme.txt
+++ /dev/null
@@ -1,19 +0,0 @@
-
-please read this README.TXT file
-
-ZIP file contains following 3 files.
- - mcert.pem
- - mpriv.pem
- - keypass.enc
-
-Copy these 3 files to directory [key/Cyworld014].
-
-Merchant ID : Cyworld014
-Key Password : 1111
-Admin Password: 1111
-
-please visit https://iniweb.inicis.com
-for your Merchant Administration.
-This site provides your payment transaction details and account details by calculation period.
-
-You can also log on this site using your Merchant ID(Cyworld014).
diff --git a/shop/inicis/key/rndseed.binary b/shop/inicis/key/rndseed.binary
deleted file mode 100644
index 6d7bc5219..000000000
Binary files a/shop/inicis/key/rndseed.binary and /dev/null differ
diff --git a/shop/inicis/libs/INICls.php b/shop/inicis/libs/INICls.php
deleted file mode 100644
index 1909cd8c8..000000000
--- a/shop/inicis/libs/INICls.php
+++ /dev/null
@@ -1,1400 +0,0 @@
-debug_msg = array("", "CRITICAL", "ERROR", "NOTICE", "4", "INFO", "6", "DEBUG", "8");
- $this->debug_mode = $request["debug"];
- $this->type = $request["type"];
- $this->log = isset($request["log"]) ? $request["log"] : '';
- $this->homedir = $request["inipayhome"];
- $this->mid = $request["mid"];
- $this->starttime = GetMicroTime();
- $this->mergelog = isset($request["mergelog"]) ? $request["mergelog"] : '';
- }
-
- function StartLog() {
- if ($this->log == "false")
- return true;
-
- if ($this->type == "chkfake")
- $type = "securepay";
- else
- $type = $this->type;
- if ($this->mergelog == "1")
- $logfile = $this->homedir . "/log/" . PROGRAM . "_" . $type . "_mergelog_" . date("ymd") . ".log";
- else
- $logfile = $this->homedir . "/log/" . PROGRAM . "_" . $type . "_" . $this->mid . "_" . date("ymd") . ".log";
- $this->handle = fopen($logfile, "a+");
- if (!$this->handle)
- return false;
- $this->WriteLog(INFO, "START " . PROGRAM . " " . $this->type . " (" . VERSION . "-" . BUILDDATE . ")(OS:" . php_uname('s') . php_uname('r') . ",PHP:" . phpversion() . ")");
- return true;
- }
-
- function WriteLog($debug, $data) {
- if ($this->log == "false" || !$this->handle)
- return;
-
- if (!$this->debug_mode && $debug >= DEBUG)
- return;
-
- $pfx = $this->debug_msg[$debug] . "\t[" . SetTimestamp() . "] <" . getmypid() . "> ";
- if (is_array($data)) {
- foreach ($data as $key => $val) {
- fwrite($this->handle, $pfx . $key . ":" . $val . "\r\n");
- }
- } else {
- fwrite($this->handle, $pfx . $data . "\r\n");
- }
- fflush($this->handle);
- }
-
- function CloseLog($msg) {
- if ($this->log == "false")
- return;
-
- $laptime = GetMicroTime() - $this->starttime;
- $this->WriteLog(INFO, "END " . $this->type . " " . $msg . " Laptime:[" . round($laptime, 3) . "sec]");
- $this->WriteLog(INFO, "===============================================================");
- fclose($this->handle);
- }
-
-}
-
-/* ----------------------------------------------------- */
-/* Data Class */
-/* -TID Generate Function */
-/* -Data Encrypt Function */
-/* -Check Field Function */
-/* ----------------------------------------------------- */
-
-class INIData {
-
- //----------------------------
- //Common
- //----------------------------
- var $m_Type;
- var $m_EscrowType;
- var $m_ErrCode;
- var $m_ErrMsg;
- var $m_EncBody;
- var $m_PG1;
- var $m_PG2;
- var $m_PG1IP;
- var $m_PG2IP;
- //----------------------------
- //IFD 요청필드
- //----------------------------
- var $m_sCmd;
- var $m_sCrypto;
- var $m_sTID;
- var $m_sPayMethod;
- var $m_MPubSN;
- var $m_PIPGPubSN;
- var $m_TXPGPubSN;
- var $m_TXVersion;
- var $m_sMsg;
- var $m_sHead;
- var $m_sBody;
- var $m_sTail;
- var $m_sEncrypted;
- var $m_sSessionKey;
- //----------------------------
- //IFD 응답헤더 필드
- //----------------------------
- var $m_FlgCrypto;
- var $m_FlgSign;
- var $m_Cmd;
- var $m_Body;
- //Xml Data
- var $m_Xml = array();
- var $m_REQUEST = array();
- var $m_REQUEST2 = array(); //User Defined Entity
- var $m_RESULT = array(); //Encrypted 필드 hash table
- var $m_RESULT2 = array(); //PG Added Entity
-
- function __construct($request, $request2) {
- $this->m_Xml = NULL;
-
- $this->m_REQUEST = $request;
- $this->m_REQUEST2 = $request2;
-
- $this->m_Type = $this->m_REQUEST["type"];
- if ($this->m_Type == TYPE_SECUREPAY || $this->m_Type == TYPE_AUTH) {
- $this->m_sCmd = CMD_REQ_PAY;
- $this->m_sCrypto = FLAG_CRYPTO_RC4;
- } else if ($this->m_Type == TYPE_CANCEL) {
- $this->m_sCmd = CMD_REQ_CAN;
- $this->m_sCrypto = FLAG_CRYPTO_3DES;
- } else if ($this->m_Type == TYPE_INQUIRY) {
- $this->m_sCmd = CMS_REQ_INQR;
- $this->m_sCrypto = FLAG_CRYPTO_3DES;
- } else if ($this->m_Type == TYPE_OPENSUB) {
- $this->m_sCmd = CMS_REQ_OPEN_SUB;
- $this->m_sCrypto = FLAG_CRYPTO_3DES;
- }
- //가상계좌 부분환불 추가
- else if (( $this->m_Type == TYPE_REPAY) || ( $this->m_Type == TYPE_VACCTREPAY)) {
- $this->m_sCmd = CMD_REQ_PRTC;
- $this->m_sCrypto = FLAG_CRYPTO_3DES;
- } else if ($this->m_Type == TYPE_CAPTURE) {
- $this->m_sCmd = CMD_REQ_CAP;
- $this->m_sCrypto = FLAG_CRYPTO_3DES;
- } else if ($this->m_Type == TYPE_ESCROW) {
- $this->m_EscrowType = $this->m_REQUEST["escrowtype"];
- if ($this->m_EscrowType == TYPE_ESCROW_DLV) {
- $this->m_sCmd = CMD_REQ_DLV;
- $this->m_sCrypto = FLAG_CRYPTO_3DES;
- } else if ($this->m_EscrowType == TYPE_ESCROW_CNF) {
- parse_str($this->m_REQUEST["encrypted"]);
- if ($iniescr_type == "1") {//confirm
- $this->m_EscrowType = TYPE_ESCROW_CNF;
- $this->m_sCmd = CMD_REQ_CNF;
- $this->m_sCrypto = FLAG_CRYPTO_RC4;
- } else if ($iniescr_type == "2") {//deny
- $this->m_EscrowType = TYPE_ESCROW_DNY;
- $this->m_sCmd = CMD_REQ_DNY;
- $this->m_sCrypto = FLAG_CRYPTO_RC4;
- }
- } else if ($this->m_EscrowType == TYPE_ESCROW_DNY_CNF) {
- $this->m_sCmd = CMD_REQ_DNY_CNF;
- $this->m_sCrypto = FLAG_CRYPTO_3DES;
- }
- } else if ($this->m_Type == TYPE_REFUND) { //가상계좌환불(09.08.05)
- $this->m_sCmd = CMD_REQ_RFD;
- $this->m_sCrypto = FLAG_CRYPTO_3DES;
- } else {
- $this->m_sCmd = CMD_REQ_PAY;
- $this->m_sCrypto = FLAG_CRYPTO_3DES;
- }
- $this->m_sPayMethod = isset($this->m_REQUEST["paymethod"]) ? $this->m_REQUEST["paymethod"] : '';
-
- $this->m_TXVersion = sprintf("%-6.6s", VERSION) .
- sprintf("B%-8.8s", BUILDDATE) .
- sprintf("%-5.5s", $this->m_Type) .
- sprintf("%-10.10s", php_uname('s')) .
- sprintf("%-3.3s", "PHP") . //modulescript
- sprintf("%-10.10s", "chkfake") . //moduledesc
- sprintf("%-30.30s", php_uname('r') . "PHP:" . phpversion()) //ETCINFO
- ;
- }
-
- function CheckField() {
- //---------------------------------
- //공통
- //---------------------------------
- if (trim($this->m_REQUEST["inipayhome"]) == "") {
- $this->m_ErrCode = NULL_DIR_ERR;
- $this->m_ErrMsg = "inipayhome";
- return false;
- }
- if (trim($this->m_REQUEST["mid"]) == "") {
- $this->m_ErrCode = NULL_MID_ERR;
- $this->m_ErrMsg = "mid";
- return false;
- }
- if (trim($this->m_REQUEST["type"]) == "") {
- $this->m_ErrCode = NULL_TYPE_ERR;
- $this->m_ErrMsg = "type";
- return false;
- }
- if (trim($this->m_REQUEST["admin"]) == "") {
- $this->m_ErrCode = NULL_KEYPW_ERR;
- $this->m_ErrMsg = "admin";
- return false;
- }
- //---------------------------------
- //type별로
- //---------------------------------
- if ($this->m_Type == TYPE_SECUREPAY) {
- /*
- //delete UIP(2009.01.21)
- if( trim($this->m_REQUEST["uip"]) == "")
- {
- $this->m_ErrCode = NULL_UIP_ERR;
- $this->m_ErrMsg = "uip";
- return false;
- }
- */
- if (trim($this->m_REQUEST["url"]) == "") {
- $this->m_ErrCode = NULL_URL_ERR;
- $this->m_ErrMsg = "url";
- return false;
- }
- if (trim($this->m_REQUEST["price"]) == "") {
- $this->m_ErrCode = NULL_PRICE_ERR;
- $this->m_ErrMsg = "price";
- return false;
- }
- if (trim($this->m_REQUEST["currency"]) == "") {
- $this->m_ErrCode = NULL_CURRENCY_ERR;
- $this->m_ErrMsg = "currency";
- return false;
- }
- if (trim($this->m_REQUEST["paymethod"]) == "") {
- $this->m_ErrCode = NULL_PAYMETHOD_ERR;
- $this->m_ErrMsg = "paymethod";
- return false;
- }
- if (trim($this->m_REQUEST["goodname"]) == "") {
- $this->m_ErrCode = NULL_GOODNAME_ERR;
- $this->m_ErrMsg = "goodname";
- return false;
- }
- if (trim($this->m_REQUEST["buyername"]) == "") {
- $this->m_ErrCode = NULL_BUYERNAME_ERR;
- $this->m_ErrMsg = "buyername";
- return false;
- }
- if (trim($this->m_REQUEST["buyertel"]) == "") {
- $this->m_ErrCode = NULL_BUYERTEL_ERR;
- $this->m_ErrMsg = "buyertel";
- return false;
- }
- if (trim($this->m_REQUEST["buyeremail"]) == "") {
- $this->m_ErrCode = NULL_BUYEREMAIL_ERR;
- $this->m_ErrMsg = "buyeremail";
- return false;
- }
- if (trim($this->m_REQUEST["sessionkey"]) == "") {
- $this->m_ErrCode = NULL_SESSIONKEY_ERR;
- $this->m_ErrMsg = "sessionkey";
- return false;
- }
- if (trim($this->m_REQUEST["encrypted"]) == "") {
- $this->m_ErrCode = NULL_ENCRYPTED_ERR;
- $this->m_ErrMsg = "encrypted";
- return false;
- }
- } else if ($this->m_Type == TYPE_CANCEL) {
- if (trim($this->m_REQUEST["tid"]) == "") {
- $this->m_ErrCode = NULL_TID_ERR;
- $this->m_ErrMsg = "tid";
- return false;
- }
- }
- //가상계좌 부분환불도 부분환불 로직에 추가
- else if (( $this->m_Type == TYPE_REPAY ) || ( $this->m_Type == TYPE_VACCTREPAY )) {
- if (trim($this->m_REQUEST["oldtid"]) == "") {
- $this->m_ErrCode = NULL_TID_ERR;
- $this->m_ErrMsg = "oldtid";
- return false;
- }
- if (trim($this->m_REQUEST["price"]) == "") {
- $this->m_ErrCode = NULL_PRICE_ERR;
- $this->m_ErrMsg = "price";
- return false;
- }
- if (trim($this->m_REQUEST["confirm_price"]) == "") {
- $this->m_ErrCode = NULL_CONFIRM_PRICE_ERR;
- $this->m_ErrMsg = "confirm_price";
- return false;
- }
-
- //가상계좌 부분환불 로직에서는 계조번호,은행코드,계좌주명이 필수
- if ($this->m_Type == TYPE_VACCTREPAY) {
- if (trim($this->m_REQUEST["refundacctnum"]) == "") {
- $this->m_ErrCode = NULL_FIELD_REFUNDACCTNUM;
- $this->m_ErrMsg = "환불계좌번호";
- return false;
- }
- if (trim($this->m_REQUEST["refundbankcode"]) == "") {
- $this->m_ErrCode = NULL_FIELD_REFUNDBANKCODE;
- $this->m_ErrMsg = "환불은행코드";
- return false;
- }
- if (trim($this->m_REQUEST["refundacctname"]) == "") {
- $this->m_ErrCode = NULL_FIELD_REFUNDACCTNAME;
- $this->m_ErrMsg = "환불계좌주성명";
- return false;
- }
- }
- } else if ($this->m_Type == TYPE_CHKFAKE) {
- if (trim($this->m_REQUEST["nointerest"]) == "") {
- $this->m_ErrCode = NULL_NOINTEREST_ERR;
- $this->m_ErrMsg = "nointerest";
- return false;
- }
- if (trim($this->m_REQUEST["quotabase"]) == "") {
- $this->m_ErrCode = NULL_QUOTABASE_ERR;
- $this->m_ErrMsg = "quotabase";
- return false;
- }
- } else if ($this->m_Type == TYPE_REFUND) {
- if (trim($this->m_REQUEST["tid"]) == "") {
- $this->m_ErrCode = NULL_TID_ERR;
- $this->m_ErrMsg = "tid";
- return false;
- }
- if (trim($this->m_REQUEST["racctnum"]) == "") {
- $this->m_ErrCode = NULL_FIELD_REFUNDACCTNUM;
- $this->m_ErrMsg = "환불계좌번호";
- return false;
- }
- if (trim($this->m_REQUEST["rbankcode"]) == "") {
- $this->m_ErrCode = NULL_FIELD_REFUNDBANKCODE;
- $this->m_ErrMsg = "환불은행코드";
- return false;
- }
- if (trim($this->m_REQUEST["racctname"]) == "") {
- $this->m_ErrCode = NULL_FIELD_REFUNDACCTNAME;
- $this->m_ErrMsg = "환불계좌주성명";
- return false;
- }
- }
- return true;
- }
-
- function MakeRN() {
- list($usec, $sec) = explode(" ", microtime());
- $datestr = date("YmdHis", $sec) . substr($usec, 2, 3); //YYYYMMDDHHMMSSSSS
- return Base64Encode($datestr . rand(10000, 99999));
- }
-
- function MakeTID() {
- list($usec, $sec) = explode(" ", microtime());
- $datestr = date("YmdHis", $sec) . substr($usec, 2, 3); //YYYYMMDDHHMMSSSSS
-
- $datestr_con = substr($datestr, 0, 14) . substr($datestr, 15, 2); //YYYYMMDDHHMMSSxSS 중간의 x값은 버림(milli second의 첫번째 자리수)
-
- mt_srand(getmypid() * mt_rand(1, 999)); //mt_rand 하기전에 srand 로 seed 적용 , seed key = pid * mt_rand(1,999)
- //pgid + mid + 16자리 날짜및 시간 + random_key 4자리 (seed적용)
- $this->m_sTID = $this->m_REQUEST["pgid"] . $this->m_REQUEST["mid"] . $datestr_con . mt_rand(1000, 9999);
- if (strlen($this->m_sTID) != TID_LEN) {
- return false;
- }
- $this->m_REQUEST["tid"] = $this->m_sTID;
- return true;
- }
-
- function GenRand($length, $nullOk, $ascii = false) {
- # mt_srand( 99999 );
- $out = '';
- for ($i = 0; $i < $length; $i++)
- $out .= chr(mt_rand($nullOk ? 0 : 1, $ascii ? 127 : 255 ));
- return $out;
- }
-
- function MakeEncrypt($INICrypto) {
- //generate key/iv
- $key = $this->GenRand(MAX_KEY_LEN, true);
- $iv = $this->GenRand(MAX_IV_LEN, true);
-
- //make XML
- $xml = new XML();
- if ($this->m_Type == TYPE_FORMPAY) {
-
- } else if ($this->m_Type == TYPE_RECEIPT) {
- $PI = $xml->add_node("", PAYMENTINFO);
- $PM = $xml->add_node($PI, PAYMENT);
- $CS = $xml->add_node($PM, NM_CSHR);
- $PD = $xml->add_node($CS, TX_CSHR_APPLPRICE, $this->m_REQUEST["cr_price"]);
- $PD = $xml->add_node($CS, TX_CSHR_SUPPLYPRICE, $this->m_REQUEST["sup_price"]);
- $PD = $xml->add_node($CS, TX_CSHR_TAX, $this->m_REQUEST["tax"]);
- $PD = $xml->add_node($CS, TX_CSHR_SERVICEPRICE, $this->m_REQUEST["srvc_price"]);
- $PD = $xml->add_node($CS, TX_CSHR_TYPE, $this->m_REQUEST["useopt"]);
- $PD = $xml->add_node($CS, TX_CSHR_REGNUM, $this->m_REQUEST["reg_num"]);
- $PD = $xml->add_node($CS, TX_CSHR_COMPANYNUM, $this->m_REQUEST["companynumber"]);
- /*
- $PD = $xml->add_node($CS, TX_CSHR_OPENMARKET, $this->m_REQUEST[""] );
- $PD = $xml->add_node($CS, TX_CSHR_SUBCNT, $this->m_REQUEST[""] );
- $PD = $xml->add_node($CS, TX_CSHR_SUBCOMPANYNAME1, $this->m_REQUEST[""] );
- $PD = $xml->add_node($CS, TX_CSHR_SUBCOMPANYNUM1, $this->m_REQUEST[""] );
- $PD = $xml->add_node($CS, TX_CSHR_SUBREGNUM1, $this->m_REQUEST[""] );
- $PD = $xml->add_node($CS, TX_CSHR_SUBMID1, $this->m_REQUEST[""] );
- $PD = $xml->add_node($CS, TX_CSHR_SUBAPPLPRICE1, $this->m_REQUEST[""] );
- $PD = $xml->add_node($CS, TX_CSHR_SUBSERVICEPRICE1, $this->m_REQUEST[""] );
- */
- } else if ($this->m_Type == TYPE_CANCEL) {
- $cancelcode = isset($this->m_REQUEST["cancelcode"]) ? $this->m_REQUEST["cancelcode"] : '';
-
- $CI = $xml->add_node("", CANCELINFO);
- $CD = $xml->add_node($CI, TX_CANCELTID, $this->m_REQUEST["tid"]);
- $CD = $xml->add_node($CI, TX_CANCELMSG, $this->m_REQUEST["cancelmsg"], array("urlencode" => "1"));
- $CD = $xml->add_node($CI, TX_CANCELREASON, $cancelcode);
-
- $node_racctnum = isset($this->m_REQUEST["racctnum"]) ? $this->m_REQUEST["racctnum"] : '';
- $node_rbankcode = isset($this->m_REQUEST["rbankcode"]) ? $this->m_REQUEST["rbankcode"] : '';
- $node_racctname = isset($this->m_REQUEST["racctname"]) ? $this->m_REQUEST["racctname"] : '';
-
- //휴대폰 익월환불 추가
- $CD = $xml->add_node($CI, TX_REFUNDACCTNUM, $node_racctnum);
- $CD = $xml->add_node($CI, TX_REFUNDBANKCODE, $node_rbankcode);
- $CD = $xml->add_node($CI, TX_REFUNDACCTNAME, $node_racctname, array("urlencode" => "1"));
-
- $this->AddUserDefinedEntity(CANCELINFO, "", $xml, $CI);
- } else if ($this->m_Type == TYPE_REPAY) {
- //PartCancelInfo(ROOT)
- $CI = $xml->add_node("", PARTCANCELINFO);
- $CD = $xml->add_node($CI, TX_PRTC_TID, $this->m_REQUEST["oldtid"]);
- $CD = $xml->add_node($CI, TX_PRTC_PRICE, $this->m_REQUEST["price"]);
- $CD = $xml->add_node($CI, TX_PRTC_REMAINS, $this->m_REQUEST["confirm_price"]);
- $CD = $xml->add_node($CI, TX_PRTC_QUOTA, $this->m_REQUEST["cardquota"]);
- $CD = $xml->add_node($CI, TX_PRTC_INTEREST, $this->m_REQUEST["quotainterest"]);
- //I계좌이체 국민은행 부분취소시 계좌번호 계좌주성명을 받음 2011-10-06
- $CD = $xml->add_node($CI, TX_PRTC_NOACCT, $this->m_REQUEST["no_acct"]);
- $CD = $xml->add_node($CI, TX_PRTC_NMACCT, $this->m_REQUEST["nm_acct"], array("urlencode" => "1"));
- //과세,비과세 추가 2014-07-23 by jung.ks
- //$CD = $xml->add_node($CI, TX_PRTC_TAX, $this->m_REQUEST["tax"] );
- //$CD = $xml->add_node($CI, TX_PRTC_TAXFREE, $this->m_REQUEST["taxfree"] );
-
- $this->AddUserDefinedEntity(PARTCANCELINFO, "", $xml, $CI);
- }
- //가상계좌 부분환불
- else if ($this->m_Type == TYPE_VACCTREPAY) {
- //PartCancelInfo(ROOT)
- $CI = $xml->add_node("", PARTCANCELINFO);
- $CD = $xml->add_node($CI, TX_PRTC_TID, $this->m_REQUEST["oldtid"]);
- $CD = $xml->add_node($CI, TX_PRTC_PRICE, $this->m_REQUEST["price"]);
- $CD = $xml->add_node($CI, TX_PRTC_REMAINS, $this->m_REQUEST["confirm_price"]);
- $CD = $xml->add_node($CI, TX_PRTC_QUOTA, $this->m_REQUEST["cardquota"]);
- $CD = $xml->add_node($CI, TX_PRTC_INTEREST, $this->m_REQUEST["quotainterest"]);
- $CD = $xml->add_node($CI, TX_PRTC_NOACCT, $this->m_REQUEST["refundacctnum"]);
- $CD = $xml->add_node($CI, TX_PRTC_NMACCT, $this->m_REQUEST["refundacctname"], array("urlencode" => "1"));
- $CD = $xml->add_node($CI, TX_PRTC_REFUNDFLGREMIT, $this->m_REQUEST["refundflgremit"]);
- $CD = $xml->add_node($CI, TX_PRTC_REFUNDBANKCODE, $this->m_REQUEST["refundbankcode"]);
- $this->AddUserDefinedEntity(PARTCANCELINFO, "", $xml, $CI);
- } else if ($this->m_Type == TYPE_CAPTURE) {
- $CI = $xml->add_node("", CAPTUREINFO);
- $CD = $xml->add_node($CI, TX_CAPTURETID, $this->m_REQUEST["tid"]);
- $this->AddUserDefinedEntity(CAPTUREINFO, "", $xml, $CI);
- } else if ($this->m_Type == TYPE_ESCROW) {
- if ($this->m_EscrowType == TYPE_ESCROW_DLV) {
- $EI = $xml->add_node("", ESCROWINFO);
- $EC = $xml->add_node($EI, ESCROW_DELIVERY);
- $ED = $xml->add_node($EC, "DLV_Oid", $this->m_REQUEST["oid"], array("urlencode" => "1"));
- $ED = $xml->add_node($EC, "DLV_SOid", $this->m_REQUEST["soid"], array("urlencode" => "1"));
- $ED = $xml->add_node($EC, "DLV_Name", $this->m_REQUEST["dlv_name"], array("urlencode" => "1"));
- $ED = $xml->add_node($EC, "DLV_IP", $this->m_REQUEST["dlv_ip"], array("urlencode" => "1"));
- $ED = $xml->add_node($EC, "DLV_MAC", $this->m_REQUEST["dlv_mac"], array("urlencode" => "1"));
- $ED = $xml->add_node($EC, "DLV_Report", $this->m_REQUEST["dlv_report"], array("urlencode" => "1"));
- $ED = $xml->add_node($EC, "DLV_SendName", $this->m_REQUEST["dlv_sendname"], array("urlencode" => "1"));
- $ED = $xml->add_node($EC, "DLV_SendPost", $this->m_REQUEST["dlv_sendpost"], array("urlencode" => "1"));
- $ED = $xml->add_node($EC, "DLV_SendAddr1", $this->m_REQUEST["dlv_sendaddr1"], array("urlencode" => "1"));
- $ED = $xml->add_node($EC, "DLV_SendAddr2", $this->m_REQUEST["dlv_sendaddr2"], array("urlencode" => "1"));
- $ED = $xml->add_node($EC, "DLV_SendTel", $this->m_REQUEST["dlv_sendtel"], array("urlencode" => "1"));
- $ED = $xml->add_node($EC, "DLV_RecvName", $this->m_REQUEST["dlv_recvname"], array("urlencode" => "1"));
- $ED = $xml->add_node($EC, "DLV_RecvPost", $this->m_REQUEST["dlv_recvpost"], array("urlencode" => "1"));
- $ED = $xml->add_node($EC, "DLV_RecvAddr", $this->m_REQUEST["dlv_recvaddr"], array("urlencode" => "1"));
- $ED = $xml->add_node($EC, "DLV_RecvTel", $this->m_REQUEST["dlv_recvtel"], array("urlencode" => "1"));
- $ED = $xml->add_node($EC, "DLV_ExCode", $this->m_REQUEST["dlv_excode"], array("urlencode" => "1"));
- $ED = $xml->add_node($EC, "DLV_ExName", $this->m_REQUEST["dlv_exname"], array("urlencode" => "1"));
- $ED = $xml->add_node($EC, "DLV_Invoice", $this->m_REQUEST["dlv_invoice"], array("urlencode" => "1"));
- $ED = $xml->add_node($EC, "DLV_Charge", $this->m_REQUEST["dlv_charge"], array("urlencode" => "1"));
- $ED = $xml->add_node($EC, "DLV_InvoiceDay", $this->m_REQUEST["dlv_invoiceday"], array("urlencode" => "1"));
- $ED = $xml->add_node($EC, "DLV_GoodsCode", $this->m_REQUEST["dlv_goodscode"], array("urlencode" => "1"));
- $ED = $xml->add_node($EC, "DLV_Goods", $this->m_REQUEST["dlv_goods"], array("urlencode" => "1"));
- $ED = $xml->add_node($EC, "DLV_GoodsCnt", $this->m_REQUEST["dlv_goodscnt"], array("urlencode" => "1"));
- $ED = $xml->add_node($EC, "DLV_Price", $this->m_REQUEST["price"], array("urlencode" => "1"));
- $ED = $xml->add_node($EC, "DLV_Reserved1", $this->m_REQUEST["dlv_reserved1"], array("urlencode" => "1"));
- $ED = $xml->add_node($EC, "DLV_Reserved2", $this->m_REQUEST["dlv_reserved2"], array("urlencode" => "1"));
- $ED = $xml->add_node($EC, "DLV_Reserved3", $this->m_REQUEST["dlv_reserved3"], array("urlencode" => "1"));
- } else if ($this->m_EscrowType == TYPE_ESCROW_CNF) {
- //PluginIn!!
- } else if ($this->m_EscrowType == TYPE_ESCROW_DNY) {
- //PluginIn!!
- } else if ($this->m_EscrowType == TYPE_ESCROW_DNY_CNF) {
- $EI = $xml->add_node("", ESCROWINFO);
- $EC = $xml->add_node($EI, ESCROW_DENYCONFIRM);
- $ED = $xml->add_node($EC, "DCNF_Name", $this->m_REQUEST["dcnf_name"], array("urlencode" => "1"));
- }
- } else if ($this->m_Type == TYPE_REFUND) {
- $CI = $xml->add_node("", CANCELINFO);
- $CD = $xml->add_node($CI, TX_CANCELTID, $this->m_REQUEST["tid"]);
- $CD = $xml->add_node($CI, TX_CANCELMSG, $this->m_REQUEST["cancelmsg"], array("urlencode" => "1"));
- $CD = $xml->add_node($CI, TX_REFUNDACCTNUM, $this->m_REQUEST["racctnum"]);
- $CD = $xml->add_node($CI, TX_REFUNDBANKCODE, $this->m_REQUEST["rbankcode"]);
- $CD = $xml->add_node($CI, TX_REFUNDACCTNAME, $this->m_REQUEST["racctname"], array("urlencode" => "1"));
- $CD = $xml->add_node($CI, TX_REFUNDFLGREMIT, $this->m_REQUEST["refundflgremit"]);
-
-
- $this->AddUserDefinedEntity(CANCELINFO, "", $xml, $CI);
- } else if ($this->m_Type == TYPE_INQUIRY) {
- $CI = $xml->add_node("", INQUIRYINFO);
- $CD = $xml->add_node($CI, TX_INQR_TID, $this->m_REQUEST["tid"]);
- $CD = $xml->add_node($CI, TX_INQR_OID, $this->m_REQUEST["oid"], array("urlencode" => "1"));
- //$this->AddUserDefinedEntity( INQUIRYINFO, "", $xml, $CI );
- } else if ($this->m_Type == TYPE_OPENSUB) {
- $OI = $xml->add_node("", OPENSUBINFO);
- $OD = $xml->add_node($OI, TX_OPENREG_TID, $this->m_REQUEST["oldtid"]);
- $OD = $xml->add_node($OI, TX_OPENREG_MID, $this->m_REQUEST["mid"]);
- //$this->AddUserDefinedEntity( INQUIRYINFO, "", $xml, $CI );
- }
- $this->m_EncBody = $xml->make_xml();
-
- //encrypt body by SYMM
- if (( $rtv = $INICrypto->SymmEncrypt($this->m_EncBody, $this->m_sEncrypted, $key, $iv)) != OK)
- return $rtv;
-
- //encrypt key/iv by ASYMM
- if (!$INICrypto->RSAPGPubEncrypt($key, $this->m_sSessionKey))
- return ENC_RSA_ERR;
-
- $this->m_sSessionKey = Base64Encode($this->m_sSessionKey . $iv);
-
- return OK;
- }
-
- function MakeHead() {
- $this->m_sHead = sprintf("%05d", strlen($this->m_sBody));
- $this->m_sHead .= sprintf("%05d", strlen($this->m_sTail));
- $this->m_sHead .= sprintf("%s", $this->m_sCrypto);
- $this->m_sHead .= sprintf("%5s", FLAG_SIGN_SHA1);
- $this->m_sHead .= sprintf("%20s", $this->m_MPubSN);
- $this->m_sHead .= sprintf("%20s", $this->m_PIPGPubSN);
- $this->m_sHead .= sprintf("%20s", $this->m_TXPGPubSN);
- $this->m_sHead .= sprintf("%4s", $this->m_sCmd);
- $this->m_sHead .= sprintf("%10s", $this->m_REQUEST["mid"]);
- if ($this->m_Type == TYPE_RECEIPT) {
- $cr_price = isset($this->m_REQUEST["cr_price"]) ? $this->m_REQUEST["cr_price"] : 0;
- $this->m_sHead .= sprintf("%20s", $cr_price);
- } else {
- $price = isset($this->m_REQUEST["price"]) ? $this->m_REQUEST["price"] : 0;
- $this->m_sHead .= sprintf("%20s", $price);
- }
- $this->m_sHead .= sprintf("%40s", $this->m_REQUEST["tid"]);
-
- $this->m_sMsg = $this->m_sHead . $this->m_sBody . $this->m_sTail;
- return true;
- }
-
- /*
- /* Add User Defined Entity
- /* Sample
- /* $inipay->SetXPath("INIpay/GoodsInfo/UserDefined1","value1");
- /* $inipay->SetXPath("INIpay/GoodsInfo/UserDefined2","value2");
- /* $inipay->SetXPath("INIpay/GoodsInfo/Goods/UserDefined3","value3");
- /* $inipay->SetXPath("INIpay/GoodsInfo/Goods/UserDefined4","value4");
- /* $inipay->SetXPath("INIpay/BuyerInfo/UserDefined5","value5");
- /* $inipay->SetXPath("INIpay/BuyerInfo/UserDefined6","value6");
- /* $inipay->SetXPath("INIpay/PaymentInfo/Payment/UserDefined7","value7");
- /* $inipay->SetXPath("INIpay/PaymentInfo/Payment/UserDefined8","value8");
- /* $inipay->SetXPath("INIpay/ManageInfo/UserDefined9","value9");
- /* $inipay->SetXPath("INIpay/ReservedInfo/UserDefined10","value10");
- */
-
- //
- function AddUserDefinedEntity($info_node, $downnode, $xml, $upnode) {
- foreach ($this->m_REQUEST2 as $key => $val) {
- $node = explode('/', $key);
- $node_cnt = count($node);
-
- if ($node_cnt < 3)
- continue; //minumum 3
- if ($node[1] != $info_node)
- continue;
- if ($node_cnt == 3 && $downnode != "")
- continue;
- if ($node_cnt == 4 && $downnode != $node[2])
- continue;
-
- $last_node = substr(strrchr($key, '/'), 1);
- $xml->add_node($upnode, $last_node, $val, array("urlencode" => "1"));
- }
- }
-
- function MakeBody() {
- $xml = new XML();
-
- //ROOT(INIpay) ROOT를 ROOTINFO로 수정 2011-05-23
- $root = $xml->add_node("", ROOTINFO);
-
- if ($this->m_Type == TYPE_SECUREPAY || $this->m_Type == TYPE_RECEIPT) {
- //GoodsInfo
- //장바구니 기능 추가(2010.04.13)
- //==goodscnt가 없을 경우(장바구니 기능이 아닐경우) 기본 값 1로 설정
- $tGoodCnt = (isset($this->m_REQUEST["goodscnt"]) && (int) $this->m_REQUEST["goodscnt"] > 0 ) ? $this->m_REQUEST["goodscnt"] : 1;
-
- $request_oid = isset($this->m_REQUEST["oid"]) ? $this->m_REQUEST["oid"] : '';
- $request_taxfree = isset($this->m_REQUEST["taxfree"]) ? $this->m_REQUEST["taxfree"] : '';
-
- $GI = $xml->add_node($root, GOODSINFO);
- //장바구니 기능 추가(2010.04.13)
- //==TX_GOOSCNT는 $tGoodCnt로 부터 입력
- //$GP = $xml->add_node($GI, TX_GOOSCNT, "1" );
- $GP = $xml->add_node($GI, TX_GOOSCNT, $tGoodCnt);
- $GP = $xml->add_node($GI, TX_MOID, $request_oid, array("urlencode" => "1"));
- $GP = $xml->add_node($GI, TX_CURRENCY, $this->m_REQUEST["currency"]);
- $GP = $xml->add_node($GI, TX_TAX, $this->m_REQUEST["tax"]);
- $GP = $xml->add_node($GI, TX_TAXFREE, $request_taxfree);
- $this->AddUserDefinedEntity(GOODSINFO, "", $xml, $GI);
-
- //장바구니 기능 추가(2010.04.13) [START]
- //==장바구니 XML 전문 추가
- $iGoodCnt = 1;
- while ($iGoodCnt <= $tGoodCnt) {
- if (isset($this->m_REQUEST["smid_" . $iGoodCnt]) && strlen($this->m_REQUEST["smid_" . $iGoodCnt]) > 0) {
- $GS = $xml->add_node($GI, GOODS);
- $GD = $xml->add_node($GS, TX_SMID, $this->m_REQUEST["smid_" . $iGoodCnt]);
- $GD = $xml->add_node($GS, TX_GOODSNAME, $this->m_REQUEST["goodsname_" . $iGoodCnt], array("urlencode" => "1"));
- $GD = $xml->add_node($GS, TX_GOODSCNTS, $this->m_REQUEST["goodscnts_" . $iGoodCnt]);
- if ($this->m_Type == TYPE_SECUREPAY)
- $GD = $xml->add_node($GS, TX_GOODSPRICE, $this->m_REQUEST["goodsprice_" . $iGoodCnt]);
- if ($this->m_Type == TYPE_RECEIPT)
- $GD = $xml->add_node($GS, TX_GOODSPRICE, $this->m_REQUEST["cr_price"]);
- }
- else {
- $GS = $xml->add_node($GI, GOODS);
- $GD = $xml->add_node($GS, TX_SMID, $this->m_REQUEST["mid"]);
- $GD = $xml->add_node($GS, TX_GOODSNAME, $this->m_REQUEST["goodname"], array("urlencode" => "1"));
-
- if ($this->m_Type == TYPE_SECUREPAY)
- $GD = $xml->add_node($GS, TX_GOODSPRICE, $this->m_REQUEST["price"]);
- if ($this->m_Type == TYPE_RECEIPT)
- $GD = $xml->add_node($GS, TX_GOODSPRICE, $this->m_REQUEST["cr_price"]);
- }
- $iGoodCnt++;
- }
- //장바구니 기능 추가(2010.04.13) [END]
-
- $request_parentemail = isset($this->m_REQUEST["parentemail"]) ? $this->m_REQUEST["parentemail"] : '';
- $request_recvname = isset($this->m_REQUEST["recvname"]) ? $this->m_REQUEST["recvname"] : '';
- $request_recvtel = isset($this->m_REQUEST["recvtel"]) ? $this->m_REQUEST["recvtel"] : '';
- $request_recvmsg = isset($this->m_REQUEST["recvmsg"]) ? $this->m_REQUEST["recvmsg"] : '';
- $request_recvaddr = isset($this->m_REQUEST["recvaddr"]) ? $this->m_REQUEST["recvaddr"] : '';
- $request_recvpostnum = isset($this->m_REQUEST["recvpostnum"]) ? $this->m_REQUEST["recvpostnum"] : '';
- $request_joincard = isset($this->m_REQUEST["joincard"]) ? $this->m_REQUEST["joincard"] : '';
- $request_joinexpire = isset($this->m_REQUEST["joinexpire"]) ? $this->m_REQUEST["joinexpire"] : '';
- $request_mailorder = isset($this->m_REQUEST["mailorder"]) ? $this->m_REQUEST["mailorder"] : '';
-
- $this->AddUserDefinedEntity(GOODSINFO, GOODS, $xml, $GS);
- //BuyerInfo
- $BI = $xml->add_node($root, BUYERINFO);
- $BP = $xml->add_node($BI, TX_BUYERNAME, $this->m_REQUEST["buyername"], array("urlencode" => "1"));
- $BP = $xml->add_node($BI, TX_BUYERTEL, $this->m_REQUEST["buyertel"]);
- $BP = $xml->add_node($BI, TX_BUYEREMAIL, $this->m_REQUEST["buyeremail"], array("urlencode" => "1"));
- $BP = $xml->add_node($BI, TX_PARENTEMAIL, $request_parentemail, array("urlencode" => "1"));
- $BP = $xml->add_node($BI, TX_RECVNAME, $request_recvname, array("urlencode" => "1"));
- $BP = $xml->add_node($BI, TX_RECVTEL, $request_recvtel, array("urlencode" => "1"));
- $BP = $xml->add_node($BI, TX_RECVMSG, $request_recvmsg, array("urlencode" => "1"));
- $BP = $xml->add_node($BI, TX_RECVADDR, $request_recvaddr, array("urlencode" => "1"));
- $BP = $xml->add_node($BI, TX_RECVPOSTNUM, $request_recvpostnum, array("urlencode" => "1"));
- $this->AddUserDefinedEntity(BUYERINFO, "", $xml, $BI);
- //PaymentInfo
- $PI = $xml->add_node($root, PAYMENTINFO);
- $PM = $xml->add_node($PI, PAYMENT);
- $PD = $xml->add_node($PM, TX_PAYMETHOD, $this->m_REQUEST["paymethod"]);
- $PD = $xml->add_node($PM, TX_JOINCARD, $request_joincard);
- $PD = $xml->add_node($PM, TX_JOINEXPIRE, $request_joinexpire);
- $PD = $xml->add_node($PM, TX_MAILORDER, $request_mailorder);
- if ($this->m_Type == TYPE_SECUREPAY) {
- $PD = $xml->add_node($PM, TX_SESSIONKEY, $this->m_REQUEST["sessionkey"]);
- $PD = $xml->add_node($PM, TX_ENCRYPTED, $this->m_REQUEST["encrypted"], array("urlencode" => "1"));
- }
- if ($this->m_Type == TYPE_RECEIPT) {
- $PD = $xml->add_node($PM, TX_SESSIONKEY, $this->m_sSessionKey);
- $PD = $xml->add_node($PM, TX_ENCRYPTED, $this->m_sEncrypted);
- }
- $this->AddUserDefinedEntity(PAYMENTINFO, PAYMENT, $xml, $PM);
- } else if ($this->m_Type == TYPE_CANCEL) {
- //CancelInfo
- $CI = $xml->add_node($root, CANCELINFO);
- $CD = $xml->add_node($CI, TX_SESSIONKEY, $this->m_sSessionKey);
- $CD = $xml->add_node($CI, TX_ENCRYPTED, $this->m_sEncrypted);
- }
- //가상계좌 부분환불추가
- else if (( $this->m_Type == TYPE_REPAY ) || ( $this->m_Type == TYPE_VACCTREPAY )) {
- //PartCancelInfo
- $CI = $xml->add_node($root, PARTCANCELINFO);
- $CD = $xml->add_node($CI, TX_SESSIONKEY, $this->m_sSessionKey);
- $CD = $xml->add_node($CI, TX_ENCRYPTED, $this->m_sEncrypted);
- if ($this->m_Type == TYPE_REPAY) {
- $CIG = $xml->add_node($root, GOODSINFO);
- $CDG = $xml->add_node($CIG, TX_PRTC_TAX, $this->m_REQUEST["tax"]);
- $CDG = $xml->add_node($CIG, TX_PRTC_TAXFREE, $this->m_REQUEST["taxfree"]);
- $CDG = $xml->add_node($CIG, TX_PRTC_CURRENCY, $this->m_REQUEST["currency"]);
- }
- } else if ($this->m_Type == TYPE_CAPTURE) {
- //CaptureInfo
- $CI = $xml->add_node($root, CAPTUREINFO);
- $CD = $xml->add_node($CI, TX_SESSIONKEY, $this->m_sSessionKey);
- $CD = $xml->add_node($CI, TX_ENCRYPTED, $this->m_sEncrypted);
- } else if ($this->m_Type == TYPE_ESCROW) {
- //EscrowInfo
- $CI = $xml->add_node($root, ESCROWINFO);
- if ($this->m_EscrowType == TYPE_ESCROW_DLV || $this->m_EscrowType == TYPE_ESCROW_DNY_CNF) {
- $CD = $xml->add_node($CI, TX_SESSIONKEY, $this->m_sSessionKey);
- $CD = $xml->add_node($CI, TX_ENCRYPTED, $this->m_sEncrypted);
- } else if ($this->m_EscrowType == TYPE_ESCROW_CNF || $this->m_EscrowType == TYPE_ESCROW_DNY) {
- $CD = $xml->add_node($CI, TX_SESSIONKEY, $this->m_REQUEST["sessionkey"]);
- $CD = $xml->add_node($CI, TX_ENCRYPTED, $this->m_REQUEST["encrypted"], array("urlencode" => "1"));
- }
- } else if ($this->m_Type == TYPE_REFUND) {
- //CancelInfo
- $CI = $xml->add_node($root, CANCELINFO);
- $CD = $xml->add_node($CI, TX_SESSIONKEY, $this->m_sSessionKey);
- $CD = $xml->add_node($CI, TX_ENCRYPTED, $this->m_sEncrypted);
- } else if ($this->m_Type == TYPE_INQUIRY) {
- //CancelInfo
- $CI = $xml->add_node($root, INQUIRYINFO);
- $CD = $xml->add_node($CI, TX_SESSIONKEY, $this->m_sSessionKey);
- $CD = $xml->add_node($CI, TX_ENCRYPTED, $this->m_sEncrypted);
- } else if ($this->m_Type == TYPE_OPENSUB) {
- //GoodsInfo
- //장바구니 기능 추가(2010.04.13)
- //==goodscnt가 없을 경우(장바구니 기능이 아닐경우) 기본 값 1로 설정
- $tSubCnt = ($this->m_REQUEST["subcnt"] != null && (int) $this->m_REQUEST["subcnt"] > 0 ) ? $this->m_REQUEST["subcnt"] : 1;
-
- $OI = $xml->add_node($root, OPENSUBINFO);
-
- $OD = $xml->add_node($OI, TX_SESSIONKEY, $this->m_sSessionKey);
- $OD = $xml->add_node($OI, TX_ENCRYPTED, $this->m_sEncrypted);
-
- $OD = $xml->add_node($OI, TX_OPENREG_SUBCNT, $tSubCnt);
-
- $iSubCnt = 1;
- while ($iSubCnt <= $tSubCnt) {
- $SG = $xml->add_node($OI, TX_OPENREG_SUBGOODS, "", array("no" => $iSubCnt));
-
- $SD = $xml->add_node($SG, TX_OPENREG_SUBCOMPNO, $this->m_REQUEST["subcompno_" . $iSubCnt]);
- $SD = $xml->add_node($SG, TX_OPENREG_SUBCOMPNM, $this->m_REQUEST["subcompnm_" . $iSubCnt], array("urlencode" => "1"));
- $SD = $xml->add_node($SG, TX_OPENREG_SUBPRSUPPLY, $this->m_REQUEST["subprsupply_" . $iSubCnt]);
- $SD = $xml->add_node($SG, TX_OPENREG_SUBPRFREE, $this->m_REQUEST["subprfree_" . $iSubCnt]);
- $SD = $xml->add_node($SG, TX_OPENREG_SUBPRTAX, $this->m_REQUEST["subprtax_" . $iSubCnt]);
- $SD = $xml->add_node($SG, TX_OPENREG_SUBPRSERVICE, $this->m_REQUEST["subprservice_" . $iSubCnt]);
- $SD = $xml->add_node($SG, TX_OPENREG_SUBPRICE, $this->m_REQUEST["subprice_" . $iSubCnt]);
-
- $iSubCnt++;
- }
- //장바구니 기능 추가(2010.04.13) [END]
- $this->AddUserDefinedEntity(OPENSUBINFO, "", $xml, $OI);
- }
-
- $node_mreserved1 = isset($this->m_REQUEST["mreserved1"]) ? $this->m_REQUEST["mreserved1"] : '';
- $node_mreserved2 = isset($this->m_REQUEST["mreserved2"]) ? $this->m_REQUEST["mreserved2"] : '';
- $node_mreserved3 = isset($this->m_REQUEST["mreserved3"]) ? $this->m_REQUEST["mreserved3"] : '';
- $node_language = isset($this->m_REQUEST["language"]) ? $this->m_REQUEST["language"] : '';
- $node_url = isset($this->m_REQUEST["url"]) ? $this->m_REQUEST["url"] : '';
- $node_id_customer = isset($this->m_REQUEST["id_customer"]) ? $this->m_REQUEST["id_customer"] : '';
- $node_id_regnum = isset($this->m_REQUEST["id_regnum"]) ? $this->m_REQUEST["id_regnum"] : '';
-
- //ReservedInfo
- $RI = $xml->add_node($root, RESERVEDINFO);
- $RD = $xml->add_node($RI, TX_MRESERVED1, $node_mreserved1);
- $RD = $xml->add_node($RI, TX_MRESERVED2, $node_mreserved2);
- $RD = $xml->add_node($RI, TX_MRESERVED3, $node_mreserved3);
- $this->AddUserDefinedEntity(RESERVEDINFO, "", $xml, $RI);
-
- //ManageInfo
- $MI = $xml->add_node($root, MANAGEINFO);
- $MD = $xml->add_node($MI, TX_LANGUAGE, $node_language);
- $MD = $xml->add_node($MI, TX_URL, $node_url, array("urlencode" => "1"));
- $MD = $xml->add_node($MI, TX_TXVERSION, $this->m_TXVersion);
- //delete UIP(2009.01.21)
- //$MD = $xml->add_node($MI, TX_TXUSERIP, $this->m_REQUEST["uip"] );
- $MD = $xml->add_node($MI, TX_TXUSERID, $node_id_customer, array("urlencode" => "1"));
- $MD = $xml->add_node($MI, TX_TXREGNUM, $node_id_regnum);
-
- //Ack, rn
- if ($this->m_Type == TYPE_SECUREPAY || $this->m_Type == TYPE_OCBSAVE ||
- $this->m_Type == TYPE_FORMPAY || $this->m_Type == TYPE_RECEIPT
- ) {
- $MD = $xml->add_node($MI, TX_ACK, "1");
- if (isset($this->m_REQUEST["rn"]) && $this->m_REQUEST["rn"])
- $MD = $xml->add_node($MI, TX_RN, $this->m_REQUEST["rn"]);
- }
- $this->AddUserDefinedEntity(MANAGEINFO, "", $xml, $MI);
-
- $this->m_sBody = $xml->make_xml();
-
- return true;
- }
-
- function ParseHead($head) {
- $iLen = BODY_LEN + TAIL_LEN;
- if (strlen($head) != MSGHEADER_LEN)
- return RESULT_MSG_FORMAT_ERR;
-
- $this->m_FlgCrypto = substr($head, $iLen, FLGCRYPTO_LEN);
- $iLen += FLGCRYPTO_LEN;
- $this->m_FlgSign = substr($head, $iLen, FLGSIGN_LEN);
- $iLen += FLGSIGN_LEN;
- $this->m_MPubSN = substr($head, $iLen, MPUBSN_LEN);
- $iLen += MPUBSN_LEN;
- $this->m_PIPGPubSN = substr($head, $iLen, PIPGPUBSN_LEN);
- $iLen += PIPGPUBSN_LEN;
- $this->m_TXPGPubSN = substr($head, $iLen, TXPGPUBSN_LEN);
- $iLen += TXPGPUBSN_LEN;
- $this->m_Cmd = substr($head, $iLen, CMD_LEN);
- $iLen += CMD_LEN;
- $this->m_RESULT[NM_MID] = substr($head, $iLen, MID_LEN);
- $iLen += MID_LEN;
- $this->m_RESULT[NM_TOTPRICE] = substr($head, $iLen, TOTPRICE_LEN);
- $iLen += TOTPRICE_LEN;
- $this->m_RESULT[NM_TID] = substr($head, $iLen, TID_LEN);
-
- return OK;
- }
-
- function ParseBody($body, &$encrypted, &$sessionkey) {
- $xml = new XML();
- if (($rtv = $xml->load_xml("", $body)) != OK)
- return $rtv;
-
- $this->m_Xml = $xml->xml_node;
-
- //GOODSINFO
- $this->m_RESULT[NM_MOID] = $this->GetXMLData('MOID');
-
- //PAYMENTINFO
- //기타지불수단이 paymethod를 주지 않아 임시로 요청 Paymethod로 대체
- //PG에서 주는 PayMethod와 요청Paymethod는 같다!
- $this->m_RESULT[NM_PAYMETHOD] = $this->m_sPayMethod;
-
- $ResultCode = $this->GetXMLData("ResultCode");
-
- //if( substr($ResultCode,2, 4) == "0000" )
- if (strcmp(substr($ResultCode, 2, 4), "0000") == 0) {
- $this->m_RESULT[NM_RESULTCODE] = "00";
- $this->m_RESULT[NM_RESULTMSG] = $this->GetXMLData("ResultMsg");
- } else {
- $this->m_RESULT[NM_RESULTCODE] = "01";
- $this->m_RESULT['NM_ERRORCODE'] = $ResultCode;
- $this->m_RESULT[NM_RESULTMSG] = "[" . $ResultCode . "|" . $this->GetXMLData("ResultMsg") . "]";
- }
- $encrypted = $this->GetXMLData("Encrypted");
- $sessionkey = $this->GetXMLData("SessionKey");
- return OK;
- }
-
- function ParseDecrypt($decrypted) {
- $xml = new XML();
- if (($rtv = $xml->load_xml("", $decrypted)) != OK)
- return $rtv;
-
- $this->m_Xml = array_merge($this->m_Xml, $xml->xml_node);
-
- if ($this->m_Type == TYPE_SECUREPAY || $this->m_Type == TYPE_RECEIPT) {
- //승인날짜(ApplDate), 승인시간(ApplTime), 승인번호(ApplNum)는 공통!!(OCB, 현금영수증 제외)
- //ISP, CARD는 CARD로 assign. 고객/상점은 ISP가 뭔지, CARD가 뭔지 알게 뭐야!!!-_-
- if ($this->m_sPayMethod == NM_TX_CARD) {
- $this->m_RESULT[APPLDATE] = $this->GetXMLData(CARD_APPLDATE);
- $this->m_RESULT[APPLTIME] = $this->GetXMLData(CARD_APPLTIME);
- $this->m_RESULT[APPLNUM] = $this->GetXMLData(CARD_APPLNUM);
- $this->m_RESULT[CARD_NUM] = $this->GetXMLData(CARD_NUM);
- $this->m_RESULT[CARD_EXPIRE] = $this->GetXMLData(CARD_EXPIRE);
- $this->m_RESULT[CARD_BANKCODE] = $this->GetXMLData(CARD_BANKCODE);
- $this->m_RESULT[CARD_CODE] = $this->GetXMLData(CARD_CODE);
- $this->m_RESULT[CARD_APPLPRICE] = $this->GetXMLData(CARD_APPLPRICE);
- $this->m_RESULT[CARD_QUOTA] = $this->GetXMLData(CARD_QUOTA);
- $this->m_RESULT[CARD_INTEREST] = $this->GetXMLData(CARD_INTEREST);
- $this->m_RESULT[CARD_POINT] = $this->GetXMLData(CARD_POINT);
- $this->m_RESULT[CARD_AUTHTYPE] = $this->GetXMLData(CARD_AUTHTYPE);
- $this->m_RESULT[CARD_REGNUM] = $this->GetXMLData(CARD_REGNUM);
- $this->m_RESULT[CARD_TERMINALNUM] = $this->GetXMLData(CARD_TERMINALNUM);
- $this->m_RESULT[CARD_MEMBERNUM] = $this->GetXMLData(CARD_MEMBERNUM);
- $this->m_RESULT[CARD_PURCHASECODE] = $this->GetXMLData(CARD_PURCHASECODE);
- } else if ($this->m_sPayMethod == NM_TX_ISP) {
- $this->m_RESULT[APPLDATE] = $this->GetXMLData(ISP_APPLDATE);
- $this->m_RESULT[APPLTIME] = $this->GetXMLData(ISP_APPLTIME);
- $this->m_RESULT[APPLNUM] = $this->GetXMLData(ISP_APPLNUM);
- $this->m_RESULT[CARD_NUM] = $this->GetXMLData(ISP_CARDNUM);
- $this->m_RESULT[CARD_EXPIRE] = $this->GetXMLData(ISP_EXPIRE);
- $this->m_RESULT[CARD_BANKCODE] = $this->GetXMLData(ISP_BANKCODE);
- $this->m_RESULT[CARD_CODE] = $this->GetXMLData(ISP_CARDCODE);
- $this->m_RESULT[CARD_APPLPRICE] = $this->GetXMLData(ISP_APPLPRICE);
- $this->m_RESULT[CARD_QUOTA] = $this->GetXMLData(ISP_QUOTA);
- $this->m_RESULT[CARD_INTEREST] = $this->GetXMLData(ISP_INTEREST);
- $this->m_RESULT[CARD_POINT] = $this->GetXMLData(ISP_POINT);
- $this->m_RESULT[CARD_TERMINALNUM] = $this->GetXMLData(ISP_TERMINALNUM);
- $this->m_RESULT[CARD_MEMBERNUM] = $this->GetXMLData(ISP_MEMBERNUM);
- $this->m_RESULT[CARD_PURCHASECODE] = $this->GetXMLData(ISP_PURCHASECODE);
- } else if ($this->m_sPayMethod == NM_TX_CSHR) {
- $this->m_RESULT[APPLDATE] = $this->GetXMLData(CSHR_APPLDATE);
- $this->m_RESULT[APPLTIME] = $this->GetXMLData(CSHR_APPLTIME);
- $this->m_RESULT[APPLNUM] = $this->GetXMLData(CSHR_APPLNUM);
- } else if ($this->m_sPayMethod == NM_TX_ACCT) {
- $this->m_RESULT[APPLDATE] = $this->GetXMLData(ACCT_APPLDATE);
- $this->m_RESULT[APPLTIME] = $this->GetXMLData(ACCT_APPLTIME);
- $this->m_RESULT[APPLNUM] = $this->GetXMLData(ACCT_APPLNUM);
- } else if ($this->m_sPayMethod == NM_TX_HPP) {
- $this->m_RESULT[APPLDATE] = $this->GetXMLData(HPP_APPLDATE);
- $this->m_RESULT[APPLTIME] = $this->GetXMLData(HPP_APPLTIME);
- $this->m_RESULT[APPLNUM] = $this->GetXMLData(HPP_APPLNUM);
- } else if ($this->m_sPayMethod == NM_TX_VACT) {
- $this->m_RESULT[APPLDATE] = $this->GetXMLData(VACT_APPLDATE);
- $this->m_RESULT[APPLTIME] = $this->GetXMLData(VACT_APPLTIME);
- } else if ($this->m_sPayMethod == NM_TX_ARSB) {
- $this->m_RESULT[APPLDATE] = $this->GetXMLData(ARSB_APPLDATE);
- $this->m_RESULT[APPLTIME] = $this->GetXMLData(ARSB_APPLTIME);
- $this->m_RESULT[APPLNUM] = $this->GetXMLData(ARSB_APPLNUM);
- } else if ($this->m_sPayMethod == NM_TX_PHNB) {
- $this->m_RESULT[APPLDATE] = $this->GetXMLData(PHNB_APPLDATE);
- $this->m_RESULT[APPLTIME] = $this->GetXMLData(PHNB_APPLTIME);
- $this->m_RESULT[APPLNUM] = $this->GetXMLData(PHNB_APPLNUM);
- } else if ($this->m_sPayMethod == NM_TX_CULT) {
- $this->m_RESULT[APPLDATE] = $this->GetXMLData(CULT_APPLDATE);
- $this->m_RESULT[APPLTIME] = $this->GetXMLData(CULT_APPLTIME);
- $this->m_RESULT[APPLNUM] = $this->GetXMLData(CULT_APPLNUM);
- } else if ($this->m_sPayMethod == NM_TX_GAMG) {
- $this->m_RESULT[APPLDATE] = $this->GetXMLData(GAMG_APPLDATE);
- $this->m_RESULT[APPLTIME] = $this->GetXMLData(GAMG_APPLTIME);
- $this->m_RESULT[APPLNUM] = $this->GetXMLData(GAMG_APPLNUM);
- $this->m_RESULT[GAMG_CNT] = $this->GetXMLData(GAMG_CNT);
- //게임문화상품권은 Multi결제 가능
- MakePathGAMG($this->m_RESULT[GAMG_CNT]);
- for ($i = 1; $i <= $this->m_RESULT[GAMG_CNT]; $i++) {
- $this->m_RESULT[constant("GAMG_NUM$i")] = $this->GetXMLData(constant("GAMG_NUM$i"));
- $this->m_RESULT[constant("GAMG_REMAINS$i")] = $this->GetXMLData(constant("GAMG_REMAINS$i"));
- $this->m_RESULT[constant("GAMG_ERRMSG$i")] = $this->GetXMLData(constant("GAMG_ERRMSG$i"));
- }
- $this->m_RESULT[GAMG_APPLPRICE] = $this->GetXMLData(GAMG_APPLPRICE);
- $this->m_RESULT[GAMG_NUM] = $this->GetXMLData(GAMG_NUM);
- $this->m_RESULT[GAMG_RESULTCODE] = $this->GetXMLData(GAMG_RESULTCODE);
- $this->m_RESULT[GAMG_RESULTMSG] = $this->GetXMLData(GAMG_RESULTMSG);
- } else if ($this->m_sPayMethod == NM_TX_EDUG) {
- $this->m_RESULT[APPLDATE] = $this->GetXMLData(EDUG_APPLDATE);
- $this->m_RESULT[APPLTIME] = $this->GetXMLData(EDUG_APPLTIME);
- $this->m_RESULT[APPLNUM] = $this->GetXMLData(EDUG_APPLNUM);
- } else if ($this->m_sPayMethod == NM_TX_TEEN) {
- $this->m_RESULT[APPLDATE] = $this->GetXMLData(TEEN_APPLDATE);
- $this->m_RESULT[APPLTIME] = $this->GetXMLData(TEEN_APPLTIME);
- $this->m_RESULT[APPLNUM] = $this->GetXMLData(TEEN_APPLNUM);
- }
- } else if ($this->m_Type == TYPE_INQUIRY) {
- $this->m_RESULT[INQR_TID] = $this->GetXMLData(INQR_TID);
- $this->m_RESULT[INQR_PRICE] = $this->GetXMLData(INQR_Price);
- $this->m_RESULT[INQR_STATUS] = $this->GetXMLData(INQR_Status);
- }
-
- return OK;
- }
-
- function GTHR($err_code, $err_msg) {
- //Set
- $data["mid"] = $this->m_REQUEST["mid"];
- $data["paymethod"] = isset($this->m_REQUEST["paymethod"]) ? $this->m_REQUEST["paymethod"] : '';
- //delete UIP(2009.01.21)
- //$data["user_ip"] = $this->m_REQUEST["uip"];
- $data["tx_version"] = $this->m_TXVersion;
- $data["err_code"] = $err_code;
- $data["err_msg"] = $err_msg;
-
- // add tid / type (2014-12-09 by jungc)
- $data["tid"] = $this->m_sTID;
- $data["type"] = $this->m_Type;
-
- //Send
- $qs = "ctype=TX&";
- foreach ($data as $key => $val)
- $qs .= $key . '=' . urlencode($val) . '&';
-
- $fp = fsockopen(G_SERVER, G_PORT, $errno, $errstr, G_TIMEOUT_CONNECT);
- if ($fp) {
- $out = "GET " . G_CGI . "?" . $qs . " HTTP/1.0\r\n";
- $out .= "Host: " . G_SERVER . "\r\n";
- $out .= "Connection: Close\r\n\r\n";
- fwrite($fp, $out);
- fclose($fp);
- }
- }
-
- function ParsePIEncrypted() {
- $output = array();
- if( isset($this->m_REQUEST["encrypted"]) ) {
- parse_str($this->m_REQUEST["encrypted"], $output);
- }
- $this->m_PIPGPubSN = isset($output['CertVer']) ? $output['CertVer'] : '';
- $this->m_PG1 = isset($output['pg1']) ? $output['pg1'] : '';
- $this->m_PG2 = isset($output['pg2']) ? $output['pg2'] : '';
- $this->m_PG1IP = isset($output['pg1ip']) ? $output['pg1ip'] : '';
- $this->m_PG2IP = isset($output['pg2ip']) ? $output['pg2ip'] : '';
- }
-
- // Xpath로 안가져온다. 한달을 헛지랄 했다!!
- // added by ddaemiri, 2007.09.03
- function GetXMLData($node) {
- $content = isset($this->m_Xml[$node . "[1]"]["text"]) ? $this->m_Xml[$node . "[1]"]["text"] : '';
- if (isset($this->m_Xml[$node . "[1]"]["attr"]["urlencode"]) && $this->m_Xml[$node . "[1]"]["attr"]["urlencode"] == "1")
- $content = urldecode($content);
-
- return $content;
- }
-
-}
-
-/* ----------------------------------------------------- */
-/* Crypto Class */
-/* PHP4.2 & OpenSSL 필요) */
-/* ----------------------------------------------------- */
-
-class INICrypto {
-
- var $homedir;
- var $mid;
- var $admin;
- var $pgpubkeyid = NULL;
- var $mprivkeyid = NULL;
- var $mkey;
- var $encMethod = "mcrypt";
-
- function __construct($request) {
- $this->homedir = $request["inipayhome"];
- $this->mid = $request["mid"];
- $this->admin = $request["admin"];
- $this->mkey = isset($request["mkey"]) ? $request["mkey"] : '';
- if(isset($request['encMethod']) && !empty($request['encMethod'])){
- $this->encMethod = strtolower($request['encMethod']);
- }
- }
-
- function LoadPGPubKey(&$pg_pubcert_SN) {
- $fp = fopen($this->homedir . "/key/pgcert.pem", "r");
- if (!$fp)
- return NULL_PGCERT_FP_ERR;
- $pub_key = fread($fp, 8192);
- if (!$pub_key) {
- fclose($fp);
- return NULL_PGCERT_FP_ERR;
- }
- fclose($fp);
-
- $this->pgpubkeyid = openssl_get_publickey($pub_key);
- if (!$this->pgpubkeyid)
- return NULL_PGCERT_ERR;
-
- $pg_pubcert = openssl_x509_parse($pub_key);
- if (!$pg_pubcert)
- return NULL_X509_ERR; //The structure of the returned data is (deliberately) not yet documented
- $pg_pubcert_SN = $pg_pubcert["serialNumber"];
-
- return OK;
- }
-
- function UpdatePGPubKey($pgpubkey) {
- $f_org = $this->homedir . "/key/pgcert.pem";
- $f_new = $this->homedir . "/key/.pgcert.pem.tmp";
- $fp = fopen($f_new, "w");
- if (!$fp)
- return PGPUB_UPDATE_ERR;
- fwrite($fp, $pgpubkey);
- fclose($fp);
-
- //rename
- if (!rename($f_new, $f_org))
- return PGPUB_UPDATE_ERR;
- return OK;
- }
-
- function LoadMPubKey(&$m_pubcert_SN) {
- if ($this->mkey == "1")
- $fp = fopen($this->homedir . "/key/mkey/mcert.pem", "r");
- else
- $fp = fopen($this->homedir . "/key/" . $this->mid . "/mcert.pem", "r");
- if (!$fp)
- return NULL_MCERT_FP_ERR;
- $pub_key = fread($fp, 8192);
- if (!$pub_key) {
- fclose($fp);
- return NULL_MCERT_FP_ERR;
- }
- fclose($fp);
-
- $m_pubcert = openssl_x509_parse($pub_key);
- if (!$m_pubcert)
- return NULL_X509_ERR; //The structure of the returned data is (deliberately) not yet documented
- $m_pubcert_SN = $m_pubcert["serialNumber"];
-
- return OK;
- }
-
- function LoadMPrivKey() {
- /*
- //get keypw
- $fp=fopen( $this->homedir . "/key/" . $this->mid . "/keypass.enc", "r");
- if( !$fp ) return GET_KEYPW_FILE_OPEN_ERR;
- $enckey=fread($fp, 8192);
- if( !$enckey ) return GET_KEYPW_FILE_OPEN_ERR;
- fclose($fp);
- if( !$this->SymmDecrypt( base64_decode($enckey), &$keypwd, $this->admin, IV ) )
- return GET_KEYPW_DECRYPT_FINAL_ERR;
- */
- $keypwd = $this->admin;
-
- //load mpriv key
- if ($this->mkey == "1")
- $fp = fopen($this->homedir . "/key/mkey/mpriv.pem", "r");
- else
- $fp = fopen($this->homedir . "/key/" . $this->mid . "/mpriv.pem", "r");
- if (!$fp)
- return PRIVKEY_FILE_OPEN_ERR;
- $priv_key = fread($fp, 8192);
- if (!$priv_key) {
- fclose($fp);
- return PRIVKEY_FILE_OPEN_ERR;
- }
- fclose($fp);
- $this->mprivkeyid = openssl_get_privatekey($priv_key, $keypwd);
- if (!$this->mprivkeyid)
- //return INVALID_KEYPASS_ERR;
- return GET_KEYPW_DECRYPT_FINAL_ERR;
- return OK;
- }
-
- function Sign($body, &$sign) {
- if (!openssl_sign($body, $sign, $this->mprivkeyid)) //default:SHA1
- return SIGN_FINAL_ERR;
- $sign = Base64Encode($sign);
- return OK;
- }
-
- function Verify($body, $tail) {
- $rtv = openssl_verify($body, base64_decode($tail), $this->pgpubkeyid);
- if (!$rtv)
- return SIGN_CHECK_ERR;
- return OK;
- }
-
- function Decrypt($sessionkey, $encrypted, &$decrypted) {
- $dec_sesskey = base64_decode($sessionkey);
- $src = substr($dec_sesskey, 0, strlen($dec_sesskey) - MAX_IV_LEN);
- if (!$this->RSAMPrivDecrypt($src, $key))
- return DEC_RSA_ERR;
- $iv = substr($dec_sesskey, strlen($dec_sesskey) - MAX_IV_LEN, MAX_IV_LEN);
- if (!$this->SymmDecrypt(base64_decode($encrypted), $decrypted, $key, $iv))
- return DEC_FINAL_ERR;
- return OK;
- }
-
- function SymmEncrypt($src_data, &$enc_data, $key, $iv) {
- if($this->encMethod == "openssl"){ //php version >= 5.3
- $enc_data = openssl_encrypt($src_data, "DES-EDE3-CBC", $key, OPENSSL_RAW_DATA, $iv);
- } else {
- $size = mcrypt_get_block_size(MCRYPT_3DES, MCRYPT_MODE_CBC);
- $src_data = $this->pkcs5_pad($src_data, $size);
- $cipher = mcrypt_module_open(MCRYPT_3DES, '', MCRYPT_MODE_CBC, '');
- mcrypt_generic_init($cipher, $key, $iv);
- $enc_data = mcrypt_generic($cipher, $src_data);
- mcrypt_generic_deinit($cipher);
- mcrypt_module_close($cipher);
- }
-
- if (!$enc_data)
- return ENC_FINAL_ERR;
- $enc_data = Base64Encode($enc_data);
-
- return OK;
- }
-
- function SymmDecrypt($enc_data, &$dec_data, $key, $iv) {
- if($this->encMethod == "openssl"){
- $dec_data = openssl_decrypt($enc_data, "DES-EDE3-CBC", $key, OPENSSL_RAW_DATA, $iv);
- } else {
- $cipher = mcrypt_module_open(MCRYPT_3DES, '', MCRYPT_MODE_CBC, '');
- mcrypt_generic_init($cipher, $key, $iv);
- $dec_data = mdecrypt_generic($cipher, $enc_data);
- mcrypt_generic_deinit($cipher);
- mcrypt_module_close($cipher);
- }
-
- if (!$dec_data)
- return false;
- $dec_data = $this->remove_ctrl($dec_data);
- return true;
- }
-
- function RSAMPrivDecrypt($enc_data, &$dec_data) {
- return openssl_private_decrypt($enc_data, $dec_data, $this->mprivkeyid);
- }
-
- function RSAMPrivEncrypt($org_data, &$enc_data) {
- if (!openssl_private_encrypt($org_data, $enc_data, $this->mprivkeyid))
- return false;
- $enc_data = Base64Encode($enc_data);
- return true;
- }
-
- function RSAPGPubEncrypt($org_data, &$enc_data) {
- return openssl_public_encrypt($org_data, $enc_data, $this->pgpubkeyid);
- }
-
- function FreePubKey() {
- if ($this->pgpubkeyid)
- openssl_free_key($this->pgpubkeyid);
- }
-
- function FreePrivKey() {
- if ($this->mprivkeyid)
- openssl_free_key($this->mprivkeyid);
- }
-
- function FreeAllKey() {
- $this->FreePubKey();
- $this->FreePrivKey();
- }
-
- function remove_ctrl($string) {
- for ($i = 0; $i < strlen($string); $i++) {
- $chr = $string[$i];
- $ord = ord($chr);
- if ($ord < 10)
- $string[$i] = " ";
- else
- $string[$i] = $chr;
- }
- return trim($string);
- }
-
- function pkcs5_pad($text, $blocksize) {
- $pad = $blocksize - (strlen($text) % $blocksize);
- return $text . str_repeat(chr($pad), $pad);
- }
-
- function pkcs5_unpad($text) {
- $pad = ord($text[strlen($text) - 1]);
- if ($pad > strlen($text))
- return false;
- if (strspn($text, chr($pad), strlen($text) - $pad) != $pad)
- return false;
- return substr($text, 0, -1 * $pad);
- }
-
- function MakeIMStr($pt, $key) {
- if (get_magic_quotes_gpc()) {
- $key = stripslashes($key);
- $pt = stripslashes($pt);
- }
- return substr(chunk_split(base64_encode($this->IMstr($key, $pt)), 64, "\n"), 0, -1);
- }
-
- function IMstr($pwd, $data) {
- $key[] = '';
- $box[] = '';
- $cipher = '';
-
- $pwd_length = strlen($pwd);
- $data_length = strlen($data);
-
- for ($i = 0; $i < 256; $i++) {
- $key[$i] = ord($pwd[$i % $pwd_length]);
- $box[$i] = $i;
- }
- for ($j = $i = 0; $i < 256; $i++) {
- $j = ($j + $box[$i] + $key[$i]) % 256;
- $tmp = $box[$i];
- $box[$i] = $box[$j];
- $box[$j] = $tmp;
- }
- for ($a = $j = $i = 0; $i < $data_length; $i++) {
- $a = ($a + 1) % 256;
- $j = ($j + $box[$a]) % 256;
- $tmp = $box[$a];
- $box[$a] = $box[$j];
- $box[$j] = $tmp;
- $k = $box[(($box[$a] + $box[$j]) % 256)];
- $cipher .= chr(ord($data[$i]) ^ $k);
- }
- return $cipher;
- }
-
-}
\ No newline at end of file
diff --git a/shop/inicis/libs/INIDFN.php b/shop/inicis/libs/INIDFN.php
deleted file mode 100644
index 98f36d5e1..000000000
--- a/shop/inicis/libs/INIDFN.php
+++ /dev/null
@@ -1,673 +0,0 @@
-5001은 망취소시 서버측에서 서명오류가 남,그래도 망취소처리는 됨)
- * @date 2008.03.12
- * @buildno 5016
- * @note pg1ip, pg2ip 추가/취소 원거래없음시 drpg로 재시도
- * @date 2008.04.02
- * @buildno 5017
- * @note 1)chkfake시 파라미터 로깅 삭제(중복)
- * 2)call-time pass-by-reference => pass-by-value로 수정
- * @date 2009.01.12
- * @buildno 5019
- * @note delete UIP
- * @date 2009.01.21
- * @note add mkey/mergelog ( for Makeshop )
- * @date 2009.02.24
- * @note 1)define MKEY deprecated 2009.02.19 ( Makeshop 초기 한번나감. 서비스되고 있는지는 모름)
- * 2)Makeshop PG Updrade용으로 새로나감 2009.02.19 (interface에서 mkey값을 받아 처리하게 변경)
- * 3)Makeshop PG Updrade용으로 새로나감 2009.02.24 (interface에서 mergelog값을 받아 처리하게 변경)
- * @date 2009.05.07
- * @note add BUILDDATE in TXVersion
- * @date 2009.08.05
- * @buildno 5030
- * @note add vacct refund
- * @date 2009.12.16
- * @buildno 5030
- * @note add recv info
- * @date 2010.07.14
- * @note add Tax, TaxFree info(TX_TAX, TX_TAXFREE)
- * @date 2010.09.09
- * @note 취소요청시 PG 설정 변경(도메인->IP, INILib.php)
- * @note BUILDDATE update(100414 -> 100909)
- * @note 2011.05.23 5030 XML ELEMENT 중 ROOT 를 ROOTINFO로 수정
- * @buildno 5032
- * @note 2012.07.09 거래조회 추가 (TYPE_INQUIRY)
- * @note 2012.07.09 PHP ini 파일 error display setting 추가
- * @buildno 5036
- * @note 2014.12.09 add gather parameter tid, type
- * @note 20151113 주문번호 거래조회 추가
- */
-ini_set('error_reporting', E_ALL ^ E_NOTICE);
-ini_set('display_errors', 'Off');
-
-/* GLOBAL */
-define("PROGRAM", "INIPHP");
-define("LANG", "PHP");
-define("VERSION", "NV5053");
-define("BUILDDATE", "20190404");
-if( ! defined('TID_LEN')) define("TID_LEN", 40);
-define("MAX_KEY_LEN", 24);
-define("MAX_IV_LEN", 8);
-
-/* TIMEOUT */
-define("TIMEOUT_CONNECT", 5);
-define("TIMEOUT_WRITE", 2);
-define("TIMEOUT_READ", 20);
-define("G_TIMEOUT_CONNECT", 2);
-define("DNS_LOOKUP_TIMEOUT", 5);
-
-/* LOG LEVEL */
-define("CRITICAL", 1);
-define("ERROR", 2);
-define("NOTICE", 3);
-define("INFO", 5);
-define("DEBUG", 7);
-
-/* SERVER INFO */
-define("PG_HOST", "formpg.inicis.com");
-define("PG_IP", "203.238.37.3");
-define("KSPG_IP", "39.115.212.10");
-define("PG_PORT", 34049);
-define("G_SERVER", "gthr.inicis.com");
-define("G_CGI", "/cgi-bin/g.cgi");
-define("G_PORT", 80);
-
-
-define("OK", "0");
-
-define("IV", "Initiative Tech");
-define("IMHK", "SFBQSU5JTkZPUk1BVElPTg==");
-define("IMHV", "SU5JQ0lTIENJUEhFUi4uLg==");
-define("IMJK", "UkVHSVNUX05PX1JDNEtFWQ==");
-define("IMJV", "UkVHSVNUX05PX1JDNElW");
-
-//define for mkey
-//deprecated 2009.02.19 ( Makeshop 초기 한번나감. 서비스되고 있는지는 모름)
-//Makeshop PG Updrade용으로 새로나감 2009.02.19 (interface에서 mkey값을 받아 처리하게 변경)
-//define("MKEY", 1);
-//non block connect immediate return check code/str
-define("ERRSTR_INPROGRESS", "Operation now in progress");
-define("ERRCODE_INPROGRESS_LINUX", 115);
-define("ERRCODE_INPROGRESS_FREEBSD", 36);
-define("ERRCODE_INPROGRESS_WIN", 10035);
-
-//------------------------------------------------------
-// IFD Header
-//------------------------------------------------------
-define("MSGHEADER_LEN", 150);
-define("BODY_LEN", 5);
-define("TAIL_LEN", 5);
-define("FLGCRYPTO_LEN", 1);
-define("FLGSIGN_LEN", 5);
-define("MPUBSN_LEN", 20);
-define("PIPGPUBSN_LEN", 20);
-define("TXPGPUBSN_LEN", 20);
-define("CMD_LEN", 4);
-define("MID_LEN", 10);
-define("TOTPRICE_LEN", 20);
-
-
-//------------------------------------------------------
-// IFD CMD
-//------------------------------------------------------
-define("CMD_REQ_PAY", "0200");
-define("CMD_RES_PAY", "0210");
-define("CMD_REQ_CAP", "0300");
-define("CMD_RES_CAP", "0310");
-define("CMD_REQ_CAN", "0420");
-define("CMD_RES_CAN", "0430");
-define("CMD_REQ_NETC", "0520");
-define("CMD_RES_NETC", "0530");
-define("CMD_REQ_PRTC", "0620");
-define("CMD_RES_PRTC", "0630");
-define("CMD_REQ_ACK", "0800");
-define("CMD_RES_ACK", "0810");
-//자체에스크로
-//added 2008.01.08
-define("CMD_REQ_DLV", "3020"); //배송등록
-define("CMD_REQ_CNF", "3030"); //구매확인
-define("CMD_REQ_DNY", "3040"); //구매거절
-define("CMD_REQ_DNY_CNF", "3080"); //거절확인
-define("CMD_REQ_DLV_NETC", "3520"); //배송등록망상취소
-define("CMD_REQ_CNF_NETC", "3530"); //구매확인망상취소
-define("CMD_REQ_DNY_NETC", "3540"); //구매거절망상취소
-//가상계좌환불(09.08.05)
-define("CMD_REQ_RFD", "0421");
-define("CMD_RES_RFD", "0431");
-
-//거래조회(12.04.20)
-define("CMS_REQ_INQR", "0900");
-define("CMS_RES_INQR", "0910");
-
-//서브몰하위가맹점등록(14.03.06)
-define("CMS_REQ_OPEN_SUB", "1040");
-define("CMS_RES_OPEN_SUB", "1041");
-
-//------------------------------------------------------
-// HEADER FLAGS
-//------------------------------------------------------
-define("FLAG_TEST", "T");
-define("FLAG_REAL", "R");
-define("FLAG_CRYPTO_NONE", "N");
-define("FLAG_CRYPTO_SEED", "S");
-define("FLAG_CRYPTO_RC4", "R");
-define("FLAG_CRYPTO_3DES", "D");
-define("FLAG_SIGN_SHA", "SHA");
-define("FLAG_SIGN_SHA1", "SHA1");
-define("FLAG_SIGN_MD5", "MD5");
-
-//------------------------------------------------------
-//TYPE(서비스별)
-//------------------------------------------------------
-define("TYPE_SECUREPAY", "securepay");
-define("TYPE_CANCEL", "cancel");
-define("TYPE_FORMPAY", "formpay");
-define("TYPE_RECEIPT", "receipt");
-define("TYPE_REPAY", "repay");
-define("TYPE_ESCROW", "escrow"); //자체에스크로!
-define("TYPE_CONFIRM", "confirm");
-define("TYPE_OCBQUERY", "ocbquery");
-define("TYPE_OCBSAVE", "ocbsave");
-define("TYPE_OCBPOINT", "OCBPoint");
-define("TYPE_AUTH", "auth");
-define("TYPE_AUTHBILL", "auth_bill");
-define("TYPE_CAPTURE", "capture");
-define("TYPE_CMS", "CMS");
-define("TYPE_VBANK", "VBank");
-define("TYPE_REQREALBILL", "reqrealbill");
-define("TYPE_FORMAUTH", "formauth");
-define("TYPE_CHKFAKE", "chkfake");
-//가상계좌환불(09.08.05)
-define("TYPE_REFUND", "refund");
-//가상계좌부분환불(12.06.05)
-define("TYPE_VACCTREPAY", "vacctrepay");
-//거래조회(12.04.20)
-define("TYPE_INQUIRY", "inquiry");
-//서브몰하위가맹점등록(14.03.06)
-define("TYPE_OPENSUB", "opensub");
-//------------------------------------------------------
-//EscrowType(자체에스크로 타입)
-//added 2008.01.08
-//------------------------------------------------------
-define("TYPE_ESCROW_DLV", "dlv");
-define("TYPE_ESCROW_CNF", "confirm"); //구매확인/거절(플러그인)
-define("TYPE_ESCROW_DNY", "deny"); //위에서 처리됨,의미없음
-define("TYPE_ESCROW_DNY_CNF", "dcnf");
-
-//------------------------------------------------------
-//PayMethod(서비스별, TX)
-//------------------------------------------------------
-define("NM_TX_ISP", "VCard");
-define("NM_TX_CARD", "Card");
-define("NM_TX_HPP", "HPP");
-define("NM_TX_ACCT", "DirectBank");
-define("NM_TX_VACT", "VBank");
-define("NM_TX_OCB", "OCBPoint");
-define("NM_TX_CSHR", "CASH");
-define("NM_TX_ARSB", "Ars1588Bill");
-define("NM_TX_PHNB", "PhoneBill");
-define("NM_TX_CULT", "Culture");
-define("NM_TX_GAMG", "DGCL");
-define("NM_TX_EDUG", "EDCL");
-define("NM_TX_TEEN", "TEEN");
-define("NM_TX_ESCR", "Escrow");
-
-//------------------------------------------------------
-//PayMethod(서비스별, PG)
-//------------------------------------------------------
-define("NM_ISP", "ISP");
-define("NM_CARD", "CARD");
-define("NM_HPP", "HPP");
-define("NM_ACCT", "ACCT");
-define("NM_VACT", "VACT");
-define("NM_OCB", "OCB");
-define("NM_CSHR", "CASH");
-define("NM_ARSB", "ARSB");
-define("NM_PHNB", "PHNB");
-define("NM_CULT", "CULT");
-define("NM_GAMG", "DGCL");
-define("NM_EDUG", "EDCL");
-define("NM_TEEN", "TEEN");
-define("NM_ESCR", "Escrow");
-
-//------------------------------------------------------
-//Charset
-//------------------------------------------------------
-define("EUCKR", "EUC-KR");
-define("UTF8", "UTF-8");
-
-//------------------------------------------------------
-//URL Encoding/Decoding Name
-//------------------------------------------------------
-define("URLENCODE", "urlencode");
-define("URLDECODE", "urldecode");
-
-//------------------------------------------------------
-//요청전문
-//------------------------------------------------------
-define("TX_GOOSCNT", "GoodsCnt");
-define("TX_MOID", "MOID");
-define("TX_CURRENCY", "Currency");
-define("TX_SMID", "SMID");
-define("TX_GOODSCNTS", "GoodsCnts");
-define("TX_GOODSNAME", "GoodsName");
-define("TX_GOODSPRICE", "GoodsPrice");
-define("TX_BUYERNAME", "BuyerName");
-define("TX_BUYEREMAIL", "BuyerEmail");
-define("TX_BUYERTEL", "BuyerTel");
-define("TX_PARENTEMAIL", "ParentEmail");
-define("TX_RECVNAME", "RecvName");
-define("TX_RECVTEL", "RecvTel");
-define("TX_RECVMSG", "RecvMsg");
-define("TX_RECVADDR", "RecvAddr");
-define("TX_RECVPOSTNUM", "RecvPostNum");
-define("TX_TAXFREE", "TaxFree");
-define("TX_TAX", "Tax");
-//PaymentInfo
-define("TX_PAYMETHOD", "PayMethod");
-define("TX_JOINCARD", "JoinCard");
-define("TX_JOINEXPIRE", "JoinExpire");
-define("TX_MAILORDER", "MailOrder");
-define("TX_SESSIONKEY", "SessionKey");
-define("TX_ENCRYPTED", "Encrypted");
-//ReservedInfo
-define("TX_MRESERVED1", "MReserved1");
-define("TX_MRESERVED2", "MReserved2");
-define("TX_MRESERVED3", "MReserved3");
-//ManageInfo
-define("TX_LANGUAGE", "Language");
-define("TX_URL", "URL");
-define("TX_TXVERSION", "TXVersion");
-define("TX_TXUSERIP", "TXUserIP");
-define("TX_TXUSERID", "TXUserID");
-define("TX_TXREGNUM", "TXRegNum");
-define("TX_ACK", "Ack");
-define("TX_RN", "TXRN");
-//CancelInfo
-define("TX_CANCELTID", "CancelTID");
-define("TX_CANCELMSG", "CancelMsg");
-define("TX_CANCELREASON", "CancelReason"); //2012-10-19 취소사유코드 추가
-//가상계좌환불(09.08.05)
-define("TX_REFUNDACCTNUM", "RefundAcctNum");
-define("TX_REFUNDBANKCODE", "RefundBankCode");
-define("TX_REFUNDACCTNAME", "RefundAcctName");
-define("TX_REFUNDFLGREMIT", "RefundFlgRemit");
-
-//PartCancelInfo
-define("TX_PRTC_TID", "PRTC_TID");
-define("TX_PRTC_PRICE", "PRTC_Price");
-define("TX_PRTC_REMAINS", "PRTC_Remains");
-define("TX_PRTC_QUOTA", "PRTC_Quota");
-define("TX_PRTC_INTEREST", "PRTC_Interest");
-define("TX_PRTC_TAX", "Tax");
-define("TX_PRTC_TAXFREE", "TaxFree");
-
-define("TX_PRTC_CURRENCY", "Currency");
-
-//국민은행 I계좌이체 부분취소시 계좌번호/계좌주성명추가 2011-10-06
-define("TX_PRTC_NOACCT", "PRTC_NoAcctFNBC");
-define("TX_PRTC_NMACCT", "PRTC_NmAcctFNBC");
-//가상계좌 부분환불 관련 추가
-define("TX_PRTC_REFUNDFLGREMIT", "PRTC_RefundFlgRemit");
-define("TX_PRTC_REFUNDBANKCODE", "PRTC_RefundBankCode");
-//CaptureInfo
-define("TX_CAPTURETID", "CaptureTID");
-//현금영수증
-define("TX_CSHR_APPLPRICE", "CSHR_ApplPrice");
-define("TX_CSHR_SUPPLYPRICE", "CSHR_SupplyPrice");
-define("TX_CSHR_TAX", "CSHR_Tax");
-define("TX_CSHR_SERVICEPRICE", "CSHR_ServicePrice");
-define("TX_CSHR_REGNUM", "CSHR_RegNum");
-define("TX_CSHR_TYPE", "CSHR_Type");
-define("TX_CSHR_COMPANYNUM", "CSHR_CompanyNum");
-define("TX_CSHR_OPENMARKET", "CSHR_OpenMarket");
-define("TX_CSHR_SUBCNT", "CSHR_SubCnt");
-define("TX_CSHR_SUBCOMPANYNAME1", "CSHR_SubCompanyName1");
-define("TX_CSHR_SUBCOMPANYNUM1", "CSHR_SubCompanyNum1");
-define("TX_CSHR_SUBREGNUM1", "CSHR_SubRegNum1");
-define("TX_CSHR_SUBMID1", "CSHR_SubMID1");
-define("TX_CSHR_SUBAPPLPRICE1", "CSHR_SubApplPrice1");
-define("TX_CSHR_SUBSERVICEPRICE1", "CSHR_SubServicePrice1");
-//거래조회(12.04.20)
-define("TX_INQR_TID", "INQR_TID");
-define("TX_INQR_OID", "INQR_OID");
-//서브몰하위가맹점등록(14.03.06)
-define("TX_OPENREG_TID", "OrgTID");
-define("TX_OPENREG_MID", "MID");
-define("TX_OPENREG_SUBCNT", "SubCnt");
-define("TX_OPENREG_SUBGOODS", "SubGoods");
-define("TX_OPENREG_SUBCOMPNO", "SubCompNo");
-define("TX_OPENREG_SUBCOMPNM", "SubCompNm");
-define("TX_OPENREG_SUBPRSUPPLY", "SubPrSupply");
-define("TX_OPENREG_SUBPRFREE", "SubPrFree");
-define("TX_OPENREG_SUBPRTAX", "SubPrTax");
-define("TX_OPENREG_SUBPRSERVICE", "SubPrService");
-define("TX_OPENREG_SUBPRICE", "SubPrice");
-
-//------------------------------------------------------
-//
-//응답전문
-//
-//------------------------------------------------------
-//HEAD
-define("NM_MID", "MID");
-define("NM_TID", "TID");
-define("NM_TOTPRICE", "TotPrice");
-
-//BODY
-define("NM_GOODSCNT", "GoodsCnt");
-define("NM_MOID", "MOID");
-define("NM_CURRENCY", "Currency");
-define("NM_SMID", "SMID");
-define("NM_GOODSNAME", "GoodsName");
-define("NM_GOODSPRICE", "GoodsPrice");
-define("NM_PAYMETHOD", "PayMethod");
-define("NM_RESULTCODE", "ResultCode");
-define("NM_RESULTERRORCODE", "ResultErrorCode");
-define("NM_RESULTMSG", "ResultMsg");
-define("NM_SESSIONKEY", "SessionKey");
-define("NM_ENCRYPTED", "Encrypted");
-define("NM_CANCELDATE", "CancelDate");
-define("NM_CANCELTIME", "CancelTime");
-define("NM_EVENTCODE", "EventCode");
-define("NM_ORGCURRENCY", "OrgCurrency");
-define("NM_ORGPRICE", "OrgPrice");
-define("NM_EXCHANGERATE", "ExchangeRate");
-define("NM_RESERVEDINFO", "ReservedInfo");
-define("NM_MRESERVED1", "MReserved1");
-define("NM_MRESERVED2", "MReserved2");
-define("NM_MRESERVED3", "MReserved3");
-define("PRTC_TID", "PRTC_TID");
-define("PRTC_PRICE", "PRTC_Price");
-define("PRTC_REMAINS", "PRTC_Remains");
-define("PRTC_QUOTA", "PRTC_Quota");
-define("PRTC_INTEREST", "PRTC_Interest");
-define("PRTC_TYPE", "PRTC_Type");
-define("PRTC_CNT", "PRTC_Cnt");
-define("NM_CAPTUREDATE", "CaptureDate");
-define("NM_CAPTURETIME", "CaptureTime");
-
-define("NM_PGPUBKEY", "PGcertKey");
-
-//RECV DATA XPATH
-//XML XPATH
-define("ROOTINFO", "INIpay");
-define("GOODSINFO", "GoodsInfo");
-define("GOODS", "Goods");
-define("BUYERINFO", "BuyerInfo");
-define("PAYMENTINFO", "PaymentInfo");
-define("PAYMENT", "Payment");
-define("MANAGEINFO", "ManageInfo");
-define("RESERVEDINFO", "ReservedInfo");
-//Cancel(NetCancel)
-define("CANCELINFO", "CancelInfo");
-//PartCancel Encrypt
-define("PARTCANCELINFO", "PartCancelInfo");
-//Capture
-define("CAPTUREINFO", "CaptureInfo");
-//거래조회(12.04.20)
-define("INQUIRYINFO", "InquiryInfo");
-//서브몰하위가맹점등록(14.03.06)
-define("OPENSUBINFO", "OpenSubInfo");
-//Escrow
-//added 2008.01.09
-define("ESCROWINFO", "EscrowInfo");
-define("ESCROW_DELIVERY", "Delivery");
-define("ESCROW_CONFIRM", "Confirm");
-define("ESCROW_DENY", "Deny");
-define("ESCROW_DENYCONFIRM", "DenyConfirm");
-
-
-//------------------------------------------------------
-//Auth Encrypt XPATH
-//------------------------------------------------------
-//CARD COMMON
-define("APPLDATE", "ApplDate");
-define("APPLTIME", "ApplTime");
-define("APPLNUM", "ApplNum");
-//CARD
-define("CARD_NUM", "CARD_Num");
-define("CARD_EXPIRE", "CARD_Expire");
-define("CARD_CODE", "CARD_Code");
-define("CARD_APPLPRICE", "CARD_ApplPrice");
-define("CARD_BANKCODE", "CARD_BankCode");
-define("CARD_QUOTA", "CARD_Quota");
-define("CARD_INTEREST", "CARD_Interest");
-define("CARD_POINT", "CARD_Point");
-define("CARD_AUTHTYPE", "CARD_AuthType");
-define("CARD_REGNUM", "CARD_RegNum");
-define("CARD_APPLDATE", "CARD_ApplDate");
-define("CARD_APPLTIME", "CARD_ApplTime");
-define("CARD_APPLNUM", "CARD_ApplNum");
-define("CARD_RESULTCODE", "CARD_ResultCode");
-define("CARD_RESULTMSG", "CARD_ResultMsg");
-define("CARD_TERMINALNUM", "CARD_TerminalNum");
-define("CARD_MEMBERNUM", "CARD_MemberNum");
-define("CARD_PURCHASECODE", "CARD_PurchaseCode");
-//ISP
-define("ISP_BANKCODE", "ISP_BankCode");
-define("ISP_QUOTA", "ISP_Quota");
-define("ISP_INTEREST", "ISP_Interest");
-define("ISP_APPLPRICE", "ISP_ApplPrice");
-define("ISP_CARDCODE", "ISP_CardCode");
-define("ISP_CARDNUM", "ISP_CardNum");
-define("ISP_POINT", "ISP_Point");
-define("ISP_APPLDATE", "ISP_ApplDate");
-define("ISP_APPLTIME", "ISP_ApplTime");
-define("ISP_APPLNUM", "ISP_ApplNum");
-define("ISP_RESULTCODE", "ISP_ResultCode");
-define("ISP_RESULTMSG", "ISP_ResultMsg");
-define("ISP_TERMINALNUM", "ISP_TerminalNum");
-define("ISP_MEMBERNUM", "ISP_MemberNum");
-define("ISP_PURCHASECODE", "ISP_PurchaseCode");
-//ACCT
-define("ACCT_APPLDATE", "ACCT_ApplDate");
-define("ACCT_APPLTIME", "ACCT_ApplTime");
-define("ACCT_APPLNUM", "ACCT_ApplNum");
-
-//HPP
-define("HPP_APPLDATE", "HPP_ApplDate");
-define("HPP_APPLTIME", "HPP_ApplTime");
-define("HPP_APPLNUM", "HPP_ApplNum");
-//VACT
-define("VACT_APPLDATE", "VACT_ApplDate");
-define("VACT_APPLTIME", "VACT_ApplTime");
-//CASH
-define("CSHR_APPLDATE", "CSHR_ApplDate");
-define("CSHR_APPLTIME", "CSHR_ApplTime");
-define("CSHR_APPLNUM", "CSHR_ApplNum");
-//ARSB
-define("ARSB_APPLDATE", "ARSB_ApplDate");
-define("ARSB_APPLTIME", "ARSB_ApplTime");
-define("ARSB_APPLNUM", "ARSB_ApplNum");
-//PHNB
-define("PHNB_APPLDATE", "PHNB_ApplDate");
-define("PHNB_APPLTIME", "PHNB_ApplTime");
-define("PHNB_APPLNUM", "PHNB_ApplNum");
-//CULT
-define("CULT_APPLDATE", "CULT_ApplDate");
-define("CULT_APPLTIME", "CULT_ApplTime");
-define("CULT_APPLNUM", "CULT_ApplNum");
-//DGCL
-define("GAMG_CNT", "GAMG_Cnt");
-define("GAMG_APPLDATE", "GAMG_ApplDate");
-define("GAMG_APPLTIME", "GAMG_ApplTime");
-define("GAMG_APPLNUM", "GAMG_ApplNum");
-
-function MakePathGAMG($cnt) {
- for ($i = 1; $i <= $cnt; $i++) {
- define("GAMG_NUM$i", "GAMG_Num$i");
- define("GAMG_REMAINS$i", "GAMG_Remains$i");
- define("GAMG_ERRMSG$i", "GAMG_ErrMsg$i");
- }
-}
-
-//EDUG
-define("EDUG_APPLDATE", "EDUG_ApplDate");
-define("EDUG_APPLTIME", "EDUG_ApplTime");
-define("EDUG_APPLNUM", "EDUG_ApplNum");
-//TEEN
-define("TEEN_APPLDATE", "TEEN_ApplDate");
-define("TEEN_APPLTIME", "TEEN_ApplTime");
-define("TEEN_APPLNUM", "TEEN_ApplNum");
-
-//----------------------------------
-//ERROR CODE
-//----------------------------------
-//!!신TX에 추가된 에러!!!
-define("NULL_DIR_ERR", "TX9001");
-define("NULL_TYPE_ERR", "TX9002");
-define("NULL_NOINTEREST_ERR", "TX9003");
-define("NULL_QUOTABASE_ERR", "TX9004");
-define("DNS_LOOKUP_ERR", "TX9005");
-define("MERCHANT_DB_ERR", "TX9006");
-define("DNS_LOOKUP_TIMEOUT_ERR", "TX9007");
-define("PGPUB_UPDATE_ERR", "TX9612");
-
-//암복호화 에러
-define("B64DECODE_UPDATE_ERR", "TX9101");
-define("B64DECODE_FINAL_ERR", "TX9102");
-define("B64DECODE_LENGTH_ERR", "TX9103");
-define("GET_KEYPW_EVP_B2K_ERR", "TX9104");
-define("GET_KEYPW_FILE_OPEN_ERR", "TX9105");
-define("GET_KEYPW_FILE_READ_ERR", "TX9106");
-define("GET_KEYPW_DECRYPT_INIT_ERR", "TX9107");
-define("GET_KEYPW_DECRYPT_UPDATE_ERR", "TX9108");
-define("GET_KEYPW_DECRYPT_FINAL_ERR", "TX9109");
-define("ENC_RAND_BYTES_ERR", "TX9110");
-define("ENC_INIT_ERR", "TX9111");
-define("ENC_UPDATE_ERR", "TX9112");
-define("ENC_FINAL_ERR", "TX9113");
-define("ENC_RSA_ERR", "TX9114");
-define("DEC_RSA_ERR", "TX9115");
-define("DEC_CIPHER_ERR", "TX9116");
-define("DEC_INIT_ERR", "TX9117");
-define("DEC_UPDATE_ERR", "TX9118");
-define("DEC_FINAL_ERR", "TX9119");
-define("SIGN_FINAL_ERR", "TX9120");
-define("SIGN_CHECK_ERR", "TX9121");
-define("ENC_NULL_F_ERR", "TX9122");
-define("ENC_INIT_RAND_ERR", "TX9123");
-define("ENC_PUTENV_ERR", "TX9124");
-//필드체크
-define("NULL_KEYPW_ERR", "TX9201");
-define("NULL_MID_ERR", "TX9202");
-define("NULL_PGID_ERR", "TX9203");
-define("NULL_TID_ERR", "TX9204");
-define("NULL_UIP_ERR", "TX9205");
-define("NULL_URL_ERR", "TX9206");
-define("NULL_PRICE_ERR", "TX9207");
-define("NULL_PRICE1_ERR", "TX9208");
-define("NULL_PRICE2_ERR", "TX9209");
-define("NULL_CARDNUMBER_ERR", "TX9210");
-define("NULL_CARDEXPIRE_ERR", "TX9211");
-define("NULL_ENCRYPTED_ERR", "TX9212");
-define("NULL_CARDQUOTA_ERR", "TX9213");
-define("NULL_QUOTAINTEREST_ERR", "TX9214");
-define("NULL_AUTHENTIFICATION_ERR", "TX9215");
-define("NULL_AUTHFIELD1_ERR", "TX9216");
-define("NULL_AUTHFIELD2_ERR", "TX9217");
-define("NULL_BANKCODE_ERR", "TX9218");
-define("NULL_BANKACCOUNT_ERR", "TX9219");
-define("NULL_REGNUMBER_ERR", "TX9220");
-define("NULL_OCBCARDNUM_ERR", "TX9221");
-define("NULL_OCBPASSWD_ERR", "TX9222");
-define("NULL_PASSWD_ERR", "TX9223");
-define("NULL_CURRENCY_ERR", "TX9224");
-define("NULL_PAYMETHOD_ERR", "TX9225");
-define("NULL_GOODNAME_ERR", "TX9226");
-define("NULL_BUYERNAME_ERR", "TX9227");
-define("NULL_BUYERTEL_ERR", "TX9228");
-define("NULL_BUYEREMAIL_ERR", "TX9229");
-define("NULL_SESSIONKEY_ERR", "TX9230");
-//pg공개키 로드 오류
-define("NULL_PGCERT_FP_ERR", "TX9231");
-define("NULL_X509_ERR", "TX9232");
-define("NULL_PGCERT_ERR", "TX9233");
-
-define("RESULT_MSG_FORMAT_ERR", "TX9234");
-
-// 가상 계좌 이체 예약
-define("NULL_PERNO_ERR", "TX9235"); // 주민번호 빠짐
-define("NULL_OID_ERR", "TX9236"); // 주문번호 빠짐
-define("NULL_VCDBANK_ERR", "TX9237"); // 은행코드 빠짐
-define("NULL_DTINPUT_ERR", "TX9238"); // 입금 예정일 빠짐
-define("NULL_NMINPUT_ERR", "TX9239"); // 송금자 성명 빠짐
-//실시간 빌링
-define("NULL_BILLKEY_ERR", "TX9240"); // 빌키 빠짐
-define("NULL_CARDPASS_ERR", "TX9241"); // 카드 비번 빠짐
-define("NULL_BILLTYPE_ERR", "TX9242"); // 빌타입 누락
-// CMS 계좌이체
-define("NULL_PRICE_ORG_ERR", "TX9250"); // CMS 출금총금액 빠짐
-define("NULL_CMSDAY_ERR", "TX9251"); // CMS 출금일자 빠짐
-define("NULL_CMSDATEFROM_ERR", "TX9252"); // CMS 출금시작월 빠짐
-define("NULL_CMSDATETO_ERR", "TX9253"); // CMS 출금종료월 빠짐
-// 부분취소
-define("NULL_CONFIRM_PRICE_ERR", "TX9260"); // 재승인 요청금액 누락 에러
-// 현금영수증 발행
-define("NULL_CR_PRICE_ERR", "TX9270"); // 현금결제 금액 빠짐
-define("NULL_SUP_PRICE_ERR", "TX9271"); // 공급가액 빠짐
-define("NULL_TAX_ERR", "TX9272"); // 부가세 빠짐
-define("NULL_SRVC_PRICE_ERR", "TX9273"); // 봉사료 빠짐
-define("NULL_REG_NUM_ERR", "TX9274"); // 주민번호(사업자번호)
-define("NULL_USEOPT_ERR", "TX9275"); // 현금영수증 용도 구분자 빠짐
-
-define("PRIVKEY_FILE_OPEN_ERR", "TX9301");
-define("INVALID_KEYPASS_ERR", "TX9302");
-
-define("MAKE_TID_ERR", "TX9401");
-define("ACK_CHECKSUM_ERR", "TX9402");
-define("NETCANCEL_SOCK_CREATE_ERR", "TX9403");
-define("NETCANCEL_SOCK_SEND_ERR", "TX9404");
-define("NETCANCEL_SOCK_RECV_ERR", "TX9405");
-define("LOG_OPEN_ERR", "TX9406");
-define("LOG_WRITE_ERR", "TX9407");
-
-define("SOCK_MAKE_EP_ERR", "TX9501");
-define("SOCK_CONN_ERR", "TX9502");
-define("SOCK_SEND1_ERR", "TX9503");
-define("SOCK_SEND2_ERR", "TX9504");
-define("SOCK_CLOSED_BY_PEER_ERR", "TX9505");
-define("SOCK_RECV1_ERR", "TX9506");
-define("SOCK_RECV2_ERR", "TX9507");
-define("SOCK_RECV_LEN_ERR", "TX9508");
-define("SOCK_TIMEO_ERR", "TX9509");
-define("SOCK_ETC1_ERR", "TX9510");
-define("SOCK_ETC2_ERR", "TX9511");
-
-define("NULL_ESCROWTYPE_ERR", "TX6000");
-define("NULL_ESCROWMSG_ERR", "TX6001");
-
-define("NULL_FIELD_REFUNDACCTNUM", "TX9245");
-define("NULL_FIELD_REFUNDBANKCODE", "TX9243");
-define("NULL_FIELD_REFUNDACCTNAME", "TX9244");
\ No newline at end of file
diff --git a/shop/inicis/libs/INILib.php b/shop/inicis/libs/INILib.php
deleted file mode 100644
index c77cf2002..000000000
--- a/shop/inicis/libs/INILib.php
+++ /dev/null
@@ -1,735 +0,0 @@
-UnsetField();
- }
-
- function UnsetField() {
- unset($this->m_REQUEST);
- unset($this->m_RESULT);
- }
-
- /* -------------------------------------------------- */
- /* */
- /* 결제/취소 요청값 Set or Add */
- /* */
- /* -------------------------------------------------- */
-
- function SetField($key, $val) { //Default Entity
- $this->m_REQUEST[$key] = $val;
- }
-
- function SetXPath($xpath, $val) { //User Defined Entity
- $this->m_REQUEST2[$xpath] = $val;
- }
-
- /* -------------------------------------------------- */
- /* */
- /* 결제/취소 결과값 fetch */
- /* */
- /* -------------------------------------------------- */
-
- function GetResult($name) { //Default Entity
- $result = isset($this->m_RESULT[$name]) ? $this->m_RESULT[$name] : '';
- if ($result == "")
- $result = $this->m_Data->GetXMLData($name);
- if ($result == "")
- $result = $this->m_Data->m_RESULT[$name];
- return $result;
- }
-
- /* -------------------------------------------------- */
- /* */
- /* 결제/취소 처리 메인 */
- /* */
- /* -------------------------------------------------- */
-
- function startAction() {
-
- /* -------------------------------------------------- */
- /* Overhead Operation */
- /* -------------------------------------------------- */
- $this->m_Data = new INIData($this->m_REQUEST, $this->m_REQUEST2);
-
- /* -------------------------------------------------- */
- /* Log Start */
- /* -------------------------------------------------- */
- $this->m_Log = new INILog($this->m_REQUEST);
- if (!$this->m_Log->StartLog()) {
- $this->MakeTXErrMsg(LOG_OPEN_ERR, "로그파일을 열수가 없습니다.[" . $this->m_REQUEST["inipayhome"] . "]");
- return;
- }
-
- /* -------------------------------------------------- */
- /* Logging Request Parameter */
- /* -------------------------------------------------- */
- $this->m_Log->WriteLog(DEBUG, $this->m_REQUEST);
-
- /* -------------------------------------------------- */
- /* Set Type */
- /* -------------------------------------------------- */
- $this->m_type = $this->m_REQUEST["type"];
-
- /* -------------------------------------------------- */
- /* Check Field */
- /* -------------------------------------------------- */
- if (!$this->m_Data->CheckField()) {
- $err_msg = "필수항목(" . $this->m_Data->m_ErrMsg . ")이 누락되었습니다.";
- $this->MakeTXErrMsg($this->m_Data->m_ErrCode, $err_msg);
- $this->m_Log->WriteLog(ERROR, $err_msg);
- $this->m_Log->CloseLog($this->GetResult(NM_RESULTMSG));
- return;
- }
- $this->m_Log->WriteLog(INFO, "Check Field OK");
-
- /* -------------------------------------------------- */
- //웹페이지위변조용 키생성. 여기서 끝!!
- /* -------------------------------------------------- */
- if ($this->m_type == TYPE_CHKFAKE) {
- return $this->MakeChkFake();
- }
-
-
- //TID 인입 기반 거래의 경우 TID 를 기록함
- $temp_request = array_change_key_case($this->m_REQUEST, CASE_LOWER);
- if(isset($temp_request['tid'])){
- $this->m_Log->WriteLog(INFO, "INPUT TID > ".$temp_request['tid']);
- }
-
- /* -------------------------------------------------- */
- //Generate TID
- /* -------------------------------------------------- */
- if ($this->m_type == TYPE_SECUREPAY || $this->m_type == TYPE_FORMPAY || $this->m_type == TYPE_OCBSAVE ||
- $this->m_type == TYPE_AUTHBILL || $this->m_type == TYPE_FORMAUTH || $this->m_type == TYPE_REQREALBILL ||
- $this->m_type == TYPE_REPAY || $this->m_type == TYPE_VACCTREPAY || $this->m_type == TYPE_RECEIPT || $this->m_type == TYPE_AUTH
- ) {
- if (!$this->m_Data->MakeTID()) {
- $err_msg = "TID생성에 실패했습니다.::" . $this->m_Data->m_sTID;
- $this->m_Log->WriteLog(ERROR, $err_msg);
- $this->MakeTXErrMsg(MAKE_TID_ERR, $err_msg);
- $this->m_Log->CloseLog($this->GetResult(NM_RESULTMSG));
- return;
- }
- $this->m_Log->WriteLog(INFO, 'Make TID OK ' . $this->m_Data->m_sTID);
- }
-
- $this->m_Crypto = new INICrypto($this->m_REQUEST);
-
- /* -------------------------------------------------- */
- //PI공개키 로드
- /* -------------------------------------------------- */
- $this->m_Data->ParsePIEncrypted();
- $this->m_Log->WriteLog(INFO, "PI PUB KEY LOAD OK [" . $this->m_Data->m_PIPGPubSN . "]");
-
- /* -------------------------------------------------- */
- //PG공개키 로드
- /* -------------------------------------------------- */
- if (($rtv = $this->m_Crypto->LoadPGPubKey($pg_cert_SN)) != OK) {
- $err_msg = "PG공개키 로드오류";
- $this->m_Log->WriteLog(ERROR, $err_msg);
- $this->MakeTXErrMsg($rtv, $err_msg);
- $this->m_Log->CloseLog($this->GetResult(NM_RESULTMSG));
- return;
- }
- $this->m_Data->m_TXPGPubSN = $pg_cert_SN;
- $this->m_Log->WriteLog(INFO, "PG PUB KEY LOAD OK [" . $this->m_Data->m_TXPGPubSN . "]");
-
- /* -------------------------------------------------- */
- //상점개인키 로드
- /* -------------------------------------------------- */
- if (($rtv = $this->m_Crypto->LoadMPrivKey()) != OK) {
- $err_msg = "상점개인키 로드오류";
- $this->m_Log->WriteLog(ERROR, $err_msg);
- $this->MakeTXErrMsg($rtv, $err_msg);
- $this->m_Log->CloseLog($this->GetResult(NM_RESULTMSG));
- $this->m_Crypto->FreePubKey();
- return;
- }
- $this->m_Log->WriteLog(INFO, "MERCHANT PRIV KEY LOAD OK");
-
- /* -------------------------------------------------- */
- //상점 공개키 로드(SN 를 알기위해!!)
- /* -------------------------------------------------- */
- if (($rtv = $this->m_Crypto->LoadMPubKey($m_cert_SN)) != OK) {
- $err_msg = "상점공개키 로드오류";
- $this->m_Log->WriteLog(ERROR, $err_msg);
- $this->MakeTXErrMsg($rtv, $err_msg);
- $this->m_Log->CloseLog($this->GetResult(NM_RESULTMSG));
- return;
- }
- $this->m_Data->m_MPubSN = $m_cert_SN;
- $this->m_Log->WriteLog(INFO, "MERCHANT PUB KEY LOAD OK [" . $this->m_Data->m_MPubSN . "]");
-
- /* -------------------------------------------------- */
- //폼페이 암호화( formpay, cancel, repay, recept, inquiry, opensub)
- /* -------------------------------------------------- */
- if ($this->m_type == TYPE_CANCEL || $this->m_type == TYPE_REPAY || $this->m_type == TYPE_VACCTREPAY ||
- $this->m_type == TYPE_FORMPAY || $this->m_type == TYPE_RECEIPT ||
- $this->m_type == TYPE_CAPTURE || $this->m_type == TYPE_INQUIRY || $this->m_type == TYPE_OPENSUB ||
- ($this->m_type == TYPE_ESCROW && $this->m_Data->m_EscrowType == TYPE_ESCROW_DLV ) ||
- ($this->m_type == TYPE_ESCROW && $this->m_Data->m_EscrowType == TYPE_ESCROW_DNY_CNF ) ||
- $this->m_type == TYPE_REFUND
- ) {
- if (($rtv = $this->m_Data->MakeEncrypt($this->m_Crypto)) != OK) {
- $err_msg = "암호화 오류";
- $this->m_Log->WriteLog(ERROR, $err_msg);
- $this->MakeTXErrMsg($rtv, $err_msg);
- $this->m_Log->CloseLog($this->GetResult(NM_RESULTMSG));
- return;
- }
- //$this->m_Log->WriteLog( DEBUG, "MAKE ENCRYPT OK" );
- $this->m_Log->WriteLog(DEBUG, "MAKE ENCRYPT OK[" . $this->m_Data->m_EncBody . "]");
- }
-
- /* -------------------------------------------------- */
- //전문생성(Body)
- /* -------------------------------------------------- */
- $this->m_Data->MakeBody();
- $this->m_Log->WriteLog(INFO, "MAKE BODY OK");
- //$this->m_Log->WriteLog( INFO, "MAKE BODY OK[".$this->m_Data->m_sBody."]" );
-
- /* -------------------------------------------------- */
- //서명(sign)
- /* -------------------------------------------------- */
- if (($rtv = $this->m_Crypto->Sign($this->m_Data->m_sBody, $sign)) != OK) {
- $err_msg = "싸인실패";
- $this->m_Log->WriteLog(ERROR, $err_msg);
- $this->MakeTXErrMsg($rtv, $err_msg);
- $this->m_Log->CloseLog($this->GetResult(NM_RESULTMSG));
- $this->m_Crypto->FreeAllKey();
- return;
- }
- $this->m_Data->m_sTail = $sign;
- $this->m_Log->WriteLog(INFO, "SIGN OK");
- //$this->m_Log->WriteLog( INFO, "SIGN OK[".$sign."]" );
-
- /* -------------------------------------------------- */
- //전문생성(Head)
- /* -------------------------------------------------- */
- $this->m_Data->MakeHead();
- $this->m_Log->WriteLog(INFO, "MAKE HEAD OK");
- //$this->m_Log->WriteLog( INFO, "MAKE HEAD OK[".$head."]" );
-
- $this->m_Log->WriteLog(DEBUG, "MSG_TO_PG:[" . $this->m_Data->m_sMsg . "]");
-
-
- /* -------------------------------------------------- */
- //소켓생성
- /* -------------------------------------------------- */
-
- //플러그인 에스크로 결제 구분 설정
- $is_plugin_escrow = FALSE;
- if($this->m_type == TYPE_ESCROW && ($this->m_Data->m_EscrowType == TYPE_ESCROW_CNF || $this->m_Data->m_EscrowType == TYPE_ESCROW_DNY)) $is_plugin_escrow = TRUE;
-
-
- if(isset($this->m_REQUEST["pgn"]) && $this->m_REQUEST["pgn"] != "") {
- $host = $this->m_REQUEST["pgn"];
- } else {
- if ($this->m_type == TYPE_SECUREPAY || $is_plugin_escrow == TRUE) { //plugin
- $host = $this->m_Data->m_PG1;
- } else if ($this->m_cancelRC == 1){ //원거래없음
- $host = KSPG_IP;
- } else {
- $host = PG_HOST;
- }
- }
-
- $this->m_Socket = new INISocket($host);
-
- //1차 NSLOOKUP FAIL
- if (($rtv = $this->m_Socket->DNSLookup()) != OK) {
- $err_msg = "[" . $host . "] 1차 DNS LOOKUP 실패" . $this->m_Socket->getErr();
- $this->m_Log->WriteLog(ERROR, $err_msg);
- $this->MakeTXErrMsg($rtv, $err_msg);
-
- if ($this->m_type == TYPE_SECUREPAY || $is_plugin_escrow == TRUE) {
- $this->m_Socket->ip = $this->m_Data->m_PG1IP;
- } else {
- if ($this->m_cancelRC == 1) $this->m_Socket->ip = KSPG_IP;
- else $this->m_Socket->ip = PG_IP;
- }
- }
-
- $this->m_Log->WriteLog(INFO, "DNS LOOKUP OK(" . $this->m_Socket->host . ", " . $this->m_Socket->ip . ":" . $this->m_Socket->port . ") laptime:" . $this->m_Socket->dns_laptime);
-
- if (($rtv = $this->m_Socket->open()) != OK) {
- $this->m_Socket->close();
-
- //PG2로 전환
- $err_msg = "[" . $host."(". $this->m_Socket->ip .") 소켓연결오류(1차):: 2차 연결시도";
- $this->m_Log->WriteLog(ERROR, $err_msg);
- $this->MakeTXErrMsg($rtv, $err_msg);
- if ($this->m_type == TYPE_SECUREPAY || $is_plugin_escrow == TRUE) {
- $host = $this->m_Data->m_PG2;
- } else {
- $host = $this->m_Socket->ip == PG_IP ? KSPG_IP:PG_IP;
- }
-
- $this->m_Socket = new INISocket($host);
-
- //SECUREPAY만 2차 NSLOOKUP 진행, 이외는 IP통신
- if ($this->m_type == TYPE_SECUREPAY || $is_plugin_escrow == TRUE) {
- if (($rtv = $this->m_Socket->DNSLookup()) != OK) {
- $err_msg = "[" . $host . "] 2차 DNS LOOKUP 실패" . $this->m_Socket->getErr();
- $this->m_Log->WriteLog(ERROR, $err_msg);
- $this->MakeTXErrMsg($rtv, $err_msg);
- $this->m_Socket->ip = $this->m_Data->m_PG2IP;
- }
- } else {
- $this->m_Socket->ip = $host;
- }
-
- $this->m_Log->WriteLog(INFO, "DNS LOOKUP OK(" . $this->m_Socket->host . ", " . $this->m_Socket->ip . ":" . $this->m_Socket->port . ") laptime:" . $this->m_Socket->dns_laptime);
-
- if (($rtv = $this->m_Socket->open()) != OK) {
- $err_msg = "[" . $host . "소켓연결오류(2차)::" . $this->m_Socket->getErr();
- $this->m_Log->WriteLog(ERROR, $err_msg);
- $this->MakeTXErrMsg($rtv, $err_msg);
- $this->m_Log->CloseLog($this->GetResult(NM_RESULTMSG));
- $this->m_Socket->close();
- $this->m_Crypto->FreeAllKey();
- return;
- }
- }
- $this->m_connIP = $this->m_Socket->ip;
- $this->m_Log->WriteLog(INFO, "SOCKET CONNECT OK");
-
- /* -------------------------------------------------- */
- //전문송신
- /* -------------------------------------------------- */
- if (($rtv = $this->m_Socket->send($this->m_Data->m_sMsg)) != OK) {
- $err_msg = "소켓송신오류(MAIN)::" . $this->m_Socket->getErr();
- $this->m_Log->WriteLog(ERROR, $err_msg);
- $this->MakeTXErrMsg($rtv, $err_msg);
- $this->m_Log->CloseLog($this->GetResult(NM_RESULTMSG));
- $this->m_Crypto->FreeAllKey();
- $this->m_Socket->close();
- return;
- }
- $this->m_Log->WriteLog(INFO, "SEND OK");
-
- /* -------------------------------------------------- */
- //전문수신
- /* -------------------------------------------------- */
- if (($rtv = $this->m_Socket->recv($head, $body, $tail)) != OK) {
- $err_msg = "소켓수신오류(MAIN)::" . $this->m_Socket->getErr();
- $this->m_Log->WriteLog(ERROR, $err_msg);
- $this->MakeTXErrMsg($rtv, $err_msg);
- $this->m_Socket->close();
- $this->NetCancel();
- $this->m_Log->CloseLog($this->GetResult(NM_RESULTMSG));
- $this->m_Crypto->FreeAllKey();
- return;
- }
- $this->m_Log->WriteLog(INFO, "RECV OK");
- $this->m_Log->WriteLog(INFO, "MSG_FROM_PG:[" . $head . $body . $tail . "]");
- $this->m_Data->m_Body = $body;
-
- /* -------------------------------------------------- */
- //서명확인
- /* -------------------------------------------------- */
- if (($rtv = $this->m_Crypto->Verify($body, $tail)) != OK) {
- $err_msg = "VERIFY FAIL";
- $this->m_Log->WriteLog(ERROR, $err_msg);
- $this->MakeTXErrMsg($rtv, $err_msg);
- $this->m_Socket->close();
- $this->NetCancel();
- $this->m_Log->CloseLog($this->GetResult(NM_RESULTMSG));
- $this->m_Crypto->FreeAllKey();
- return;
- }
- $this->m_Log->WriteLog(INFO, "VERIFY OK");
-
- /* -------------------------------------------------- */
- //Head 파싱
- /* -------------------------------------------------- */
- if (($rtv = $this->m_Data->ParseHead($head)) != OK) {
- $err_msg = "수신전문(HEAD) 파싱 오류";
- $this->m_Log->WriteLog(ERROR, $err_msg);
- $this->MakeTXErrMsg($rtv, $err_msg);
- $this->m_Socket->close();
- $this->NetCancel();
- $this->m_Log->CloseLog($this->GetResult(NM_RESULTMSG));
- $this->m_Crypto->FreeAllKey();
- return;
- }
- $this->m_Log->WriteLog(INFO, "PARSE HEAD OK");
-
- /* -------------------------------------------------- */
- //Body 파싱
- /* -------------------------------------------------- */
- if (($rtv = $this->m_Data->ParseBody($body, $encrypted, $sessionkey)) != OK) {
- $err_msg = "수신전문(Body) 파싱 오류";
- $this->m_Log->WriteLog(ERROR, $err_msg);
- $this->MakeTXErrMsg($rtv, $err_msg);
- $this->m_Socket->close();
- $this->NetCancel();
- $this->m_Log->CloseLog($this->GetResult(NM_RESULTMSG));
- $this->m_Crypto->FreeAllKey();
- return;
- }
- $this->m_Log->WriteLog(INFO, "PARSE BODY OK");
-
- /* -------------------------------------------------- */
- //복호화
- /* -------------------------------------------------- */
- if ($this->m_type == TYPE_SECUREPAY || $this->m_type == TYPE_FORMPAY || $this->m_type == TYPE_OCBSAVE ||
- $this->m_type == TYPE_CANCEL || $this->m_type == TYPE_AUTHBILL || $this->m_type == TYPE_FORMAUTH ||
- $this->m_type == TYPE_REQREALBILL || $this->m_type == TYPE_REPAY || $this->m_type == TYPE_VACCTREPAY || $this->m_type == TYPE_RECEIPT ||
- $this->m_type == TYPE_AUTH || $this->m_type == TYPE_CAPTURE || $this->m_type == TYPE_ESCROW ||
- $this->m_type == TYPE_REFUND || $this->m_type == TYPE_INQUIRY || $this->m_type == TYPE_OPENSUB
- ) {
- if (($rtv = $this->m_Crypto->Decrypt($sessionkey, $encrypted, $decrypted)) != OK) {
- $err_msg = "복호화 실패[" . $this->GetResult(NM_RESULTMSG) . "]";
- $this->m_Log->WriteLog(ERROR, $err_msg);
- $this->MakeTXErrMsg($rtv, $err_msg);
- $this->m_Socket->close();
- $this->NetCancel();
- $this->m_Log->CloseLog($this->GetResult(NM_RESULTMSG));
- $this->m_Crypto->FreeAllKey();
- return;
- }
- $this->m_Log->WriteLog(INFO, "DECRYPT OK");
- $this->m_Log->WriteLog(DEBUG, "DECRYPT MSG:[" . $decrypted . "]");
-
- //Parse Decrypt
- $this->m_Data->ParseDecrypt($decrypted);
- $this->m_Log->WriteLog(INFO, "DECRYPT PARSE OK");
- }
-
- /* -------------------------------------------------- */
- //Assign Interface Variables
- /* -------------------------------------------------- */
- $this->m_RESULT = $this->m_Data->m_RESULT;
-
- /* -------------------------------------------------- */
- //ACK
- /* -------------------------------------------------- */
- //if( $this->GetResult(NM_RESULTCODE) == "00" &&
- if ((strcmp($this->GetResult(NM_RESULTCODE), "00") == 0) &&
- ( $this->m_type == TYPE_SECUREPAY || $this->m_type == TYPE_OCBSAVE ||
- $this->m_type == TYPE_FORMPAY || $this->m_type == TYPE_RECEIPT
- )
- ) {
- $this->m_Log->WriteLog(INFO, "WAIT ACK INVOKING");
- if (($rtv = $this->Ack()) != OK) {
- //ERROR
- $err_msg = "ACK 실패";
- $this->m_Log->WriteLog(ERROR, $err_msg);
- $this->MakeTXErrMsg($rtv, $err_msg);
- $this->m_Socket->close();
- $this->NetCancel();
- $this->m_Log->CloseLog($this->GetResult(NM_RESULTMSG));
- $this->m_Crypto->FreeAllKey();
- return;
- }
- $this->m_Log->WriteLog(INFO, "SUCCESS ACK INVOKING");
- }
- /* -------------------------------------------------- */
- //PG 공개키가 바뀌었으면 공개키 UPDATE
- /* -------------------------------------------------- */
- $pgpubkey = $this->m_Data->GetXMLData(NM_PGPUBKEY);
- if ($pgpubkey != "") {
- if (($rtv = $this->m_Crypto->UpdatePGPubKey($pgpubkey)) != OK) {
- $err_msg = "PG공개키 업데이트 실패";
- $this->m_Log->WriteLog(ERROR, $err_msg);
- $this->m_Data->GTHR($rtv, $err_msg);
- } else
- $this->m_Log->WriteLog(INFO, "PGPubKey UPDATED!!");
- }
-
- $this->m_Log->CloseLog($this->GetResult(NM_RESULTMSG));
- $this->m_Crypto->FreeAllKey();
- $this->m_Socket->close();
-
- return;
- }
-
-// End of StartAction
-
- /* -------------------------------------------------- */
- /* */
- /* 웹페이지 위변조 방지용 데이타 생성 */
- /* */
- /* -------------------------------------------------- */
-
- function MakeChkFake() {
- $this->m_Crypto = new INICrypto($this->m_REQUEST);
-
- /* -------------------------------------------------- */
- //상점개인키 로드
- /* -------------------------------------------------- */
- if (($rtv = $this->m_Crypto->LoadMPrivKey()) != OK) {
- $err_msg = "상점개인키 로드오류";
- $this->m_Log->WriteLog(ERROR, $err_msg);
- $this->MakeTXErrMsg($rtv, $err_msg);
- $this->m_Log->CloseLog($this->GetResult(NM_RESULTMSG));
- $this->m_Crypto->FreePubKey();
- return;
- }
- $this->m_Log->WriteLog(INFO, "MERCHANT PRIV KEY LOAD OK");
-
- /* -------------------------------------------------- */
- //상점 공개키 로드(SN 를 알기위해!!)
- /* -------------------------------------------------- */
- if (($rtv = $this->m_Crypto->LoadMPubKey($m_cert_SN)) != OK) {
- $err_msg = "상점공개키 로드오류";
- $this->m_Log->WriteLog(ERROR, $err_msg);
- $this->MakeTXErrMsg($rtv, $err_msg);
- $this->m_Log->CloseLog($this->GetResult(NM_RESULTMSG));
- return;
- }
- $this->m_Log->WriteLog(INFO, "MERCHANT PUB KEY LOAD OK [" . $this->m_Data->m_MPubSN . "]");
-
- foreach ($this->m_REQUEST as $key => $val) {
- if ($key == "inipayhome" || $key == "type" || $key == "debug" ||
- $key == "admin" || $key == "checkopt" || $key == "enctype")
- continue;
- if ($key == "mid")
- $temp1 .= $key . "=" . $val . "&"; //msg
- else
- $temp2 .= $key . "=" . $val . "&"; //hashmsg
- }
- //Make RN
- $this->m_RESULT["rn"] = $this->m_Data->MakeRN();
- $temp1 .= "rn=" . $this->m_RESULT["rn"] . "&";
-
- $checkMsg = $temp1;
- $checkHashMsg = $temp2;
-
- $retHashStr = Base64Encode(sha1($checkHashMsg, TRUE));
- $checkMsg .= "data=" . $retHashStr;
-
- $HashMid = Base64Encode(sha1($this->m_REQUEST["mid"], TRUE));
-
- $this->m_Crypto->RSAMPrivEncrypt($checkMsg, $RSATemp);
- $this->m_RESULT["encfield"] = "enc=" . $RSATemp . "&src=" . Base64Encode($checkHashMsg);
- $this->m_RESULT["certid"] = $HashMid . $m_cert_SN;
-
- $this->m_Log->WriteLog(INFO, "CHKFAKE KEY MAKE OK:" . $this->m_RESULT["rn"]);
-
- $this->m_Log->CloseLog($this->GetResult(NM_RESULTMSG));
- $this->m_Crypto->FreeAllKey();
- $this->m_RESULT[NM_RESULTCODE] = "00";
- return;
- }
-
- /* -------------------------------------------------- */
- /* */
- /* 결제처리 확인 메세지 전송 */
- /* */
- /* -------------------------------------------------- */
-
- function Ack() {
- //ACK용 Data
- $this->m_Data->m_sBody = "";
- $this->m_Data->m_sTail = "";
- $this->m_Data->m_sCmd = CMD_REQ_ACK;
-
- //전문생성(Head)
- $this->m_Data->MakeHead();
- $this->m_Log->WriteLog(DEBUG, "MAKE HEAD OK");
- //$this->m_Log->WriteLog( DEBUG, "MSG_TO_PG:[".$this->m_Data->m_sMsg."]" );
- //Send
- if (($rtv = $this->m_Socket->send($this->m_Data->m_sMsg)) != OK) {
- $err_msg = "ACK 전송오류";
- $this->m_Log->WriteLog(ERROR, $err_msg);
- return ACK_CHECKSUM_ERR;
- }
- //$this->m_Log->WriteLog( DEBUG, "SEND OK" );
-
- if (($rtv = $this->m_Socket->recv($head, $body, $tail)) != OK) {
- $err_msg = "ACK 수신오류(ACK)";
- $this->m_Log->WriteLog(ERROR, $err_msg);
- return ACK_CHECKSUM_ERR;
- }
- //$this->m_Log->WriteLog( DEBUG, "RECV OK" );
- //$this->m_Log->WriteLog( INFO, "MSG_FROM_PG:[".$recv."]" );
- return OK;
- }
-
- /* -------------------------------------------------- */
- /* */
- /* 망취소 메세지 전송 */
- /* */
- /* -------------------------------------------------- */
-
- function NetCancel() {
- $this->m_Log->WriteLog(INFO, "WAIT NETCANCEL INVOKING");
-
- if ($this->m_type == TYPE_CANCEL || $this->m_type == TYPE_REPAY || $this->m_type == TYPE_VACCTREPAY || $this->m_type == TYPE_RECEIPT ||
- $this->m_type == TYPE_CONFIRM || $this->m_type == TYPE_OCBQUERY || $this->m_type == TYPE_ESCROW ||
- $this->m_type == TYPE_CAPTURE || $this->m_type == TYPE_AUTH || $this->m_type == TYPE_AUTHBILL ||
- ($this->m_type == TYPE_ESCROW && $this->m_Data->m_EscrowType == TYPE_ESCROW_DNY_CNF ) ||
- $this->m_type == TYPE_NETCANCEL
- ) {
- $this->m_Log->WriteLog(INFO, "DON'T NEED NETCANCEL");
- return true;
- }
-
- //NetCancel용 Data
- $this->m_Data->m_REQUEST["cancelmsg"] = "망취소";
- $body = "";
- $sign = "";
-
- $this->m_Data->m_Type = TYPE_CANCEL; //망취소 전문은 취소전문과 같음.헤더만틀리고..쩝~
- //added escrow netcancel, 08.03.11
- if ($this->m_type == TYPE_ESCROW && $this->m_Data->m_EscrowType == TYPE_ESCROW_DLV)
- $this->m_Data->m_sCmd = CMD_REQ_DLV_NETC;
- else if ($this->m_type == TYPE_ESCROW && $this->m_Data->m_EscrowType == TYPE_ESCROW_CNF)
- $this->m_Data->m_sCmd = CMD_REQ_CNF_NETC;
- else if ($this->m_type == TYPE_ESCROW && $this->m_Data->m_EscrowType == TYPE_ESCROW_DNY)
- $this->m_Data->m_sCmd = CMD_REQ_DNY_NETC;
- else
- $this->m_Data->m_sCmd = CMD_REQ_NETC;
-
- $this->m_Data->m_sCrypto = FLAG_CRYPTO_3DES;
-
- //암호화
- if (($rtv = $this->m_Data->MakeEncrypt($this->m_Crypto)) != OK) {
- $err_msg = "암호화 오류";
- $this->m_Log->WriteLog(ERROR, $err_msg);
- //$this->MakeTXErrMsg( $rtv, $err_msg );
- return;
- }
- $this->m_Log->WriteLog(DEBUG, "MAKE ENCRYPT OK[" . $this->m_Data->m_EncBody . "]");
-
- //전문생성(Body)
- $this->m_Data->MakeBody();
- $this->m_Log->WriteLog(INFO, "MAKE BODY OK");
-
- //서명(sign)
- if (($rtv = $this->m_Crypto->Sign($this->m_Data->m_sBody, $sign)) != OK) {
- $err_msg = "싸인실패";
- $this->m_Log->WriteLog(ERROR, $err_msg);
- //$this->MakeTXErrMsg( $rtv, $err_msg );
- return false;
- }
- $this->m_Data->m_sTail = $sign;
- $this->m_Log->WriteLog(INFO, "SIGN OK");
-
- //전문생성(Head)
- $this->m_Data->MakeHead();
- $this->m_Log->WriteLog(INFO, "MAKE HEAD OK");
-
- $this->m_Log->WriteLog(DEBUG, "MSG_TO_PG:[" . $this->m_Data->m_sMsg . "]");
-
- //소켓생성
- $this->m_Socket = new INISocket("");
- $this->m_Socket->ip = $this->m_connIP; //기존연결된 IP 사용, 08.03.12
- if (($rtv = $this->m_Socket->open()) != OK) {
- $err_msg = "[" . $this->m_Socket->ip . "]소켓연결오류(NETC)::" . $this->m_Socket->getErr();
- $this->m_Log->WriteLog(ERROR, $err_msg);
- //$this->MakeTXErrMsg( $rtv, $err_msg );
- $this->m_Log->CloseLog($this->GetResult(NM_RESULTMSG));
- $this->m_Socket->close();
- $this->m_Crypto->FreeAllKey();
- return;
- }
- $this->m_Log->WriteLog(INFO, "SOCKET CONNECT OK::" . $this->m_Socket->ip);
-
- //전문송신
- if (($rtv = $this->m_Socket->send($this->m_Data->m_sMsg)) != OK) {
- $err_msg = "소켓송신오류(NETC)" . $this->m_Socket->getErr();
- $this->m_Log->WriteLog(ERROR, $err_msg);
- //$this->MakeTXErrMsg( $rtv, $err_msg );
- $this->m_Socket->close();
- return false;
- }
- $this->m_Log->WriteLog(INFO, "SEND OK");
-
- //전문수신
- if (($rtv = $this->m_Socket->recv($head, $body, $tail)) != OK) {
- $err_msg = "소켓수신오류(NETC)";
- $this->m_Log->WriteLog(ERROR, $err_msg);
- //$this->MakeTXErrMsg( $rtv, $err_msg );
- $this->m_Socket->close();
- return false;
- }
- $this->m_Log->WriteLog(INFO, "RECV OK");
- $this->m_Log->WriteLog(DEBUG, "MSG_FROM_PG:[" . $head . $body . $tail . "]");
-
- //서명확인
- if (($rtv = $this->m_Crypto->Verify($body, $tail)) != OK) {
- $err_msg = "VERIFY FAIL";
- $this->m_Log->WriteLog(ERROR, $err_msg);
- //$this->MakeTXErrMsg( $rtv, $err_msg );
- $this->m_Socket->close();
- return false;
- }
- $this->m_Log->WriteLog(INFO, "VERIFY OK");
-
- //이하 헤더나 본문은 파싱하지 않는다!!!!
- //그냥 여기서 끝내자 피곤하다.-_-;;
- //Head 파싱
- if (($rtv = $this->m_Data->ParseHead($head)) != OK) {
- $err_msg = "수신전문(HEAD) 파싱 오류";
- $this->m_Log->WriteLog(ERROR, $err_msg);
- //$this->MakeTXErrMsg( $rtv, $err_msg );
- $this->m_Socket->close();
- return;
- }
- //Body 파싱
- if (($rtv = $this->m_Data->ParseBody($body, $encrypted, $sessionkey)) != OK) {
- $err_msg = "수신전문(Body) 파싱 오류";
- $this->m_Log->WriteLog(ERROR, $err_msg);
- //$this->MakeTXErrMsg( $rtv, $err_msg );
- $this->m_Socket->close();
- return;
- }
-
- //if( $this->GetResult(NM_RESULTCODE) == "00" )
- if (strcmp($this->GetResult(NM_RESULTCODE), "00") == 0)
- $this->m_Log->WriteLog(INFO, "SUCCESS NETCANCEL");
- else
- $this->m_Log->WriteLog(ERROR, "ERROR NETCANCEL[" . $this->GetResult(NM_RESULTMSG) . "]");
- return true;
- }
-
- function MakeIMStr($s, $t) {
- $this->m_Crypto = new INICrypto($this->m_REQUEST);
- if ($t == "H")
- return $this->m_Crypto->MakeIMStr($s, base64_decode(IMHK));
- else if ($t == "J")
- return $this->m_Crypto->MakeIMStr($s, base64_decode(IMJK));
- }
-
- /* -------------------------------------------------- */
- /* */
- /* 에러메세지 Make */
- /* */
- /* -------------------------------------------------- */
-
- function MakeTXErrMsg($err_code, $err_msg) {
- $this->m_RESULT[NM_RESULTCODE] = "01";
- $this->m_RESULT[NM_RESULTERRORCODE] = $err_code;
- $this->m_RESULT[NM_RESULTMSG] = "[" . $err_code . "|" . $err_msg . "]";
- $this->m_Data->GTHR($err_code, $err_msg);
- return;
- }
-
-}
\ No newline at end of file
diff --git a/shop/inicis/libs/INISoc.php b/shop/inicis/libs/INISoc.php
deleted file mode 100644
index c073040bc..000000000
--- a/shop/inicis/libs/INISoc.php
+++ /dev/null
@@ -1,226 +0,0 @@
-hnd);
- if ($errCode != 0) {
- //Connection reset by peer
- if ($errCode == 104)
- $this->bConnected = false;
- $errMsg = socket_strerror($errCode);
- $this->sSocErr = "(" . $errCode . ")(" . $errMsg . ")";
- socket_clear_error($this->hnd);
- }
- elseif (strlen($msg)) {
- $this->sSocErr = $errMsg;
- }
- return false;
- }
-
- function __construct($host) {
- $this->family = AF_INET;
- $this->type = SOCK_STREAM;
- $this->protocol = SOL_TCP;
- $this->hnd = @socket_create($this->family, $this->type, $this->protocol);
- $this->error();
- $this->sBuffer = false;
- $this->ip = null;
- $this->host = $host;
- $this->port = PG_PORT;
- }
-
- function DNSLookUP() {
- $starttime = GetMicroTime();
- $ip = @gethostbyname($this->host);
- if ($ip == PG_IP || $ip == KSPG_IP) {
- $this->ip = $ip;
- } else {
- $this->error("Hostname " . $this->host . " could not be resolved");
- return DNS_LOOKUP_ERR;
- }
-
- $this->dns_laptime = round(GetMicroTime() - $starttime, 3);
- if ($this->dns_laptime > DNS_LOOKUP_TIMEOUT)
- return DNS_LOOKUP_TIMEOUT_ERR;
-
- return OK;
- }
-
- function open() {
- //Connect timeout Trickkkkkkkkk ##2. NONBLOCKING NEED , less CPU clocking!!^^
- //modified by ddaemiri, 2007.08.30
-
- socket_set_nonblock($this->hnd);
- if (!@socket_connect($this->hnd, $this->ip, $this->port)) {
- $err = socket_last_error($this->hnd);
- $err_str = socket_strerror($err);
- if ($err == 106) { //EISCONN
- $this->bConnected = true;
- socket_set_block($this->hnd);
- return OK;
- }
- //EINPROGRESS( Linux:115, Window Socket:10035, FreeBSD4.10:36, 모든 OS 체크 불가능해서 str으로도 검색 )
- if ($err != ERRCODE_INPROGRESS_LINUX && $err != ERRCODE_INPROGRESS_WIN &&
- $err != ERRCODE_INPROGRESS_FREEBSD && $err_str != ERRSTR_INPROGRESS) {
- $this->error();
- socket_close($this->hnd);
- return SOCK_CONN_ERR;
- }
- }
-
- $read = array($this->hnd);
- $write = array($this->hnd);
- $except = NULL;
- $rtv = @socket_select($read, $write, $except, TIMEOUT_CONNECT);
- if ($rtv == 0) { //TIMEOUT
- $this->error();
- socket_close($this->hnd);
- return SOCK_TIMEO_ERR;
- } else if ($rtv === FALSE) {
- $this->error();
- socket_close($this->hnd);
- return SOCK_ETC1_ERR;
- }
- if (in_array($this->hnd, $read) || in_array($this->hnd, $write)) {
- if (@socket_get_option($this->hnd, SOL_SOCKET, SO_ERROR) === FALSE) {
- $this->error();
- socket_close($this->hnd);
- return SOCK_ETC2_ERR;
- }
- }
- $this->bConnected = true;
- socket_set_block($this->hnd);
- return OK;
- }
-
- function close() {
- //if(!$this->bConnected) return;
- @socket_shutdown($this->hnd, 2);
- @socket_close($this->hnd);
- }
-
- function send($sBuf) {
- if (!$this->bConnected) {
- $this->error("Socket error. Cannot send data on a closed socket.");
- return SOCK_SEND1_ERR;
- }
-
- $vWrite = array($this->hnd);
- $vRead = null;
- $vExcept = null;
-
- while (($rtv = @socket_select($vRead, $vWrite, $vExcept, TIMEOUT_WRITE)) === FALSE);
-
- if ($rtv == 0) {
- $this->error();
- //return SOCK_TIMEO_ERR;
- return SOCK_CONN_ERR; //modify 2008.04.01
- }
- if ($rtv === FALSE) {
- $this->error();
- return SOCK_SEND2_ERR;
- }
-
- $tmpBuf = strlen($sBuf) ? $sBuf : $this->sBuffer;
- $iBufLen = strlen($tmpBuf);
- $res = @socket_send($this->hnd, $tmpBuf, $iBufLen, 0);
-
- if ($res === FALSE) {
- $this->error();
- return SOCK_SEND2_ERR;
- } elseif ($res < $iBufLen) {
- $tmpBuf = substr($tmpBuf, $res);
- $this->send($tmpBuf);
- }
- return OK;
- }
-
- function WaitRecv(&$recv_buf, $nleft) {
- $recv_buf = null;
- $read = array($this->hnd);
- $buf = null;
- while ($nleft > 0) {
- $write = null;
- $except = null;
-
- $rtv = @socket_select($read, $write, $except, TIMEOUT_READ);
- if ($rtv == 0) {
- $this->error();
- return SOCK_TIMEO_ERR;
- } else if ($rtv === FALSE) {
- $this->error();
- return SOCK_ETC1_ERR;
- }
-
- if (!in_array($this->hnd, $read)) {
- $this->error();
- return SOCK_RECV1_ERR;
- }
- if ($buf = @socket_read($this->hnd, $nleft)) {
- $recv_buf .= $buf;
- } else {
- $this->error();
- return SOCK_RECV1_ERR;
- }
- $nleft -= strlen($buf);
- }
- return OK;
- }
-
- function recv(&$head, &$body, &$tail) {
- if (!$this->bConnected) {
- $this->error("Socket error. Cannot read any data on a closed socket.");
- return SOCK_RECV1_ERR;
- }
-
- //------------------------------------------------------
- //head
- //------------------------------------------------------
- if (($rtv = $this->WaitRecv($head, MSGHEADER_LEN)) != OK)
- return $rtv;
-
- if ($head == "")
- return SOCK_RECV2_ERR;
- $body_len = intval(substr($head, 0, BODY_LEN));
- $tail_len = intval(substr($head, BODY_LEN, TAIL_LEN));
-
- //------------------------------------------------------
- //body
- //------------------------------------------------------
- if (($rtv = $this->WaitRecv($body, $body_len)) != OK)
- return $rtv;
-
- //------------------------------------------------------
- //tail
- //------------------------------------------------------
- if (($rtv = $this->WaitRecv($tail, $tail_len)) != OK)
- return $rtv;
-
- return OK;
- }
-
- function getErr() {
- return $this->sSocErr;
- }
-
-}
\ No newline at end of file
diff --git a/shop/inicis/libs/INIXml.php b/shop/inicis/libs/INIXml.php
deleted file mode 100644
index 284f31223..000000000
--- a/shop/inicis/libs/INIXml.php
+++ /dev/null
@@ -1,3140 +0,0 @@
- version 1.0 |
-// | Copyright (c) 2001 Michael P. Mehl. All rights reserved. |
-// +----------------------------------------------------------------------+
-// | Latest releases are available at http://phpxml.org/. For feedback or |
-// | bug reports, please contact the author at mpm@phpxml.org. Thanks! |
-// +----------------------------------------------------------------------+
-// | The contents of this file are subject to the Mozilla Public License |
-// | Version 1.1 (the "License"); you may not use this file except in |
-// | compliance with the License. You may obtain a copy of the License at |
-// | http://www.mozilla.org/MPL/ |
-// | |
-// | Software distributed under the License is distributed on an "AS IS" |
-// | basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See |
-// | the License for the specific language governing rights and |
-// | limitations under the License. |
-// | |
-// | The Original Code is . |
-// | |
-// | The Initial Developer of the Original Code is Michael P. Mehl. |
-// | Portions created by Michael P. Mehl are Copyright (C) 2001 Michael |
-// | P. Mehl. All Rights Reserved. |
-// +----------------------------------------------------------------------+
-// | Authors: |
-// | Michael P. Mehl |
-// +----------------------------------------------------------------------+
-//
-
-/**
- * Class for accessing XML data through the XPath language.
- *
- * This class offers methods for accessing the nodes of a XML document using
- * the XPath language. You can add or remove nodes, set or modify their
- * content and their attributes. No additional PHP extensions like DOM XML
- * or something similar are required to use these features.
- *
- * @link http://www.phpxml.org/ Latest release of this class
- * @link http://www.w3.org/TR/xpath W3C XPath Recommendation
- * @copyright Copyright (c) 2001 Michael P. Mehl. All rights reserved.
- * @author Michael P. Mehl
- * @version 1.0 (2001-03-08)
- * @access public
- */
-
-/**
- *
- * 해당 라이브러리는 절대 수정되어서는 안됩니다.
- * 임의로 수정된 코드에 대한 책임은 전적으로 수정자에게 있음을 알려드립니다.
- *
- */
-class XML {
-
- /**
- * List of all document nodes.
- *
- * This array contains a list of all document nodes saved as an
- * associative array.
- *
- * @access private
- * @var array
- */
- var $nodes = array();
-
- /**
- * List of document node IDs.
- *
- * This array contains a list of all IDs of all document nodes that
- * are used for counting when adding a new node.
- *
- * @access private
- * @var array
- */
- var $ids = array();
-
- /**
- * Current document path.
- *
- * This variable saves the current path while parsing a XML file and adding
- * the nodes being read from the file.
- *
- * @access private
- * @var string
- */
- var $path = "";
-
- /**
- * Current document position.
- *
- * This variable counts the current document position while parsing a XML
- * file and adding the nodes being read from the file.
- *
- * @access private
- * @var int
- */
- var $position = 0;
-
- /**
- * Path of the document root.
- *
- * This string contains the full path to the node that acts as the root
- * node of the whole document.
- *
- * @access private
- * @var string
- */
- var $root = "";
-
- /**
- * Current XPath expression.
- *
- * This string contains the full XPath expression being parsed currently.
- *
- * @access private
- * @var string
- */
- var $xpath = "";
-
- /**
- * List of entities to be converted.
- *
- * This array contains a list of entities to be converted when an XPath
- * expression is evaluated.
- *
- * @access private
- * @var array
- */
- var $entities = array("&" => "&", "<" => "<", ">" => ">",
- "'" => "&apos", '"' => """);
-
- /**
- * List of supported XPath axes.
- *
- * This array contains a list of all valid axes that can be evaluated in an
- * XPath expression.
- *
- * @access private
- * @var array
- */
- var $axes = array("child", "descendant", "parent", "ancestor",
- "following-sibling", "preceding-sibling", "following", "preceding",
- "attribute", "namespace", "self", "descendant-or-self",
- "ancestor-or-self");
-
- /**
- * List of supported XPath functions.
- *
- * This array contains a list of all valid functions that can be evaluated
- * in an XPath expression.
- *
- * @access private
- * @var array
- */
- var $functions = array("last", "position", "count", "id", "name",
- "string", "concat", "starts-with", "contains", "substring-before",
- "substring-after", "substring", "string-length", "translate",
- "boolean", "not", "true", "false", "lang", "number", "sum", "floor",
- "ceiling", "round", "text");
-
- /**
- * List of supported XPath operators.
- *
- * This array contains a list of all valid operators that can be evaluated
- * in a predicate of an XPath expression. The list is ordered by the
- * precedence of the operators (lowest precedence first).
- *
- * @access private
- * @var array
- */
- var $operators = array(" or ", " and ", "=", "!=", "<=", "<", ">=", ">",
- "+", "-", "*", " div ", " mod ");
- var $xml_node = array();
-
- /**
- * Constructor of the class.
- *
- * This constructor initializes the class and, when a filename is given,
- * tries to read and parse the given file.
- *
- * @access public
- * @author Michael P. Mehl
- * @param string $file Path and name of the file to read and parsed.
- * @see load_xml()
- */
- //modify by ddaemiri, 2007.05.28
- //load_file -> load_xml로 파일 및 string 으로 모두 입력받을 수 있음.
- function __construct($file = "") {
- // Check whether a file was given.
- if (!empty($file)) {
- // Load the XML file.
- return $this->load_xml($file, "");
- }
- }
-
- /**
- * Reads a file and parses the XML data.
- *
- * This method reads the content of a XML file, tries to parse its
- * content and upon success stores the information retrieved from
- * the file into an array.
- *
- * @access public
- * @author Michael P. Mehl
- * @param string $file Path and name of the file to be read and parsed.
- * @see handle_start_element(), handle_end_element(),
- * handle_character_data()
- */
- function remove_ctrl($string) {
- for ($i = 0; $i < strlen($string); $i++) {
- $chr = $string[$i];
- $ord = ord($chr);
- if ($ord < 10)
- $string[$i] = " ";
- else
- $string[$i] = $chr;
- }
- return trim($string);
- }
- //modify by ddaemiri, 2007.05.28
- //load_file -> load_xml로 파일 및 string 으로 모두 입력받을 수 있음.
- function load_xml($file, $str) {
- // Check whether the file exists and is readable.
- if ((file_exists($file) && is_readable($file)) || $str != "") {
- // Read the content of the file.
- if ($str == "")
- $content = implode("", file($file));
- else
- $content = $this->remove_ctrl($str);
-
- // Check whether content has been read.
- if (!empty($content)) {
- // Create an XML parser.
- $parser = xml_parser_create();
-
- // Set the options for parsing the XML data.
- xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
- xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
-
- // Set the object for the parser.
- xml_set_object($parser, $this);
-
- // Set the element handlers for the parser.
- xml_set_element_handler($parser, "handle_start_element", "handle_end_element");
- xml_set_character_data_handler($parser, "handle_character_data");
-
- // Parse the XML file.
- if (!xml_parse($parser, $content, true)) {
- // Display an error message.
- $this->display_error("XML error in file %s, line %d: %s", $file, xml_get_current_line_number($parser), xml_error_string(xml_get_error_code($parser)));
- }
-
- // Free the parser.
- xml_parser_free($parser);
-
- return OK;
- }
- } else {
- // Display an error message.
- //$this->display_error("File %s could not be found or read.", $file);
- return RESULT_MSG_FORMAT_ERR;
- }
- }
-
- //modify by ddaemiri, 2007.05.28
- //charset 추가( header 생성 )
- function make_xml($highlight = array(), $root = "", $level = 0, $charset = "UTF-8") {
- // header 추가
- $header = "" . "\n";
- $body = $this->get_xml($highlight, $root, $level);
- return $header . $body;
- }
-
- /**
- * Generates a XML file with the content of the current document.
- *
- * This method creates a string containing the XML data being read
- * and modified by this class before. This string can be used to save
- * a modified document back to a file or doing other nice things with
- * it.
- *
- * @access public
- * @author Michael P. Mehl
- * @param array $highlight Array containing a list of full document
- * paths of nodes to be highlighted by ... tags
- * in the generated XML string.
- * @param string $root While doing a recursion with this method, this
- * parameter is used for internal purpose.
- * @param int $level While doing a recursion with this method, this
- * parameter is used for internal purpose.
- * @return string The returned string contains well-formed XML data
- * representing the content of this document.
- * @see load_xml(), evaluate(), get_content()
- */
- //modify by ddaemiri, 2007.05.28
- //get_file -> get_xml 로 함수이름 변경.
- function get_xml($highlight = array(), $root = "", $level = 0) {
-
- // Create a string to save the generated XML data.
- $xml = "";
-
- // Create two strings containing the tags for highlighting a node.
- $highlight_start = "";
- $highlight_end = "";
-
- // Generate a string to be displayed before the tags.
- $before = "";
-
- // Calculate the amount of whitespaces to display.
- for ($i = 0; $i < ( $level * 2 ); $i++) {
- // Add a whitespaces to the string.
- $before .= " ";
- }
-
- // Check whether a root node is given.
- if (empty($root)) {
- // Set it to the document root.
- $root = $this->root;
- }
-
- // Check whether the node is selected.
- $selected = in_array($root, $highlight);
-
- // Now add the whitespaces to the XML data.
- $xml .= $before;
-
- // Check whether the node is selected.
- if ($selected) {
- // Add the highlight code to the XML data.
- $xml .= $highlight_start;
- }
-
- // Now open the tag.
- $xml .= "<" . $this->nodes[$root]["name"];
-
- $count_root_attributes = (isset($this->nodes[$root]["attributes"]) && is_array($this->nodes[$root]["attributes"])) ? count($this->nodes[$root]["attributes"]) : 0;
- // Check whether there are attributes for this node.
- if ($count_root_attributes > 0) {
- // Run through all attributes.
- foreach ((array) $this->nodes[$root]["attributes"] as $key => $value) {
- // Check whether this attribute is highlighted.
- if (in_array($root . "/attribute::" . $key, $highlight)) {
- // Add the highlight code to the XML data.
- $xml .= $highlight_start;
- }
-
- // Add the attribute to the XML data.
- $xml .= " " . $key . "=\"" . trim(stripslashes($value)) . "\"";
-
- // Check whether this attribute is highlighted.
- if (in_array($root . "/attribute::" . $key, $highlight)) {
- // Add the highlight code to the XML data.
- $xml .= $highlight_end;
- }
- }
- }
-
- // Check whether the node contains character data or has children.
- if ($this->nodes[$root]["text"] == "" &&
- !isset($this->nodes[$root]["children"])) {
- // Add the end to the tag.
- $xml .= "/";
- }
-
- // Close the tag.
- //$xml .= ">\n";
- $xml .= ">";
-
- // Check whether the node is selected.
- if ($selected) {
- // Add the highlight code to the XML data.
- $xml .= $highlight_end;
- }
-
- // Check whether the node contains character data.
- if ($this->nodes[$root]["text"] != "") {
- // Add the character data to the XML data.
- //$xml .= $before." ".$this->nodes[$root]["text"]."\n";
- //$xml .= $before.$this->nodes[$root]["text"];
- $xml .= $this->nodes[$root]["text"];
- }
-
- // Check whether the node has children.
- if (isset($this->nodes[$root]["children"])) {
- // Run through all children with different names.
- foreach ($this->nodes[$root]["children"] as $child => $pos) {
- // Run through all children with the same name.
- for ($i = 1; $i <= $pos; $i++) {
- // Generate the full path of the child.
- $fullchild = $root . "/" . $child . "[" . $i . "]";
-
- // Add the child's XML data to the existing data.
- $xml .= "\n\t" . $this->get_xml($highlight, $fullchild, $level + 1);
- }
- }
- }
-
- // Check whether there are attributes for this node.
- if ($this->nodes[$root]["text"] != "" ||
- isset($this->nodes[$root]["children"])) {
- // Add the whitespaces to the XML data.
- //$xml .= $before;
- // Check whether the node is selected.
- if ($selected) {
- // Add the highlight code to the XML data.
- $xml .= $highlight_start;
- }
-
- // Add the closing tag.
- $xml .= "" . $this->nodes[$root]["name"] . ">";
-
- // Check whether the node is selected.
- if ($selected) {
- // Add the highlight code to the XML data.
- $xml .= $highlight_end;
- }
-
- // Add a linebreak.
- //$xml .= "\n";
- }
-
- // Return the XML data.
- return $xml;
- }
-
- /**
- * Adds a new node to the XML document.
- *
- * This method adds a new node to the tree of nodes of the XML document
- * being handled by this class. The new node is created according to the
- * parameters passed to this method.
- *
- * @access public
- * @author Michael P. Mehl
- * @param string $content Full path of the parent, to which the new
- * node should be added as a child.
- * @param string $name Name of the new node.
- * @return string The string returned by this method will contain the
- * full document path of the created node.
- * @see remove_node(), evaluate()
- */
- function add_node($context, $name, $value = "", $attr_arr = NULL) {
- // Check whether a name for this element is already set.
- if (empty($this->root)) {
- // Use this tag as the root element.
- $this->root = "/" . $name . "[1]";
- }
-
- // Calculate the full path for this element.
- $path = $context . "/" . $name;
-
- // Set the relative context and the position.
-
- $othis_ids_path = isset($this->ids[$path]) ? (int) $this->ids[$path] : 0;
- $position = ++$othis_ids_path;
- $relative = $name . "[" . $position . "]";
-
- // Calculate the full path.
- $fullpath = $context . "/" . $relative;
-
- // Calculate the context position, which is the position of this
- // element within elements of the same name in the parent node.
- $this->nodes[$fullpath]["context-position"] = $position;
-
- // Calculate the position for the following and preceding axis
- // detection.
- $othis_document_position = isset($this->nodes[$context]["document-position"]) ? (int) $this->nodes[$context]["document-position"] : 0;
- $this->nodes[$fullpath]["document-position"] = $othis_document_position + 1;
-
- // Save the information about the node.
- $this->nodes[$fullpath]["name"] = $name;
- $this->nodes[$fullpath]["text"] = "";
- $this->nodes[$fullpath]["parent"] = $context;
-
- // Add this element to the element count array.
- if (! (isset($this->nodes[$context]["children"][$name]) && $this->nodes[$context]["children"][$name])) {
- // Set the default name.
- $this->nodes[$context]["children"][$name] = 1;
- } else {
- // Calculate the name.
- $this->nodes[$context]["children"][$name] = $this->nodes[$context]["children"][$name] + 1;
- }
-
- if ($value != "" && is_array($attr_arr)) {
- $this->set_attributes($fullpath, $attr_arr);
- if ($attr_arr["urlencode"] == "1")
- $value = urlencode($value);
- }
- if ($value != "") {
- $this->set_content($fullpath, $value);
- }
-
- // Return the path of the new node.
- return $fullpath;
- }
-
- /**
- * Removes a node from the XML document.
- *
- * This method removes a node from the tree of nodes of the XML document.
- * If the node is a document node, all children of the node and its
- * character data will be removed. If the node is an attribute node,
- * only this attribute will be removed, the node to which the attribute
- * belongs as well as its children will remain unmodified.
- *
- * @access public
- * @author Michael P. Mehl
- * @param string $node Full path of the node to be removed.
- * @see add_node(), evaluate()
- */
- function remove_node($node) {
- // Check whether the node is an attribute node.
- if (preg_match("/attribute::/", $node)) {
- // Get the path to the attribute node's parent.
- $parent = $this->prestr($node, "/attribute::");
-
- // Get the name of the attribute.
- $attribute = $this->afterstr($node, "/attribute::");
-
- // Check whether the attribute exists.
- if (isset($this->nodes[$parent]["attributes"][$attribute])) {
- // Create a new array.
- $new = array();
-
- // Run through the existing attributes.
- foreach ($this->nodes[$parent]["attributes"]
- as $key => $value) {
- // Check whether it's the attribute to remove.
- if ($key != $attribute) {
- // Add it to the new array again.
- $new[$key] = $value;
- }
- }
-
- // Save the new attributes.
- $this->nodes[$parent]["attributes"] = $new;
- }
- } else {
- // Create an associative array, which contains information about
- // all nodes that required to be renamed.
- $rename = array();
-
- // Get the name, the parent and the siblings of current node.
- $name = $this->nodes[$node]["name"];
- $parent = $this->nodes[$node]["parent"];
- $siblings = $this->nodes[$parent]["children"][$name];
-
- // Decrease the number of children.
- $this->nodes[$parent]["children"][$name] --;
-
- // Create a counter for renumbering the siblings.
- $counter = 1;
-
- // Now run through the siblings.
- for ($i = 1; $i <= $siblings; $i++) {
- // Create the name of the sibling.
- $sibling = $parent . "/" . $name . "[" . $i . "]";
-
- // Check whether it's the name of the current node.
- if ($sibling != $node) {
- // Create the new name for the sibling.
- $new = $parent . "/" . $name . "[" . $counter . "]";
-
- // Increase the counter.
- $counter++;
-
- // Add the old and the new name to the list of nodes
- // to be renamed.
- $rename[$sibling] = $new;
- }
- }
-
- // Create an array for saving the new node-list.
- $nodes = array();
-
- // Now run through through the existing nodes.
- foreach ($this->nodes as $name => $values) {
- // Check the position of the path of the node to be deleted
- // in the path of the current node.
- $position = strpos($name, $node);
-
- // Check whether it's not the node to be deleted.
- if ($position === false) {
- // Run through the array of nodes to be renamed.
- foreach ($rename as $old => $new) {
- // Check whether this node and it's parent requires to
- // be renamed.
- $name = str_replace($old, $new, $name);
- $values["parent"] = str_replace($old, $new, $values["parent"]);
- }
-
- // Add the node to the list of nodes.
- $nodes[$name] = $values;
- }
- }
-
- // Save the new array of nodes.
- $this->nodes = $nodes;
- }
- }
-
- /**
- * Add content to a node.
- *
- * This method adds content to a node. If it's an attribute node, then
- * the value of the attribute will be set, otherwise the character data of
- * the node will be set. The content is appended to existing content,
- * so nothing will be overwritten.
- *
- * @access public
- * @author Michael P. Mehl
- * @param string $path Full document path of the node.
- * @param string $value String containing the content to be added.
- * @see get_content(), evaluate()
- */
- function add_content($path, $value) {
- // Check whether it's an attribute node.
- if (preg_match("/attribute::/", $path)) {
- // Get the path to the attribute node's parent.
- $parent = $this->prestr($path, "/attribute::");
-
- // Get the parent node.
- $parent = $this->nodes[$parent];
-
- // Get the name of the attribute.
- $attribute = $this->afterstr($path, "/attribute::");
-
- // Set the attribute.
- $parent["attributes"][$attribute] .= $value;
- } else {
- // Set the character data of the node.
- $this->nodes[$path]["text"] .= $value;
- }
- }
-
- /**
- * Set the content of a node.
- *
- * This method sets the content of a node. If it's an attribute node, then
- * the value of the attribute will be set, otherwise the character data of
- * the node will be set. Existing content will be overwritten.
- *
- * @access public
- * @author Michael P. Mehl
- * @param string $path Full document path of the node.
- * @param string $value String containing the content to be set.
- * @see get_content(), evaluate()
- */
- function set_content($path, $value) {
- // Check whether it's an attribute node.
- if (preg_match("/attribute::/", $path)) {
- // Get the path to the attribute node's parent.
- $parent = $this->prestr($path, "/attribute::");
-
- // Get the parent node.
- $parent = $this->nodes[$parent];
-
- // Get the name of the attribute.
- $attribute = $this->afterstr($path, "/attribute::");
-
- // Set the attribute.
- $parent["attributes"][$attribute] = $value;
- } else {
- // Set the character data of the node.
- $this->nodes[$path]["text"] = strtr($value, $this->entities);
- }
- }
-
- /**
- * Retrieves the content of a node.
- *
- * This method retrieves the content of a node. If it's an attribute
- * node, then the value of the attribute will be retrieved, otherwise
- * it'll be the character data of the node.
- *
- * @access public
- * @author Michael P. Mehl
- * @param string $path Full document path of the node, from which the
- * content should be retrieved.
- * @return string The returned string contains either the value or the
- * character data of the node.
- * @see set_content(), evaluate()
- */
- function get_content($path) {
- // Check whether it's an attribute node.
- if (preg_match("/attribute::/", $path)) {
- // Get the path to the attribute node's parent.
- $parent = $this->prestr($path, "/attribute::");
-
- // Get the parent node.
- $parent = $this->nodes[$parent];
-
- // Get the name of the attribute.
- $attribute = $this->afterstr($path, "/attribute::");
-
- // Get the attribute.
- $attribute = $parent["attributes"][$attribute];
-
- // Return the value of the attribute.
- return $attribute;
- } else {
- // Return the cdata of the node.
- return stripslashes($this->nodes[$path]["text"]);
- }
- }
-
- /**
- * Add attributes to a node.
- *
- * This method adds attributes to a node. Existing attributes will not be
- * overwritten.
- *
- * @access public
- * @author Michael P. Mehl
- * @param string $path Full document path of the node, the attributes
- * should be added to.
- * @param array $attributes Associative array containing the new
- * attributes for the node.
- * @see set_content(), get_content()
- */
- function add_attributes($path, $attributes) {
- // Add the attributes to the node.
- $this->nodes[$path]["attributes"] = array_merge($attributes, $this->nodes[$path]["attributes"]);
- }
-
- /**
- * Sets the attributes of a node.
- *
- * This method sets the attributes of a node and overwrites all existing
- * attributes by doing this.
- *
- * @access public
- * @author Michael P. Mehl
- * @param string $path Full document path of the node, the attributes
- * of which should be set.
- * @param array $attributes Associative array containing the new
- * attributes for the node.
- * @see set_content(), get_content()
- */
- function set_attributes($path, $attributes) {
- // Set the attributes of the node.
- $this->nodes[$path]["attributes"] = $attributes;
- }
-
- /**
- * Retrieves a list of all attributes of a node.
- *
- * This method retrieves a list of all attributes of the node specified in
- * the argument.
- *
- * @access public
- * @author Michael P. Mehl
- * @param string $path Full document path of the node, from which the
- * list of attributes should be retrieved.
- * @return array The returned associative array contains the all
- * attributes of the specified node.
- * @see get_content(), $nodes, $ids
- */
- function get_attributes($path) {
- // Return the attributes of the node.
- return $this->nodes[$path]["attributes"];
- }
-
- /**
- * Retrieves the name of a document node.
- *
- * This method retrieves the name of document node specified in the
- * argument.
- *
- * @access public
- * @author Michael P. Mehl
- * @param string $path Full document path of the node, from which the
- * name should be retrieved.
- * @return string The returned array contains the name of the specified
- * node.
- * @see get_content(), $nodes, $ids
- */
- function get_name($path) {
- // Return the name of the node.
- return $this->nodes[$path]["name"];
- }
-
- /**
- * Evaluates an XPath expression.
- *
- * This method tries to evaluate an XPath expression by parsing it. A
- * XML document has to be read before this method is able to work.
- *
- * @access public
- * @author Michael P. Mehl
- * @param string $path XPath expression to be evaluated.
- * @param string $context Full path of a document node, starting
- * from which the XPath expression should be evaluated.
- * @return array The returned array contains a list of the full
- * document paths of all nodes that match the evaluated
- * XPath expression.
- * @see $nodes, $ids
- */
- function evaluate($path, $context = "") {
- // Remove slashes and quote signs.
- $path = stripslashes($path);
- $path = str_replace("\"", "", $path);
- $path = str_replace("'", "", $path);
-
- // Split the paths into different paths.
- $paths = $this->split_paths($path);
-
- // Create an empty set to save the result.
- $result = array();
-
- // Run through all paths.
- foreach ($paths as $path) {
- // Trim the path.
- $path = trim($path);
-
- // Save the current path.
- $this->xpath = $path;
-
- // Convert all entities.
- $path = strtr($path, array_flip($this->entities));
-
- // Split the path at every slash.
- $steps = $this->split_steps($path);
-
- // Check whether the first element is empty.
- if (empty($steps[0])) {
- // Remove the first and empty element.
- array_shift($steps);
- }
-
- // Start to evaluate the steps.
- $nodes = $this->evaluate_step($context, $steps);
-
- // Remove duplicated nodes.
- $nodes = array_unique($nodes);
-
- // Add the nodes to the result set.
- $result = array_merge($result, $nodes);
- }
-
- // Return the result.
- return $result;
- }
-
- /**
- * Handles opening XML tags while parsing.
- *
- * While parsing a XML document for each opening tag this method is
- * called. It'll add the tag found to the tree of document nodes.
- *
- * @access private
- * @author Michael P. Mehl
- * @param int $parser Handler for accessing the current XML parser.
- * @param string $name Name of the opening tag found in the document.
- * @param array $attributes Associative array containing a list of
- * all attributes of the tag found in the document.
- * @see handle_end_element(), handle_character_data(), $nodes, $ids
- */
- function handle_start_element($parser, $name, $attributes) {
- // Add a node.
- $this->path = $this->add_node($this->path, $name);
-
- // Set the attributes.
- // Xpath로 안가져온다. 한달을 헛지랄 했다!!
- // modifyed by ddaemiri, 2007.09.03
- // $this->set_attributes($this->path, $attributes);
- // add array, added by ddaemiri, 2007.09.03
- $arr = preg_split("/[\/]+/", $this->path, -1, PREG_SPLIT_NO_EMPTY);
- $this->xml_node[$arr[count($arr) - 1]]["attr"] = $attributes;
- }
-
- /**
- * Handles closing XML tags while parsing.
- *
- * While parsing a XML document for each closing tag this method is
- * called.
- *
- * @access private
- * @author Michael P. Mehl
- * @param int $parser Handler for accessing the current XML parser.
- * @param string $name Name of the closing tag found in the document.
- * @see handle_start_element(), handle_character_data(), $nodes, $ids
- */
- function handle_end_element($parser, $name) {
- // Jump back to the parent element.
- $this->path = substr($this->path, 0, strrpos($this->path, "/"));
- }
-
- /**
- * Handles character data while parsing.
- *
- * While parsing a XML document for each character data this method
- * is called. It'll add the character data to the document tree.
- *
- * @access private
- * @author Michael P. Mehl
- * @param int $parser Handler for accessing the current XML parser.
- * @param string $text Character data found in the document.
- * @see handle_start_element(), handle_end_element(), $nodes, $ids
- */
- function handle_character_data($parser, $text) {
- // Replace entities.
- $text = strtr($text, $this->entities);
-
- // Save the text.
- // Xpath로 안가져온다. 한달을 헛지랄 했다!!
- // modifyed by ddaemiri, 2007.09.03
- //$this->add_content($this->path, addslashes(trim($text)));
- // add array, added by ddaemiri, 2007.09.03
- $arr = preg_split("/[\/]+/", $this->path, -1, PREG_SPLIT_NO_EMPTY);
- //edited by ddaemiri. libexpat은 \n을 분리자로 인식
- //$this->xml_node[$arr[count($arr)-1]]["text"] = addslashes(trim($text));
- $othis_count_text = isset($this->xml_node[$arr[count($arr) - 1]]["text"]) ? $this->xml_node[$arr[count($arr) - 1]]["text"] : '';
- $this->xml_node[$arr[count($arr) - 1]]["text"] = $othis_count_text . addslashes(trim($text));
- }
-
- /**
- * Splits an XPath expression into its different expressions.
- *
- * This method splits an XPath expression. Each expression can consists of
- * list of expression being separated from each other by a | character.
- *
- * @access private
- * @author Michael P. Mehl
- * @param string $expression The complete expression to be splitted
- * into its different expressions.
- * @return array The array returned from this method contains a list
- * of all expressions found in the expression passed to this
- * method as a parameter.
- * @see evalute()
- */
- function split_paths($expression) {
- // Create an empty array.
- $paths = array();
-
- // Save the position of the slash.
- $position = -1;
-
- // Run through the expression.
- do {
- // Search for a slash.
- $position = $this->search_string($expression, "|");
-
- // Check whether a | was found.
- if ($position >= 0) {
- // Get the left part of the expression.
- $left = substr($expression, 0, $position);
- $right = substr($expression, $position + 1);
-
- // Add the left value to the steps.
- $paths[] = $left;
-
- // Reduce the expression to the right part.
- $expression = $right;
- }
- } while ($position > -1);
-
- // Add the remaing expression to the list of steps.
- $paths[] = $expression;
-
- // Return the steps.
- return $paths;
- }
-
- /**
- * Splits an XPath expression into its different steps.
- *
- * This method splits an XPath expression. Each expression can consists of
- * list of steps being separated from each other by a / character.
- *
- * @access private
- * @author Michael P. Mehl
- * @param string $expression The complete expression to be splitted
- * into its different steps.
- * @return array The array returned from this method contains a list
- * of all steps found in the expression passed to this
- * method as a parameter.
- * @see evalute()
- */
- function split_steps($expression) {
- // Create an empty array.
- $steps = array();
-
- // Replace a double slashes, because they'll cause problems otherwise.
- $expression = str_replace("//@", "/descendant::*/@", $expression);
- $expression = str_replace("//", "/descendant::", $expression);
-
- // Save the position of the slash.
- $position = -1;
-
- // Run through the expression.
- do {
- // Search for a slash.
- $position = $this->search_string($expression, "/");
-
- // Check whether a slash was found.
- if ($position >= 0) {
- // Get the left part of the expression.
- $left = substr($expression, 0, $position);
- $right = substr($expression, $position + 1);
-
- // Add the left value to the steps.
- $steps[] = $left;
-
- // Reduce the expression to the right part.
- $expression = $right;
- }
- } while ($position > -1);
-
- // Add the remaing expression to the list of steps.
- $steps[] = $expression;
-
- // Return the steps.
- return $steps;
- }
-
- /**
- * Retrieves axis information from an XPath expression step.
- *
- * This method tries to extract the name of the axis and its node-test
- * from a given step of an XPath expression at a given node.
- *
- * @access private
- * @author Michael P. Mehl
- * @param string $step String containing a step of an XPath expression.
- * @param string $node Full document path of the node on which the
- * step is executed.
- * @return array This method returns an array containing information
- * about the axis found in the step.
- * @see evaluate_step()
- */
- function get_axis($step, $node) {
- // Create an array to save the axis information.
- $axis = array(
- "axis" => "",
- "node-test" => "",
- "predicate" => array()
- );
-
- // Check whether there are predicates.
- if (preg_match("/\[/", $step)) {
- // Get the predicates.
- $predicates = substr($step, strpos($step, "["));
-
- // Reduce the step.
- $step = $this->prestr($step, "[");
-
- // Try to split the predicates.
- $predicates = str_replace("][", "]|[", $predicates);
- $predicates = explode("|", $predicates);
-
- // Run through all predicates.
- foreach ($predicates as $predicate) {
- // Remove the brackets.
- $predicate = substr($predicate, 1, strlen($predicate) - 2);
-
- // Add the predicate to the list of predicates.
- $axis["predicate"][] = $predicate;
- }
- }
-
- // Check whether the axis is given in plain text.
- if ($this->search_string($step, "::") > -1) {
- // Split the step to extract axis and node-test.
- $axis["axis"] = $this->prestr($step, "::");
- $axis["node-test"] = $this->afterstr($step, "::");
- } else {
- // Check whether the step is empty.
- if (empty($step)) {
- // Set it to the default value.
- $step = ".";
- }
-
- // Check whether is an abbreviated syntax.
- if ($step == "*") {
- // Use the child axis and select all children.
- $axis["axis"] = "child";
- $axis["node-test"] = "*";
- }
- //elseif ( ereg("\(", $step) )
- //elseif ( preg_match("\(", $step) )
- elseif (preg_match("/\(/", $step)) {
- // Check whether it's a function.
- if ($this->is_function($this->prestr($step, "("))) {
- // Get the position of the first bracket.
- $start = strpos($step, "(");
- $end = strpos($step, ")", $start);
-
- // Get everything before, between and after the brackets.
- $before = substr($step, 0, $start);
- $between = substr($step, $start + 1, $end - $start - 1);
- $after = substr($step, $end + 1);
-
- // Trim each string.
- $before = trim($before);
- $between = trim($between);
- $after = trim($after);
-
- // Save the evaluated function.
- $axis["axis"] = "function";
- $axis["node-test"] = $this->evaluate_function($before, $between, $node);
- } else {
- // Use the child axis and a function.
- $axis["axis"] = "child";
- $axis["node-test"] = $step;
- }
- }
- //elseif ( eregi("^@", $step) )
- //elseif ( preg_match("^@/i", $step) )
- elseif (preg_match("/^@/i", $step)) {
- // Use the attribute axis and select the attribute.
- $axis["axis"] = "attribute";
- $axis["node-test"] = substr($step, 1);
- }
- //elseif ( eregi("\]$", $step) )
- //elseif ( preg_match("\]$/i", $step) )
- elseif (preg_match("/\]$/i", $step)) {
- // Use the child axis and select a position.
- $axis["axis"] = "child";
- $axis["node-test"] = substr($step, strpos($step, "["));
- } elseif ($step == ".") {
- // Select the self axis.
- $axis["axis"] = "self";
- $axis["node-test"] = "*";
- } elseif ($step == "..") {
- // Select the parent axis.
- $axis["axis"] = "parent";
- $axis["node-test"] = "*";
- }
- //elseif ( ereg("^[a-zA-Z0-9\-_]+$", $step) )
- //elseif ( preg_match("^[a-zA-Z0-9\-_]+$", $step) )
- elseif (preg_match("/^[a-zA-Z0-9\-_]+$/", $step)) {
- // Select the child axis and the child.
- $axis["axis"] = "child";
- $axis["node-test"] = $step;
- } else {
- // Use the child axis and a name.
- $axis["axis"] = "child";
- $axis["node-test"] = $step;
- }
- }
-
- // Check whether it's a valid axis.
- if (!in_array($axis["axis"], array_merge($this->axes, array("function")))) {
- // Display an error message.
- $this->display_error("While parsing an XPath expression, in " .
- "the step \"%s\" the invalid axis \"%s\" was found.", str_replace($step, "" . $step . "", $this->xpath), #
- $axis["axis"]);
- }
-
- // Return the axis information.
- return $axis;
- }
-
- /**
- * Looks for a string within another string.
- *
- * This method looks for a string within another string. Brackets in the
- * string the method is looking through will be respected, which means that
- * only if the string the method is looking for is located outside of
- * brackets, the search will be successful.
- *
- * @access private
- * @author Michael P. Mehl
- * @param string $term String in which the search shall take place.
- * @param string $expression String that should be searched.
- * @return int This method returns -1 if no string was found, otherwise
- * the offset at which the string was found.
- * @see evaluate_step()
- */
- function search_string($term, $expression) {
- // Create a new counter for the brackets.
- $brackets = 0;
-
- // Run through the string.
- for ($i = 0; $i < strlen($term); $i++) {
- // Get the character at the position of the string.
- $character = substr($term, $i, 1);
-
- // Check whether it's a breacket.
- if (( $character == "(" ) || ( $character == "[" )) {
- // Increase the number of brackets.
- $brackets++;
- } elseif (( $character == ")" ) || ( $character == "]" )) {
- // Decrease the number of brackets.
- $brackets--;
- } elseif ($brackets == 0) {
- // Check whether we can find the expression at this index.
- if (substr($term, $i, strlen($expression)) == $expression) {
- // Return the current index.
- return $i;
- }
- }
- }
-
- // Check whether we had a valid number of brackets.
- if ($brackets != 0) {
- // Display an error message.
- $this->display_error("While parsing an XPath expression, in the " .
- "predicate \"%s\", there was an invalid number of brackets.", str_replace($term, "" . $term . "", $this->xpath));
- }
-
- // Nothing was found.
- return (-1);
- }
-
- /**
- * Checks for a valid function name.
- *
- * This method check whether an expression contains a valid name of an
- * XPath function.
- *
- * @access private
- * @author Michael P. Mehl
- * @param string $expression Name of the function to be checked.
- * @return boolean This method returns true if the given name is a valid
- * XPath function name, otherwise false.
- * @see evaluate()
- */
- function is_function($expression) {
- // Check whether it's in the list of supported functions.
- if (in_array($expression, $this->functions)) {
- // It's a function.
- return true;
- } else {
- // It's not a function.
- return false;
- }
- }
-
- /**
- * Evaluates a step of an XPath expression.
- *
- * This method tries to evaluate a step from an XPath expression at a
- * specific context.
- *
- * @access private
- * @author Michael P. Mehl
- * @param string $context Full document path of the context from
- * which starting the step should be evaluated.
- * @param array $steps Array containing the remaining steps of the
- * current XPath expression.
- * @return array This method returns an array containing all nodes
- * that are the result of evaluating the given XPath step.
- * @see evaluate()
- */
- function evaluate_step($context, $steps) {
- // Create an empty array for saving the nodes found.
- $nodes = array();
-
- // Check whether the context is an array of contexts.
- if (is_array($context)) {
- // Run through the array.
- foreach ($context as $path) {
- // Call this method for this single path.
- $nodes = array_merge($nodes, $this->evaluate_step($path, $steps));
- }
- } else {
- // Get this step.
- $step = array_shift($steps);
-
- // Create an array to save the new contexts.
- $contexts = array();
-
- // Get the axis of the current step.
- $axis = $this->get_axis($step, $context);
-
- // Check whether it's a function.
- if ($axis["axis"] == "function") {
- // Check whether an array was return by the function.
- if (is_array($axis["node-test"])) {
- // Add the results to the list of contexts.
- $contexts = array_merge($contexts, $axis["node-test"]);
- } else {
- // Add the result to the list of contexts.
- $contexts[] = $axis["node-test"];
- }
- } else {
- // Create the name of the method.
- $method = "handle_axis_" . str_replace("-", "_", $axis["axis"]);
-
- // Check whether the axis handler is defined.
- if (!method_exists($this, $method)) {
- // Display an error message.
- $this->display_error("While parsing an XPath expression, " .
- "the axis \"%s\" could not be handled, because this " .
- "version does not support this axis.", $axis["axis"]);
- }
-
- // Perform an axis action.
- $contexts = call_user_func(array($this, $method), $axis, $context);
-
- // Check whether there are predicates.
- if (count($axis["predicate"]) > 0) {
- // Check whether each node fits the predicates.
- $contexts = $this->check_predicates($contexts, $axis["predicate"]);
- }
- }
-
- // Check whether there are more steps left.
- if (count($steps) > 0) {
- // Continue the evaluation of the next steps.
- $nodes = $this->evaluate_step($contexts, $steps);
- } else {
- // Save the found contexts.
- $nodes = $contexts;
- }
- }
-
- // Return the nodes found.
- return $nodes;
- }
-
- /**
- * Evaluates an XPath function
- *
- * This method evaluates a given XPath function with its arguments on a
- * specific node of the document.
- *
- * @access private
- * @author Michael P. Mehl
- * @param string $function Name of the function to be evaluated.
- * @param string $arguments String containing the arguments being
- * passed to the function.
- * @param string $node Full path to the document node on which the
- * function should be evaluated.
- * @return mixed This method returns the result of the evaluation of
- * the function. Depending on the function the type of the
- * return value can be different.
- * @see evaluate()
- */
- function evaluate_function($function, $arguments, $node) {
- // Remove whitespaces.
- $function = trim($function);
- $arguments = trim($arguments);
-
- // Create the name of the function handling function.
- $method = "handle_function_" . str_replace("-", "_", $function);
-
- // Check whether the function handling function is available.
- if (!method_exists($this, $method)) {
- // Display an error message.
- $this->display_error("While parsing an XPath expression, " .
- "the function \"%s\" could not be handled, because this " .
- "version does not support this function.", $function);
- }
-
- // Return the result of the function.
- return call_user_func(array($this, $method), $axis, $context);
- }
-
- /**
- * Evaluates a predicate on a node.
- *
- * This method tries to evaluate a predicate on a given node.
- *
- * @access private
- * @author Michael P. Mehl
- * @param string $node Full path of the node on which the predicate
- * should be evaluated.
- * @param string $predicate String containing the predicate expression
- * to be evaluated.
- * @return mixed This method is called recursively. The first call should
- * return a boolean value, whether the node matches the predicate
- * or not. Any call to the method being made during the recursion
- * may also return other types for further processing.
- * @see evaluate()
- */
- function evaluate_predicate($node, $predicate) {
- // Set the default position and the type of the operator.
- $position = 0;
- $operator = "";
-
- // Run through all operators and try to find them.
- foreach ($this->operators as $expression) {
- // Check whether a position was already found.
- if ($position <= 0) {
- // Try to find the operator.
- $position = $this->search_string($predicate, $expression);
-
- // Check whether a operator was found.
- if ($position > 0) {
- // Save the operator.
- $operator = $expression;
-
- // Check whether it's the equal operator.
- if ($operator == "=") {
- // Also look for other operators containing the
- // equal sign.
- if ($this->search_string($predicate, "!=") ==
- ( $position - 1 )) {
- // Get the new position.
- $position = $this->search_string($predicate, "!=");
-
- // Save the new operator.
- $operator = "!=";
- }
- if ($this->search_string($predicate, "<=") ==
- ( $position - 1 )) {
- // Get the new position.
- $position = $this->search_string($predicate, "<=");
-
- // Save the new operator.
- $operator = "<=";
- }
- if ($this->search_string($predicate, ">=") ==
- ( $position - 1 )) {
- // Get the new position.
- $position = $this->search_string($predicate, ">=");
-
- // Save the new operator.
- $operator = ">=";
- }
- }
- }
- }
- }
-
- // Check whether the operator is a - sign.
- if ($operator == "-") {
- // Check whether it's not a function containing a - in its name.
- foreach ($this->functions as $function) {
- // Check whether there's a - sign in the function name.
- //if ( ereg("-", $function) )
- //if ( preg_match("-", $function) )
- if (preg_match("/-/", $function)) {
- // Get the position of the - in the function name.
- $sign = strpos($function, "-");
-
- // Extract a substring from the predicate.
- $sub = substr($predicate, $position - $sign, strlen($function));
-
- // Check whether it's the function.
- if ($sub == $function) {
- // Don't use the operator.
- $operator = "";
- $position = -1;
- }
- }
- }
- } elseif ($operator == "*") {
- // Get some substrings.
- $character = substr($predicate, $position - 1, 1);
- $attribute = substr($predicate, $position - 11, 11);
-
- // Check whether it's an attribute selection.
- if (( $character == "@" ) || ( $attribute == "attribute::" )) {
- // Don't use the operator.
- $operator = "";
- $position = -1;
- }
- }
-
- // Check whether an operator was found.
- if ($position > 0) {
- // Get the left and the right part of the expression.
- $left = substr($predicate, 0, $position);
- $right = substr($predicate, $position + strlen($operator));
-
- // Remove whitespaces.
- $left = trim($left);
- $right = trim($right);
-
- // Evaluate the left and the right part.
- $left = $this->evaluate_predicate($node, $left);
- $right = $this->evaluate_predicate($node, $right);
-
- // Check the kind of operator.
- switch ($operator) {
- case " or ":
- // Return the two results connected by an "or".
- return ( $left or $right );
-
- case " and ":
- // Return the two results connected by an "and".
- return ( $left and $right );
-
- case "=":
- // Compare the two results.
- return ( $left == $right );
-
- case "!=":
- // Check whether the two results are not equal.
- return ( $left != $right );
-
- case "<=":
- // Compare the two results.
- return ( $left <= $right );
-
- case "<":
- // Compare the two results.
- return ( $left < $right );
-
- case ">=":
- // Compare the two results.
- return ( $left >= $right );
-
- case ">":
- // Compare the two results.
- return ( $left > $right );
-
- case "+":
- // Return the result by adding one result to the other.
- return ( $left + $right );
-
- case "-":
- // Return the result by decrease one result by the other.
- return ( $left - $right );
-
- case "*":
- // Return a multiplication of the two results.
- return ( $left * $right );
-
- case " div ":
- // Return a division of the two results.
- if ($right == 0) {
- // Display an error message.
- $this->display_error("While parsing an XPath " .
- "predicate, a error due a division by zero " .
- "occured.");
- } else {
- // Return the result of the division.
- return ( $left / $right );
- }
- break;
-
- case " mod ":
- // Return a modulo of the two results.
- return ( $left % $right );
- }
- }
-
- // Check whether the predicate is a function.
- //if ( ereg("\(", $predicate) )
- //if ( preg_match("\(", $predicate) )
- if (preg_match("/\(/", $predicate)) {
- // Get the position of the first bracket.
- $start = strpos($predicate, "(");
- $end = strpos($predicate, ")", $start);
-
- // Get everything before, between and after the brackets.
- $before = substr($predicate, 0, $start);
- $between = substr($predicate, $start + 1, $end - $start - 1);
- $after = substr($predicate, $end + 1);
-
- // Trim each string.
- $before = trim($before);
- $between = trim($between);
- $after = trim($after);
-
- // Check whether there's something after the bracket.
- if (!empty($after)) {
- // Display an error message.
- $this->display_error("While parsing an XPath expression " .
- "there was found an error in the predicate \"%s\", " .
- "because after a closing bracket there was found " .
- "something unknown.", str_replace($predicate, "" . $predicate . "", $this->xpath));
- }
-
- // Check whether it's a function.
- if (empty($before) && empty($after)) {
- // Evaluate the content of the brackets.
- return $this->evaluate_predicate($node, $between);
- } elseif ($this->is_function($before)) {
- // Return the evaluated function.
- return $this->evaluate_function($before, $between, $node);
- } else {
- // Display an error message.
- $this->display_error("While parsing a predicate in an XPath " .
- "expression, a function \"%s\" was found, which is not " .
- "yet supported by the parser.", str_replace($before, "" . $before . "", $this->xpath));
- }
- }
-
- // Check whether the predicate is just a digit.
- //if ( ereg("^[0-9]+(\.[0-9]+)?$", $predicate) || ereg("^\.[0-9]+$", $predicate) )
- //if ( preg_match("^[0-9]+(\.[0-9]+)?$", $predicate) || preg_match("^\.[0-9]+$", $predicate) )
- if (preg_match("/^[0-9]+(\.[0-9]+)?$/", $predicate) || preg_match("/^\.[0-9]+$/", $predicate)) {
- // Return the value of the digit.
- return doubleval($predicate);
- }
-
- // Check whether it's an XPath expression.
- $result = $this->evaluate($predicate, $node);
- if (count($result) > 0) {
- // Convert the array.
- $result = explode("|", implode("|", $result));
-
- // Get the value of the first result.
- $value = $this->get_content($result[0]);
-
- // Return the value.
- return $value;
- }
-
- // Return the predicate as a string.
- return $predicate;
- }
-
- /**
- * Checks whether a node matches predicates.
- *
- * This method checks whether a list of nodes passed to this method match
- * a given list of predicates.
- *
- * @access private
- * @author Michael P. Mehl
- * @param array $nodes Array of full paths of all nodes to be tested.
- * @param array $predicates Array of predicates to use.
- * @return array The array returned by this method contains a list of
- * all nodes matching the given predicates.
- * @see evaluate_step()
- */
- function check_predicates($nodes, $predicates) {
- // Create an empty set of nodes.
- $result = array();
-
- // Run through all nodes.
- foreach ($nodes as $node) {
- // Create a variable whether to add this node to the node-set.
- $add = true;
-
- // Run through all predicates.
- foreach ($predicates as $predicate) {
- // Check whether the predicate is just an number.
- //if ( ereg("^[0-9]+$", $predicate) )
- //if ( preg_match("^[0-9]+$", $predicate) )
- if (preg_match("/^[0-9]+$/", $predicate)) {
- // Enhance the predicate.
- $predicate .= "=position()";
- }
-
- // Do the predicate check.
- $check = $this->evaluate_predicate($node, $predicate);
-
- // Check whether it's a string.
- if (is_string($check) && ( ( $check == "" ) ||
- ( $check == $predicate ) )) {
- // Set the result to false.
- $check = false;
- }
-
- // Check whether it's an integer.
- if (is_int($check)) {
- // Check whether it's the current position.
- if ($check == $this->handle_function_position($node, "")) {
- // Set it to true.
- $check = true;
- } else {
- // Set it to false.
- $check = false;
- }
- }
-
- // Check whether the predicate is OK for this node.
- $add = $add && $check;
- }
-
- // Check whether to add this node to the node-set.
- if ($add) {
- // Add the node to the node-set.
- $result[] = $node;
- }
- }
-
- // Return the array of nodes.
- return $result;
- }
-
- /**
- * Checks whether a node matches a node-test.
- *
- * This method checks whether a node in the document matches a given
- * node-test.
- *
- * @access private
- * @author Michael P. Mehl
- * @param string $context Full path of the node, which should be tested
- * for matching the node-test.
- * @param string $node_test String containing the node-test for the
- * node.
- * @return boolean This method returns true if the node matches the
- * node-test, otherwise false.
- * @see evaluate()
- */
- function check_node_test($context, $node_test) {
- // Check whether it's a function.
- //if ( ereg("\(", $node_test) )
- if (preg_match("/\(/", $node_test)) {
- // Get the type of function to use.
- $function = $this->prestr($node_test, "(");
-
- // Check whether the node fits the method.
- switch ($function) {
- case "node":
- // Add this node to the list of nodes.
- return true;
-
- case "text":
- // Check whether the node has some text.
- if (!empty($this->nodes[$context]["text"])) {
- // Add this node to the list of nodes.
- return true;
- }
- break;
-
- case "comment":
- // Check whether the node has some comment.
- if (!empty($this->nodes[$context]["comment"])) {
- // Add this node to the list of nodes.
- return true;
- }
- break;
-
- case "processing-instruction":
- // Get the literal argument.
- $literal = $this->afterstr($axis["node-test"], "(");
-
- // Cut the literal.
- $literal = substr($literal, 0, strlen($literal) - 1);
-
- // Check whether a literal was given.
- if (!empty($literal)) {
- // Check whether the node's processing instructions
- // are matching the literals given.
- if ($this->nodes[$context]
- ["processing-instructions"] == $literal) {
- // Add this node to the node-set.
- return true;
- }
- } else {
- // Check whether the node has processing
- // instructions.
- if (!empty($this->nodes[$context]
- ["processing-instructions"])) {
- // Add this node to the node-set.
- return true;
- }
- }
- break;
-
- default:
- // Display an error message.
- $this->display_error("While parsing an XPath " .
- "expression there was found an undefined " .
- "function called \"%s\".", str_replace($function, "" . $function . "", $this->xpath));
- }
- } elseif ($node_test == "*") {
- // Add this node to the node-set.
- return true;
- }
- //elseif ( ereg("^[a-zA-Z0-9\-_]+", $node_test) )
- //elseif ( preg_match("^[a-zA-Z0-9\-_]+", $node_test) )
- elseif (preg_match("/^[a-zA-Z0-9\-_]+/", $node_test)) {
- // Check whether the node-test can be fulfilled.
- if ($this->nodes[$context]["name"] == $node_test) {
- // Add this node to the node-set.
- return true;
- }
- } else {
- // Display an error message.
- $this->display_error("While parsing the XPath expression \"%s\" " .
- "an empty and therefore invalid node-test has been found.", $this->xpath);
- }
-
- // Don't add this context.
- return false;
- }
-
- /**
- * Handles the XPath child axis.
- *
- * This method handles the XPath child axis.
- *
- * @access private
- * @author Michael P. Mehl
- * @param array $axis Array containing information about the axis.
- * @param string $context Node from which starting the axis should
- * be processed.
- * @return array This method returns an array containing all nodes
- * that were found during the evaluation of the given axis.
- * @see evaluate()
- */
- function handle_axis_child($axis, $context) {
- // Create an empty node-set.
- $nodes = array();
-
- // Get a list of all children.
- $children = $this->nodes[$context]["children"];
-
- // Check whether there are children.
- if (!empty($children)) {
- // Run through all children.
- foreach ($children as $child_name => $child_position) {
- // Run through all childs with this name.
- for ($i = 1; $i <= $child_position; $i++) {
- // Create the path of the child.
- $child = $context . "/" . $child_name . "[" . $i . "]";
-
- // Check whether
- if ($this->check_node_test($child, $axis["node-test"])) {
- // Add the child to the node-set.
- $nodes[] = $child;
- }
- }
- }
- }
-
- // Return the nodeset.
- return $nodes;
- }
-
- /**
- * Handles the XPath parent axis.
- *
- * This method handles the XPath parent axis.
- *
- * @access private
- * @author Michael P. Mehl
- * @param array $axis Array containing information about the axis.
- * @param string $context Node from which starting the axis should
- * be processed.
- * @return array This method returns an array containing all nodes
- * that were found during the evaluation of the given axis.
- * @see evaluate()
- */
- function handle_axis_parent($axis, $context) {
- // Create an empty node-set.
- $nodes = array();
-
- // Check whether the parent matches the node-test.
- if ($this->check_node_test($this->nodes[$context]["parent"], $axis["node-test"])) {
- // Add this node to the list of nodes.
- $nodes[] = $this->nodes[$context]["parent"];
- }
-
- // Return the nodeset.
- return $nodes;
- }
-
- /**
- * Handles the XPath attribute axis.
- *
- * This method handles the XPath attribute axis.
- *
- * @access private
- * @author Michael P. Mehl
- * @param array $axis Array containing information about the axis.
- * @param string $context Node from which starting the axis should
- * be processed.
- * @return array This method returns an array containing all nodes
- * that were found during the evaluation of the given axis.
- * @see evaluate()
- */
- function handle_axis_attribute($axis, $context) {
- // Create an empty node-set.
- $nodes = array();
-
- // Check whether all nodes should be selected.
- if ($axis["node-test"] == "*") {
- // Check whether there are attributes.
- if (count($this->nodes[$context]["attributes"]) > 0) {
- // Run through the attributes.
- foreach ($this->nodes[$context]["attributes"] as $key => $value) {
- // Add this node to the node-set.
- $nodes[] = $context . "/attribute::" . $key;
- }
- }
- } elseif (!empty($this->nodes[$context]["attributes"]
- [$axis["node-test"]])) {
- // Add this node to the node-set.
- $nodes[] = $context . "/attribute::" . $axis["node-test"];
- }
-
- // Return the nodeset.
- return $nodes;
- }
-
- /**
- * Handles the XPath self axis.
- *
- * This method handles the XPath self axis.
- *
- * @access private
- * @author Michael P. Mehl
- * @param array $axis Array containing information about the axis.
- * @param string $context Node from which starting the axis should
- * be processed.
- * @return array This method returns an array containing all nodes
- * that were found during the evaluation of the given axis.
- * @see evaluate()
- */
- function handle_axis_self($axis, $context) {
- // Create an empty node-set.
- $nodes = array();
-
- // Check whether the context match the node-test.
- if ($this->check_node_test($context, $axis["node-test"])) {
- // Add this node to the node-set.
- $nodes[] = $context;
- }
-
- // Return the nodeset.
- return $nodes;
- }
-
- /**
- * Handles the XPath descendant axis.
- *
- * This method handles the XPath descendant axis.
- *
- * @access private
- * @author Michael P. Mehl
- * @param array $axis Array containing information about the axis.
- * @param string $context Node from which starting the axis should
- * be processed.
- * @return array This method returns an array containing all nodes
- * that were found during the evaluation of the given axis.
- * @see evaluate()
- */
- function handle_axis_descendant($axis, $context) {
- // Create an empty node-set.
- $nodes = array();
-
- // Check whether the current node has children.
- if (count($this->nodes[$context]["children"]) > 0) {
- // Get a list of children.
- $children = $this->nodes[$context]["children"];
-
- // Run through all children.
- foreach ($children as $child_name => $child_position) {
- // Run through all children of this name.
- for ($i = 1; $i <= $child_position; $i++) {
- // Create the full path for the children.
- $child = $context . "/" . $child_name . "[" . $i . "]";
-
- // Check whether the child matches the node-test.
- if ($this->check_node_test($child, $axis["node-test"])) {
- // Add the child to the list of nodes.
- $nodes[] = $child;
- }
-
- // Recurse to the next level.
- $nodes = array_merge($nodes, $this->handle_axis_descendant($axis, $child));
- }
- }
- }
-
- // Return the nodeset.
- return $nodes;
- }
-
- /**
- * Handles the XPath ancestor axis.
- *
- * This method handles the XPath ancestor axis.
- *
- * @access private
- * @author Michael P. Mehl
- * @param array $axis Array containing information about the axis.
- * @param string $context Node from which starting the axis should
- * be processed.
- * @return array This method returns an array containing all nodes
- * that were found during the evaluation of the given axis.
- * @see evaluate()
- */
- function handle_axis_ancestor($axis, $context) {
- // Create an empty node-set.
- $nodes = array();
-
- // Get the parent of the current node.
- $parent = $this->nodes[$context]["parent"];
-
- // Check whether the parent isn't empty.
- if (!empty($parent)) {
- // Check whether the parent matches the node-test.
- if ($this->check_node_test($parent, $axis["node-test"])) {
- // Add the parent to the list of nodes.
- $nodes[] = $parent;
- }
-
- // Handle all other ancestors.
- $nodes = array_merge($nodes, $this->handle_axis_ancestor($axis, $parent));
- }
-
- // Return the nodeset.
- return $nodes;
- }
-
- /**
- * Handles the XPath namespace axis.
- *
- * This method handles the XPath namespace axis.
- *
- * @access private
- * @author Michael P. Mehl
- * @param array $axis Array containing information about the axis.
- * @param string $context Node from which starting the axis should
- * be processed.
- * @return array This method returns an array containing all nodes
- * that were found during the evaluation of the given axis.
- * @see evaluate()
- */
- function handle_axis_namespace($axis, $context) {
- // Create an empty node-set.
- $nodes = array();
-
- // Check whether all nodes should be selected.
- if (!empty($this->nodes[$context]["namespace"])) {
- // Add this node to the node-set.
- $nodes[] = $context;
- }
-
- // Return the nodeset.
- return $nodes;
- }
-
- /**
- * Handles the XPath following axis.
- *
- * This method handles the XPath following axis.
- *
- * @access private
- * @author Michael P. Mehl
- * @param array $axis Array containing information about the axis.
- * @param string $context Node from which starting the axis should
- * be processed.
- * @return array This method returns an array containing all nodes
- * that were found during the evaluation of the given axis.
- * @see evaluate()
- */
- function handle_axis_following($axis, $context) {
- // Create an empty node-set.
- $nodes = array();
-
- // Get the current document position.
- $position = $this->nodes[$context]["document-position"];
-
- // Create a flag, whether we already found the context node.
- $found = false;
-
- // Run through all nodes of the document.
- foreach ($this->nodes as $node => $data) {
- // Check whether the context node has already been found.
- if ($found) {
- // Check whether the position is correct.
- if ($this->nodes[$node]["document-position"] == $position) {
- // Check whether the node fits the node-test.
- if ($this->check_node_test($node, $axis["node-test"])) {
- // Add the node to the list of nodes.
- $nodes[] = $node;
- }
- }
- }
-
- // Check whether this is the context node.
- if ($node == $context) {
- // After this we'll look for more nodes.
- $found = true;
- }
- }
-
- // Return the nodeset.
- return $nodes;
- }
-
- /**
- * Handles the XPath preceding axis.
- *
- * This method handles the XPath preceding axis.
- *
- * @access private
- * @author Michael P. Mehl
- * @param array $axis Array containing information about the axis.
- * @param string $context Node from which starting the axis should
- * be processed.
- * @return array This method returns an array containing all nodes
- * that were found during the evaluation of the given axis.
- * @see evaluate()
- */
- function handle_axis_preceding($axis, $context) {
- // Create an empty node-set.
- $nodes = array();
-
- // Get the current document position.
- $position = $this->nodes[$context]["document-position"];
-
- // Create a flag, whether we already found the context node.
- $found = true;
-
- // Run through all nodes of the document.
- foreach ($this->nodes as $node => $data) {
- // Check whether this is the context node.
- if ($node == $context) {
- // After this we won't look for more nodes.
- $found = false;
- }
-
- // Check whether the context node has already been found.
- if ($found) {
- // Check whether the position is correct.
- if ($this->nodes[$node]["document-position"] == $position) {
- // Check whether the node fits the node-test.
- if ($this->check_node_test($node, $axis["node-test"])) {
- // Add the node to the list of nodes.
- $nodes[] = $node;
- }
- }
- }
- }
-
- // Return the nodeset.
- return $nodes;
- }
-
- /**
- * Handles the XPath following-sibling axis.
- *
- * This method handles the XPath following-sibling axis.
- *
- * @access private
- * @author Michael P. Mehl
- * @param array $axis Array containing information about the axis.
- * @param string $context Node from which starting the axis should
- * be processed.
- * @return array This method returns an array containing all nodes
- * that were found during the evaluation of the given axis.
- * @see evaluate()
- */
- function handle_axis_following_sibling($axis, $context) {
- // Create an empty node-set.
- $nodes = array();
-
- // Get all children from the parent.
- $siblings = $this->handle_axis_child($axis, $this->nodes[$context]["parent"]);
-
- // Create a flag whether the context node was already found.
- $found = false;
-
- // Run through all siblings.
- foreach ($siblings as $sibling) {
- // Check whether the context node was already found.
- if ($found) {
- // Check whether the sibling is a real sibling.
- if ($this->nodes[$sibling]["name"] ==
- $this->nodes[$context]["name"]) {
- // Check whether the sibling matches the node-test.
- if ($this->check_node_test($sibling, $axis["node-test"])) {
- // Add the sibling to the list of nodes.
- $nodes[] = $sibling;
- }
- }
- }
-
- // Check whether this is the context node.
- if ($sibling == $context) {
- // Continue looking for other siblings.
- $found = true;
- }
- }
-
- // Return the nodeset.
- return $nodes;
- }
-
- /**
- * Handles the XPath preceding-sibling axis.
- *
- * This method handles the XPath preceding-sibling axis.
- *
- * @access private
- * @author Michael P. Mehl
- * @param array $axis Array containing information about the axis.
- * @param string $context Node from which starting the axis should
- * be processed.
- * @return array This method returns an array containing all nodes
- * that were found during the evaluation of the given axis.
- * @see evaluate()
- */
- function handle_axis_preceding_sibling($axis, $context) {
- // Create an empty node-set.
- $nodes = array();
-
- // Get all children from the parent.
- $siblings = $this->handle_axis_child($axis, $this->nodes[$context]["parent"]);
-
- // Create a flag whether the context node was already found.
- $found = true;
-
- // Run through all siblings.
- foreach ($siblings as $sibling) {
- // Check whether this is the context node.
- if ($sibling == $context) {
- // Don't continue looking for other siblings.
- $found = false;
- }
-
- // Check whether the context node was already found.
- if ($found) {
- // Check whether the sibling is a real sibling.
- if ($this->nodes[$sibling]["name"] ==
- $this->nodes[$context]["name"]) {
- // Check whether the sibling matches the node-test.
- if ($this->check_node_test($sibling, $axis["node-test"])) {
- // Add the sibling to the list of nodes.
- $nodes[] = $sibling;
- }
- }
- }
- }
-
- // Return the nodeset.
- return $nodes;
- }
-
- /**
- * Handles the XPath descendant-or-self axis.
- *
- * This method handles the XPath descendant-or-self axis.
- *
- * @access private
- * @author Michael P. Mehl
- * @param array $axis Array containing information about the axis.
- * @param string $context Node from which starting the axis should
- * be processed.
- * @return array This method returns an array containing all nodes
- * that were found during the evaluation of the given axis.
- * @see evaluate()
- */
- function handle_axis_descendant_or_self($axis, $context) {
- // Create an empty node-set.
- $nodes = array();
-
- // Read the nodes.
- $nodes = array_merge(
- $this->handle_axis_descendant($axis, $context), $this->handle_axis_self($axis, $context));
-
- // Return the nodeset.
- return $nodes;
- }
-
- /**
- * Handles the XPath ancestor-or-self axis.
- *
- * This method handles the XPath ancestor-or-self axis.
- *
- * @access private
- * @author Michael P. Mehl
- * @param array $axis Array containing information about the axis.
- * @param string $context Node from which starting the axis should
- * be processed.
- * @return array This method returns an array containing all nodes
- * that were found during the evaluation of the given axis.
- * @see evaluate()
- */
- function handle_axis_ancestor_or_self($axis, $context) {
- // Create an empty node-set.
- $nodes = array();
-
- // Read the nodes.
- $nodes = array_merge(
- $this->handle_axis_ancestor($axis, $context), $this->handle_axis_self($axis, $context));
-
- // Return the nodeset.
- return $nodes;
- }
-
- /**
- * Handles the XPath function last.
- *
- * This method handles the XPath function last.
- *
- * @access private
- * @author Michael P. Mehl
- * @param string $node Full path of the node on which the function
- * should be processed.
- * @param string $arguments String containing the arguments that were
- * passed to the function.
- * @return mixed Depending on the type of function being processed this
- * method returns different types.
- * @see evaluate()
- */
- function handle_function_last($node, $arguments) {
- // Calculate the size of the context.
- $parent = $this->nodes[$node]["parent"];
- $children = $this->nodes[$parent]["children"];
- $context = $children[$this->nodes[$node]["name"]];
-
- // Return the size.
- return $context;
- }
-
- /**
- * Handles the XPath function position.
- *
- * This method handles the XPath function position.
- *
- * @access private
- * @author Michael P. Mehl
- * @param string $node Full path of the node on which the function
- * should be processed.
- * @param string $arguments String containing the arguments that were
- * passed to the function.
- * @return mixed Depending on the type of function being processed this
- * method returns different types.
- * @see evaluate()
- */
- function handle_function_position($node, $arguments) {
- // return the context-position.
- return $this->nodes[$node]["context-position"];
- }
-
- /**
- * Handles the XPath function count.
- *
- * This method handles the XPath function count.
- *
- * @access private
- * @author Michael P. Mehl
- * @param string $node Full path of the node on which the function
- * should be processed.
- * @param string $arguments String containing the arguments that were
- * passed to the function.
- * @return mixed Depending on the type of function being processed this
- * method returns different types.
- * @see evaluate()
- */
- function handle_function_count($node, $arguments) {
- // Evaluate the argument of the method as an XPath and return
- // the number of results.
- return count($this->evaluate($arguments, $node));
- }
-
- /**
- * Handles the XPath function id.
- *
- * This method handles the XPath function id.
- *
- * @access private
- * @author Michael P. Mehl
- * @param string $node Full path of the node on which the function
- * should be processed.
- * @param string $arguments String containing the arguments that were
- * passed to the function.
- * @return mixed Depending on the type of function being processed this
- * method returns different types.
- * @see evaluate()
- */
- function handle_function_id($node, $arguments) {
- // Trim the arguments.
- $arguments = trim($arguments);
-
- // Now split the arguments.
- $arguments = explode(" ", $arguments);
-
- // Check whether
- // Create a list of nodes.
- $nodes = array();
-
- // Run through all document node.
- foreach ($this->nodes as $node => $position) {
- // Check whether the node has the ID we're looking for.
- if (in_array($this->nodes[$node]["attributes"]["id"], $arguments)) {
- // Add this node to the list of nodes.
- $nodes[] = $node;
- }
- }
-
- // Return the list of nodes.
- return $nodes;
- }
-
- /**
- * Handles the XPath function name.
- *
- * This method handles the XPath function name.
- *
- * @access private
- * @author Michael P. Mehl
- * @param string $node Full path of the node on which the function
- * should be processed.
- * @param string $arguments String containing the arguments that were
- * passed to the function.
- * @return mixed Depending on the type of function being processed this
- * method returns different types.
- * @see evaluate()
- */
- function handle_function_name($node, $arguments) {
- // Return the name of the node.
- return $this->nodes[$node]["name"];
- }
-
- /**
- * Handles the XPath function string.
- *
- * This method handles the XPath function string.
- *
- * @access private
- * @author Michael P. Mehl
- * @param string $node Full path of the node on which the function
- * should be processed.
- * @param string $arguments String containing the arguments that were
- * passed to the function.
- * @return mixed Depending on the type of function being processed this
- * method returns different types.
- * @see evaluate()
- */
- function handle_function_string($node, $arguments) {
- // Check what type of parameter is given
- //if ( ereg("^[0-9]+(\.[0-9]+)?$", $arguments) || ereg("^\.[0-9]+$", $arguments) )
- //if ( preg_match("^[0-9]+(\.[0-9]+)?$", $arguments) || preg_match("^\.[0-9]+$", $arguments) )
- if (preg_match("/^[0-9]+(\.[0-9]+)?$/", $arguments) || preg_match("/^\.[0-9]+$/", $arguments)) {
- // Convert the digits to a number.
- $number = doubleval($arguments);
-
- // Return the number.
- return strval($number);
- } elseif (is_bool($arguments)) {
- // Check whether it's true.
- if ($arguments == true) {
- // Return true as a string.
- return "true";
- } else {
- // Return false as a string.
- return "false";
- }
- } elseif (!empty($arguments)) {
- // Use the argument as an XPath.
- $result = $this->evaluate($arguments, $node);
-
- // Get the first argument.
- $result = explode("|", implode("|", $result));
-
- // Return the first result as a string.
- return $result[0];
- } elseif (empty($arguments)) {
- // Return the current node.
- return $node;
- } else {
- // Return an empty string.
- return "";
- }
- }
-
- /**
- * Handles the XPath function concat.
- *
- * This method handles the XPath function concat.
- *
- * @access private
- * @author Michael P. Mehl
- * @param string $node Full path of the node on which the function
- * should be processed.
- * @param string $arguments String containing the arguments that were
- * passed to the function.
- * @return mixed Depending on the type of function being processed this
- * method returns different types.
- * @see evaluate()
- */
- function handle_function_concat($node, $arguments) {
- // Split the arguments.
- $arguments = explode(",", $arguments);
-
- // Run through each argument and evaluate it.
- for ($i = 0; $i < sizeof($arguments); $i++) {
- // Trim each argument.
- $arguments[$i] = trim($arguments[$i]);
-
- // Evaluate it.
- $arguments[$i] = $this->evaluate_predicate($node, $arguments[$i]);
- }
-
- // Put the string together.
- $arguments = implode("", $arguments);
-
- // Return the string.
- return $arguments;
- }
-
- /**
- * Handles the XPath function starts-with.
- *
- * This method handles the XPath function starts-with.
- *
- * @access private
- * @author Michael P. Mehl
- * @param string $node Full path of the node on which the function
- * should be processed.
- * @param string $arguments String containing the arguments that were
- * passed to the function.
- * @return mixed Depending on the type of function being processed this
- * method returns different types.
- * @see evaluate()
- */
- function handle_function_starts_with($node, $arguments) {
- // Get the arguments.
- $first = trim($this->prestr($arguments, ","));
- $second = trim($this->afterstr($arguments, ","));
-
- // Evaluate each argument.
- $first = $this->evaluate_predicate($node, $first);
- $second = $this->evaluate_predicate($node, $second);
-
- // Check whether the first string starts with the second one.
- //if ( ereg("^".$second, $first) )
- //if ( preg_match("^".$second, $first) )
- if (preg_match("/^" . $second . "/", $first)) {
- // Return true.
- return true;
- } else {
- // Return false.
- return false;
- }
- }
-
- /**
- * Handles the XPath function contains.
- *
- * This method handles the XPath function contains.
- *
- * @access private
- * @author Michael P. Mehl
- * @param string $node Full path of the node on which the function
- * should be processed.
- * @param string $arguments String containing the arguments that were
- * passed to the function.
- * @return mixed Depending on the type of function being processed this
- * method returns different types.
- * @see evaluate()
- */
- function handle_function_contains($node, $arguments) {
- // Get the arguments.
- $first = trim($this->prestr($arguments, ","));
- $second = trim($this->afterstr($arguments, ","));
-
- // Evaluate each argument.
- $first = $this->evaluate_predicate($node, $first);
- $second = $this->evaluate_predicate($node, $second);
-
- // Check whether the first string starts with the second one.
- //if ( ereg($second, $first) )
- //if ( preg_match($second, $first) )
- if (preg_match("/^" . $second . "/", $first)) {
- // Return true.
- return true;
- } else {
- // Return false.
- return false;
- }
- }
-
- /**
- * Handles the XPath function substring-before.
- *
- * This method handles the XPath function substring-before.
- *
- * @access private
- * @author Michael P. Mehl
- * @param string $node Full path of the node on which the function
- * should be processed.
- * @param string $arguments String containing the arguments that were
- * passed to the function.
- * @return mixed Depending on the type of function being processed this
- * method returns different types.
- * @see evaluate()
- */
- function handle_function_substring_before($node, $arguments) {
- // Get the arguments.
- $first = trim($this->prestr($arguments, ","));
- $second = trim($this->afterstr($arguments, ","));
-
- // Evaluate each argument.
- $first = $this->evaluate_predicate($node, $first);
- $second = $this->evaluate_predicate($node, $second);
-
- // Return the substring.
- return $this->prestr(strval($first), strval($second));
- }
-
- /**
- * Handles the XPath function substring-after.
- *
- * This method handles the XPath function substring-after.
- *
- * @access private
- * @author Michael P. Mehl
- * @param string $node Full path of the node on which the function
- * should be processed.
- * @param string $arguments String containing the arguments that were
- * passed to the function.
- * @return mixed Depending on the type of function being processed this
- * method returns different types.
- * @see evaluate()
- */
- function handle_function_substring_after($node, $arguments) {
- // Get the arguments.
- $first = trim($this->prestr($arguments, ","));
- $second = trim($this->afterstr($arguments, ","));
-
- // Evaluate each argument.
- $first = $this->evaluate_predicate($node, $first);
- $second = $this->evaluate_predicate($node, $second);
-
- // Return the substring.
- return $this->afterstr(strval($first), strval($second));
- }
-
- /**
- * Handles the XPath function substring.
- *
- * This method handles the XPath function substring.
- *
- * @access private
- * @author Michael P. Mehl
- * @param string $node Full path of the node on which the function
- * should be processed.
- * @param string $arguments String containing the arguments that were
- * passed to the function.
- * @return mixed Depending on the type of function being processed this
- * method returns different types.
- * @see evaluate()
- */
- function handle_function_substring($node, $arguments) {
- // Split the arguments.
- $arguments = explode(",", $arguments);
-
- // Run through all arguments.
- for ($i = 0; $i < sizeof($arguments); $i++) {
- // Trim the string.
- $arguments[$i] = trim($arguments[$i]);
-
- // Evaluate each argument.
- $arguments[$i] = $this->evaluate_predicate($node, $arguments[$i]);
- }
-
- // Check whether a third argument was given.
- if (!empty($arguments[2])) {
- // Return the substring.
- return substr(strval($arguments[0]), $arguments[1] - 1, $arguments[2]);
- } else {
- // Return the substring.
- return substr(strval($arguments[0]), $arguments[1] - 1);
- }
- }
-
- /**
- * Handles the XPath function string-length.
- *
- * This method handles the XPath function string-length.
- *
- * @access private
- * @author Michael P. Mehl
- * @param string $node Full path of the node on which the function
- * should be processed.
- * @param string $arguments String containing the arguments that were
- * passed to the function.
- * @return mixed Depending on the type of function being processed this
- * method returns different types.
- * @see evaluate()
- */
- function handle_function_string_length($node, $arguments) {
- // Trim the argument.
- $arguments = trim($arguments);
-
- // Evaluate the argument.
- $arguments = $this->evaluate_predicate($node, $arguments);
-
- // Return the length of the string.
- return strlen(strval($arguments));
- }
-
- /**
- * Handles the XPath function translate.
- *
- * This method handles the XPath function translate.
- *
- * @access private
- * @author Michael P. Mehl
- * @param string $node Full path of the node on which the function
- * should be processed.
- * @param string $arguments String containing the arguments that were
- * passed to the function.
- * @return mixed Depending on the type of function being processed this
- * method returns different types.
- * @see evaluate()
- */
- function handle_function_translate($node, $arguments) {
- // Split the arguments.
- $arguments = explode(",", $arguments);
-
- // Run through all arguments.
- for ($i = 0; $i < sizeof($arguments); $i++) {
- // Trim the argument.
- $arguments[$i] = trim($arguments[$i]);
-
- // Evaluate the argument.
- $arguments[$i] = $this->evaluate_predicate($node, $arguments[$i]);
- }
-
- // Return the translated string.
- return strtr($arguments[0], $arguments[1], $arguments[2]);
- }
-
- /**
- * Handles the XPath function boolean.
- *
- * This method handles the XPath function boolean.
- *
- * @access private
- * @author Michael P. Mehl
- * @param string $node Full path of the node on which the function
- * should be processed.
- * @param string $arguments String containing the arguments that were
- * passed to the function.
- * @return mixed Depending on the type of function being processed this
- * method returns different types.
- * @see evaluate()
- */
- function handle_function_boolean($node, $arguments) {
- // Trim the arguments.
- $arguments = trim($arguments);
-
- // Check what type of parameter is given
- //if ( ereg("^[0-9]+(\.[0-9]+)?$", $arguments) || ereg("^\.[0-9]+$", $arguments) )
- //if ( preg_match("^[0-9]+(\.[0-9]+)?$", $arguments) || preg_match("^\.[0-9]+$", $arguments) )
- if (preg_match("/^[0-9]+(\.[0-9]+)?$/", $arguments) || preg_match("/^\.[0-9]+$/", $arguments)) {
- // Convert the digits to a number.
- $number = doubleval($arguments);
-
- // Check whether the number zero.
- if ($number == 0) {
- // Return false.
- return false;
- } else {
- // Return true.
- return true;
- }
- } elseif (empty($arguments)) {
- // Sorry, there were no arguments.
- return false;
- } else {
- // Try to evaluate the argument as an XPath.
- $result = $this->evaluate($arguments, $node);
-
- // Check whether we found something.
- if (count($result) > 0) {
- // Return true.
- return true;
- } else {
- // Return false.
- return false;
- }
- }
- }
-
- /**
- * Handles the XPath function not.
- *
- * This method handles the XPath function not.
- *
- * @access private
- * @author Michael P. Mehl
- * @param string $node Full path of the node on which the function
- * should be processed.
- * @param string $arguments String containing the arguments that were
- * passed to the function.
- * @return mixed Depending on the type of function being processed this
- * method returns different types.
- * @see evaluate()
- */
- function handle_function_not($node, $arguments) {
- // Trim the arguments.
- $arguments = trim($arguments);
-
- // Return the negative value of the content of the brackets.
- return !$this->evaluate_predicate($node, $arguments);
- }
-
- /**
- * Handles the XPath function true.
- *
- * This method handles the XPath function true.
- *
- * @access private
- * @author Michael P. Mehl
- * @param string $node Full path of the node on which the function
- * should be processed.
- * @param string $arguments String containing the arguments that were
- * passed to the function.
- * @return mixed Depending on the type of function being processed this
- * method returns different types.
- * @see evaluate()
- */
- function handle_function_true($node, $arguments) {
- // Return true.
- return true;
- }
-
- /**
- * Handles the XPath function false.
- *
- * This method handles the XPath function false.
- *
- * @access private
- * @author Michael P. Mehl
- * @param string $node Full path of the node on which the function
- * should be processed.
- * @param string $arguments String containing the arguments that were
- * passed to the function.
- * @return mixed Depending on the type of function being processed this
- * method returns different types.
- * @see evaluate()
- */
- function handle_function_false($node, $arguments) {
- // Return false.
- return false;
- }
-
- /**
- * Handles the XPath function lang.
- *
- * This method handles the XPath function lang.
- *
- * @access private
- * @author Michael P. Mehl
- * @param string $node Full path of the node on which the function
- * should be processed.
- * @param string $arguments String containing the arguments that were
- * passed to the function.
- * @return mixed Depending on the type of function being processed this
- * method returns different types.
- * @see evaluate()
- */
- function handle_function_lang($node, $arguments) {
- // Trim the arguments.
- $arguments = trim($arguments);
-
- // Check whether the node has an language attribute.
- if (empty($this->nodes[$node]["attributes"]["xml:lang"])) {
- // Run through the ancestors.
- while (!empty($node)) {
- // Select the parent node.
- $node = $this->nodes[$node]["parent"];
-
- // Check whether there's a language definition.
- if (!empty($this->nodes[$node]["attributes"]["xml:lang"])) {
- // Check whether it's the language, the user asks for.
- //if ( eregi("^".$arguments, $this->nodes[$node]
- // ["attributes"]["xml:lang"]) )
- //if ( preg_match("^/i".$arguments, $this->nodes[$node]
- if (preg_match("/^" . $arguments . "/i", $this->nodes[$node]
- ["attributes"]["xml:lang"])) {
- // Return true.
- return true;
- } else {
- // Return false.
- return false;
- }
- }
- }
-
- // Return false.
- return false;
- } else {
- // Check whether it's the language, the user asks for.
- //if ( eregi("^".$arguments, $this->nodes[$node]["attributes"]
- // ["xml:lang"]) )
- //if ( preg_match("^/i".$arguments, $this->nodes[$node]["attributes"]
- if (preg_match("/^" . $arguments . "/i", $this->nodes[$node]["attributes"]
- ["xml:lang"])) {
- // Return true.
- return true;
- } else {
- // Return false.
- return false;
- }
- }
- }
-
- /**
- * Handles the XPath function number.
- *
- * This method handles the XPath function number.
- *
- * @access private
- * @author Michael P. Mehl
- * @param string $node Full path of the node on which the function
- * should be processed.
- * @param string $arguments String containing the arguments that were
- * passed to the function.
- * @return mixed Depending on the type of function being processed this
- * method returns different types.
- * @see evaluate()
- */
- function handle_function_number($node, $arguments) {
- // Check the type of argument.
- //if ( ereg("^[0-9]+(\.[0-9]+)?$", $arguments) ||
- // ereg("^\.[0-9]+$", $arguments) )
- //if ( preg_match("^[0-9]+(\.[0-9]+)?$", $arguments) || preg_match("^\.[0-9]+$", $arguments) )
- if (preg_match("/^[0-9]+(\.[0-9]+)?$/", $arguments) || preg_match("/^\.[0-9]+$/", $arguments)) {
- // Return the argument as a number.
- return doubleval($arguments);
- } elseif (is_bool($arguments)) {
- // Check whether it's true.
- if ($arguments == true) {
- // Return 1.
- return 1;
- } else {
- // Return 0.
- return 0;
- }
- }
- }
-
- /**
- * Handles the XPath function sum.
- *
- * This method handles the XPath function sum.
- *
- * @access private
- * @author Michael P. Mehl
- * @param string $node Full path of the node on which the function
- * should be processed.
- * @param string $arguments String containing the arguments that were
- * passed to the function.
- * @return mixed Depending on the type of function being processed this
- * method returns different types.
- * @see evaluate()
- */
- function handle_function_sum($node, $arguments) {
- // Trim the arguments.
- $arguments = trim($arguments);
-
- // Evaluate the arguments as an XPath expression.
- $results = $this->evaluate($arguments, $node);
-
- // Create a variable to save the sum.
- $sum = 0;
-
- // Run through all results.
- foreach ($results as $result) {
- // Get the value of the node.
- $result = $this->get_content($result);
-
- // Add it to the sum.
- $sum += doubleval($result);
- }
-
- // Return the sum.
- return $sum;
- }
-
- /**
- * Handles the XPath function floor.
- *
- * This method handles the XPath function floor.
- *
- * @access private
- * @author Michael P. Mehl
- * @param string $node Full path of the node on which the function
- * should be processed.
- * @param string $arguments String containing the arguments that were
- * passed to the function.
- * @return mixed Depending on the type of function being processed this
- * method returns different types.
- * @see evaluate()
- */
- function handle_function_floor($node, $arguments) {
- // Trim the arguments.
- $arguments = trim($arguments);
-
- // Convert the arguments to a number.
- $arguments = doubleval($arguments);
-
- // Return the result
- return floor($arguments);
- }
-
- /**
- * Handles the XPath function ceiling.
- *
- * This method handles the XPath function ceiling.
- *
- * @access private
- * @author Michael P. Mehl
- * @param string $node Full path of the node on which the function
- * should be processed.
- * @param string $arguments String containing the arguments that were
- * passed to the function.
- * @return mixed Depending on the type of function being processed this
- * method returns different types.
- * @see evaluate()
- */
- function handle_function_ceiling($node, $arguments) {
- // Trim the arguments.
- $arguments = trim($arguments);
-
- // Convert the arguments to a number.
- $arguments = doubleval($arguments);
-
- // Return the result
- return ceil($arguments);
- }
-
- /**
- * Handles the XPath function round.
- *
- * This method handles the XPath function round.
- *
- * @access private
- * @author Michael P. Mehl
- * @param string $node Full path of the node on which the function
- * should be processed.
- * @param string $arguments String containing the arguments that were
- * passed to the function.
- * @return mixed Depending on the type of function being processed this
- * method returns different types.
- * @see evaluate()
- */
- function handle_function_round($node, $arguments) {
- // Trim the arguments.
- $arguments = trim($arguments);
-
- // Convert the arguments to a number.
- $arguments = doubleval($arguments);
-
- // Return the result
- return round($arguments);
- }
-
- /**
- * Handles the XPath function text.
- *
- * This method handles the XPath function text.
- *
- * @access private
- * @author Michael P. Mehl
- * @param string $node Full path of the node on which the function
- * should be processed.
- * @param string $arguments String containing the arguments that were
- * passed to the function.
- * @return mixed Depending on the type of function being processed this
- * method returns different types.
- * @see evaluate()
- */
- function handle_function_text($node, $arguments) {
- // Return the character data of the node.
- return $this->nodes[$node]["text"];
- }
-
- /**
- * Retrieves a substring before a delimiter.
- *
- * This method retrieves everything from a string before a given delimiter,
- * not including the delimiter.
- *
- * @access private
- * @author Michael P. Mehl
- * @param string $string String, from which the substring should be
- * extracted.
- * @param string $delimiter String containing the delimiter to use.
- * @return string Substring from the original string before the
- * delimiter.
- * @see afterstr()
- */
- function prestr($string, $delimiter) {
- // Return the substring.
- return substr($string, 0, strlen($string) - strlen(strstr($string, "$delimiter")));
- }
-
- /**
- * Retrieves a substring after a delimiter.
- *
- * This method retrieves everything from a string after a given delimiter,
- * not including the delimiter.
- *
- * @access private
- * @author Michael P. Mehl
- * @param string $string String, from which the substring should be
- * extracted.
- * @param string $delimiter String containing the delimiter to use.
- * @return string Substring from the original string after the
- * delimiter.
- * @see prestr()
- */
- function afterstr($string, $delimiter) {
- // Return the substring.
- return substr($string, strpos($string, $delimiter) + strlen($delimiter));
- }
-
- /**
- * Displays an error message.
- *
- * This method displays an error messages and stops the execution of the
- * script. This method is called exactly in the same way as the printf
- * function. The first argument contains the message and additional
- * arguments of various types may be passed to this method to be inserted
- * into the message.
- *
- * @access private
- * @author Michael P. Mehl
- * @param string $message Error message to be displayed.
- */
- function display_error($message) {
- // Check whether more than one argument was given.
- if (func_num_args() > 1) {
- // Read all arguments.
- $arguments = func_get_args();
-
- //보안 이슈로 eval 함수 제거 20161011 jhkim
- array_shift($arguments);
- $message = vsprintf($message, $arguments);
- }
-
- // Display the error message.
- echo "phpXML error: " . $message;
-
- // End the execution of this script.
- exit;
- }
-
- //added by ddaemiri, 2007.05.28
- //entity 가 하나만 있다고 가정!! 배열의 첫번째만 가져옴.
- function get_content_fetch($path) {
- $e = $this->evaluate($path);
- $content = $this->get_content($e[0]);
- $a = $this->get_attributes_patch($path, "urlencode");
- if ($a != "")
- $content = urldecode($content);
- return $content;
- }
-
- function get_attributes_patch($path, $attr) {
- $e = $this->evaluate($path);
- $a = $this->get_attributes($e[0]);
- return $a[$attr];
- }
-
-}
\ No newline at end of file
diff --git a/shop/inicis/libs/inicis_youngcart_fn.php b/shop/inicis/libs/inicis_youngcart_fn.php
new file mode 100644
index 000000000..5d9afd20c
--- /dev/null
+++ b/shop/inicis/libs/inicis_youngcart_fn.php
@@ -0,0 +1,134 @@
+ 상점정보 > 계약정보 > 부가정보 > INIAPI key 생성조회
+ $key = isset($args['key']) ? $args['key'] : get_inicis_iniapi_key();
+ $type = "Refund"; // 고정
+ $paymethod = isset($args['paymethod']) ? $args['paymethod'] : "Card";
+ $timestamp = isset($args['timestamp']) ? $args['timestamp'] : date("YmdHis");
+ $clientIp = isset($args['clientIp']) ? $args['clientIp'] : $_SERVER['SERVER_ADDR'];
+ $mid = isset($args['mid']) ? $args['mid'] : $default['de_inicis_mid'];
+ $tid = $args['tid'];
+ $msg = $args['msg'];
+
+ // 부분취소인 경우
+ if ($is_part){
+ $type = 'PartialRefund';
+ $price = $args['price'];
+ $confirmPrice = $args['confirmPrice'];
+
+ // INIAPIKey + type + paymethod + timestamp + clientIp + mid + tid + price + confirmPrice
+ $hashData = hash("sha512",(string)$key.(string)$type.(string)$paymethod.(string)$timestamp.(string)$clientIp.(string)$mid.(string)$tid.(string)$price.(string)$confirmPrice); // hash 암호화
+
+ //step2. key=value 로 post 요청
+ $data = array(
+ 'type' => $type,
+ 'paymethod' => $paymethod,
+ 'timestamp' => $timestamp,
+ 'clientIp' => $clientIp,
+ 'mid' => $mid,
+ 'tid' => $tid,
+ 'price' => $price,
+ 'confirmPrice' => $confirmPrice,
+ 'msg' => $msg,
+ 'hashData'=> $hashData
+ );
+ } else {
+ // 전체취소인 경우
+ // INIAPIKey + type + paymethod + timestamp + clientIp + mid + tid
+ $hashData = hash("sha512", (string)$key.(string)$type.(string)$paymethod.(string)$timestamp.(string)$clientIp.(string)$mid.(string)$tid); // hash 암호화
+
+ //step2. key=value 로 post 요청
+ $data = array(
+ 'type' => $type,
+ 'paymethod' => $paymethod,
+ 'timestamp' => $timestamp,
+ 'clientIp' => $clientIp,
+ 'mid' => $mid,
+ 'tid' => $tid,
+ 'msg' => $msg,
+ 'hashData'=> $hashData
+ );
+ }
+
+ $url = "https://iniapi.inicis.com/api/v1/refund";
+
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_URL, $url);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
+ curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded; charset=utf-8'));
+ curl_setopt($ch, CURLOPT_POST, 1);
+
+ $response = curl_exec($ch);
+ curl_close($ch);
+
+ //step3. 요청 결과
+ return $response;
+}
+
+function get_type_inicis_paymethod($od_settle_case){
+ $ini_paymethod = '';
+
+ switch ($od_settle_case) {
+ case '신용카드':
+ case '간편결제':
+ $ini_paymethod = 'Card';
+ break;
+ case '가상계좌':
+ $ini_paymethod = 'GVacct'; // 가상계좌 (입금전, 채번취소 시 사용)
+ break;
+ case '계좌이체':
+ $ini_paymethod = 'Acct';
+ break;
+ case '휴대폰':
+ $ini_paymethod = 'HPP';
+ break;
+ }
+
+ if (! $ini_paymethod) {
+ if (is_inicis_order_pay($od_settle_case)) {
+ $ini_paymethod = 'Card';
+ }
+ }
+
+ return $ini_paymethod;
+}
\ No newline at end of file
diff --git a/shop/inicis/orderpartcancel.inc.php b/shop/inicis/orderpartcancel.inc.php
index a21f9edb3..e987f86e3 100644
--- a/shop/inicis/orderpartcancel.inc.php
+++ b/shop/inicis/orderpartcancel.inc.php
@@ -9,52 +9,29 @@ $vat_mny = round((int)$tax_mny / 1.1);
$currency = 'WON';
$oldtid = $od['od_tno'];
-$price = (int)$tax_mny + (int)$free_mny;
-$confirm_price = (int)$od['od_receipt_price'] - (int)$od['od_refund_price'] - $price;
+$price = (int)$tax_mny + (int)$free_mny; // 취소요청 금액
+$confirm_price = (int)$od['od_receipt_price'] - (int)$od['od_refund_price'] - $price; // 부분취소 후 남은금액
$buyeremail = $od['od_email'];
-$tax = (int)$tax_mny - $vat_mny;
-$taxfree = (int)$free_mny;
+$tax = (int)$tax_mny - $vat_mny; // 부가세
+$taxfree = (int)$free_mny; // 비과세
-/***********************
- * 3. 재승인 정보 설정 *
- ***********************/
-$inipay->SetField("type", "repay"); // 고정 (절대 수정 불가)
-$inipay->SetField("pgid", "INIphpRPAY"); // 고정 (절대 수정 불가)
-$inipay->SetField("subpgip", "203.238.3.10"); // 고정
-$inipay->SetField("mid", $default['de_inicis_mid']); // 상점아이디
-$inipay->SetField("admin", $default['de_inicis_admin_key']); //비대칭 사용키 키패스워드
-$inipay->SetField("oldtid", $oldtid); // 취소할 거래의 거래아이디
-$inipay->SetField("currency", $currency); // 화폐단위
-$inipay->SetField("price", $price); // 취소금액
-$inipay->SetField("confirm_price", $confirm_price); // 승인요청금액
-$inipay->SetField("buyeremail", $buyeremail); // 구매자 이메일 주소
-$inipay->SetField("tax", $tax); // 부가세금액
-$inipay->SetField("taxfree", $taxfree); // 비과세금액
+$args = array(
+ 'paymethod' => get_type_inicis_paymethod($od['od_settle_case']),
+ 'tid' => $od['od_tno'],
+ 'msg' => $od['od_id'].' '.$mod_memo,
+ 'price' => $price,
+ 'confirmPrice' => $confirm_price,
+ 'tax' => $tax,
+ 'taxFree' => $taxfree
+);
-/******************
- * 4. 재승인 요청 *
- ******************/
-$inipay->startAction();
+$response = inicis_tid_cancel($args, true); // KG 이니시스 부분취소일 경우 inicis_tid_cancel 함수 2번째 인자값을 true로
+$result = json_decode($response, true);
-
-/*******************************************************************
- * 5. 재승인 결과 *
- * *
- * 신거래번호 : $inipay->getResult('TID') *
- * 결과코드 : $inipay->getResult('ResultCode') ("00"이면 재승인 성공) *
- * 결과내용 : $inipay->getResult('ResultMsg') (재승인결과에 대한 설명) *
- * 원거래 번호 : $inipay->getResult('PRTC_TID') *
- * 최종결제 금액 : $inipay->getResult('PRTC_Remains') *
- * 부분취소 금액 : $inipay->getResult('PRTC_Price') *
- * 부분취소,재승인 구분값 : $inipay->getResult('PRTC_Type') *
- * ("0" : 재승인, "1" : 부분취소) *
- * 부분취소(재승인) 요청횟수 : $inipay->getResult('PRTC_Cnt') *
- *******************************************************************/
-
- if($inipay->getResult('ResultCode') == '00') {
+ if(isset($result['resultCode']) && $result['resultCode'] == '00') {
// 환불금액기록
- $tno = $inipay->getResult('PRTC_TID');
- $re_price = $inipay->getResult('PRTC_Price');
+ $tno = $result['prtcTid'];
+ $re_price = $result['prtcPrice'];
$sql = " update {$g5['g5_shop_order_table']}
set od_refund_price = od_refund_price + '$re_price',
@@ -74,5 +51,9 @@ $inipay->startAction();
where od_id = '$od_id' ";
sql_query($sql);
} else {
- alert(iconv_utf8($inipay->GetResult("ResultMsg")).' 코드 : '.$inipay->GetResult("ResultCode"));
+ if (isset($result['resultCode'])){
+ alert($result['resultMsg'].' 코드 : '.$result['resultCode']);
+ } else {
+ alert('curl 오류로 부분환불에 실패했습니다.');
+ }
}
\ No newline at end of file
diff --git a/shop/inicis/taxsave_result.php b/shop/inicis/taxsave_result.php
index 141429d52..be7aa3c00 100644
--- a/shop/inicis/taxsave_result.php
+++ b/shop/inicis/taxsave_result.php
@@ -2,14 +2,18 @@
include_once('./_common.php');
include_once(G5_SHOP_PATH.'/settle_inicis.inc.php');
-/* INIreceipt.php
+$iv = get_inicis_iniapi_iv();
+if (strlen($iv) !== 16){
+ alert('쇼핑몰설정 < KG이니시스 INIAPI IV 값을 16자리로 설정 후 이용해 주세요.');
+}
+
+/*
*
* 현금결제(실시간 은행계좌이체, 무통장입금)에 대한 현금결제 영수증 발행 요청한다.
*
*
* http://www.inicis.com
* http://support.inicis.com
- * Copyright (C) 2006 Inicis, Co. All rights reserved.
*/
$companynumber = isset($_REQUEST['companynumber']) ? clean_xss_tags($_REQUEST['companynumber'], 1, 1) : '';
@@ -50,66 +54,90 @@ $reg_num = $id_info;
$useopt = $tr_code;
$currency = 'WON';
-/*********************
- * 3. 발급 정보 설정 *
- *********************/
-$inipay->SetField("type" ,"receipt"); // 고정
-$inipay->SetField("pgid" ,"INIphpRECP"); // 고정
-$inipay->SetField("paymethod" ,"CASH"); // 고정 (요청분류)
-$inipay->SetField("currency" ,$currency); // 화폐단위 (고정)
-/**************************************************************************************************
-* admin 은 키패스워드 변수명입니다. 수정하시면 안됩니다. 1111의 부분만 수정해서 사용하시기 바랍니다.
-* 키패스워드는 상점관리자 페이지(https://iniweb.inicis.com)의 비밀번호가 아닙니다. 주의해 주시기 바랍니다.
-* 키패스워드는 숫자 4자리로만 구성됩니다. 이 값은 키파일 발급시 결정됩니다.
-* 키패스워드 값을 확인하시려면 상점측에 발급된 키파일 안의 readme.txt 파일을 참조해 주십시오.
-**************************************************************************************************/
-$inipay->SetField("admin" ,$default['de_inicis_admin_key']); // 키패스워드(상점아이디에 따라 변경)
-$inipay->SetField("mid" ,$default['de_inicis_mid']); // 상점아이디
-$inipay->SetField("goodname" ,iconv_euckr($goodname)); // 상품명
-$inipay->SetField("cr_price" ,$amt_tot); // 총 현금결제 금액
-$inipay->SetField("sup_price" ,$amt_sup); // 공급가액
-$inipay->SetField("tax" ,$amt_tax); // 부가세
-$inipay->SetField("srvc_price" ,$amt_svc); // 봉사료
-$inipay->SetField("buyername" ,iconv_euckr($buyername)); // 구매자 성명
-$inipay->SetField("buyeremail" ,$buyeremail); // 구매자 이메일 주소
-$inipay->SetField("buyertel" ,$buyertel); // 구매자 전화번호
-$inipay->SetField("reg_num" ,$reg_num); // 현금결제자 주민등록번호
-$inipay->SetField("useopt" ,$useopt); // 현금영수증 발행용도 ("1" - 소비자 소득공제용, "2" - 사업자 지출증빙용)
-$inipay->SetField("companynumber" ,$companynumber); // 서브몰 사업자번호
+//step1. 요청을 위한 파라미터 설정
+// 가맹점관리자 > 상점정보 > 계약정보 > 부가정보 > INIAPI key 생성조회, IV 도 조회 가능
+$key = get_inicis_iniapi_key();
+$iv = get_inicis_iniapi_iv();
+$type = "Issue";// 고정
+$paymethod = "Receipt";// 고정
+$timestamp = date("YmdHis");
+$clientIp = $_SERVER['SERVER_ADDR'];// 가맹점 요청 서버IP (추후 거래 확인 등에 사용됨)
+$mid = $default['de_inicis_mid'];
+$goodName = $goodname; // 상품명
+$crPrice = $amt_tot;// 총 현금결제 금액
+$supPrice = $amt_sup;// 공급가액
+$tax = $amt_tax;// 부가세
+$srcvPrice = $amt_svc;// 봉사료
+$buyerName = $buyername;// 구매자 성명
+$buyerEmail = $buyeremail;// 구매자 이메일 주소
+$buyerTel = $buyertel;// 구매자 전화번호
+$useOpt = $useopt;// 현금영수증 발행용도 ("1" - 소비자 소득공제용, "2" - 사업자 지출증빙용)
+$regNum = $reg_num;// 현금결제자 주민등록번호
+// AES 암호화 (regNum)
+if (function_exists('openssl_encrypt')) {
+ $enregNum = base64_encode(openssl_encrypt($regNum, 'aes-128-cbc', $key, OPENSSL_RAW_DATA, $iv));
+} else if (function_exists('mcrypt_encrypt')) {
+ $padSize = 16 - (strlen($regNum) % 16);
+ $value = $regNum.str_repeat(chr($padSize), $padSize);
+ $enregNum = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $value, MCRYPT_MODE_CBC, $iv));
+} else {
+ alert('openssl_encrypt 함수가 없어서 실행할수 없습니다.');
+}
-/****************
- * 4. 발급 요청 *
- ****************/
-$inipay->startAction();
+// SHA512 Hash 암호화
+// INIAPIKey + type + paymethod + timestamp + clientIp + mid + tid + crPrice + supPrice + srcvPrice + enregNum
+$hashData = hash("sha512", (string)$key.(string)$type.(string)$paymethod.(string)$timestamp.(string)$clientIp.(string)$mid.(string)$crPrice.(string)$supPrice.(string)$srcvPrice.(string)$enregNum);
+//step2. key=value 로 post 요청
-/********************************************************************************
- * 5. 발급 결과 *
- * *
- * 결과코드 : $inipay->GetResult('ResultCode') ("00" 이면 발행 성공) *
- * 승인번호 : $inipay->GetResult('ApplNum') (현금영수증 발행 승인번호) *
- * 승인날짜 : $inipay->GetResult('ApplDate') (YYYYMMDD) *
- * 승인시각 : $inipay->GetResult('ApplTime') (HHMMSS) *
- * 거래번호 : $inipay->GetResult('TID') *
- * 총현금결제 금액 : $inipay->GetResult('CSHR_ApplPrice') *
- * 공급가액 : $inipay->GetResult('CSHR_SupplyPrice') *
- * 부가세 : $inipay->GetResult('CSHR_Tax') *
- * 봉사료 : $inipay->GetResult('CSHR_ServicePrice') *
- * 사용구분 : $inipay->GetResult('CSHR_Type') *
- ********************************************************************************/
+$data = array(
+ 'type' => $type,
+ 'paymethod' => $paymethod,
+ 'timestamp' => $timestamp,
+ 'clientIp' => $clientIp,
+ 'mid' => $mid,
+ 'goodName' => $goodName,
+ 'crPrice' => $crPrice,
+ 'supPrice' => $supPrice,
+ 'tax' => $tax,
+ 'srcvPrice' => $srcvPrice,
+ 'buyerName' => $buyerName,
+ 'buyerEmail' => $buyerEmail,
+ 'buyerTel' => $buyerTel,
+ 'regNum' => $enregNum,
+ 'useOpt' => $useOpt,
+ 'compayNumber' => $companynumber,
+ 'hashData'=> $hashData
+);
+$url = "https://iniapi.inicis.com/api/v1/receipt";
-// DB 반영
-if($inipay->GetResult('ResultCode') == '00') {
- $cash_no = $inipay->GetResult('ApplNum');
+$ch = curl_init();
+curl_setopt($ch, CURLOPT_URL, $url);
+curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
+curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
+curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
+curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded; charset=utf-8'));
+curl_setopt($ch, CURLOPT_POST, 1);
+
+$response = curl_exec($ch);
+curl_close($ch);
+
+//step3. 요청 결과
+$ini_result = json_decode($response, true);
+
+if (isset($ini_result['resultCode']) && $ini_result['resultCode'] == '00') {
+ // DB 반영
+ $cash_no = $ini_result['authNo']; // 현금영수증 승인번호
$cash = array();
- $cash['TID'] = $inipay->GetResult('TID');
- $cash['ApplNum'] = $inipay->GetResult('ApplNum');
- $cash['ApplDate'] = $inipay->GetResult('ApplDate');
- $cash['ApplTime'] = $inipay->GetResult('ApplTime');
- $cash['CSHR_Type'] = $inipay->GetResult('CSHR_Type');
+ $cash['TID'] = $ini_result['tid'];
+ $cash['ApplNum'] = $cash_no;
+ $cash['ApplDate'] = $ini_result['authDate'];
+ $cash['ApplTime'] = $ini_result['authTime'];
+ $cash['CSHR_Type'] = $ini_result['authUseOpt'];
$cash_info = serialize($cash);
if($tx == 'personalpay') {
@@ -128,8 +156,6 @@ if($inipay->GetResult('ResultCode') == '00') {
$result = sql_query($sql, false);
- if(!$result)
- include G5_SHOP_PATH.'/inicis/inipay_cancel.php';
}
$g5['title'] = '현금영수증 발급';
@@ -139,7 +165,7 @@ include_once(G5_PATH.'/head.sub.php');
@@ -156,23 +182,23 @@ function showreceipt() // 현금 영수증 출력
| 결과코드 |
- GetResult('ResultCode'); ?> |
+ |
| 결과 메세지 |
- GetResult('ResultMsg')); ?> |
+ |
| 현금영수증 거래번호 |
- GetResult('TID'); ?> |
+ |
| 현금영수증 승인번호 |
- GetResult('ApplNum'); ?> |
+ |
| 승인시간 |
- GetResult('ApplDate').$inipay->GetResult('ApplTime')); ?> |
+ |
| 현금영수증 URL |
diff --git a/shop/kakaopay/kakaopay_cancel.php b/shop/kakaopay/kakaopay_cancel.php
index 3fe1e0086..94ffdd75e 100644
--- a/shop/kakaopay/kakaopay_cancel.php
+++ b/shop/kakaopay/kakaopay_cancel.php
@@ -62,27 +62,24 @@ if($cancelFlag == "true")
}
- if(! (isset($inipay) && method_exists($inipay, 'SetField'))) return;
+ $args = array(
+ 'key' => isset($default['de_kakaopay_iniapi_key']) ? $default['de_kakaopay_iniapi_key'] : '',
+ 'mid' => $default['de_kakaopay_mid'],
+ 'paymethod' => 'Card',
+ 'tid' => $tno,
+ 'msg' => $cancel_msg // 취소사유
+ );
- $TID = $tno;
- $inipay->SetField("type", "cancel"); // 고정
- if( $default['de_kakaopay_cancelpwd'] ){
- $inipay->SetField("mid", $default['de_kakaopay_mid']);
- $inipay->SetField("admin", $default['de_kakaopay_cancelpwd']);
- }
- $inipay->SetField("tid", $TID); // 고정
- $inipay->SetField("cancelmsg", $cancel_msg); // 취소사유
- $inipay->startAction();
- if($inipay->GetResult('ResultCode') == "00" && $db_check)
- {
- $inipay->MakeTXErrMsg(MERCHANT_DB_ERR,"Merchant DB FAIL");
- }
+ $response = inicis_tid_cancel($args);
+ $result = json_decode($response, true);
- $res_cd = $inipay->getResult('ResultCode');
- $res_msg = $inipay->getResult('ResultMsg');
-
- if($res_cd != '00') {
- $pg_res_cd = $res_cd;
- $pg_res_msg = iconv_utf8($res_msg);
+ if (isset($result['resultCode'])) {
+ if ($result['resultCode'] != '00') {
+ $pg_res_cd = $result['resultCode'];
+ $pg_res_msg = $result['resultMsg'];
+ }
+ } else {
+ $pg_res_cd = '';
+ $pg_res_msg = 'curl 로 데이터를 받지 못했습니다.';
}
}
\ No newline at end of file
diff --git a/shop/kakaopay/orderpartcancel.inc.php b/shop/kakaopay/orderpartcancel.inc.php
index 60449ff5f..7e9cebeb5 100644
--- a/shop/kakaopay/orderpartcancel.inc.php
+++ b/shop/kakaopay/orderpartcancel.inc.php
@@ -15,46 +15,25 @@ $buyeremail = $od['od_email'];
$tax = (int)$tax_mny - $vat_mny;
$taxfree = (int)$free_mny;
-/***********************
- * 3. 재승인 정보 설정 *
- ***********************/
-$inipay->SetField("type", "repay"); // 고정 (절대 수정 불가)
-$inipay->SetField("pgid", "INIphpRPAY"); // 고정 (절대 수정 불가)
-$inipay->SetField("subpgip", "203.238.3.10"); // 고정
-$inipay->SetField("mid", $default['de_kakaopay_mid']); // 상점아이디
-$inipay->SetField("admin", $default['de_kakaopay_cancelpwd']); //비대칭 사용키 키패스워드
-$inipay->SetField("oldtid", $oldtid); // 취소할 거래의 거래아이디
-$inipay->SetField("currency", $currency); // 화폐단위
-$inipay->SetField("price", $price); // 취소금액
-$inipay->SetField("confirm_price", $confirm_price); // 승인요청금액
-$inipay->SetField("buyeremail", $buyeremail); // 구매자 이메일 주소
-$inipay->SetField("tax", $tax); // 부가세금액
-$inipay->SetField("taxfree", $taxfree); // 비과세금액
+$args = array(
+ 'key' => isset($default['de_kakaopay_iniapi_key']) ? $default['de_kakaopay_iniapi_key'] : '',
+ 'mid' => $default['de_kakaopay_mid'],
+ 'paymethod' => get_type_inicis_paymethod($od['od_settle_case']),
+ 'tid' => $od['od_tno'],
+ 'msg' => $od['od_id'].' '.$mod_memo,
+ 'price' => $price,
+ 'confirmPrice' => $confirm_price,
+ 'tax' => $tax,
+ 'taxFree' => $taxfree
+);
-/******************
- * 4. 재승인 요청 *
- ******************/
-$inipay->startAction();
+$response = inicis_tid_cancel($args, true); // KG 이니시스 부분취소일 경우 inicis_tid_cancel 함수 2번째 인자값을 true로
+$result = json_decode($response, true);
-
-/*******************************************************************
- * 5. 재승인 결과 *
- * *
- * 신거래번호 : $inipay->getResult('TID') *
- * 결과코드 : $inipay->getResult('ResultCode') ("00"이면 재승인 성공) *
- * 결과내용 : $inipay->getResult('ResultMsg') (재승인결과에 대한 설명) *
- * 원거래 번호 : $inipay->getResult('PRTC_TID') *
- * 최종결제 금액 : $inipay->getResult('PRTC_Remains') *
- * 부분취소 금액 : $inipay->getResult('PRTC_Price') *
- * 부분취소,재승인 구분값 : $inipay->getResult('PRTC_Type') *
- * ("0" : 재승인, "1" : 부분취소) *
- * 부분취소(재승인) 요청횟수 : $inipay->getResult('PRTC_Cnt') *
- *******************************************************************/
-
- if($inipay->getResult('ResultCode') == '00') {
+if (isset($result['resultCode']) && $result['resultCode'] == '00') {
// 환불금액기록
- $tno = $inipay->getResult('PRTC_TID');
- $re_price = $inipay->getResult('PRTC_Price');
+ $tno = $result['prtcTid'];
+ $re_price = $result['prtcPrice'];
$sql = " update {$g5['g5_shop_order_table']}
set od_refund_price = od_refund_price + '$re_price',
@@ -74,5 +53,9 @@ $inipay->startAction();
where od_id = '$od_id' ";
sql_query($sql);
} else {
- alert(iconv_utf8($inipay->GetResult("ResultMsg")).' 코드 : '.$inipay->GetResult("ResultCode"));
+ if (isset($result['resultCode'])){
+ alert($result['resultMsg'].' 코드 : '.$result['resultCode']);
+ } else {
+ alert('curl 오류로 부분환불에 실패했습니다.');
+ }
}
\ No newline at end of file
diff --git a/shop/orderinquirycancel.php b/shop/orderinquirycancel.php
index c2c549211..0791df696 100644
--- a/shop/orderinquirycancel.php
+++ b/shop/orderinquirycancel.php
@@ -66,44 +66,30 @@ if($od['od_tno']) {
break;
case 'inicis':
include_once(G5_SHOP_PATH.'/settle_inicis.inc.php');
- $cancel_msg = iconv_euckr('주문자 본인 취소-'.$cancel_memo);
+ $cancel_msg = '주문자 본인 취소-'.$cancel_memo;
- /*********************
- * 3. 취소 정보 설정 *
- *********************/
- $inipay->SetField("type", "cancel"); // 고정 (절대 수정 불가)
- $inipay->SetField("mid", $default['de_inicis_mid']); // 상점아이디
- /**************************************************************************************************
- * admin 은 키패스워드 변수명입니다. 수정하시면 안됩니다. 1111의 부분만 수정해서 사용하시기 바랍니다.
- * 키패스워드는 상점관리자 페이지(https://iniweb.inicis.com)의 비밀번호가 아닙니다. 주의해 주시기 바랍니다.
- * 키패스워드는 숫자 4자리로만 구성됩니다. 이 값은 키파일 발급시 결정됩니다.
- * 키패스워드 값을 확인하시려면 상점측에 발급된 키파일 안의 readme.txt 파일을 참조해 주십시오.
- **************************************************************************************************/
- $inipay->SetField("admin", $default['de_inicis_admin_key']); //비대칭 사용키 키패스워드
- $inipay->SetField("tid", $od['od_tno']); // 취소할 거래의 거래아이디
- $inipay->SetField("cancelmsg", $cancel_msg); // 취소사유
+ $args = array(
+ 'paymethod' => get_type_inicis_paymethod($od['od_settle_case']),
+ 'tid' => $od['od_tno'],
+ 'msg' => $cancel_msg
+ );
- /****************
- * 4. 취소 요청 *
- ****************/
- $inipay->startAction();
+ $response = inicis_tid_cancel($args);
+ $result = json_decode($response, true);
- /****************************************************************
- * 5. 취소 결과 *
- * *
- * 결과코드 : $inipay->getResult('ResultCode') ("00"이면 취소 성공) *
- * 결과내용 : $inipay->getResult('ResultMsg') (취소결과에 대한 설명) *
- * 취소날짜 : $inipay->getResult('CancelDate') (YYYYMMDD) *
- * 취소시각 : $inipay->getResult('CancelTime') (HHMMSS) *
- * 현금영수증 취소 승인번호 : $inipay->getResult('CSHR_CancelNum') *
- * (현금영수증 발급 취소시에만 리턴됨) *
- ****************************************************************/
+ $res_cd = '';
+ $res_msg = 'curl 로 데이터를 받지 못했습니다.';
- $res_cd = $inipay->getResult('ResultCode');
- $res_msg = $inipay->getResult('ResultMsg');
+ if (isset($result['resultCode'])) {
+ $res_cd = $result['resultCode'];
+ $res_msg = $result['resultMsg'];
+ } else {
+ $res_cd = '';
+ $res_msg = 'curl 로 데이터를 받지 못했습니다.';
+ }
if($res_cd != '00') {
- alert(iconv_utf8($res_msg).' 코드 : '.$res_cd);
+ alert($res_msg.' 코드 : '.$res_cd);
}
break;
default:
diff --git a/shop/settle_inicis.inc.php b/shop/settle_inicis.inc.php
index 8e502166f..2de141225 100644
--- a/shop/settle_inicis.inc.php
+++ b/shop/settle_inicis.inc.php
@@ -7,13 +7,11 @@ if ($default['de_card_test']) {
if ($default['de_escrow_use'] == 1) {
// 에스크로결제 테스트
$default['de_inicis_mid'] = 'iniescrow0';
- $default['de_inicis_admin_key'] = '1111';
$default['de_inicis_sign_key'] = 'SU5JTElURV9UUklQTEVERVNfS0VZU1RS';
}
else {
// 일반결제 테스트
$default['de_inicis_mid'] = 'INIpayTest';
- $default['de_inicis_admin_key'] = '1111';
$default['de_inicis_sign_key'] = 'SU5JTElURV9UUklQTEVERVNfS0VZU1RS';
}
@@ -41,25 +39,13 @@ else {
/**************************
* 1. 라이브러리 인클루드 *
**************************/
-require_once(G5_SHOP_PATH.'/inicis/libs/INILib.php');
require_once(G5_SHOP_PATH.'/inicis/libs/INIStdPayUtil.php');
require_once(G5_SHOP_PATH.'/inicis/libs/sha256.inc.php');
+require_once(G5_SHOP_PATH.'/inicis/libs/inicis_youngcart_fn.php');
$mid = $default['de_inicis_mid'];
$signKey = $default['de_inicis_sign_key'];
-/***************************************
- * 2. INIpay50 클래스의 인스턴스 생성 *
- ***************************************/
-$inipay = new INIpay50;
-
-$inipay->SetField("inipayhome", G5_SHOP_PATH.'/inicis'); // 이니페이 홈디렉터리(상점수정 필요)
-$inipay->SetField("debug", "false");
-
-if( ! function_exists('mcrypt_encrypt')) { // mcrypt 관련 함수가 없다면 취소시 openssl로 합니다.
- $inipay->SetField("encMethod", "openssl");
-}
-
$util = new INIStdPayUtil();
$timestamp = $util->getTimestamp(); // util에 의해서 자동생성