/** * Adds static header(s) to the HTTP request headers * * @param HttpClient $request HTTP channel object. * * @return \HTTP_Request2 */ public function handleRequest($request) { foreach ($this->_headers as $key => $value) { $headers = $request->getHeaders(); if (!array_key_exists($key, $headers)) { $request->setHeader($key, $value); } } return $request; }
/** * Adds authentication header to the request headers. * * @param HttpClient $request HTTP channel object. * * @return \HTTP_Request2 */ public function handleRequest($request) { $signedKey = $this->_sharedKeyAuthentication->getAuthorizationHeader($request->getHeaders(), $request->getUrl(), $request->getUrl()->getQueryVariables(), $request->getMethod()); $request->setHeader(Resources::AUTHENTICATION, $signedKey); return $request; }
/** * parse the response of an access token request and store it in dataStore * * @param \OAuth2\HttpClient $http * @param string $oldRefreshToken * @return \OAuth2\Token */ private function _parseAccessTokenResponse(HttpClient $http, $oldRefreshToken = null) { $headers = $http->getHeaders(); $type = 'text'; if (isset($headers['Content-Type']) && strpos($headers['Content-Type'], 'application/json') !== false) { $type = 'json'; } switch ($type) { case 'json': $response = json_decode($http->getResponse(), true); break; case 'text': default: $response = HttpClient::parseStringToArray($http->getResponse(), '&', '='); break; } if (isset($response['error'])) { throw new Exception('got error while requesting access token: ' . $response['error']); } if (!isset($response['access_token'])) { throw new Exception('no access_token found'); } $token = new Token($response['access_token'], isset($response['refresh_token']) ? $response['refresh_token'] : $oldRefreshToken, isset($response['expires_in']) ? $response['expires_in'] : null); unset($response['access_token']); unset($response['refresh_token']); unset($response['expires_in']); // add additional parameters which may be returned depending on service and scope foreach ($response as $key => $value) { $token->{'set' . $key}($value); } $this->_dataStore->storeAccessToken($token); return $token; }
function startAction() { if (trim($this->m_ActionType) == "") { $this->MakeErrorMsg(ERR_WRONG_ACTIONTYPE, "actionType 설정이 잘못되었습니다."); return; } $NICELog = new NICELog($this->m_log, $this->m_debug, $this->m_ActionType); if (!$NICELog->StartLog($this->m_NicepayHome, $this->m_MID)) { $this->MakeErrorMsg(ERR_OPENLOG, "로그파일을 열수가 없습니다."); return; } // 취소인 경우, if (trim($this->m_ActionType) == "CLO") { if (trim($this->m_TID) == "") { $this->MakeErrorMsg(ERR_WRONG_PARAMETER, "요청페이지 파라메터가 잘못되었습니다. [TID]"); return; } else { if (trim($this->m_CancelAmt) == "") { $this->MakeErrorMsg(ERROR_WRONG_PARAMETER, "요청페이지 파라메터가 잘못되었습니다. [CancelAmt]"); return; } else { if (trim($this->m_CancelMsg) == "") { $this->MakeErrorMsg(ERROR_WRONG_PARAMETER, "요청페이지 파라메터가 잘못되었습니다. [CancelMsg]"); return; } } } $this->m_uri = "/lite/cancelProcess.jsp"; unset($this->m_queryString); $this->m_queryString = $_POST; $this->m_queryString["MID"] = substr($this->m_TID, 0, 10); $this->m_queryString["TID"] = $this->m_TID; $this->m_queryString["CancelAmt"] = $this->m_CancelAmt; $this->m_queryString["CancelMsg"] = $this->m_CancelMsg; $this->m_queryString["CancelPwd"] = $this->m_CancelPwd; $this->m_queryString["PartialCancelCode"] = $this->m_PartialCancelCode; $NICELog->WriteLog($this->m_queryString["TID"]); //입금 후 취소 } else { if (trim($this->m_ActionType) == "DPO") { if (trim($this->m_TID) == "") { $this->MakeErrorMsg(ERR_WRONG_PARAMETER, "요청페이지 파라메터가 잘못되었습니다. [TID]"); return; } else { if (trim($this->m_CancelAmt) == "") { $this->MakeErrorMsg(ERROR_WRONG_PARAMETER, "요청페이지 파라메터가 잘못되었습니다. [CancelAmt]"); return; } else { if (trim($this->m_CancelMsg) == "") { $this->MakeErrorMsg(ERROR_WRONG_PARAMETER, "요청페이지 파라메터가 잘못되었습니다. [CancelMsg]"); return; } } } $this->m_uri = "/lite/setOffProcess.jsp"; unset($this->m_queryString); $this->m_queryString["MID"] = substr($this->m_TID, 0, 10); $this->m_queryString["TID"] = $this->m_TID; $this->m_queryString["CancelAmt"] = $this->m_CancelAmt; $this->m_queryString["CancelMsg"] = $this->m_CancelMsg; $this->m_queryString["PartialCancelCode"] = $this->m_PartialCancelCode; $this->m_queryString["ExpDate"] = $this->m_ExpDate; $this->m_queryString["ReqName"] = $this->m_ReqName; $this->m_queryString["ReqTel"] = $this->m_ReqTel; $NICELog->WriteLog($this->m_queryString["TID"]); // 빌링 승인 } else { if (trim($this->m_ActionType) == "PYO" && trim($this->m_PayMethod) == "BILL") { $this->m_uri = "/lite/billingProcess.jsp"; unset($this->m_queryString); $this->m_queryString["BillKey"] = $this->m_BillKey; // new $this->m_queryString["BuyerName"] = $this->m_BuyerName; $this->m_queryString["Amt"] = $this->m_Amt; $this->m_queryString["MID"] = $this->m_MID; $this->m_TID = genTID($this->m_MID, "01", "16"); $this->m_queryString["TID"] = $this->m_TID; $this->m_queryString["EncodeKey"] = $this->m_LicenseKey; $this->m_queryString["MallIP"] = $_SERVER['SERVER_NAME']; $this->m_queryString["actionType"] = $this->m_ActionType; $this->m_queryString["PayMethod"] = $this->m_PayMethod; $this->m_queryString["Moid"] = $this->m_Moid; $this->m_queryString["GoodsName"] = $this->m_GoodsName; if ($this->m_charSet == "UTF8") { $this->m_queryString["BuyerName"] = iconv("UTF-8", "EUC-KR", $this->m_queryString["BuyerName"]); $this->m_queryString["GoodsName"] = iconv("UTF-8", "EUC-KR", $this->m_queryString["GoodsName"]); } $NICELog->WriteLog($this->m_queryString["TID"]); // 빌키 발급 } else { if (trim($this->m_ActionType) == "PYO" && trim($this->m_PayMethod) == "BILLKEY") { $this->m_uri = "/lite/billkeyProcess.jsp"; unset($this->m_queryString); $this->m_queryString["CardNo"] = $this->m_CardNo; // new $this->m_queryString["ExpYear"] = $this->m_ExpYear; $this->m_queryString["ExpMonth"] = $this->m_ExpMonth; $this->m_queryString["IDNo"] = $this->m_IDNo; $this->m_queryString["CardPw"] = $this->m_CardPw; $this->m_queryString["MID"] = $this->m_MID; $this->m_queryString["EncodeKey"] = $this->m_LicenseKey; $this->m_queryString["MallIP"] = $_SERVER['SERVER_NAME']; $this->m_queryString["actionType"] = $this->m_ActionType; $this->m_queryString["PayMethod"] = $this->m_PayMethod; // 지급 대행 서브몰 등록 } else { if (trim($this->m_ActionType) == "PYO" && trim($this->m_PayMethod) == "OM_SUB_INS") { $this->m_uri = "/lite/payproxy/subMallSetProcess.jsp"; unset($this->m_queryString); $this->m_queryString = $_POST; $this->m_queryString["EncodeKey"] = $this->m_LicenseKey; // 서브몰 이체 } else { if (trim($this->m_ActionType) == "PYO" && trim($this->m_PayMethod) == "OM_SUB_PAY") { $this->m_uri = "/lite/payproxy/subMallIcheProcess.jsp"; unset($this->m_queryString); $this->m_queryString = $_POST; $this->m_queryString["EncodeKey"] = $this->m_LicenseKey; // SMS } else { if (trim($this->m_ActionType) == "PYO" && trim($this->m_PayMethod) == "SMS_REQ") { $this->m_uri = "/api/sendSmsForETAX.jsp"; unset($this->m_queryString); $this->m_queryString = $_POST; $this->m_queryString["EncodeKey"] = $this->m_LicenseKey; // 현금영수증, } else { if (trim($this->m_ActionType) == "PYO" && trim($this->m_PayMethod) == "RECEIPT") { $this->m_uri = "/lite/cashReceiptProcess.jsp"; unset($this->m_queryString); $this->m_queryString["MID"] = $this->m_MID; $this->m_queryString["TID"] = $this->m_MID . "04" . "01" . SetTimestamp1(); $this->m_queryString["GoodsName"] = $this->m_GoodsName; $this->m_queryString["BuyerName"] = $this->m_BuyerName; $this->m_queryString["Amt"] = $this->m_Amt; $this->m_queryString["ReceiptAmt"] = $this->m_ReceiptAmt; $this->m_queryString["ReceiptSupplyAmt"] = $this->m_ReceiptSupplyAmt; $this->m_queryString["ReceiptVAT"] = $this->m_ReceiptVAT; $this->m_queryString["ReceiptServiceAmt"] = $this->m_ReceiptServiceAmt; $this->m_queryString["ReceiptType"] = $this->m_ReceiptType; $this->m_queryString["ReceiptTypeNo"] = $this->m_ReceiptTypeNo; $this->m_queryString["EncodeKey"] = $this->m_LicenseKey; $this->m_queryString["actionType"] = $this->m_ActionType; $this->m_queryString["PayMethod"] = $this->m_PayMethod; $this->m_queryString["CancelPwd"] = $this->m_CancelPwd; $this->m_queryString["CancelAmt"] = $this->m_Amt; $this->m_queryString["MallIP"] = $_SERVER['SERVER_NAME']; // 승인인 경우, } else { if (trim($this->m_ActionType) == "PYO" && trim($this->m_PayMethod) != "RECEIPT") { if (trim($_POST["MID"]) == "") { $this->MakeErrorMsg(ERROR_WRONG_PARAMETER, "요청페이지 파라메터가 잘못되었습니다. [MID]"); return; } else { if (trim($_POST["Amt"]) == "") { $this->MakeErrorMsg(ERROR_WRONG_PARAMETER, "요청페이지 파라메터가 잘못되었습니다. [Amt]"); return; } } $this->m_uri = "/lite/payProcess.jsp"; unset($this->m_queryString); $this->m_queryString = $_POST; $this->m_queryString["EncodeKey"] = $this->m_LicenseKey; $this->m_queryString["TID"] = ""; if ($this->m_charSet == "UTF8") { $this->m_queryString["BuyerName"] = iconv("UTF-8", "EUC-KR", $this->m_queryString["BuyerName"]); $this->m_queryString["GoodsName"] = iconv("UTF-8", "EUC-KR", $this->m_queryString["GoodsName"]); $this->m_queryString["BuyerAddr"] = iconv("UTF-8", "EUC-KR", $this->m_queryString["BuyerAddr"]); } } } } } } } } } } $httpclient = new HttpClient($this->m_ssl); //connect if (!$httpclient->HttpConnect($NICELog)) { $NICELog->WriteLog('Server Connect Error!!' . $httpclient->getErrorMsg()); $resultMsg = $httpclient->getErrorMsg() . "서버연결을 할 수가 없습니다."; if ($this->m_ssl == "true") { $resultMsg .= "<br>귀하의 서버는 SSL통신을 지원하지 않습니다. 결제처리파일에서 m_ssl=false로 셋팅하고 시도하세오."; $this->MakeErrorMsg(ERR_SSLCONN, $resultMsg); } else { $this->MakeErrorMsg(ERR_CONN, $resultMsg); } $NICELog->CloseNiceLog(""); return; } //request if (!$httpclient->HttpRequest($this->m_uri, $this->m_queryString, $NICELog)) { // 요청 오류시 처리 $NICELog->WriteLog('POST Error!!' . $httpclient->getErrorMsg()); $this->MakeErrorMsg(ERR_NO_RESPONSE, "서버 응답 오류"); //NET CANCEL Start--------------------------------- if ($httpclient->getErrorCode() == READ_TIMEOUT_ERR) { $NICELog->WriteLog("Net Cancel Start"); $this->m_uri = "/lite/cancelProcess.jsp"; unset($this->m_queryString); $this->m_queryString["MID"] = substr($this->m_TID, 0, 10); $this->m_queryString["TID"] = $this->m_TID; $this->m_queryString["CancelAmt"] = $this->m_NetCancelAmt; $this->m_queryString["CancelMsg"] = "NICE_NET_CANCEL"; $this->m_queryString["CancelPwd"] = $this->m_NetCancelPW; $this->m_queryString["NetCancelCode"] = "1"; $NICELog->WriteLog($this->m_queryString["TID"]); if (!$httpclient->HttpConnect($NICELog)) { $NICELog->WriteLog('Server Connect Error!!' . $httpclient->getErrorMsg()); $resultMsg = $httpclient->getErrorMsg() . "서버연결을 할 수가 없습니다."; $this->MakeErrorMsg(ERR_CONN, $resultMsg); $NICELog->CloseNiceLog($this->m_resultMsg); return; } if (!$httpclient->HttpRequest($this->m_uri, $this->m_queryString, $NICELog) && $httpclient->getErrorCode() == READ_TIMEOUT_ERR) { $NICELog->WriteLog("Net Cancel FAIL"); if ($this->m_ActionType == "PYO") { $this->MakeErrorMsg(ERR_NO_RESPONSE, "승인여부 확인요망"); } else { if ($this->m_ActionType == "CLO") { $this->MakeErrorMsg(ERR_NO_RESPONSE, "취소여부 확인요망"); } } } else { $NICELog->WriteLog("Net Cancel SUCESS"); } } //NET CANCEL End--------------------------------- $this->ParseMsg($httpclient->getBody(), $NICELog); $NICELog->CloseNiceLog($this->m_resultMsg); return; } if ($httpclient->getStatus() == "200") { $this->ParseMsg($httpclient->getBody(), $NICELog); $NICELog->WriteLog("TID -> " . "[" . $this->m_ResultData['TID'] . "]"); $NICELog->WriteLog($this->m_ResultData['ResultCode'] . "[" . $this->m_ResultData['ResultMsg'] . "]"); $NICELog->CloseNiceLog(""); } else { $NICELog->WriteLog('SERVER CONNECT FAIL:' . $httpclient->getStatus() . $httpclient->getErrorMsg() . $httpclient->getHeaders()); $resultMsg = $httpclient->getStatus() . "서버에러가 발생했습니다."; $this->MakeErrorMsg(ERR_NO_RESPONSE, $resultMsg); //NET CANCEL Start--------------------------------- if ($httpclient->getStatus() != 200) { $NICELog->WriteLog("Net Cancel Start"); //Set Field $this->m_uri = "/lite/cancelProcess.jsp"; unset($this->m_queryString); $this->m_queryString["MID"] = substr($this->m_TID, 0, 10); $this->m_queryString["TID"] = $this->m_TID; $this->m_queryString["CancelAmt"] = $this->m_NetCancelAmt; $this->m_queryString["CancelMsg"] = "NICE_NET_CANCEL"; $this->m_queryString["CancelPwd"] = $this->m_NetCancelPW; $this->m_queryString["NetCancelCode"] = "1"; if (!$httpclient->HttpConnect($NICELog)) { $NICELog->WriteLog('Server Connect Error!!' . $httpclient->getErrorMsg()); $resultMsg = $httpclient->getErrorMsg() . "서버연결을 할 수가 없습니다."; $this->MakeErrorMsg(ERR_CONN, $resultMsg); $NICELog->CloseNiceLog($this->m_resultMsg); return; } if (!$httpclient->HttpRequest($this->m_uri, $this->m_queryString, $NICELog)) { $NICELog->WriteLog("Net Cancel FAIL"); if ($this->m_ActionType == "PYO") { $this->MakeErrorMsg(ERR_NO_RESPONSE, "승인여부 확인요망"); } else { if ($this->m_ActionType == "CLO") { $this->MakeErrorMsg(ERR_NO_RESPONSE, "취소여부 확인요망"); } } } else { $NICELog->WriteLog("Net Cancel SUCESS"); } } //NET CANCEL End--------------------------------- $this->ParseMsg($httpclient->getBody(), $NICELog); $NICELog->CloseNiceLog(""); return; } }