이니시스 웹표준 결제모듈 적용

This commit is contained in:
chicpro
2016-04-22 12:26:35 +09:00
parent 39dae2e214
commit 95b60db165
28 changed files with 4872 additions and 3779 deletions

View File

@ -0,0 +1,120 @@
<?php
class CreateIdModule {
function makeTid($payMetod, $mid, $mobileType) {
date_default_timezone_set('Asia/Seoul');
$date = new DateTime();
$prefix = "";
if ($mobileType) {
$prefix = "StdMX_";
} else {
$prefix = "Stdpay";
}
/////////////
list($usec, $sec) = explode(" ", microtime());
$time = date("YmdHis", $sec) . intval(round($usec * 1000));
if (strlen($time) == 17) {
} elseif (strlen($time) == 16) {
$time = $time . "0";
} else {
$time = $time . "00";
}
/////////////
$tid = $prefix . $this->getPGID($payMetod) . $mid . $time . $this->makeRandNum();
return $tid;
}
function getPGID($payMethod) {
$pgid = "";
if ($payMethod == "Card") {
$pgid = "CARD";
} elseif ($payMethod == "Account") {
$pgid = "ACCT";
} elseif ($payMethod == "DirectBank") {
$pgid = "DBNK";
} elseif ($payMethod == "OCBPoint") {
$pgid = "OCBP";
} elseif ($payMethod == "VCard") {
$pgid = "ISP_";
} elseif ($payMethod == "HPP") {
$pgid = "HPP_";
} elseif ($payMethod == "Nemo") {
$pgid = "NEMO";
} elseif ($payMethod == "ArsBill") {
$pgid = "ARSB";
} elseif ($payMethod == "PhoneBill") {
$pgid = "PHNB";
} elseif ($payMethod == "Ars1588Bill") {
$pgid = "1588";
} elseif ($payMethod == "VBank") {
$pgid = "VBNK";
} elseif ($payMethod == "Culture") {
$pgid = "CULT";
} elseif ($payMethod == "CMS") {
$pgid = "CMS_";
} elseif ($payMethod == "AUTH") {
$pgid = "AUTH";
} elseif ($payMethod == "INIcard") {
$pgid = "INIC";
} elseif ($payMethod == "MDX") {
$pgid = "MDX_";
} elseif ($payMethod == "CASH") {
$pgid = "CASH";
} elseif (strlen($payMethod) > 4) {
$pgid = strtoupper($payMethod);
$pgid = substr($pgid, 0, 4);
} else {
$pgid = trim($pgid);
}
return $pgid;
}
//랜덤 숫자 생성
function makeRandNum() {
$strNum = "";
$randNum = rand(0, 300);
if ($randNum < 10) {
$strNum = $strNum . "00" . $randNum;
} elseif ($randNum < 100) {
$strNum = $strNum . "0" . $randNum;
} else {
$strNum = $randNum;
}
return $strNum;
}
}
?>

View File

@ -0,0 +1,149 @@
<?php
define("CONNECT_TIMEOUT", 5);
define("READ_TIMEOUT", 15);
//$explode_data = explode('/', $P_REQ_URL);
//$host = $explode_data[2];
//$path = "/" . $explode_data[3] . "/" . $explode_data[4];
class HttpClient {
var $sock = 0;
var $ssl;
var $host;
var $port;
var $path;
var $status;
var $headers = "";
var $body = "";
var $reqeust;
var $errorcode;
var $errormsg;
function processHTTP($url, $param) {
$data = "";
foreach ($param as $key => $value) {
$key2 = urlencode($key);
$value2 = urlencode($value);
$data .= "&$key2=$value2";
}
$data = substr($data, 1); // remove leading "&"
$url_data = parse_url($url);
if ($url_data["scheme"] == "https") {
$this->ssl = "ssl://";
$this->port = 443;
}
$this->host = $url_data["host"];
/*
if (is_null($url_data["port"])) {
$this->port = "80";
} else {
$this->port = $url_data["port"];
}
*/
$this->path = $url_data["path"];
if (!$this->sock = @fsockopen($this->ssl . $this->host, $this->port, $errno, $errstr, CONNECT_TIMEOUT)) {
switch ($errno) {
case -3:
$this->errormsg = 'Socket creation failed (-3)';
case -4:
$this->errormsg = 'DNS lookup failure (-4)';
case -5:
$this->errormsg = 'Connection refused or timed out (-5)';
default:
$this->errormsg = 'Connection failed (' . $errno . ')';
$this->errormsg .= ' ' . $errstr;
}
return false;
}
$this->headers = "";
$this->body = "";
/* Write */
$request = "POST " . $this->path . " HTTP/1.0\r\n";
$request .= "Connection: close\r\n";
$request .= "Host: " . $this->host . "\r\n";
$request .= "Content-type: application/x-www-form-urlencoded\r\n";
$request .= "Content-length: " . strlen($data) . "\r\n";
$request .= "Accept: */*\r\n";
$request .= "\r\n";
$request .= $data . "\r\n";
$request .= "\r\n";
fwrite($this->sock, $request);
/* Read */
stream_set_blocking($this->sock, FALSE);
$atStart = true;
$IsHeader = true;
$timeout = false;
$start_time = time();
while (!feof($this->sock) && !$timeout) {
$line = fgets($this->sock, 4096);
$diff = time() - $start_time;
if ($diff >= READ_TIMEOUT) {
$timeout = true;
}
if ($IsHeader) {
if ($line == "") {
continue;
}
if (substr($line, 0, 2) == "\r\n") {
$IsHeader = false;
continue;
}
$this->headers .= $line;
if ($atStart) {
$atStart = false;
if (!preg_match('/HTTP\/(\\d\\.\\d)\\s*(\\d+)\\s*(.*)/', $line, $m)) {
$this->errormsg = "Status code line invalid: " . htmlentities($line) . $m[1] . $m[2] . $m[3];
fclose($this->sock);
return false;
}
$http_version = $m[1];
$this->status = $m[2];
$status_string = $m[3];
continue;
}
} else {
$this->body .= $line;
}
}
fclose($this->sock);
if ($timeout) {
$this->errorcode = READ_TIMEOUT_ERR;
$this->errormsg = "Socket Timeout(" . $diff . "SEC)";
return false;
}
return true;
// return false;
}
function getErrorCode() {
return $this->errorcode;
}
function getErrorMsg() {
return $this->errormsg;
}
function getBody() {
return $this->body;
}
}
?>

View File

