You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

441 lines
17 KiB

1 year ago
  1. using Common.Model;
  2. using Common.Model.KftcSendMoney;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace Business.KFTCSendMoneyBussiness
  9. {
  10. public class KftcSendMoney : IKftcSendMoney
  11. {
  12. public DbResult DebitAccount(KftcSendMoneyRequest model)
  13. {
  14. DbResult _dbRes = new DbResult();
  15. DbResult _logResp = new DbResult();
  16. string customerId = model.CustomerId;
  17. string accessToken = model.AccessToken;
  18. string fintechUseNo = model.FintechUseNo;
  19. string cAmt = model.CollAmt;
  20. string accountName = model.AccountName;
  21. string customerBankCode = model.BankCode;
  22. string accountNum = model.AccountNum;
  23. string accHolderInfoType = model.AccHolderInfoType;
  24. string accHolderInfo = model.AccHolderInfo;
  25. if (string.IsNullOrWhiteSpace(customerId)
  26. || string.IsNullOrWhiteSpace(accessToken)
  27. || string.IsNullOrWhiteSpace(fintechUseNo)
  28. || string.IsNullOrWhiteSpace(cAmt)
  29. || string.IsNullOrWhiteSpace(accountName)
  30. || string.IsNullOrWhiteSpace(customerBankCode)
  31. || string.IsNullOrWhiteSpace(accountNum)
  32. || string.IsNullOrWhiteSpace(accHolderInfoType)
  33. || string.IsNullOrWhiteSpace(accHolderInfo))
  34. {
  35. _dbRes.ResponseCode = "999";
  36. _dbRes.Msg = "Oops! Something went wrong please re-login and try again.";
  37. return _dbRes;
  38. }
  39. cAmt = cAmt.Split('.')[0];
  40. _dbRes = CheckBankStatus(customerBankCode, customerId);
  41. if (_dbRes.ResponseCode != "A0000")
  42. {
  43. return _dbRes;
  44. }
  45. if (String.IsNullOrEmpty(accHolderInfoType) == true)
  46. {
  47. _dbRes.ResponseCode = "999";
  48. _dbRes.Msg = "[FAIL] Customer's real name number type is null ";
  49. return _dbRes;
  50. }
  51. if (String.IsNullOrEmpty(accHolderInfo) == true)
  52. {
  53. _dbRes.ResponseCode = "999";
  54. _dbRes.Msg = "[FAIL] Customer's real name number is null ";
  55. return _dbRes;
  56. }
  57. if (String.IsNullOrEmpty(accountNum) == true)
  58. {
  59. _dbRes.ResponseCode = "999";
  60. _dbRes.Msg = "[FAIL] Customer's real number is null ";
  61. return _dbRes;
  62. }
  63. var accountHolderInfoType = accHolderInfoType;
  64. var accountHolderInfo = accHolderInfo.Replace("-", "").Trim();
  65. _dbRes = CheckRealName(customerId, customerBankCode, accountNum, accountHolderInfoType, accountHolderInfo);
  66. /* 계좌실명조회가 실패하면... */
  67. if (_dbRes.ResponseCode != "A0000")
  68. {
  69. return _dbRes;
  70. }
  71. /*
  72. *
  73. *
  74. * */
  75. var req = new Common.KFTC.Request.withdraw();
  76. req.dps_print_content = accountName; //입금계좌내역
  77. req.fintech_use_num = fintechUseNo; //산업은행-1234567890
  78. req.tran_amt = cAmt; //거래금액
  79. req.tran_dtime = DateTime.Now.ToString("yyyyMMddHHmmss"); //요청일시
  80. string tranDtime = req.tran_dtime;
  81. //string tranDtime_1 = DateTime.Now.AddSeconds(-1).ToString("yyyyMMddHHmmss");
  82. string _URL = _utility.ReadWebConfig("TRANSFER_WITHDRAW", ""); //@"transfer/withdraw";
  83. var access_token = accessToken;
  84. //log request
  85. _logResp = _utility.LogRequestKFTC(customerId, "DebitAccount", "access_token :" + access_token + "req :" + JsonConvert.SerializeObject(req));
  86. KFTCPostGet kftcRequest = new KFTCPostGet();
  87. try
  88. {
  89. string postData = JsonConvert.SerializeObject(req);
  90. /*
  91. *
  92. * */
  93. var resp = kftcRequest.PostToKFTC(_URL, access_token, postData);
  94. /*
  95. * !!!
  96. * */
  97. if (string.IsNullOrEmpty(resp))
  98. {
  99. _dbRes.ResponseCode = "999";
  100. _dbRes.Msg = "FAILED TO KFTC OPEN-FLATFORM (TRANSFER/WITHDRAW)!";
  101. //log response
  102. _utility.LogResponseKFTC(_logResp.Id, resp, _dbRes.ResponseCode, _dbRes.Msg);
  103. return _dbRes;
  104. }
  105. var respObj = JsonConvert.DeserializeObject<Response.withdraw>(resp);
  106. //log response
  107. _utility.LogResponseKFTC(_logResp.Id, resp, respObj.rsp_code, (respObj.rsp_code == "A0000") ? "Success!" : respObj.rsp_message);
  108. if (respObj.rsp_code == "A0001")
  109. {
  110. Thread.Sleep(1 * 60 * 1000);
  111. /*
  112. * */
  113. respObj = transfer_result(ref respObj, customerId, "1");
  114. if (respObj.rsp_code == "A0001")
  115. {
  116. Thread.Sleep(2 * 60 * 1000);
  117. /*
  118. * */
  119. respObj = transfer_result(ref respObj, customerId, "2");
  120. if (respObj.rsp_code == "A0001")
  121. {
  122. _dbRes.ResponseCode = respObj.rsp_code;
  123. _dbRes.Msg = respObj.rsp_message;
  124. _dbRes.Id = respObj.api_tran_id;
  125. _dbRes.Extra = respObj.api_tran_dtm;
  126. return _dbRes;
  127. }
  128. }
  129. }
  130. DbResult _saveKFTCData = new DbResult();
  131. if (respObj.rsp_code == "A0000")
  132. {
  133. /*
  134. *
  135. *
  136. * @Max-2018.09.07
  137. * */
  138. //string fromTime = respObj.api_tran_dtm.Substring(0, 14);
  139. //max-20180615
  140. //_dbRes = CheckRemittant(fromTime, customerId, accountNum, accountName, processId);
  141. //respObj.remittance_check = (_dbRes.ResponseCode == "A0000") ? "Y" : "N";
  142. respObj.remittance_check = "Y";
  143. _saveKFTCData = SaveKFTCTranData(respObj, customerId);
  144. //if (_dbRes.ResponseCode != "A0000")
  145. //{
  146. // return _dbRes;
  147. //}
  148. }
  149. _dbRes.ResponseCode = respObj.rsp_code;
  150. _dbRes.Msg = respObj.rsp_message;
  151. _dbRes.Id = _saveKFTCData.Id;
  152. return _dbRes;
  153. }
  154. catch (Exception ex)
  155. {
  156. //log response
  157. _utility.LogResponseKFTC(_logResp.Id, "Exception occured!", "999", ex.Message);
  158. _dbRes.SetError("999", ex.Message, null);
  159. return _dbRes;
  160. }
  161. }
  162. private DbResult CheckBankStatus(string customerBankCode, string customerId)
  163. {
  164. DbResult dbRes = new DbResult();
  165. DbResult logRes = new DbResult();
  166. KFTCPostGet kftcRequest = new KFTCPostGet();
  167. //string _URL = @"bank/status";
  168. string httpUrl = _utility.ReadWebConfig("BANK_STATUS", "");
  169. string access_token = _utility.ReadSession("oob_access_token", "");
  170. string gmeBankCode = _utility.ReadSession("gmeBankCode", "");
  171. string processId = _utility.ReadSession(_utility.GetSessionKey(customerId), "");
  172. //log request
  173. logRes = _utility.LogRequestKFTC(customerId, "CheckBankStatus", "_URL :" + httpUrl + " access_token :" + access_token, processId);
  174. try
  175. {
  176. /*
  177. * !!!
  178. * */
  179. var resBankStatusStr = kftcRequest.GetFromKFTC(httpUrl, access_token);
  180. /*
  181. * !!!
  182. * */
  183. if (string.IsNullOrEmpty(resBankStatusStr))
  184. {
  185. dbRes.ErrorCode = "999";
  186. dbRes.Msg = "[FAIL] KFTC OPEN-FLATFORM (BANK/STATUS)!";
  187. //log response
  188. _utility.LogResponseKFTC(logRes.Id, null, dbRes.ErrorCode, dbRes.Msg);
  189. return dbRes;
  190. }
  191. var resBankStatusObj = JsonConvert.DeserializeObject<Response.bank_status>(resBankStatusStr);
  192. //log response
  193. //_utility.LogResponseKFTC(_logResp.Id, resp, bankList.rsp_code, bankList.rsp_message);
  194. //정상응답이 아닌경우...
  195. if (resBankStatusObj.rsp_code != "A0000")
  196. {
  197. dbRes.SetError("999", resBankStatusObj.rsp_message, null);
  198. //log response
  199. _utility.LogResponseKFTC(logRes.Id, null, resBankStatusObj.rsp_code, dbRes.Msg);
  200. return dbRes;
  201. }
  202. List<Response.bank_unit> bankUnit = resBankStatusObj.res_list;
  203. //dbRes.Extra = logRes.Extra;
  204. //dbRes.Id = "";
  205. //고객은행과 GME은행이 정상이면 "YY"
  206. string bankStatus = "N";
  207. foreach (var item in bankUnit)
  208. {
  209. //customer bank
  210. if (item.bank_code_std == customerBankCode)
  211. {
  212. bankStatus = item.bank_status;
  213. }
  214. }
  215. if (bankStatus != "Y")
  216. {
  217. dbRes.ErrorCode = "999";
  218. dbRes.Msg = String.Format("[FAIL] This bank{0} service is not available right now, please try again later !!", customerBankCode);
  219. //log response
  220. _utility.LogResponseKFTC(logRes.Id, null, dbRes.ErrorCode, dbRes.Msg);
  221. return dbRes;
  222. }
  223. bankStatus = "N";
  224. foreach (var item in bankUnit)
  225. {
  226. //GME bank
  227. if (item.bank_code_std == gmeBankCode)
  228. {
  229. bankStatus = item.bank_status;
  230. }
  231. }
  232. if (bankStatus != "Y")
  233. {
  234. dbRes.ErrorCode = "999";
  235. dbRes.Msg = String.Format("[FAIL] This bank {0} service is not available right now, please try again later !!", gmeBankCode);
  236. //log response
  237. _utility.LogResponseKFTC(logRes.Id, null, dbRes.ErrorCode, dbRes.Msg);
  238. return dbRes;
  239. }
  240. //성공
  241. dbRes.SetError("A0000", "", null);
  242. return dbRes;
  243. }
  244. catch (Exception ex)
  245. {
  246. dbRes.SetError("999", ex.Message, null);
  247. //log response
  248. _utility.LogResponseKFTC(logRes.Id, "Exception occured", "999", ex.Message);
  249. return dbRes;
  250. }
  251. }
  252. public DbResult CheckRealName(string customerId, string custBankCode, string custAccountNum, string accountHolderInfoType, string accountHolderInfo)
  253. {
  254. DbResult _dbRes = new DbResult();
  255. DbResult _logResp = new DbResult();
  256. KFTCPostGet kftcRequest = new KFTCPostGet();
  257. string httpUrl = _utility.ReadWebConfig("INQUIRY_REALNAME", ""); //@"inquiry/real_name";
  258. string oob_access_token = _utility.ReadSession("oob_access_token", "");
  259. string processId = _utility.ReadSession(_utility.GetSessionKey(customerId), "");
  260. //주민등록번호 Resident registration number
  261. if (accountHolderInfoType == "8008")
  262. {
  263. accountHolderInfoType = "1";
  264. }
  265. //외국인등록번호 Foreigner registration number
  266. else if (accountHolderInfoType == "1302")
  267. {
  268. accountHolderInfoType = "2";
  269. }
  270. //여권번호이면 조합주민번호로 조회 Passport with Combination no
  271. else if (accountHolderInfoType == "10997")
  272. {
  273. accountHolderInfoType = "5";
  274. }
  275. //사업자등록번호 Company Registration Number
  276. else if (accountHolderInfoType == "10988")
  277. {
  278. accountHolderInfoType = "6";
  279. }
  280. var reqRealNameObj = new Common.KFTC.Request.real_name();
  281. reqRealNameObj.bank_code_std = custBankCode;
  282. reqRealNameObj.account_num = custAccountNum;
  283. reqRealNameObj.account_holder_info_type = accountHolderInfoType;
  284. reqRealNameObj.account_holder_info = accountHolderInfo;
  285. reqRealNameObj.tran_dtime = DateTime.Now.ToString("yyyyMMddHHmmss");
  286. try
  287. {
  288. string reqRealNameStr = JsonConvert.SerializeObject(reqRealNameObj);
  289. //로그-요청로그
  290. _logResp = _utility.LogRequestKFTC(customerId, httpUrl, reqRealNameStr, processId);
  291. var resRealNameStr = kftcRequest.PostToKFTC(httpUrl, oob_access_token, reqRealNameStr);
  292. /*
  293. * !!!
  294. * */
  295. if (string.IsNullOrEmpty(resRealNameStr))
  296. {
  297. _dbRes.ErrorCode = "999";
  298. _dbRes.Msg = "[FAIL] KFTC OPEN-FLATFORM (inquiry/real_name)";
  299. //로그-결과로그(실패)
  300. _utility.LogResponseKFTC(_logResp.Id, null, _dbRes.ErrorCode, _dbRes.Msg);
  301. return _dbRes;
  302. }
  303. var resRealNameObj = JsonConvert.DeserializeObject<Response.real_name>(resRealNameStr);
  304. //응답메시지가 성공일때...
  305. if (resRealNameObj.rsp_code == "A0000" && resRealNameObj.bank_rsp_code == "000")
  306. {
  307. _dbRes.ErrorCode = "A0000";
  308. _dbRes.Msg = "[SUCCESS] KFTC OPEN-FLATFORM INQUIRY";
  309. }
  310. //응답메시지가 성공이 아닐때..
  311. else if (resRealNameObj.rsp_code != "A0000")
  312. {
  313. _dbRes.ErrorCode = resRealNameObj.rsp_code;
  314. _dbRes.Msg = String.Format("[FAIL] KFTC OPEN-FLATFORM INQUIRY rsp_message:{0}",
  315. resRealNameObj.rsp_message);
  316. //_dbRes.Msg = String.Format("[FAIL] inquiry/real_name : rsp_message={0}, req_type={1}, req_num={2}, res_type={3}, res_num={4}",
  317. // resRealNameObj.rsp_message,
  318. // accountHolderInfoType,
  319. // accountHolderInfo,
  320. // resRealNameObj.account_holder_info_type,
  321. // resRealNameObj.account_holder_info);
  322. }
  323. else if (resRealNameObj.bank_rsp_code != "000")
  324. {
  325. _dbRes.ErrorCode = resRealNameObj.bank_rsp_code;
  326. _dbRes.Msg = String.Format("[FAIL] KFTC OPEN-FLATFORM INQUIRY bank_rsp_message:{0}",
  327. resRealNameObj.bank_rsp_message);
  328. //_dbRes.Msg = String.Format("[FAIL] inquiry/real_name : rsp_message={0}, req_type={1}, req_num={2}, res_type={3}, res_num={4}",
  329. // resRealNameObj.bank_rsp_message,
  330. // accountHolderInfoType,
  331. // accountHolderInfo,
  332. // resRealNameObj.account_holder_info_type,
  333. // resRealNameObj.account_holder_info);
  334. }
  335. else
  336. {
  337. _dbRes.ErrorCode = resRealNameObj.rsp_code;
  338. _dbRes.Msg = "[FAIL] KFTC OPEN-FLATFORM INQUIRY";
  339. }
  340. // 로그-응답로그
  341. _utility.LogResponseKFTC(_logResp.Id, resRealNameStr, _dbRes.ErrorCode, _dbRes.Msg);
  342. _dbRes.SetError(_dbRes.ErrorCode, _dbRes.Msg, null);
  343. return _dbRes;
  344. }
  345. catch (Exception ex)
  346. {
  347. //로그-응답로그
  348. _utility.LogResponseKFTC(_logResp.Id, "Exception occured!", "999", ex.Message);
  349. _dbRes.SetError("999", ex.Message, null);
  350. return _dbRes;
  351. }
  352. }
  353. }
  354. }