KG이니시스 TX모듈을 사용하는 코드를 API로 전환 건
This commit is contained in:
@ -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');
|
||||
<script>
|
||||
function showreceipt() // 현금 영수증 출력
|
||||
{
|
||||
var showreceiptUrl = "https://iniweb.inicis.com/DefaultWebApp/mall/cr/cm/Cash_mCmReceipt.jsp?noTid=<?php echo($inipay->GetResult('TID')); ?>" + "&clpaymethod=22";
|
||||
var showreceiptUrl = "https://iniweb.inicis.com/DefaultWebApp/mall/cr/cm/Cash_mCmReceipt.jsp?noTid=<?php echo($ini_result['tid']); ?>" + "&clpaymethod=22";
|
||||
window.open(showreceiptUrl,"showreceipt","width=380,height=540, scrollbars=no,resizable=no");
|
||||
}
|
||||
</script>
|
||||
@ -156,23 +182,23 @@ function showreceipt() // 현금 영수증 출력
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row">결과코드</th>
|
||||
<td><?php echo $inipay->GetResult('ResultCode'); ?></td>
|
||||
<td><?php echo $ini_result['resultCode']; ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">결과 메세지</th>
|
||||
<td><?php echo iconv_utf8($inipay->GetResult('ResultMsg')); ?></td>
|
||||
<td><?php echo $ini_result['resultMsg']; ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">현금영수증 거래번호</th>
|
||||
<td><?php echo $inipay->GetResult('TID'); ?></td>
|
||||
<td><?php echo $ini_result['tid']; ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">현금영수증 승인번호</th>
|
||||
<td><?php echo $inipay->GetResult('ApplNum'); ?></td>
|
||||
<td><?php echo $ini_result['authNo']; ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">승인시간</th>
|
||||
<td><?php echo preg_replace("/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/", "\\1-\\2-\\3 \\4:\\5:\\6",$inipay->GetResult('ApplDate').$inipay->GetResult('ApplTime')); ?></td>
|
||||
<td><?php echo preg_replace("/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/", "\\1-\\2-\\3 \\4:\\5:\\6",$ini_result['authDate'].$ini_result['authTime']); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">현금영수증 URL</th>
|
||||
|
||||
Reference in New Issue
Block a user