키움결제 테스트
This commit is contained in:
@@ -32,6 +32,7 @@ import org.bouncycastle.openssl.jcajce.JceOpenSSLPKCS8DecryptorProviderBuilder;
|
||||
import org.bouncycastle.operator.InputDecryptorProvider;
|
||||
import org.bouncycastle.pkcs.PKCS8EncryptedPrivateKeyInfo;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.JSONValue;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -1468,10 +1469,94 @@ public class BOPayService{
|
||||
}
|
||||
|
||||
|
||||
/* ============================================================================== */
|
||||
/* = 여기서 부터 Kiwoom
|
||||
/* = -------------------------------------------------------------------------- = */
|
||||
|
||||
/**
|
||||
* Kiwoom 결제
|
||||
* @param BOPayVO
|
||||
*/
|
||||
public Map<String, Object> insertKiwoomPay(BOPayVO payVO) throws Exception {
|
||||
|
||||
//관련 키값 DB 조회
|
||||
/*DataMap resultMap = selectPayLink(payVO.getSopmalCd());
|
||||
String reSetleAmt = StringUtil.isNullToString(selectRlSetleAmt(payVO.getSopmalCd(),payVO.getOrderId()));
|
||||
reSetleAmt = reSetleAmt.isEmpty()? "10" : reSetleAmt; //0원은 정상거래로 인정되어서 10원으로 지정함*/
|
||||
|
||||
log.info("insertKiwoomPay step1 ");
|
||||
|
||||
String cpId = f_get_parm( payVO.getCpId());
|
||||
String payMethod = f_get_parm( payVO.getPayMethod());
|
||||
String orderNo = f_get_parm( payVO.getOrderId());
|
||||
String type = f_get_parm( payVO.getType());
|
||||
String amount = f_get_parm( payVO.getAmount());
|
||||
|
||||
JSONObject jsonObj = new JSONObject();
|
||||
jsonObj.put("CPID", cpId);
|
||||
jsonObj.put("PAYMETHOD", payMethod);
|
||||
jsonObj.put("ORDERNO", orderNo);
|
||||
jsonObj.put("TYPE", type);
|
||||
jsonObj.put("AMOUNT", amount);
|
||||
|
||||
log.info("insertKiwoomPay step2 ::: {}", jsonObj);
|
||||
|
||||
|
||||
//결제등록 요청시 실결제값(good_mny)
|
||||
/*String payType = getPayMethod(payVO.getPayMethod());
|
||||
jsonReq.put("ordr_mony", reSetleAmt); // ** 결제금액 유효성 검증 **
|
||||
jsonReq.put("pay_type", payType); // ** 결제수단 유효성 검증 **
|
||||
jsonReq.put("ordr_no", payVO.getOrderId()); // ** 주문번호검증 **
|
||||
*/
|
||||
|
||||
String kiwoom_ENC = "";
|
||||
try {
|
||||
String url = "https://apitest.kiwoompay.co.kr/pay/hash";
|
||||
URL goUrl = new URL(url);
|
||||
|
||||
HttpURLConnection con = (HttpURLConnection) goUrl.openConnection();
|
||||
con.setRequestMethod("POST");
|
||||
con.setRequestProperty("Content-Type", "application/json");
|
||||
con.setUseCaches(false);
|
||||
con.setDoOutput(true);
|
||||
con.setDoInput(true);
|
||||
|
||||
OutputStream os = con.getOutputStream();
|
||||
os.write((jsonObj.toString()).getBytes("euc-kr"));
|
||||
os.flush();
|
||||
os.close();
|
||||
|
||||
int responseCode = con.getResponseCode();
|
||||
|
||||
if (responseCode == 200) {
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
|
||||
String inputLine;
|
||||
StringBuffer response1 = new StringBuffer();
|
||||
|
||||
while ((inputLine = in.readLine()) != null) {
|
||||
response1.append(inputLine);
|
||||
}
|
||||
in.close();
|
||||
|
||||
JSONObject jObj = (JSONObject) JSONValue.parse(response1.toString());
|
||||
kiwoom_ENC = (String) jObj.get("KIWOOM_ENC");
|
||||
|
||||
log.info("insertKiwoomPay step3 ::: {}", jObj);
|
||||
}
|
||||
con.disconnect();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
JSONObject resultObj = new JSONObject();
|
||||
resultObj.put("KIWOOM_ENC", kiwoom_ENC);
|
||||
|
||||
log.info("insertKiwoomPay step4 ::: {}", resultObj.get("KIWOOM_ENC"));
|
||||
|
||||
return new HashMap<>() {{
|
||||
put("response", resultObj.toString());
|
||||
}};
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -292,6 +292,9 @@ public class BOPayVO extends AbstractVO {
|
||||
/** 테스트 여부 - 테스트용 */
|
||||
private String testAt;
|
||||
|
||||
/** 키움 - 상점ID */
|
||||
private String cpId;
|
||||
|
||||
|
||||
// cookie
|
||||
/** 에이전트 ID */
|
||||
|
||||
@@ -22,9 +22,7 @@ import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.wb.domainserver.domain.sopmal.ordr.vo.PayVO;
|
||||
@@ -630,4 +628,164 @@ public class PayController {
|
||||
return message;
|
||||
}
|
||||
|
||||
|
||||
/* *********************************************
|
||||
* 키움결제
|
||||
********************************************* */
|
||||
|
||||
/**
|
||||
* 키움 결제 화면
|
||||
* @return PayKiwoomSucsC.jsp
|
||||
* @author 이경숙
|
||||
*/
|
||||
@Policy(AuthPolicy.RESTRICTED)
|
||||
@RequestMapping(value="/selectKiwoomSimple")
|
||||
public String selectKiwoonPay(ModelMap model) throws Exception {
|
||||
log.debug("selectKiwoonPay = {}");
|
||||
return "sopmal/ordr/PayKiwoomPayC";
|
||||
}
|
||||
|
||||
@Policy(AuthPolicy.RESTRICTED)
|
||||
@RequestMapping(value="/selectKiwoomSimple2")
|
||||
public String selectKiwoonPay2(ModelMap model) throws Exception {
|
||||
log.debug("selectKiwoonPay = {}");
|
||||
return "sopmal/ordr/PayKiwoomPay2C";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 키움 결제 연계 전 getEnc 값 받아오기
|
||||
* @return PayKiwoomSucsC.jsp
|
||||
* @author 이경숙
|
||||
*/
|
||||
@Policy(AuthPolicy.RESTRICTED)
|
||||
@ResponseBody
|
||||
@RequestMapping(value="/kiwoomPayGetEnc")
|
||||
public Map<String, Object> selectKiwoomGetEnc(HttpServletRequest request) throws Exception {
|
||||
|
||||
BOPayVO payVO = new BOPayVO();
|
||||
|
||||
log.debug("kiwoomPayGetEnc = {}");
|
||||
|
||||
payVO.setCpId(request.getParameter("CPID"));
|
||||
payVO.setPayMethod(request.getParameter("PAYMETHOD"));
|
||||
payVO.setOrderId(request.getParameter("ORDERNO"));
|
||||
payVO.setType(request.getParameter("TYPE"));
|
||||
payVO.setAmount(request.getParameter("AMOUNT"));
|
||||
|
||||
Map<String, Object> message;
|
||||
String sopmalCd = payVO.getSopmalCd();
|
||||
try {
|
||||
message = service.insertKiwoomPay(payVO);
|
||||
|
||||
} catch (Exception e) {
|
||||
message = new HashMap<>() {{
|
||||
put("response", "결제를 실패하였습니다.\n관리자에게 문의하시기 바랍니다.");
|
||||
}};
|
||||
}
|
||||
|
||||
|
||||
log.info("insertKiwoomPay step5 ::: {}", message.get("KIWOOM_ENC"));
|
||||
|
||||
//model.addAttribute("message", message);
|
||||
//return "sopmal/ordr/PayKiwoomSucsC";
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 키움 결제 연계처리 - 결과통보페이지
|
||||
* @return PayKiwoomSucsC.jsp
|
||||
* @author 이경숙
|
||||
*/
|
||||
@Policy(AuthPolicy.RESTRICTED)
|
||||
@RequestMapping(value="/kiwoomPayWebhook")
|
||||
@ResponseBody
|
||||
public ResponseEntity<String> selectPaymentkiwoomWebhook(HttpServletRequest request) throws Exception {
|
||||
|
||||
String resultCode = request.getParameter("RESULTCODE");
|
||||
String orderNo = request.getParameter("ORDERNO");
|
||||
String amount = request.getParameter("AMOUNT");
|
||||
|
||||
System.out.println("콜백 수신");
|
||||
System.out.println("RESULTCODE = " + resultCode);
|
||||
System.out.println("ORDERNO = " + orderNo);
|
||||
System.out.println("AMOUNT = " + amount);
|
||||
|
||||
/* 실제 처리해야 되는 부분
|
||||
// 1. 주문 조회
|
||||
Order order = orderService.find(orderNo);
|
||||
|
||||
// 2. 중복 방지
|
||||
if ("PAID".equals(order.getStatus())) return "OK";
|
||||
|
||||
// 3. 금액 검증
|
||||
if (!order.getAmount().equals(Integer.parseInt(amount))) {
|
||||
order.setStatus("FAIL");
|
||||
return "OK";
|
||||
}
|
||||
|
||||
// 4. 성공 처리
|
||||
if ("0000".equals(resultCode)) {
|
||||
order.setStatus("PAID");
|
||||
} else {
|
||||
order.setStatus("FAIL");
|
||||
}
|
||||
|
||||
orderService.save(order);
|
||||
*/
|
||||
String response = "<html><body><RESULT>SUCCESS</RESULT></body></html>";
|
||||
|
||||
return ResponseEntity.ok()
|
||||
.contentType(MediaType.TEXT_HTML)
|
||||
.body(response);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 키움 결제 연계처리 - 성공결과페이지
|
||||
* @return PayKiwoomSucsC.jsp
|
||||
* @author 이경숙
|
||||
*/
|
||||
@Policy(AuthPolicy.RESTRICTED)
|
||||
@RequestMapping(value="/kiwoomPaySuccss")
|
||||
public String confirmPaymentkiwoom(HttpServletRequest request, ModelMap model) throws Exception {
|
||||
|
||||
BOPayVO payVO = new BOPayVO();
|
||||
|
||||
payVO.setCode(request.getParameter("RESULTCODE"));
|
||||
payVO.setOrderId(request.getParameter("ORDERNO"));
|
||||
payVO.setAmount(request.getParameter("AMOUNT"));
|
||||
payVO.setPayMethod(request.getParameter("PAYMETHOD"));
|
||||
|
||||
Map<String, Object> message = new HashMap<>();
|
||||
/*String sopmalCd = payVO.getSopmalCd();
|
||||
try {
|
||||
message = service.insertKcpPay(payVO);
|
||||
|
||||
} catch (Exception e) {
|
||||
message = new HashMap<>() {{
|
||||
put("response", "결제를 실패하였습니다.\n관리자에게 문의하시기 바랍니다.");
|
||||
}};
|
||||
}*/
|
||||
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("code", payVO.getCode());
|
||||
jsonObject.put("orderId", payVO.getOrderId());
|
||||
jsonObject.put("amount", payVO.getAmount());
|
||||
jsonObject.put("payMethod", payVO.getPayMethod());
|
||||
message.put("response",jsonObject.toString());
|
||||
|
||||
model.addAttribute("message", message);
|
||||
// responseHandler.handleResponse(
|
||||
// sendToResrc.ofPost(RESRC.GCONEBO, "/gcone/ordr/pay/kcpPayProc", payVO),
|
||||
// model,
|
||||
// "message"
|
||||
// );
|
||||
|
||||
return "sopmal/ordr/PayKiwoomSucsC";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user