@ -3,8 +3,8 @@
/**
* Copyright (C) 2007 INICIS Inc.
*
* <EFBFBD>ش<EFBFBD> <20><><EFBFBD>̺귯<CCBA><EAB7AF><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Ǿ<C7BE><EEBCAD> <20>ȵ˴ϴ<CBB4>.
* <EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ڵ忡 <20><><EFBFBD><EFBFBD> å<><C3A5><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ڿ<EFBFBD><DABF><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>˷<EFBFBD><CBB7><EFBFBD>ϴ<EFBFBD>.
* 해당 라이브러리는 절대 수정되어서는 안됩니다.
* 임의로 수정된 코드에 대한 책임은 전적으로 수정자에게 있음을 알려드립니다.
*
*/
require_once ( "INIDFN.php" );
@ -16,57 +16,57 @@ require_once ( "INIXml.php" );
extract($_POST);
extract($_GET);
switch ($paymethod) {
case(Card): // <EFBFBD>ſ<EFBFBD>ī<EFBFBD><EFBFBD>
case(Card): // 신용카드
$pgid = "CARD";
break;
case(Account): // <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><>ü
case(Account): // 은행 계좌 이체
$pgid = "ACCT";
break;
case(DirectBank): // <EFBFBD>ǽð<EFBFBD> <20><><EFBFBD><EFBFBD> <20><>ü
case(DirectBank): // 실시간 계좌 이체
$pgid = "DBNK";
break;
case(OCBPoint): // OCB
$pgid = "OCBP";
break;
case(VCard): // ISP <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
case(VCard): // ISP 결제
$pgid = "ISP_";
break;
case(HPP): // <EFBFBD>޴<EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
case(HPP): // 휴대폰 결제
$pgid = "HPP_";
break;
case(ArsBill): // 700 <EFBFBD><EFBFBD>ȭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
case(ArsBill): // 700 전화결제
$pgid = "ARSB";
break;
case(PhoneBill): // PhoneBill <EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<28>޴<EFBFBD> <20><>ȭ)
case(PhoneBill): // PhoneBill 결제(받는 전화)
$pgid = "PHNB";
break;
case(Ars1588Bill):// 1588 <EFBFBD><EFBFBD>ȭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
case(Ars1588Bill):// 1588 전화결제
$pgid = "1588";
break;
case(VBank): // <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>ü
case(VBank): // 가상계좌 이체
$pgid = "VBNK";
break;
case(Culture): // <EFBFBD><EFBFBD>ȭ<EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
case(Culture): // 문화상품권 결제
$pgid = "CULT";
break;
case(CMS): // CMS <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
case(CMS): // CMS 결제
$pgid = "CMS_";
break;
case(AUTH): // <EFBFBD>ſ<EFBFBD>ī<EFBFBD><EFBFBD> <20><>ȿ<EFBFBD><C8BF> <20>˻<EFBFBD>
case(AUTH): // 신용카드 유효성 검사
$pgid = "AUTH";
break;
case(INIcard): // <EFBFBD><EFBFBD>Ƽ<EFBFBD>Ӵ<EFBFBD> <20><><EFBFBD><EFBFBD>
case(INIcard): // 네티머니 결제
$pgid = "INIC";
break;
case(MDX): // <EFBFBD>󵦽<EFBFBD>ī<EFBFBD><EFBFBD>
case(MDX): // 몬덱스카드
$pgid = "MDX_";
break;
default: // <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>Ҽ<EFBFBD><D2BC><EFBFBD> <20><> <20>߰<EFBFBD><DFB0>Ǵ<EFBFBD> <20><><EFBFBD>Ҽ<EFBFBD><D2BC><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><EFBFBD><E2BABB><EFBFBD><EFBFBD> paymethod<6F><64> 4<>ڸ<EFBFBD><DAB8><EFBFBD> <20>Ѿ<EFBFBD><D1BE>´<EFBFBD>.
default: // 상기 지불수단 외 추가되는 지불수단의 경우 기본으로 paymethod가 4자리로 넘어온다.
$pgid = $paymethod;
}
if ($quotainterest == "1") {
$interest = "(<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Һ<EFBFBD>)";
$interest = "(무이자할부)";
}
/* ----------------------------------------------------- */
@ -188,7 +188,7 @@ class INIData {
var $m_PG1IP;
var $m_PG2IP;
//----------------------------
//IFD <EFBFBD><EFBFBD>û<EFBFBD>ʵ<EFBFBD>
//IFD 요청필드
//----------------------------
var $m_sCmd;
var $m_sCrypto;
@ -205,7 +205,7 @@ class INIData {
var $m_sEncrypted;
var $m_sSessionKey;
//----------------------------
//IFD <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ʵ<EFBFBD>
//IFD 응답헤더 필드
//----------------------------
var $m_FlgCrypto;
var $m_FlgSign;
@ -215,7 +215,7 @@ class INIData {
var $m_Xml = array();
var $m_REQUEST = array();
var $m_REQUEST2 = array(); //User Defined Entity
var $m_RESULT = array(); //Encrypted <EFBFBD>ʵ<EFBFBD> hash table
var $m_RESULT = array(); //Encrypted 필드 hash table
var $m_RESULT2 = array(); //PG Added Entity
function INIData($request, $request2) {
@ -238,7 +238,7 @@ class INIData {
$this->m_sCmd = CMS_REQ_OPEN_SUB;
$this->m_sCrypto = FLAG_CRYPTO_3DES;
}
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>κ<EFBFBD>ȯ<EFBFBD><C8AF> <20>߰<EFBFBD>
//가상계좌 부분환불 추가
else if (( $this->m_Type == TYPE_REPAY) || ( $this->m_Type == TYPE_VACCTREPAY)) {
$this->m_sCmd = CMD_REQ_PRTC;
$this->m_sCrypto = FLAG_CRYPTO_3DES;
@ -265,7 +265,7 @@ class INIData {
$this->m_sCmd = CMD_REQ_DNY_CNF;
$this->m_sCrypto = FLAG_CRYPTO_3DES;
}
} else if ($this->m_Type == TYPE_REFUND) { //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȯ<EFBFBD><EFBFBD>(09.08.05)
} else if ($this->m_Type == TYPE_REFUND) { //가상계좌환불(09.08.05)
$this->m_sCmd = CMD_REQ_RFD;
$this->m_sCrypto = FLAG_CRYPTO_3DES;
} else {
@ -286,7 +286,7 @@ class INIData {
function CheckField() {
//---------------------------------
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//공통
//---------------------------------
if (trim($this->m_REQUEST["inipayhome"]) == "") {
$this->m_ErrCode = NULL_DIR_ERR;
@ -309,7 +309,7 @@ class INIData {
return false;
}
//---------------------------------
//type<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//type별로
//---------------------------------
if ($this->m_Type == TYPE_SECUREPAY) {
/*
@ -378,7 +378,7 @@ class INIData {
return false;
}
}
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>κ<EFBFBD>ȯ<EFBFBD>ҵ<EFBFBD> <20>κ<EFBFBD>ȯ<EFBFBD><C8AF> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>߰<EFBFBD>
//가상계좌 부분환불도 부분환불 로직에 추가
else if (( $this->m_Type == TYPE_REPAY ) || ( $this->m_Type == TYPE_VACCTREPAY )) {
if (trim($this->m_REQUEST["oldtid"]) == "") {
$this->m_ErrCode = NULL_TID_ERR;
@ -396,21 +396,21 @@ class INIData {
return false;
}
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>κ<EFBFBD>ȯ<EFBFBD><C8AF> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȣ,<2C><><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD> <20>ʼ<EFBFBD>
//가상계좌 부분환불 로직에서는 계조번호,은행코드,계좌주명이 필수
if ($this->m_Type == TYPE_VACCTREPAY) {
if (trim($this->m_REQUEST["refundacctnum"]) == "") {
$this->m_ErrCode = NULL_FIELD_REFUNDACCTNUM;
$this->m_ErrMsg = "ȯ<EFBFBD>Ұ<EFBFBD><EFBFBD>¹<EFBFBD>ȣ";
$this->m_ErrMsg = "환불계좌번호";
return false;
}
if (trim($this->m_REQUEST["refundbankcode"]) == "") {
$this->m_ErrCode = NULL_FIELD_REFUNDBANKCODE;
$this->m_ErrMsg = "ȯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>";
$this->m_ErrMsg = "환불은행코드";
return false;
}
if (trim($this->m_REQUEST["refundacctname"]) == "") {
$this->m_ErrCode = NULL_FIELD_REFUNDACCTNAME;
$this->m_ErrMsg = "ȯ<EFBFBD>Ұ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ּ<EFBFBD><EFBFBD><EFBFBD>";
$this->m_ErrMsg = "환불계좌주성명";
return false;
}
}
@ -433,17 +433,17 @@ class INIData {
}
if (trim($this->m_REQUEST["racctnum"]) == "") {
$this->m_ErrCode = NULL_FIELD_REFUNDACCTNUM;
$this->m_ErrMsg = "ȯ<EFBFBD>Ұ<EFBFBD><EFBFBD>¹<EFBFBD>ȣ";
$this->m_ErrMsg = "환불계좌번호";
return false;
}
if (trim($this->m_REQUEST["rbankcode"]) == "") {
$this->m_ErrCode = NULL_FIELD_REFUNDBANKCODE;
$this->m_ErrMsg = "ȯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>";
$this->m_ErrMsg = "환불은행코드";
return false;
}
if (trim($this->m_REQUEST["racctname"]) == "") {
$this->m_ErrCode = NULL_FIELD_REFUNDACCTNAME;
$this->m_ErrMsg = "ȯ<EFBFBD>Ұ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ּ<EFBFBD><EFBFBD><EFBFBD>";
$this->m_ErrMsg = "환불계좌주성명";
return false;
}
}
@ -460,10 +460,10 @@ class INIData {
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 <EFBFBD>߰<EFBFBD><EFBFBD><EFBFBD> x<><78><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>(milli second<6E><64> ù<><C3B9>° <20>ڸ<EFBFBD><DAB8><EFBFBD>)
$datestr_con = substr($datestr, 0, 14) . substr($datestr, 15, 2); //YYYYMMDDHHMMSSxSS 중간의 x값은 버림(milli second의 첫번째 자리수)
mt_srand(getmypid() * mt_rand(1, 999)); //mt_rand <EFBFBD>ϱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> srand <EFBFBD><EFBFBD> seed <EFBFBD><EFBFBD><EFBFBD><EFBFBD> , seed key = pid * mt_rand(1,999)
//pgid + mid + 16<EFBFBD>ڸ<EFBFBD> <20><>¥<EFBFBD><C2A5> <20>ð<EFBFBD> + random_key 4<EFBFBD>ڸ<EFBFBD> (seed<EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
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;
@ -524,16 +524,16 @@ class INIData {
$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<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ü <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>κ<EFBFBD><CEBA><EFBFBD><EFBFBD>ҽ<EFBFBD> <20><><EFBFBD>¹<EFBFBD>ȣ <20><><EFBFBD><EFBFBD><EFBFBD>ּ<EFBFBD><D6BC><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> 2011-10-06
//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"));
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>߰<EFBFBD> 2014-07-23 by jung.ks
//과세,비과세 추가 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);
}
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>κ<EFBFBD>ȯ<EFBFBD><C8AF>
//가상계좌 부분환불
else if ($this->m_Type == TYPE_VACCTREPAY) {
//PartCancelInfo(ROOT)
$CI = $xml->add_node("", PARTCANCELINFO);
@ -682,18 +682,18 @@ class INIData {
function MakeBody() {
$xml = new XML();
//ROOT(INIpay) ROOT<EFBFBD><EFBFBD> ROOTINFO<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> 2011-05-23
//ROOT(INIpay) ROOT ROOTINFO로 수정 2011-05-23
$root = $xml->add_node("", ROOTINFO);
if ($this->m_Type == TYPE_SECUREPAY || $this->m_Type == TYPE_RECEIPT) {
//GoodsInfo
//<EFBFBD><EFBFBD><EFBFBD>ٱ<EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>߰<EFBFBD>(2010.04.13)
//==goodscnt<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>(<28><><EFBFBD>ٱ<EFBFBD><D9B1><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ƴҰ<C6B4><D2B0><EFBFBD>) <20><20><> 1<><31> <20><><EFBFBD><EFBFBD>
//장바구니 기능 추가(2010.04.13)
//==goodscnt가 없을 경우(장바구니 기능이 아닐경우) 기본 값 1로 설정
$tGoodCnt = ($this->m_REQUEST["goodscnt"] != null && (int) $this->m_REQUEST["goodscnt"] > 0 ) ? $this->m_REQUEST["goodscnt"] : 1;
$GI = $xml->add_node($root, GOODSINFO);
//<EFBFBD><EFBFBD><EFBFBD>ٱ<EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>߰<EFBFBD>(2010.04.13)
//==TX_GOOSCNT<EFBFBD><EFBFBD> $tGoodCnt<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>Է<EFBFBD>
//장바구니 기능 추가(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, $this->m_REQUEST["oid"], array("urlencode" => "1"));
@ -702,8 +702,8 @@ class INIData {
$GP = $xml->add_node($GI, TX_TAXFREE, $this->m_REQUEST["taxfree"]);
$this->AddUserDefinedEntity(GOODSINFO, "", $xml, $GI);
//<EFBFBD><EFBFBD><EFBFBD>ٱ<EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>߰<EFBFBD>(2010.04.13) [START]
//==<EFBFBD><EFBFBD><EFBFBD>ٱ<EFBFBD><EFBFBD><EFBFBD> XML <20><><EFBFBD><EFBFBD> <20>߰<EFBFBD>
//장바구니 기능 추가(2010.04.13) [START]
//==장바구니 XML 전문 추가
$iGoodCnt = 1;
while ($iGoodCnt <= $tGoodCnt) {
if ($this->m_REQUEST["smid_" . $iGoodCnt] != "" && strlen($this->m_REQUEST["smid_" . $iGoodCnt]) > 0) {
@ -728,7 +728,7 @@ class INIData {
}
$iGoodCnt++;
}
//<EFBFBD><EFBFBD><EFBFBD>ٱ<EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>߰<EFBFBD>(2010.04.13) [END]
//장바구니 기능 추가(2010.04.13) [END]
$this->AddUserDefinedEntity(GOODSINFO, GOODS, $xml, $GS);
//BuyerInfo
@ -765,7 +765,7 @@ class INIData {
$CD = $xml->add_node($CI, TX_SESSIONKEY, $this->m_sSessionKey);
$CD = $xml->add_node($CI, TX_ENCRYPTED, $this->m_sEncrypted);
}
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>κ<EFBFBD>ȯ<EFBFBD><C8AF><EFBFBD>߰<EFBFBD>
//가상계좌 부분환불추가
else if (( $this->m_Type == TYPE_REPAY ) || ( $this->m_Type == TYPE_VACCTREPAY )) {
//PartCancelInfo
$CI = $xml->add_node($root, PARTCANCELINFO);
@ -804,8 +804,8 @@ class INIData {
$CD = $xml->add_node($CI, TX_ENCRYPTED, $this->m_sEncrypted);
} else if ($this->m_Type == TYPE_OPENSUB) {
//GoodsInfo
//<EFBFBD><EFBFBD><EFBFBD>ٱ<EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>߰<EFBFBD>(2010.04.13)
//==goodscnt<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>(<28><><EFBFBD>ٱ<EFBFBD><D9B1><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ƴҰ<C6B4><D2B0><EFBFBD>) <20><20><> 1<><31> <20><><EFBFBD><EFBFBD>
//장바구니 기능 추가(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);
@ -829,7 +829,7 @@ class INIData {
$iSubCnt++;
}
//<EFBFBD><EFBFBD><EFBFBD>ٱ<EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>߰<EFBFBD>(2010.04.13) [END]
//장바구니 기능 추가(2010.04.13) [END]
$this->AddUserDefinedEntity(OPENSUBINFO, "", $xml, $OI);
}
//ReservedInfo
@ -901,8 +901,8 @@ class INIData {
$this->m_RESULT[NM_MOID] = $this->GetXMLData(MOID);
//PAYMENTINFO
//<EFBFBD><EFBFBD>Ÿ<EFBFBD><EFBFBD><EFBFBD>Ҽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> paymethod<6F><64> <20><><EFBFBD><EFBFBD> <20>ʾ<EFBFBD> <20>ӽ÷<D3BD> <20><>û Paymethod<EFBFBD><EFBFBD> <20><>ü
//PG<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ִ<EFBFBD> PayMethod<EFBFBD><EFBFBD> <20><>ûPaymethod<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>!
//기타지불수단이 paymethod를 주지 않아 임시로 요청 Paymethod로 대체
//PG에서 주는 PayMethod와 요청Paymethod는 같다!
$this->m_RESULT[NM_PAYMETHOD] = $this->m_sPayMethod;
$ResultCode = $this->GetXMLData("ResultCode");
@ -928,8 +928,8 @@ class INIData {
$this->m_Xml = array_merge($this->m_Xml, $xml->xml_node);
if ($this->m_Type == TYPE_SECUREPAY || $this->m_Type == TYPE_RECEIPT) {
//<EFBFBD><EFBFBD><EFBFBD>γ<EFBFBD>¥(ApplDate), <EFBFBD><EFBFBD><EFBFBD>νð<EFBFBD>(ApplTime), <EFBFBD><EFBFBD><EFBFBD>ι<EFBFBD>ȣ(ApplNum)<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>!!(OCB, <EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>)
//ISP, CARD<EFBFBD><EFBFBD> CARD<EFBFBD><EFBFBD> assign. <EFBFBD><EFBFBD><EFBFBD><EFBFBD>/<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ISP<53><50> <20><><EFBFBD><EFBFBD>, CARD<52><44> <20><><EFBFBD><EFBFBD> <20>˰<EFBFBD> <20><><EFBFBD><EFBFBD>!!!-_-
//승인날짜(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);
@ -994,7 +994,7 @@ class INIData {
$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);
//<EFBFBD><EFBFBD><EFBFBD>ӹ<EFBFBD>ȭ<EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> Multi<74><69><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
//게임문화상품권은 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"));
@ -1061,7 +1061,7 @@ class INIData {
$this->m_PG2IP = $pg2ip;
}
// Xpath<EFBFBD><EFBFBD> <20>Ȱ<EFBFBD><C8B0><EFBFBD><EFBFBD>´<EFBFBD>. <20>Ѵ<EFBFBD><D1B4><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ߴ<EFBFBD>!!
// Xpath로 안가져온다. 한달을 헛지랄 했다!!
// added by ddaemiri, 2007.09.03
function GetXMLData($node) {
$content = $this->m_Xml[$node . "[1]"]["text"];
@ -1074,7 +1074,7 @@ class INIData {
/* ----------------------------------------------------- */
/* Crypto Class */
/* PHP4.2 & OpenSSL <EFBFBD>ʿ<EFBFBD>) */
/* PHP4.2 & OpenSSL 필요) */
/* ----------------------------------------------------- */
class INICrypto {

View File

@ -3,8 +3,8 @@
/**
* Copyright (C) 2007 INICIS Inc.
*
* <EFBFBD>ش<EFBFBD> <20><><EFBFBD>̺귯<CCBA><EAB7AF><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Ǿ<C7BE><EEBCAD> <20>ȵ˴ϴ<CBB4>.
* <EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ڵ忡 <20><><EFBFBD><EFBFBD> å<><C3A5><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ڿ<EFBFBD><DABF><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>˷<EFBFBD><CBB7><EFBFBD>ϴ<EFBFBD>.
* 해당 라이브러리는 절대 수정되어서는 안됩니다.
* 임의로 수정된 코드에 대한 책임은 전적으로 수정자에게 있음을 알려드립니다.
*
* @version 5.0
* @author ddaemiri
@ -15,37 +15,37 @@
*
* @buildno 5001
* @date 2008.01.15
* @note <EFBFBD><EFBFBD>ü<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ũ<EFBFBD><EFBFBD> <20>߰<EFBFBD>, DNS Lookup Timeout <EFBFBD>߰<EFBFBD>, DNS Lookup <EFBFBD><EFBFBD><EFBFBD>н<EFBFBD> socket close<EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD> <20>κ<EFBFBD> <20>߰<EFBFBD>
* @note 자체에스크로 추가, DNS Lookup Timeout 추가, DNS Lookup 실패시 socket close안하는 부분 추가
* @date 2008.01.16
* @note Encrypt,Decrypt <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>, pkcs5 padding <EFBFBD>߰<EFBFBD>
* @note Encrypt,Decrypt 모듈 개선, pkcs5 padding 추가
* @date 2008.01.24
* @note non block connect immediate return check code/str
* @date 2008.02.11
* @note key load <EFBFBD><EFBFBD> read<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߻<EFBFBD><EFBFBD><EFBFBD> fclose <EFBFBD>߰<EFBFBD>
* @note key load read에러발생시 fclose 추가
* @date 2008.03.03
* @note <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>(passing by reference) <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @note 참조에 의한 전달(passing by reference) 수정
* @date 2008.03.11
* @note <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ũ<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Cmd <EFBFBD>߰<EFBFBD>
* @note 에스크로 망취소 Cmd 추가
* @date 2008.03.12
* @note <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> IP<49><50> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
* @note 기존 연결된 IP로 망취소 수정
* @buildno 5002
* @note <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҽ<EFBFBD> Sign<67>߰<EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>->5001<30><31> <20><><EFBFBD><EFBFBD><EFBFBD>ҽ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>,<2C>׷<EFBFBD><D7B7><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD> <20><>)
* @note 망취소시 Sign추가(기존에 안했음->5001은 망취소시 서버측에서 서명오류가 남,그래도 망취소처리는 됨)
* @date 2008.03.12
* @buildno 5016
* @note pg1ip, pg2ip <EFBFBD>߰<EFBFBD>/<2F><><EFBFBD><EFBFBD> <20><><EFBFBD>ŷ<EFBFBD><C5B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> drpg<70><67> <20><><EFBFBD>õ<EFBFBD>
* @note pg1ip, pg2ip 추가/취소 원거래없음시 drpg로 재시도
* @date 2008.04.02
* @buildno 5017
* @note 1)chkfake<EFBFBD><EFBFBD> <20>Ķ<EFBFBD><C4B6><EFBFBD><EFBFBD><EFBFBD> <20>α<EFBFBD> <20><><EFBFBD><EFBFBD>(<28>ߺ<EFBFBD>)
* 2)call-time pass-by-reference => pass-by-value<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
* @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 <EFBFBD>ʱ<EFBFBD> <20>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD><EFBFBD>. <20><><EFBFBD>񽺵ǰ<F1BDBAB5> <20>ִ<EFBFBD><D6B4><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>)
* 2)Makeshop PG Updrade<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>γ<EFBFBD><CEB3><EFBFBD> 2009.02.19 (interface<EFBFBD><EFBFBD><EFBFBD><EFBFBD> mkey<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>޾<EFBFBD> ó<><C3B3><EFBFBD>ϰ<EFBFBD> <20><><EFBFBD><EFBFBD>)
* 3)Makeshop PG Updrade<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>γ<EFBFBD><CEB3><EFBFBD> 2009.02.24 (interface<EFBFBD><EFBFBD><EFBFBD><EFBFBD> mergelog<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>޾<EFBFBD> ó<><C3B3><EFBFBD>ϰ<EFBFBD> <20><><EFBFBD><EFBFBD>)
* @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
@ -57,12 +57,12 @@
* @date 2010.07.14
* @note add Tax, TaxFree info(TX_TAX, TX_TAXFREE)
* @date 2010.09.09
* @note <EFBFBD><EFBFBD><EFBFBD>ҿ<EFBFBD>û<EFBFBD><EFBFBD> PG <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>->IP, INILib.php)
* @note 취소요청시 PG 설정 변경(도메인->IP, INILib.php)
* @note BUILDDATE update(100414 -> 100909)
* @note 2011.05.23 5030 XML ELEMENT <EFBFBD><EFBFBD> ROOT <EFBFBD><EFBFBD> ROOTINFO<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
* @note 2011.05.23 5030 XML ELEMENT ROOT ROOTINFO로 수정
* @buildno 5032
* @note 2012.07.09 <EFBFBD>ŷ<EFBFBD><EFBFBD><EFBFBD>ȸ <20>߰<EFBFBD> (TYPE_INQUIRY)
* @note 2012.07.09 PHP ini <EFBFBD><EFBFBD><EFBFBD><EFBFBD> error display setting <EFBFBD>߰<EFBFBD>
* @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
*/
@ -111,8 +111,8 @@ define("IMJK", "UkVHSVNUX05PX1JDNEtFWQ==");
define("IMJV", "UkVHSVNUX05PX1JDNElW");
//define for mkey
//deprecated 2009.02.19 ( Makeshop <EFBFBD>ʱ<EFBFBD> <20>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD><EFBFBD>. <20><><EFBFBD>񽺵ǰ<F1BDBAB5> <20>ִ<EFBFBD><D6B4><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>)
//Makeshop PG Updrade<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>γ<EFBFBD><CEB3><EFBFBD> 2009.02.19 (interface<EFBFBD><EFBFBD><EFBFBD><EFBFBD> mkey<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>޾<EFBFBD> ó<><C3B3><EFBFBD>ϰ<EFBFBD> <20><><EFBFBD><EFBFBD>)
//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");
@ -152,24 +152,24 @@ define("CMD_REQ_PRTC", "0620");
define("CMD_RES_PRTC", "0630");
define("CMD_REQ_ACK", "0800");
define("CMD_RES_ACK", "0810");
//<EFBFBD><EFBFBD>ü<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ũ<EFBFBD><EFBFBD>
//자체에스크로
//added 2008.01.08
define("CMD_REQ_DLV", "3020"); //<EFBFBD><EFBFBD><EFBFBD>۵<EFBFBD><EFBFBD><EFBFBD>
define("CMD_REQ_CNF", "3030"); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȯ<EFBFBD><EFBFBD>
define("CMD_REQ_DNY", "3040"); //<EFBFBD><EFBFBD><EFBFBD>Ű<EFBFBD><EFBFBD><EFBFBD>
define("CMD_REQ_DNY_CNF", "3080"); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȯ<EFBFBD><EFBFBD>
define("CMD_REQ_DLV_NETC", "3520"); //<EFBFBD><EFBFBD><EFBFBD>۵<EFBFBD><EFBFBD>ϸ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
define("CMD_REQ_CNF_NETC", "3530"); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȯ<EFBFBD>θ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
define("CMD_REQ_DNY_NETC", "3540"); //<EFBFBD><EFBFBD><EFBFBD>Ű<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȯ<EFBFBD><EFBFBD>(09.08.05)
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");
//<EFBFBD>ŷ<EFBFBD><EFBFBD><EFBFBD>ȸ(12.04.20)
//거래조회(12.04.20)
define("CMS_REQ_INQR", "0900");
define("CMS_RES_INQR", "0910");
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(14.03.06)
//서브몰하위가맹점등록(14.03.06)
define("CMS_REQ_OPEN_SUB", "1040");
define("CMS_RES_OPEN_SUB", "1041");
@ -187,14 +187,14 @@ define("FLAG_SIGN_SHA1", "SHA1");
define("FLAG_SIGN_MD5", "MD5");
//------------------------------------------------------
//TYPE(<EFBFBD><EFBFBD><EFBFBD>񽺺<EFBFBD>)
//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"); //<EFBFBD><EFBFBD>ü<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ũ<EFBFBD><EFBFBD>!
define("TYPE_ESCROW", "escrow"); //자체에스크로!
define("TYPE_CONFIRM", "confirm");
define("TYPE_OCBQUERY", "ocbquery");
define("TYPE_OCBSAVE", "ocbsave");
@ -207,26 +207,26 @@ define("TYPE_VBANK", "VBank");
define("TYPE_REQREALBILL", "reqrealbill");
define("TYPE_FORMAUTH", "formauth");
define("TYPE_CHKFAKE", "chkfake");
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȯ<EFBFBD><EFBFBD>(09.08.05)
//가상계좌환불(09.08.05)
define("TYPE_REFUND", "refund");
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ºκ<EFBFBD>ȯ<EFBFBD><EFBFBD>(12.06.05)
//가상계좌부분환불(12.06.05)
define("TYPE_VACCTREPAY", "vacctrepay");
//<EFBFBD>ŷ<EFBFBD><EFBFBD><EFBFBD>ȸ(12.04.20)
//거래조회(12.04.20)
define("TYPE_INQUIRY", "inquiry");
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(14.03.06)
//서브몰하위가맹점등록(14.03.06)
define("TYPE_OPENSUB", "opensub");
//------------------------------------------------------
//EscrowType(<EFBFBD><EFBFBD>ü<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ũ<EFBFBD><EFBFBD> Ÿ<><C5B8>)
//EscrowType(자체에스크로 타입)
//added 2008.01.08
//------------------------------------------------------
define("TYPE_ESCROW_DLV", "dlv");
define("TYPE_ESCROW_CNF", "confirm"); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȯ<EFBFBD><EFBFBD>/<2F><><EFBFBD><EFBFBD>(<28>÷<EFBFBD><C3B7><EFBFBD><EFBFBD><EFBFBD>)
define("TYPE_ESCROW_DNY", "deny"); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ó<><C3B3><EFBFBD><EFBFBD>,<2C>ǹ̾<C7B9><CCBE><EFBFBD>
define("TYPE_ESCROW_CNF", "confirm"); //구매확인/거절(플러그인)
define("TYPE_ESCROW_DNY", "deny"); //위에서 처리됨,의미없음
define("TYPE_ESCROW_DNY_CNF", "dcnf");
//------------------------------------------------------
//PayMethod(<EFBFBD><EFBFBD><EFBFBD>񽺺<EFBFBD>, TX)
//PayMethod(서비스별, TX)
//------------------------------------------------------
define("NM_TX_ISP", "VCard");
define("NM_TX_CARD", "Card");
@ -244,7 +244,7 @@ define("NM_TX_TEEN", "TEEN");
define("NM_TX_ESCR", "Escrow");
//------------------------------------------------------
//PayMethod(<EFBFBD><EFBFBD><EFBFBD>񽺺<EFBFBD>, PG)
//PayMethod(서비스별, PG)
//------------------------------------------------------
define("NM_ISP", "ISP");
define("NM_CARD", "CARD");
@ -274,7 +274,7 @@ define("URLENCODE", "urlencode");
define("URLDECODE", "urldecode");
//------------------------------------------------------
//<EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//요청전문
//------------------------------------------------------
define("TX_GOOSCNT", "GoodsCnt");
define("TX_MOID", "MOID");
@ -317,8 +317,8 @@ define("TX_RN", "TXRN");
//CancelInfo
define("TX_CANCELTID", "CancelTID");
define("TX_CANCELMSG", "CancelMsg");
define("TX_CANCELREASON", "CancelReason"); //2012-10-19 <EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD> <20>߰<EFBFBD>
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȯ<EFBFBD><EFBFBD>(09.08.05)
define("TX_CANCELREASON", "CancelReason"); //2012-10-19 취소사유코드 추가
//가상계좌환불(09.08.05)
define("TX_REFUNDACCTNUM", "RefundAcctNum");
define("TX_REFUNDBANKCODE", "RefundBankCode");
define("TX_REFUNDACCTNAME", "RefundAcctName");
@ -333,15 +333,15 @@ define("TX_PRTC_TAXFREE", "TaxFree");
define("TX_PRTC_CURRENCY", "Currency");
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> I<><49><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ü <20>κ<EFBFBD><CEBA><EFBFBD><EFBFBD>ҽ<EFBFBD> <20><><EFBFBD>¹<EFBFBD>ȣ/<2F><><EFBFBD><EFBFBD><EFBFBD>ּ<EFBFBD><D6BC><EFBFBD><EFBFBD>߰<EFBFBD> 2011-10-06
//국민은행 I계좌이체 부분취소시 계좌번호/계좌주성명추가 2011-10-06
define("TX_PRTC_NOACCT", "PRTC_NoAcctFNBC");
define("TX_PRTC_NMACCT", "PRTC_NmAcctFNBC");
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>κ<EFBFBD>ȯ<EFBFBD><C8AF> <20><><EFBFBD><EFBFBD> <20>߰<EFBFBD>
//가상계좌 부분환불 관련 추가
define("TX_PRTC_REFUNDFLGREMIT", "PRTC_RefundFlgRemit");
define("TX_PRTC_REFUNDBANKCODE", "PRTC_RefundBankCode");
//CaptureInfo
define("TX_CAPTURETID", "CaptureTID");
//<EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//현금영수증
define("TX_CSHR_APPLPRICE", "CSHR_ApplPrice");
define("TX_CSHR_SUPPLYPRICE", "CSHR_SupplyPrice");
define("TX_CSHR_TAX", "CSHR_Tax");
@ -357,9 +357,9 @@ define("TX_CSHR_SUBREGNUM1", "CSHR_SubRegNum1");
define("TX_CSHR_SUBMID1", "CSHR_SubMID1");
define("TX_CSHR_SUBAPPLPRICE1", "CSHR_SubApplPrice1");
define("TX_CSHR_SUBSERVICEPRICE1", "CSHR_SubServicePrice1");
//<EFBFBD>ŷ<EFBFBD><EFBFBD><EFBFBD>ȸ(12.04.20)
//거래조회(12.04.20)
define("TX_INQR_TID", "INQR_TID");
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(14.03.06)
//서브몰하위가맹점등록(14.03.06)
define("TX_OPENREG_TID", "OrgTID");
define("TX_OPENREG_MID", "MID");
define("TX_OPENREG_SUBCNT", "SubCnt");
@ -374,7 +374,7 @@ define("TX_OPENREG_SUBPRICE", "SubPrice");
//------------------------------------------------------
//
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//응답전문
//
//------------------------------------------------------
//HEAD
@ -433,9 +433,9 @@ define("CANCELINFO", "CancelInfo");
define("PARTCANCELINFO", "PartCancelInfo");
//Capture
define("CAPTUREINFO", "CaptureInfo");
//<EFBFBD>ŷ<EFBFBD><EFBFBD><EFBFBD>ȸ(12.04.20)
//거래조회(12.04.20)
define("INQUIRYINFO", "InquiryInfo");
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(14.03.06)
//서브몰하위가맹점등록(14.03.06)
define("OPENSUBINFO", "OpenSubInfo");
//Escrow
//added 2008.01.09
@ -541,7 +541,7 @@ define("TEEN_APPLNUM", "TEEN_ApplNum");
//----------------------------------
//ERROR CODE
//----------------------------------
//!!<EFBFBD><EFBFBD>TX<EFBFBD><EFBFBD> <20>߰<EFBFBD><DFB0><EFBFBD> <20><><EFBFBD><EFBFBD>!!!
//!!신TX에 추가된 에러!!!
define("NULL_DIR_ERR", "TX9001");
define("NULL_TYPE_ERR", "TX9002");
define("NULL_NOINTEREST_ERR", "TX9003");
@ -551,7 +551,7 @@ define("MERCHANT_DB_ERR", "TX9006");
define("DNS_LOOKUP_TIMEOUT_ERR", "TX9007");
define("PGPUB_UPDATE_ERR", "TX9612");
//<EFBFBD>Ϻ<EFBFBD>ȣȭ <20><><EFBFBD><EFBFBD>
//암복호화 에러
define("B64DECODE_UPDATE_ERR", "TX9101");
define("B64DECODE_FINAL_ERR", "TX9102");
define("B64DECODE_LENGTH_ERR", "TX9103");
@ -576,7 +576,7 @@ define("SIGN_CHECK_ERR", "TX9121");
define("ENC_NULL_F_ERR", "TX9122");
define("ENC_INIT_RAND_ERR", "TX9123");
define("ENC_PUTENV_ERR", "TX9124");
//<EFBFBD>ʵ<EFBFBD>üũ
//필드체크
define("NULL_KEYPW_ERR", "TX9201");
define("NULL_MID_ERR", "TX9202");
define("NULL_PGID_ERR", "TX9203");
@ -607,37 +607,37 @@ define("NULL_BUYERNAME_ERR", "TX9227");
define("NULL_BUYERTEL_ERR", "TX9228");
define("NULL_BUYEREMAIL_ERR", "TX9229");
define("NULL_SESSIONKEY_ERR", "TX9230");
//pg<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ű <20>ε<EFBFBD> <20><><EFBFBD><EFBFBD>
//pg공개키 로드 오류
define("NULL_PGCERT_FP_ERR", "TX9231");
define("NULL_X509_ERR", "TX9232");
define("NULL_PGCERT_ERR", "TX9233");
define("RESULT_MSG_FORMAT_ERR", "TX9234");
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><>ü <20><><EFBFBD><EFBFBD>
define("NULL_PERNO_ERR", "TX9235"); // <EFBFBD>ֹι<EFBFBD>ȣ <20><><EFBFBD><EFBFBD>
define("NULL_OID_ERR", "TX9236"); // <EFBFBD>ֹ<EFBFBD><EFBFBD><EFBFBD>ȣ <20><><EFBFBD><EFBFBD>
define("NULL_VCDBANK_ERR", "TX9237"); // <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD> <20><><EFBFBD><EFBFBD>
define("NULL_DTINPUT_ERR", "TX9238"); // <EFBFBD>Ա<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
define("NULL_NMINPUT_ERR", "TX9239"); // <EFBFBD>۱<EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
//<EFBFBD>ǽð<EFBFBD> <20><><EFBFBD><EFBFBD>
define("NULL_BILLKEY_ERR", "TX9240"); // <EFBFBD><EFBFBD>Ű <20><><EFBFBD><EFBFBD>
define("NULL_CARDPASS_ERR", "TX9241"); // ī<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
define("NULL_BILLTYPE_ERR", "TX9242"); // <EFBFBD><EFBFBD>Ÿ<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
// CMS <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ü
define("NULL_PRICE_ORG_ERR", "TX9250"); // CMS <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѱݾ<EFBFBD> <20><><EFBFBD><EFBFBD>
define("NULL_CMSDAY_ERR", "TX9251"); // CMS <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
define("NULL_CMSDATEFROM_ERR", "TX9252"); // CMS <EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><EFBFBD>ۿ<EFBFBD> <20><><EFBFBD><EFBFBD>
define("NULL_CMSDATETO_ERR", "TX9253"); // CMS <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
// <EFBFBD>κ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
define("NULL_CONFIRM_PRICE_ERR", "TX9260"); // <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>û<EFBFBD>ݾ<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
// <EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
define("NULL_CR_PRICE_ERR", "TX9270"); // <EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><EFBFBD><EFBFBD> <20>ݾ<EFBFBD> <20><><EFBFBD><EFBFBD>
define("NULL_SUP_PRICE_ERR", "TX9271"); // <EFBFBD><EFBFBD><EFBFBD>ް<EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
define("NULL_TAX_ERR", "TX9272"); // <EFBFBD>ΰ<EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
define("NULL_SRVC_PRICE_ERR", "TX9273"); // <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
define("NULL_REG_NUM_ERR", "TX9274"); // <EFBFBD>ֹι<EFBFBD>ȣ(<28><><EFBFBD><EFBFBD><EFBFBD>ڹ<EFBFBD>ȣ)
define("NULL_USEOPT_ERR", "TX9275"); // <EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
// 가상 계좌 이체 예약
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");

File diff suppressed because it is too large Load Diff

View File

@ -1,251 +1,222 @@
<?php
/**
* Copyright (C) 2007 INICIS Inc.
*
* <EFBFBD>ش<EFBFBD> <20><><EFBFBD>̺귯<CCBA><EAB7AF><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Ǿ<C7BE><EEBCAD> <20>ȵ˴ϴ<CBB4>.
* <EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ڵ忡 <20><><EFBFBD><EFBFBD> å<><C3A5><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ڿ<EFBFBD><DABF><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>˷<EFBFBD><CBB7><EFBFBD>ϴ<EFBFBD>.
* 해당 라이브러리는 절대 수정되어서는 안됩니다.
* 임의로 수정된 코드에 대한 책임은 전적으로 수정자에게 있음을 알려드립니다.
*
*/
class INISocket {
class INISocket{
var $hnd;
var $host;
var $ip;
var $port;
var $type;
var $family;
var $protocol;
var $bConnected;
var $sBuffer;
var $sSocErr;
var $dns_laptime;
var $hnd;
var $host;
var $ip;
var $port;
var $type;
var $family;
var $protocol;
var $bConnected;
var $sBuffer;
var $sSocErr;
var $dns_laptime;
function error($msg=null)
{
$errCode = socket_last_error($this->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 INISocket($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)
{
$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, <20><><EFBFBD><EFBFBD> OS üũ <20>Ұ<EFBFBD><D2B0><EFBFBD><EFBFBD>ؼ<EFBFBD> str<74><72><EFBFBD>ε<EFBFBD> <20>˻<EFBFBD> )
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;
}
function error($msg = null) {
$errCode = socket_last_error($this->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;
}
$read = array($this->hnd);
$write = array($this->hnd);
$rtv = @socket_select($read,$write,$except=NULL,TIMEOUT_CONNECT);
if( $rtv == 0 ) //TIMEOUT
{
$this->error();
socket_close($this->hnd);
return SOCK_TIMEO_ERR;
function INISocket($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;
}
else if ( $rtv === FALSE )
{
$this->error();
socket_close($this->hnd);
return SOCK_ETC1_ERR;
function DNSLookUP() {
$starttime = GetMicroTime();
$ip = @gethostbyname($this->host);
if ($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;
}
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;
}
function open() {
//Connect timeout Trickkkkkkkkk ##2. NONBLOCKING NEED , less CPU clocking!!^^
//modified by ddaemiri, 2007.08.30
$vWrite = array($this->hnd);
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;
}
}
while(($rtv = @socket_select($vRead = null,$vWrite ,$vExcept = null, TIMEOUT_WRITE)) === FALSE);
$read = array($this->hnd);
$write = array($this->hnd);
$rtv = @socket_select($read, $write, $except = NULL, 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;
}
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;
}
function close() {
//if(!$this->bConnected) return;
@socket_shutdown($this->hnd, 2);
@socket_close($this->hnd);
}
$tmpBuf = strlen($sBuf) ? $sBuf : $this->sBuffer;
$iBufLen = strlen($tmpBuf);
$res = @socket_send($this->hnd,$tmpBuf,$iBufLen,0);
function send($sBuf) {
if (!$this->bConnected) {
$this->error("Socket error. Cannot send data on a closed socket.");
return SOCK_SEND1_ERR;
}
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 )
{
$rtv = @socket_select($read,$write=NULL,$except=NULL,TIMEOUT_READ);
if( $rtv == 0 )
{
$this->error();
return SOCK_TIMEO_ERR;
}
else if ( $rtv === FALSE )
{
$this->error();
return SOCK_ETC1_ERR;
}
$vWrite = array($this->hnd);
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;
}
while (($rtv = @socket_select($vRead = null, $vWrite, $vExcept = null, TIMEOUT_WRITE)) === FALSE);
//------------------------------------------------------
//head
//------------------------------------------------------
if( ($rtv = $this->WaitRecv( $head, MSGHEADER_LEN)) != OK ) return $rtv;
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;
}
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;
$tmpBuf = strlen($sBuf) ? $sBuf : $this->sBuffer;
$iBufLen = strlen($tmpBuf);
$res = @socket_send($this->hnd, $tmpBuf, $iBufLen, 0);
return OK;
}
function getErr()
{
return $this->sSocErr;
}
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) {
$rtv = @socket_select($read, $write = NULL, $except = NULL, 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;
}
}
?>

View File

@ -0,0 +1,74 @@
<?php
class INIStdPayUtil {
function getTimestamp() {
// timezone 을 설정하지 않으면 getTimestapme() 실행시 오류가 발생한다.
// php.ini 에 timezone 설정이 되어 잇으면 아래 코드가 필요없다.
// php 5.3 이후로는 반드시 timezone 설정을 해야하기 때문에 아래 코드가 필요없을 수 있음. 나중에 확인 후 수정필요.
// 이니시스 플로우에서 timestamp 값이 중요하게 사용되는 것으로 보이기 때문에 정확한 timezone 설정후 timestamp 값이 필요하지 않을까 함.
/**********php5
date_default_timezone_set('Asia/Seoul');
$date = new DateTime();
*/
putenv('TZ=Asia/Seoul');
$milliseconds = round(microtime(true) * 1000);
$tempValue1 = round($milliseconds / 1000); //max integer 자릿수가 9이므로 뒤 3자리를 뺀다
$tempValue2 = round(microtime(false) * 1000); //뒤 3자리를 저장
switch (strlen($tempValue2)) {
case '3':
break;
case '2':
$tempValue2 = "0" . $tempValue2;
break;
case '1':
$tempValue2 = "00" . $tempValue2;
break;
default:
$tempValue2 = "000";
break;
}
return "" . $tempValue1 . $tempValue2;
}
/*
//*** 위변조 방지체크를 signature 생성 ***
mid, price, timestamp 3개의 키와 값을
key=value 형식으로 하여 '&'로 연결한 하여 SHA-256 Hash로 생성 된값
ex) mid=INIpayTest&price=819000&timestamp=2012-02-01 09:19:04.004
* key기준 알파벳 정렬
* timestamp는 반드시 signature생성에 사용한 timestamp 값을 timestamp input에 그데로 사용하여야함
*/
function makeSignature($signParam) {
ksort($signParam);
$string = "";
foreach ($signParam as $key => $value) {
$string .= "&$key=$value";
}
$string = substr($string, 1); // remove leading "&"
$sign = hash( "sha256", $string);
return $sign;
}
function makeHash($data, $alg) {
// $s = hash_hmac('sha256', $data, 'secret', true);
// return base64_encode($s);
///$ret = openssl_digest($data, $alg);
$ret = hash($alg, $data);
return $ret;
}
}
?>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,15 @@
<?php
require_once('../libs/INIStdPayUtil.php');
$SignatureUtil = new INIStdPayUtil();
$input = "oid=" . $_REQUEST["oid"] . "&price=" . $_REQUEST["price"] . "&timestamp=" . $_REQUEST["timestamp"];
$output['signature'] = array(
///'signature' => $SignatureUtil->makeHash($input, "sha256")
'signature' => hash("sha256", $input)
);
echo json_encode($output);
?>

806
shop/inicis/libs/JSON.php Normal file
View File

@ -0,0 +1,806 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Converts to and from JSON format.
*
* JSON (JavaScript Object Notation) is a lightweight data-interchange
* format. It is easy for humans to read and write. It is easy for machines
* to parse and generate. It is based on a subset of the JavaScript
* Programming Language, Standard ECMA-262 3rd Edition - December 1999.
* This feature can also be found in Python. JSON is a text format that is
* completely language independent but uses conventions that are familiar
* to programmers of the C-family of languages, including C, C++, C#, Java,
* JavaScript, Perl, TCL, and many others. These properties make JSON an
* ideal data-interchange language.
*
* This package provides a simple encoder and decoder for JSON notation. It
* is intended for use with client-side Javascript applications that make
* use of HTTPRequest to perform server communication functions - data can
* be encoded into JSON notation for use in a client-side javascript, or
* decoded from incoming Javascript requests. JSON format is native to
* Javascript, and can be directly eval()'ed with no further parsing
* overhead
*
* All strings should be in ASCII or UTF-8 format!
*
* LICENSE: Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met: Redistributions of source code must retain the
* above copyright notice, this list of conditions and the following
* disclaimer. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
* NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
* @category
* @package Services_JSON
* @author Michal Migurski <mike-json@teczno.com>
* @author Matt Knapp <mdknapp[at]gmail[dot]com>
* @author Brett Stimmerman <brettstimmerman[at]gmail[dot]com>
* @copyright 2005 Michal Migurski
* @version CVS: $Id: JSON.php,v 1.31 2006/06/28 05:54:17 migurski Exp $
* @license http://www.opensource.org/licenses/bsd-license.php
* @link http://pear.php.net/pepr/pepr-proposal-show.php?id=198
*/
/**
* Marker constant for Services_JSON::decode(), used to flag stack state
*/
define('SERVICES_JSON_SLICE', 1);
/**
* Marker constant for Services_JSON::decode(), used to flag stack state
*/
define('SERVICES_JSON_IN_STR', 2);
/**
* Marker constant for Services_JSON::decode(), used to flag stack state
*/
define('SERVICES_JSON_IN_ARR', 3);
/**
* Marker constant for Services_JSON::decode(), used to flag stack state
*/
define('SERVICES_JSON_IN_OBJ', 4);
/**
* Marker constant for Services_JSON::decode(), used to flag stack state
*/
define('SERVICES_JSON_IN_CMT', 5);
/**
* Behavior switch for Services_JSON::decode()
*/
define('SERVICES_JSON_LOOSE_TYPE', 16);
/**
* Behavior switch for Services_JSON::decode()
*/
define('SERVICES_JSON_SUPPRESS_ERRORS', 32);
/**
* Converts to and from JSON format.
*
* Brief example of use:
*
* <code>
* // create a new instance of Services_JSON
* $json = new Services_JSON();
*
* // convert a complexe value to JSON notation, and send it to the browser
* $value = array('foo', 'bar', array(1, 2, 'baz'), array(3, array(4)));
* $output = $json->encode($value);
*
* print($output);
* // prints: ["foo","bar",[1,2,"baz"],[3,[4]]]
*
* // accept incoming POST data, assumed to be in JSON notation
* $input = file_get_contents('php://input', 1000000);
* $value = $json->decode($input);
* </code>
*/
class Services_JSON
{
/**
* constructs a new JSON instance
*
* @param int $use object behavior flags; combine with boolean-OR
*
* possible values:
* - SERVICES_JSON_LOOSE_TYPE: loose typing.
* "{...}" syntax creates associative arrays
* instead of objects in decode().
* - SERVICES_JSON_SUPPRESS_ERRORS: error suppression.
* Values which can't be encoded (e.g. resources)
* appear as NULL instead of throwing errors.
* By default, a deeply-nested resource will
* bubble up with an error, so all return values
* from encode() should be checked with isError()
*/
function Services_JSON($use = 0)
{
$this->use = $use;
}
/**
* convert a string from one UTF-16 char to one UTF-8 char
*
* Normally should be handled by mb_convert_encoding, but
* provides a slower PHP-only method for installations
* that lack the multibye string extension.
*
* @param string $utf16 UTF-16 character
* @return string UTF-8 character
* @access private
*/
function utf162utf8($utf16)
{
// oh please oh please oh please oh please oh please
if(function_exists('mb_convert_encoding')) {
return mb_convert_encoding($utf16, 'UTF-8', 'UTF-16');
}
$bytes = (ord($utf16{0}) << 8) | ord($utf16{1});
switch(true) {
case ((0x7F & $bytes) == $bytes):
// this case should never be reached, because we are in ASCII range
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
return chr(0x7F & $bytes);
case (0x07FF & $bytes) == $bytes:
// return a 2-byte UTF-8 character
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
return chr(0xC0 | (($bytes >> 6) & 0x1F))
. chr(0x80 | ($bytes & 0x3F));
case (0xFFFF & $bytes) == $bytes:
// return a 3-byte UTF-8 character
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
return chr(0xE0 | (($bytes >> 12) & 0x0F))
. chr(0x80 | (($bytes >> 6) & 0x3F))
. chr(0x80 | ($bytes & 0x3F));
}
// ignoring UTF-32 for now, sorry
return '';
}
/**
* convert a string from one UTF-8 char to one UTF-16 char
*
* Normally should be handled by mb_convert_encoding, but
* provides a slower PHP-only method for installations
* that lack the multibye string extension.
*
* @param string $utf8 UTF-8 character
* @return string UTF-16 character
* @access private
*/
function utf82utf16($utf8)
{
// oh please oh please oh please oh please oh please
if(function_exists('mb_convert_encoding')) {
return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8');
}
switch(strlen($utf8)) {
case 1:
// this case should never be reached, because we are in ASCII range
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
return $utf8;
case 2:
// return a UTF-16 character from a 2-byte UTF-8 char
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
return chr(0x07 & (ord($utf8{0}) >> 2))
. chr((0xC0 & (ord($utf8{0}) << 6))
| (0x3F & ord($utf8{1})));
case 3:
// return a UTF-16 character from a 3-byte UTF-8 char
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
return chr((0xF0 & (ord($utf8{0}) << 4))
| (0x0F & (ord($utf8{1}) >> 2)))
. chr((0xC0 & (ord($utf8{1}) << 6))
| (0x7F & ord($utf8{2})));
}
// ignoring UTF-32 for now, sorry
return '';
}
/**
* encodes an arbitrary variable into JSON format
*
* @param mixed $var any number, boolean, string, array, or object to be encoded.
* see argument 1 to Services_JSON() above for array-parsing behavior.
* if var is a strng, note that encode() always expects it
* to be in ASCII or UTF-8 format!
*
* @return mixed JSON string representation of input var or an error if a problem occurs
* @access public
*/
function encode($var)
{
switch (gettype($var)) {
case 'boolean':
return $var ? 'true' : 'false';
case 'NULL':
return 'null';
case 'integer':
return (int) $var;
case 'double':
case 'float':
return (float) $var;
case 'string':
// STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT
$ascii = '';
$strlen_var = strlen($var);
/*
* Iterate over every character in the string,
* escaping with a slash or encoding to UTF-8 where necessary
*/
for ($c = 0; $c < $strlen_var; ++$c) {
$ord_var_c = ord($var{$c});
switch (true) {
case $ord_var_c == 0x08:
$ascii .= '\b';
break;
case $ord_var_c == 0x09:
$ascii .= '\t';
break;
case $ord_var_c == 0x0A:
$ascii .= '\n';
break;
case $ord_var_c == 0x0C:
$ascii .= '\f';
break;
case $ord_var_c == 0x0D:
$ascii .= '\r';
break;
case $ord_var_c == 0x22:
case $ord_var_c == 0x2F:
case $ord_var_c == 0x5C:
// double quote, slash, slosh
$ascii .= '\\'.$var{$c};
break;
case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)):
// characters U-00000000 - U-0000007F (same as ASCII)
$ascii .= $var{$c};
break;
case (($ord_var_c & 0xE0) == 0xC0):
// characters U-00000080 - U-000007FF, mask 110XXXXX
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
$char = pack('C*', $ord_var_c, ord($var{$c + 1}));
$c += 1;
$utf16 = $this->utf82utf16($char);
$ascii .= sprintf('\u%04s', bin2hex($utf16));
break;
case (($ord_var_c & 0xF0) == 0xE0):
// characters U-00000800 - U-0000FFFF, mask 1110XXXX
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
$char = pack('C*', $ord_var_c,
ord($var{$c + 1}),
ord($var{$c + 2}));
$c += 2;
$utf16 = $this->utf82utf16($char);
$ascii .= sprintf('\u%04s', bin2hex($utf16));
break;
case (($ord_var_c & 0xF8) == 0xF0):
// characters U-00010000 - U-001FFFFF, mask 11110XXX
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
$char = pack('C*', $ord_var_c,
ord($var{$c + 1}),
ord($var{$c + 2}),
ord($var{$c + 3}));
$c += 3;
$utf16 = $this->utf82utf16($char);
$ascii .= sprintf('\u%04s', bin2hex($utf16));
break;
case (($ord_var_c & 0xFC) == 0xF8):
// characters U-00200000 - U-03FFFFFF, mask 111110XX
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
$char = pack('C*', $ord_var_c,
ord($var{$c + 1}),
ord($var{$c + 2}),
ord($var{$c + 3}),
ord($var{$c + 4}));
$c += 4;
$utf16 = $this->utf82utf16($char);
$ascii .= sprintf('\u%04s', bin2hex($utf16));
break;
case (($ord_var_c & 0xFE) == 0xFC):
// characters U-04000000 - U-7FFFFFFF, mask 1111110X
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
$char = pack('C*', $ord_var_c,
ord($var{$c + 1}),
ord($var{$c + 2}),
ord($var{$c + 3}),
ord($var{$c + 4}),
ord($var{$c + 5}));
$c += 5;
$utf16 = $this->utf82utf16($char);
$ascii .= sprintf('\u%04s', bin2hex($utf16));
break;
}
}
return '"'.$ascii.'"';
case 'array':
/*
* As per JSON spec if any array key is not an integer
* we must treat the the whole array as an object. We
* also try to catch a sparsely populated associative
* array with numeric keys here because some JS engines
* will create an array with empty indexes up to
* max_index which can cause memory issues and because
* the keys, which may be relevant, will be remapped
* otherwise.
*
* As per the ECMA and JSON specification an object may
* have any string as a property. Unfortunately due to
* a hole in the ECMA specification if the key is a
* ECMA reserved word or starts with a digit the
* parameter is only accessible using ECMAScript's
* bracket notation.
*/
// treat as a JSON object
if (is_array($var) && count($var) && (array_keys($var) !== range(0, sizeof($var) - 1))) {
$properties = array_map(array($this, 'name_value'),
array_keys($var),
array_values($var));
foreach($properties as $property) {
if(Services_JSON::isError($property)) {
return $property;
}
}
return '{' . join(',', $properties) . '}';
}
// treat it like a regular array
$elements = array_map(array($this, 'encode'), $var);
foreach($elements as $element) {
if(Services_JSON::isError($element)) {
return $element;
}
}
return '[' . join(',', $elements) . ']';
case 'object':
$vars = get_object_vars($var);
$properties = array_map(array($this, 'name_value'),
array_keys($vars),
array_values($vars));
foreach($properties as $property) {
if(Services_JSON::isError($property)) {
return $property;
}
}
return '{' . join(',', $properties) . '}';
default:
return ($this->use & SERVICES_JSON_SUPPRESS_ERRORS)
? 'null'
: new Services_JSON_Error(gettype($var)." can not be encoded as JSON string");
}
}
/**
* array-walking function for use in generating JSON-formatted name-value pairs
*
* @param string $name name of key to use
* @param mixed $value reference to an array element to be encoded
*
* @return string JSON-formatted name-value pair, like '"name":value'
* @access private
*/
function name_value($name, $value)
{
$encoded_value = $this->encode($value);
if(Services_JSON::isError($encoded_value)) {
return $encoded_value;
}
return $this->encode(strval($name)) . ':' . $encoded_value;
}
/**
* reduce a string by removing leading and trailing comments and whitespace
*
* @param $str string string value to strip of comments and whitespace
*
* @return string string value stripped of comments and whitespace
* @access private
*/
function reduce_string($str)
{
$str = preg_replace(array(
// eliminate single line comments in '// ...' form
'#^\s*//(.+)$#m',
// eliminate multi-line comments in '/* ... */' form, at start of string
'#^\s*/\*(.+)\*/#Us',
// eliminate multi-line comments in '/* ... */' form, at end of string
'#/\*(.+)\*/\s*$#Us'
), '', $str);
// eliminate extraneous space
return trim($str);
}
/**
* decodes a JSON string into appropriate variable
*
* @param string $str JSON-formatted string
*
* @return mixed number, boolean, string, array, or object
* corresponding to given JSON input string.
* See argument 1 to Services_JSON() above for object-output behavior.
* Note that decode() always returns strings
* in ASCII or UTF-8 format!
* @access public
*/
function decode($str)
{
$str = $this->reduce_string($str);
switch (strtolower($str)) {
case 'true':
return true;
case 'false':
return false;
case 'null':
return null;
default:
$m = array();
if (is_numeric($str)) {
// Lookie-loo, it's a number
// This would work on its own, but I'm trying to be
// good about returning integers where appropriate:
// return (float)$str;
// Return float or int, as appropriate
return ((float)$str == (integer)$str)
? (integer)$str
: (float)$str;
} elseif (preg_match('/^("|\').*(\1)$/s', $str, $m) && $m[1] == $m[2]) {
// STRINGS RETURNED IN UTF-8 FORMAT
$delim = substr($str, 0, 1);
$chrs = substr($str, 1, -1);
$utf8 = '';
$strlen_chrs = strlen($chrs);
for ($c = 0; $c < $strlen_chrs; ++$c) {
$substr_chrs_c_2 = substr($chrs, $c, 2);
$ord_chrs_c = ord($chrs{$c});
switch (true) {
case $substr_chrs_c_2 == '\b':
$utf8 .= chr(0x08);
++$c;
break;
case $substr_chrs_c_2 == '\t':
$utf8 .= chr(0x09);
++$c;
break;
case $substr_chrs_c_2 == '\n':
$utf8 .= chr(0x0A);
++$c;
break;
case $substr_chrs_c_2 == '\f':
$utf8 .= chr(0x0C);
++$c;
break;
case $substr_chrs_c_2 == '\r':
$utf8 .= chr(0x0D);
++$c;
break;
case $substr_chrs_c_2 == '\\"':
case $substr_chrs_c_2 == '\\\'':
case $substr_chrs_c_2 == '\\\\':
case $substr_chrs_c_2 == '\\/':
if (($delim == '"' && $substr_chrs_c_2 != '\\\'') ||
($delim == "'" && $substr_chrs_c_2 != '\\"')) {
$utf8 .= $chrs{++$c};
}
break;
case preg_match('/\\\u[0-9A-F]{4}/i', substr($chrs, $c, 6)):
// single, escaped unicode character
$utf16 = chr(hexdec(substr($chrs, ($c + 2), 2)))
. chr(hexdec(substr($chrs, ($c + 4), 2)));
$utf8 .= $this->utf162utf8($utf16);
$c += 5;
break;
case ($ord_chrs_c >= 0x20) && ($ord_chrs_c <= 0x7F):
$utf8 .= $chrs{$c};
break;
case ($ord_chrs_c & 0xE0) == 0xC0:
// characters U-00000080 - U-000007FF, mask 110XXXXX
//see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
$utf8 .= substr($chrs, $c, 2);
++$c;
break;
case ($ord_chrs_c & 0xF0) == 0xE0:
// characters U-00000800 - U-0000FFFF, mask 1110XXXX
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
$utf8 .= substr($chrs, $c, 3);
$c += 2;
break;
case ($ord_chrs_c & 0xF8) == 0xF0:
// characters U-00010000 - U-001FFFFF, mask 11110XXX
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
$utf8 .= substr($chrs, $c, 4);
$c += 3;
break;
case ($ord_chrs_c & 0xFC) == 0xF8:
// characters U-00200000 - U-03FFFFFF, mask 111110XX
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
$utf8 .= substr($chrs, $c, 5);
$c += 4;
break;
case ($ord_chrs_c & 0xFE) == 0xFC:
// characters U-04000000 - U-7FFFFFFF, mask 1111110X
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
$utf8 .= substr($chrs, $c, 6);
$c += 5;
break;
}
}
return $utf8;
} elseif (preg_match('/^\[.*\]$/s', $str) || preg_match('/^\{.*\}$/s', $str)) {
// array, or object notation
if ($str{0} == '[') {
$stk = array(SERVICES_JSON_IN_ARR);
$arr = array();
} else {
if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
$stk = array(SERVICES_JSON_IN_OBJ);
$obj = array();
} else {
$stk = array(SERVICES_JSON_IN_OBJ);
$obj = new stdClass();
}
}
array_push($stk, array('what' => SERVICES_JSON_SLICE,
'where' => 0,
'delim' => false));
$chrs = substr($str, 1, -1);
$chrs = $this->reduce_string($chrs);
if ($chrs == '') {
if (reset($stk) == SERVICES_JSON_IN_ARR) {
return $arr;
} else {
return $obj;
}
}
//print("\nparsing {$chrs}\n");
$strlen_chrs = strlen($chrs);
for ($c = 0; $c <= $strlen_chrs; ++$c) {
$top = end($stk);
$substr_chrs_c_2 = substr($chrs, $c, 2);
if (($c == $strlen_chrs) || (($chrs{$c} == ',') && ($top['what'] == SERVICES_JSON_SLICE))) {
// found a comma that is not inside a string, array, etc.,
// OR we've reached the end of the character list
$slice = substr($chrs, $top['where'], ($c - $top['where']));
array_push($stk, array('what' => SERVICES_JSON_SLICE, 'where' => ($c + 1), 'delim' => false));
//print("Found split at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
if (reset($stk) == SERVICES_JSON_IN_ARR) {
// we are in an array, so just push an element onto the stack
array_push($arr, $this->decode($slice));
} elseif (reset($stk) == SERVICES_JSON_IN_OBJ) {
// we are in an object, so figure
// out the property name and set an
// element in an associative array,
// for now
$parts = array();
if (preg_match('/^\s*(["\'].*[^\\\]["\'])\s*:\s*(\S.*),?$/Uis', $slice, $parts)) {
// "name":value pair
$key = $this->decode($parts[1]);
$val = $this->decode($parts[2]);
if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
$obj[$key] = $val;
} else {
$obj->$key = $val;
}
} elseif (preg_match('/^\s*(\w+)\s*:\s*(\S.*),?$/Uis', $slice, $parts)) {
// name:value pair, where name is unquoted
$key = $parts[1];
$val = $this->decode($parts[2]);
if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
$obj[$key] = $val;
} else {
$obj->$key = $val;
}
}
}
} elseif ((($chrs{$c} == '"') || ($chrs{$c} == "'")) && ($top['what'] != SERVICES_JSON_IN_STR)) {
// found a quote, and we are not inside a string
array_push($stk, array('what' => SERVICES_JSON_IN_STR, 'where' => $c, 'delim' => $chrs{$c}));
//print("Found start of string at {$c}\n");
} elseif (($chrs{$c} == $top['delim']) &&
($top['what'] == SERVICES_JSON_IN_STR) &&
((strlen(substr($chrs, 0, $c)) - strlen(rtrim(substr($chrs, 0, $c), '\\'))) % 2 != 1)) {
// found a quote, we're in a string, and it's not escaped
// we know that it's not escaped becase there is _not_ an
// odd number of backslashes at the end of the string so far
array_pop($stk);
//print("Found end of string at {$c}: ".substr($chrs, $top['where'], (1 + 1 + $c - $top['where']))."\n");
} elseif (($chrs{$c} == '[') &&
in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
// found a left-bracket, and we are in an array, object, or slice
array_push($stk, array('what' => SERVICES_JSON_IN_ARR, 'where' => $c, 'delim' => false));
//print("Found start of array at {$c}\n");
} elseif (($chrs{$c} == ']') && ($top['what'] == SERVICES_JSON_IN_ARR)) {
// found a right-bracket, and we're in an array
array_pop($stk);
//print("Found end of array at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
} elseif (($chrs{$c} == '{') &&
in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
// found a left-brace, and we are in an array, object, or slice
array_push($stk, array('what' => SERVICES_JSON_IN_OBJ, 'where' => $c, 'delim' => false));
//print("Found start of object at {$c}\n");
} elseif (($chrs{$c} == '}') && ($top['what'] == SERVICES_JSON_IN_OBJ)) {
// found a right-brace, and we're in an object
array_pop($stk);
//print("Found end of object at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
} elseif (($substr_chrs_c_2 == '/*') &&
in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
// found a comment start, and we are in an array, object, or slice
array_push($stk, array('what' => SERVICES_JSON_IN_CMT, 'where' => $c, 'delim' => false));
$c++;
//print("Found start of comment at {$c}\n");
} elseif (($substr_chrs_c_2 == '*/') && ($top['what'] == SERVICES_JSON_IN_CMT)) {
// found a comment end, and we're in one now
array_pop($stk);
$c++;
for ($i = $top['where']; $i <= $c; ++$i)
$chrs = substr_replace($chrs, ' ', $i, 1);
//print("Found end of comment at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
}
}
if (reset($stk) == SERVICES_JSON_IN_ARR) {
return $arr;
} elseif (reset($stk) == SERVICES_JSON_IN_OBJ) {
return $obj;
}
}
}
}
/**
* @todo Ultimately, this should just call PEAR::isError()
*/
function isError($data, $code = null)
{
if (class_exists('pear')) {
return PEAR::isError($data, $code);
} elseif (is_object($data) && (get_class($data) == 'services_json_error' ||
is_subclass_of($data, 'services_json_error'))) {
return true;
}
return false;
}
}
if (class_exists('PEAR_Error')) {
class Services_JSON_Error extends PEAR_Error
{
function Services_JSON_Error($message = 'unknown error', $code = null,
$mode = null, $options = null, $userinfo = null)
{
parent::PEAR_Error($message, $code, $mode, $options, $userinfo);
}
}
} else {
/**
* @todo Ultimately, this class shall be descended from PEAR_Error
*/
class Services_JSON_Error
{
function Services_JSON_Error($message = 'unknown error', $code = null,
$mode = null, $options = null, $userinfo = null)
{
}
}
}
?>

View File

@ -0,0 +1,30 @@
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2015-11-05
* Time: 오후 2:59
*/
if (!function_exists('json_decode')) {
function json_decode($content, $assoc=false) {
require_once 'JSON.php';
if ($assoc) {
$json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
}
else {
$json = new Services_JSON;
}
return $json->decode($content);
}
}
if (!function_exists('json_encode')) {
function json_encode($content) {
require_once 'JSON.php';
$json = new Services_JSON;
return $json->encode($content);
}
}
?>

View File

@ -0,0 +1,414 @@
<?php
/*
* Transparent SHA-256 Implementation for PHP 4 and PHP 5
*
* Author: Perry McGee (pmcgee@nanolink.ca)
* Website: http://www.nanolink.ca/pub/sha256
*
* Copyright (C) 2006,2007,2008,2009 Nanolink Solutions
*
* Created: Feb 11, 2006
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* or see <http://www.gnu.org/licenses/>.
*
* Include:
*
* require_once("[path/]sha256.inc.php");
*
* Usage Options:
*
* 1) $shaStr = hash('sha256', $string_to_hash);
*
* 2) $shaStr = sha256($string_to_hash[, bool ignore_php5_hash = false]);
*
* 3) $obj = new nanoSha2([bool $upper_case_output = false]);
* $shaStr = $obj->hash($string_to_hash[, bool $ignore_php5_hash = false]);
*
* Reference: http://csrc.nist.gov/groups/ST/toolkit/secure_hashing.html
*
* 2007-12-13: Cleaned up for initial public release
* 2008-05-10: Moved all helper functions into a class. API access unchanged.
* 2009-06-23: Created abstraction of hash() routine
* 2009-07-23: Added detection of 32 vs 64bit platform, and patches.
* Ability to define "_NANO_SHA2_UPPER" to yeild upper case hashes.
* 2009-08-01: Added ability to attempt to use mhash() prior to running pure
* php code.
*
* NOTE: Some sporadic versions of PHP do not handle integer overflows the
* same as the majority of builds. If you get hash results of:
* 7fffffff7fffffff7fffffff7fffffff7fffffff7fffffff7fffffff7fffffff
*
* If you do not have permissions to change PHP versions (if you did
* you'd probably upgrade to PHP 5 anyway) it is advised you install a
* module that will allow you to use their hashing routines, examples are:
* - mhash module : http://ca3.php.net/mhash
* - Suhosin : http://www.hardened-php.net/suhosin/
*
* If you install the Suhosin module, this script will transparently
* use their routine and define the PHP routine as _nano_sha256().
*
* If the mhash module is present, and $ignore_php5_hash = false the
* script will attempt to use the output from mhash prior to running
* the PHP code.
*/
if (!class_exists('nanoSha2'))
{
class nanoSha2
{
// php 4 - 5 compatable class properties
var $toUpper;
var $platform;
// Php 4 - 6 compatable constructor
function nanoSha2($toUpper = false) {
// Determine if the caller wants upper case or not.
$this->toUpper = is_bool($toUpper)
? $toUpper
: ((defined('_NANO_SHA2_UPPER')) ? true : false);
// Deteremine if the system is 32 or 64 bit.
$tmpInt = (int)4294967295;
$this->platform = ($tmpInt > 0) ? 64 : 32;
}
// Do the SHA-256 Padding routine (make input a multiple of 512 bits)
function char_pad($str)
{
$tmpStr = $str;
$l = strlen($tmpStr)*8; // # of bits from input string
$tmpStr .= "\x80"; // append the "1" bit followed by 7 0's
$k = (512 - (($l + 8 + 64) % 512)) / 8; // # of 0 bytes to append
$k += 4; // PHP Strings will never exceed (2^31)-1, 1st 32bits of
// the 64-bit value representing $l can be all 0's
for ($x = 0; $x < $k; $x++) {
$tmpStr .= "\0";
}
// append the 32-bits representing # of bits from input string ($l)
$tmpStr .= chr((($l>>24) & 0xFF));
$tmpStr .= chr((($l>>16) & 0xFF));
$tmpStr .= chr((($l>>8) & 0xFF));
$tmpStr .= chr(($l & 0xFF));
return $tmpStr;
}
// Here are the bitwise and functions as defined in FIPS180-2 Standard
function addmod2n($x, $y, $n = 4294967296) // Z = (X + Y) mod 2^32
{
$mask = 0x80000000;
if ($x < 0) {
$x &= 0x7FFFFFFF;
$x = (float)$x + $mask;
}
if ($y < 0) {
$y &= 0x7FFFFFFF;
$y = (float)$y + $mask;
}
$r = $x + $y;
if ($r >= $n) {
while ($r >= $n) {
$r -= $n;
}
}
return (int)$r;
}
// Logical bitwise right shift (PHP default is arithmetic shift)
function SHR($x, $n) // x >> n
{
if ($n >= 32) { // impose some limits to keep it 32-bit
return (int)0;
}
if ($n <= 0) {
return (int)$x;
}
$mask = 0x40000000;
if ($x < 0) {
$x &= 0x7FFFFFFF;
$mask = $mask >> ($n-1);
return ($x >> $n) | $mask;
}
return (int)$x >> (int)$n;
}
function ROTR($x, $n) { return (int)(($this->SHR($x, $n) | ($x << (32-$n)) & 0xFFFFFFFF)); }
function Ch($x, $y, $z) { return ($x & $y) ^ ((~$x) & $z); }
function Maj($x, $y, $z) { return ($x & $y) ^ ($x & $z) ^ ($y & $z); }
function Sigma0($x) { return (int) ($this->ROTR($x, 2)^$this->ROTR($x, 13)^$this->ROTR($x, 22)); }
function Sigma1($x) { return (int) ($this->ROTR($x, 6)^$this->ROTR($x, 11)^$this->ROTR($x, 25)); }
function sigma_0($x) { return (int) ($this->ROTR($x, 7)^$this->ROTR($x, 18)^$this->SHR($x, 3)); }
function sigma_1($x) { return (int) ($this->ROTR($x, 17)^$this->ROTR($x, 19)^$this->SHR($x, 10)); }
/*
* Custom functions to provide PHP support
*/
// split a byte-string into integer array values
function int_split($input)
{
$l = strlen($input);
if ($l <= 0) {
return (int)0;
}
if (($l % 4) != 0) { // invalid input
return false;
}
for ($i = 0; $i < $l; $i += 4)
{
$int_build = (ord($input[$i]) << 24);
$int_build += (ord($input[$i+1]) << 16);
$int_build += (ord($input[$i+2]) << 8);
$int_build += (ord($input[$i+3]));
$result[] = $int_build;
}
return $result;
}
/**
* Process and return the hash.
*
* @param $str Input string to hash
* @param $ig_func Option param to ignore checking for php > 5.1.2
* @return string Hexadecimal representation of the message digest
*/
function hash($str, $ig_func = false)
{
unset($binStr); // binary representation of input string
unset($hexStr); // 256-bit message digest in readable hex format
// check for php's internal sha256 function, ignore if ig_func==true
if ($ig_func == false) {
if (version_compare(PHP_VERSION,'5.1.2','>=')) {
return hash("sha256", $str, false);
} else if (function_exists('mhash') && defined('MHASH_SHA256')) {
return base64_encode(bin2hex(mhash(MHASH_SHA256, $str)));
}
}
/*
* SHA-256 Constants
* Sequence of sixty-four constant 32-bit words representing the
* first thirty-two bits of the fractional parts of the cube roots
* of the first sixtyfour prime numbers.
*/
$K = array((int)0x428a2f98, (int)0x71374491, (int)0xb5c0fbcf,
(int)0xe9b5dba5, (int)0x3956c25b, (int)0x59f111f1,
(int)0x923f82a4, (int)0xab1c5ed5, (int)0xd807aa98,
(int)0x12835b01, (int)0x243185be, (int)0x550c7dc3,
(int)0x72be5d74, (int)0x80deb1fe, (int)0x9bdc06a7,
(int)0xc19bf174, (int)0xe49b69c1, (int)0xefbe4786,
(int)0x0fc19dc6, (int)0x240ca1cc, (int)0x2de92c6f,
(int)0x4a7484aa, (int)0x5cb0a9dc, (int)0x76f988da,
(int)0x983e5152, (int)0xa831c66d, (int)0xb00327c8,
(int)0xbf597fc7, (int)0xc6e00bf3, (int)0xd5a79147,
(int)0x06ca6351, (int)0x14292967, (int)0x27b70a85,
(int)0x2e1b2138, (int)0x4d2c6dfc, (int)0x53380d13,
(int)0x650a7354, (int)0x766a0abb, (int)0x81c2c92e,
(int)0x92722c85, (int)0xa2bfe8a1, (int)0xa81a664b,
(int)0xc24b8b70, (int)0xc76c51a3, (int)0xd192e819,
(int)0xd6990624, (int)0xf40e3585, (int)0x106aa070,
(int)0x19a4c116, (int)0x1e376c08, (int)0x2748774c,
(int)0x34b0bcb5, (int)0x391c0cb3, (int)0x4ed8aa4a,
(int)0x5b9cca4f, (int)0x682e6ff3, (int)0x748f82ee,
(int)0x78a5636f, (int)0x84c87814, (int)0x8cc70208,
(int)0x90befffa, (int)0xa4506ceb, (int)0xbef9a3f7,
(int)0xc67178f2);
// Pre-processing: Padding the string
$binStr = $this->char_pad($str);
// Parsing the Padded Message (Break into N 512-bit blocks)
$M = str_split($binStr, 64);
// Set the initial hash values
$h[0] = (int)0x6a09e667;
$h[1] = (int)0xbb67ae85;
$h[2] = (int)0x3c6ef372;
$h[3] = (int)0xa54ff53a;
$h[4] = (int)0x510e527f;
$h[5] = (int)0x9b05688c;
$h[6] = (int)0x1f83d9ab;
$h[7] = (int)0x5be0cd19;
// loop through message blocks and compute hash. ( For i=1 to N : )
$N = count($M);
for ($i = 0; $i < $N; $i++)
{
// Break input block into 16 32bit words (message schedule prep)
$MI = $this->int_split($M[$i]);
// Initialize working variables
$_a = (int)$h[0];
$_b = (int)$h[1];
$_c = (int)$h[2];
$_d = (int)$h[3];
$_e = (int)$h[4];
$_f = (int)$h[5];
$_g = (int)$h[6];
$_h = (int)$h[7];
unset($_s0);
unset($_s1);
unset($_T1);
unset($_T2);
$W = array();
// Compute the hash and update
for ($t = 0; $t < 16; $t++)
{
// Prepare the first 16 message schedule values as we loop
$W[$t] = $MI[$t];
// Compute hash
$_T1 = $this->addmod2n($this->addmod2n($this->addmod2n($this->addmod2n($_h, $this->Sigma1($_e)), $this->Ch($_e, $_f, $_g)), $K[$t]), $W[$t]);
$_T2 = $this->addmod2n($this->Sigma0($_a), $this->Maj($_a, $_b, $_c));
// Update working variables
$_h = $_g; $_g = $_f; $_f = $_e; $_e = $this->addmod2n($_d, $_T1);
$_d = $_c; $_c = $_b; $_b = $_a; $_a = $this->addmod2n($_T1, $_T2);
}
for (; $t < 64; $t++)
{
// Continue building the message schedule as we loop
$_s0 = $W[($t+1)&0x0F];
$_s0 = $this->sigma_0($_s0);
$_s1 = $W[($t+14)&0x0F];
$_s1 = $this->sigma_1($_s1);
$W[$t&0xF] = $this->addmod2n($this->addmod2n($this->addmod2n($W[$t&0xF], $_s0), $_s1), $W[($t+9)&0x0F]);
// Compute hash
$_T1 = $this->addmod2n($this->addmod2n($this->addmod2n($this->addmod2n($_h, $this->Sigma1($_e)), $this->Ch($_e, $_f, $_g)), $K[$t]), $W[$t&0xF]);
$_T2 = $this->addmod2n($this->Sigma0($_a), $this->Maj($_a, $_b, $_c));
// Update working variables
$_h = $_g; $_g = $_f; $_f = $_e; $_e = $this->addmod2n($_d, $_T1);
$_d = $_c; $_c = $_b; $_b = $_a; $_a = $this->addmod2n($_T1, $_T2);
}
$h[0] = $this->addmod2n($h[0], $_a);
$h[1] = $this->addmod2n($h[1], $_b);
$h[2] = $this->addmod2n($h[2], $_c);
$h[3] = $this->addmod2n($h[3], $_d);
$h[4] = $this->addmod2n($h[4], $_e);
$h[5] = $this->addmod2n($h[5], $_f);
$h[6] = $this->addmod2n($h[6], $_g);
$h[7] = $this->addmod2n($h[7], $_h);
}
// Convert the 32-bit words into human readable hexadecimal format.
$hexStr = sprintf("%08x%08x%08x%08x%08x%08x%08x%08x", $h[0], $h[1], $h[2], $h[3], $h[4], $h[5], $h[6], $h[7]);
return ($this->toUpper) ? strtoupper($hexStr) : $hexStr;
}
}
}
if (!function_exists('str_split'))
{
/**
* Splits a string into an array of strings with specified length.
* Compatability with older verions of PHP
*/
function str_split($string, $split_length = 1)
{
$sign = ($split_length < 0) ? -1 : 1;
$strlen = strlen($string);
$split_length = abs($split_length);
if (($split_length == 0) || ($strlen == 0)) {
$result = false;
} elseif ($split_length >= $strlen) {
$result[] = $string;
} else {
$length = $split_length;
for ($i = 0; $i < $strlen; $i++)
{
$i = (($sign < 0) ? $i + $length : $i);
$result[] = substr($string, $sign*$i, $length);
$i--;
$i = (($sign < 0) ? $i : $i + $length);
$length = (($i + $split_length) > $strlen)
? ($strlen - ($i + 1))
: $split_length;
}
}
return $result;
}
}
/**
* Main routine called from an application using this include.
*
* General usage:
* require_once('sha256.inc.php');
* $hashstr = sha256('abc');
*
* Note:
* PHP Strings are limitd to (2^31)-1, so it is not worth it to
* check for input strings > 2^64 as the FIPS180-2 defines.
*/
// 2009-07-23: Added check for function as the Suhosin plugin adds this routine.
if (!function_exists('sha256')) {
function sha256($str, $ig_func = false) {
$obj = new nanoSha2((defined('_NANO_SHA2_UPPER')) ? true : false);
return $obj->hash($str, $ig_func);
}
} else {
function _nano_sha256($str, $ig_func = false) {
$obj = new nanoSha2((defined('_NANO_SHA2_UPPER')) ? true : false);
return $obj->hash($str, $ig_func);
}
}
// support to give php4 the hash() routine which abstracts this code.
if (!function_exists('hash'))
{
function hash($algo, $data)
{
if (empty($algo) || !is_string($algo) || !is_string($data)) {
return false;
}
if (function_exists($algo)) {
return $algo($data);
}
}
}
?>