719 lines
42 KiB
C#
719 lines
42 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.Mvc;
|
|
|
|
using NP.Model;
|
|
using NP.Base.Auth;
|
|
|
|
using XPayClientNet;
|
|
using System.Security.Cryptography;
|
|
using System.Text;
|
|
namespace NP.FO.Controllers
|
|
{
|
|
public class FOBaseController : NP.Base.BaseController
|
|
{
|
|
//전역변수 SNS 로그인 ClientID
|
|
public string naverClientID = "CEaGg2S0nrdOgmafAKgF";
|
|
public string kakaoClientID = "e85ec9c124e5dc6441f58254ddceb454";
|
|
public string googleClientID = "382613036220-4dbillsob2mf81g70t5b9b1hchukqtn4.apps.googleusercontent.com";
|
|
|
|
protected override void OnActionExecuting(ActionExecutingContext filterContext)
|
|
{
|
|
if (Request.AcceptTypes == null && !Request.Url.AbsolutePath.ToUpper().StartsWith("/OPEN/") && !Request.Url.AbsolutePath.ToUpper().StartsWith("/ACCOUNT/PAYVBANKMONEY"))
|
|
{
|
|
if ("Y".Equals(GetConfig("isdebug")))
|
|
{
|
|
var rtn = System.Threading.Tasks.Task.Run(async () => Console.WriteLine(await Dao.Log(
|
|
new NP.Model.PageLog() { uno = SUserInfo.UserNo, uip = GetUserIP(), logsite = 1, loginfo = "fobaseempry: "+Request.Url.ToString() + Request.Params.ToString() })));
|
|
}
|
|
filterContext.Result = new EmptyResult();
|
|
}
|
|
else
|
|
{
|
|
if (Request.IsSecureConnection &&
|
|
(Request.Url.AbsolutePath.ToUpper().StartsWith("/CROOM/") ||
|
|
Request.Url.AbsolutePath.ToUpper() == "/CROOM" ||
|
|
Request.Url.AbsolutePath.ToUpper().StartsWith("/CDMS/")) &&
|
|
Request.Url.AbsolutePath.ToUpper() != "/CDMS/HTTPS")
|
|
{
|
|
//Response.Redirect("http://" + Request.Url.Host + Request.Url.PathAndQuery, true);
|
|
filterContext.Result = new RedirectResult("http://" + Request.Url.Host + Request.Url.PathAndQuery);
|
|
}
|
|
else if ("Y".Equals(GetConfig("usessl")) &&
|
|
!Request.IsSecureConnection &&
|
|
!Request.Url.AbsolutePath.StartsWith("/Open/") &&
|
|
!(Request.Url.AbsolutePath.ToUpper().StartsWith("/CROOM/") || Request.Url.AbsolutePath.ToUpper() == "/CROOM") &&
|
|
!(Request.Url.AbsolutePath.ToUpper().StartsWith("/CDMS/") || Request.Url.AbsolutePath.ToUpper() == "/CDMS") &&
|
|
!Request.Url.AbsolutePath.ToUpper().StartsWith("/ACCOUNT/ERROR"))
|
|
{
|
|
filterContext.Result = new RedirectResult("https://" + Request.Url.Host + Request.Url.PathAndQuery);
|
|
}
|
|
//여기서 로그 남겨?
|
|
base.OnActionExecuting(filterContext);
|
|
if (Request.Cookies["yicte"] != null && !string.IsNullOrEmpty(Request.Cookies["yicte"].Value))
|
|
{
|
|
Response.Cookies["yicte"].Value = Request.Cookies["yicte"].Value + ";SameSite=None; Secure";
|
|
}
|
|
var cm = new Model.MenuPage() { };
|
|
//if (Request.Url.AbsolutePath.ToUpper().StartsWith("/DIVISION/A"))
|
|
//{
|
|
// cm = GetMENUPAGES.Where(w => (w.usertype == 0 || w.usertype == SUserInfo.UserType) && w.pageurl.Equals(Request.Url.PathAndQuery)).OrderByDescending(od => od.pdepth).FirstOrDefault();
|
|
//}
|
|
//else
|
|
//{
|
|
cm = GetMENUPAGES.Where(w => (w.usertype == 0 || w.usertype == SUserInfo.UserType) && (w.pageurl ?? "").ToUpper().Equals(Request.Url.AbsolutePath.ToUpper())).OrderByDescending(od => od.pdepth).FirstOrDefault();
|
|
//}
|
|
if (cm != null || Request.Url.AbsolutePath.ToUpper().Equals("/HOME/HTML")
|
|
|| Request.Url.AbsolutePath.ToUpper().StartsWith("/ACCOUNT/BANEMAIL")
|
|
|| Request.Url.AbsolutePath.ToUpper().StartsWith("/ACCOUNT/LOGOUT")
|
|
|| Request.Url.AbsolutePath.ToUpper().StartsWith("/BOARD/"))
|
|
{
|
|
ViewBag.Title = (cm ?? new Model.MenuPage()).pagename;
|
|
ViewBag.MenuPage = (cm ?? new Model.MenuPage());
|
|
ViewBag.MenuPageNo = (cm ?? new Model.MenuPage()).pno;
|
|
ViewBag.Menus = GetMENUPAGES.Where(w => w.usertype == 0 || w.usertype == base.SUserInfo.UserType).ToList();
|
|
if (!Request.IsAjaxRequest())
|
|
{
|
|
ViewBag.TopMenu = GetGnbTop(SUserInfo.UserNo);
|
|
ViewBag.TopMenu2 = SUserInfo.UserNo < 1 ? GNBTOP2 : GNBTOP2AUTH;
|
|
ViewBag.TopMenu3 = SUserInfo.UserNo < 1 ? GNBTOP3 : GNBTOP3AUTH;
|
|
ViewBag.TopMenuM = SUserInfo.UserNo < 1 ? GNBTOPM : GNBTOPMAUTH;
|
|
var pno = GetInt(Request["menupageno"]);
|
|
if (pno > 0)
|
|
{
|
|
ViewBag.MenuPage = GetMENUPAGES.Where(w => w.pno == pno).FirstOrDefault();
|
|
ViewBag.MenuPageNo = ViewBag.MenuPage.pno;
|
|
ViewBag.Title = ViewBag.MenuPage.pagename;
|
|
}
|
|
}
|
|
//접속로그
|
|
if (Request.Url.AbsolutePath.ToUpper() != "/ACCOUNT/INDEX")
|
|
{
|
|
var rtn = System.Threading.Tasks.Task.Run(async () => Console.WriteLine(await Dao.Log(
|
|
new NP.Model.PageLog() { uno = SUserInfo.UserNo, uip = GetUserIP(), logsite = 1, pno = cm.pno < 1 ? (int?)null : cm.pno, loginfo = (cm.ppagename ?? "") + " > " + cm.pagename })));
|
|
}
|
|
}
|
|
else if (GetMENUPAGES.Where(w => (w.pageurl ?? "").ToUpper().Equals(Request.Url.AbsolutePath.ToUpper())).OrderByDescending(od => od.pdepth).FirstOrDefault() != null
|
|
//&& !Request.Url.AbsolutePath.ToUpper().StartsWith("/CDMS/PLAY")
|
|
//&& !Request.Url.AbsolutePath.ToUpper().StartsWith("/CONTENTS")
|
|
)
|
|
{
|
|
filterContext.Result = new RedirectResult("/Account/Index?fobase=xx&ru=" + Request.Url.AbsolutePath, true);
|
|
//학습창 등이 안뜨고 로그인창으로 갈 경우 여기에 urlreferrer suserinfo, viewbag.ssuser~, GetMENUPAGES 등의 값들을 로깅해본다.
|
|
//~~
|
|
//Response.Redirect("/Account/Index?ru=" + Request.Url.AbsolutePath, true);
|
|
}
|
|
else if (!Request.Url.AbsolutePath.ToUpper().StartsWith("/OPEN/") &&
|
|
!Request.Url.AbsolutePath.ToUpper().StartsWith("/HOME/POPUP") &&
|
|
!Request.Url.AbsolutePath.ToUpper().StartsWith("/ACCOUNT/ERROR") &&
|
|
Request.Url.AbsolutePath.ToUpper() != "/ACCOUNT/ADMINEE")
|
|
{
|
|
filterContext.Result = new RedirectResult("/Account/Error");
|
|
}
|
|
//if (Request.IsSecureConnection &&
|
|
//!Request.Url.AbsolutePath.ToUpper().StartsWith("/ACCOUNT/") &&
|
|
//!Request.Url.AbsolutePath.ToUpper().StartsWith("/OPEN/"))
|
|
//{
|
|
// //Redirect("http://" + Request.Url.Host + Request.Url.PathAndQuery);
|
|
// filterContext.Result = new RedirectResult("http://" + Request.Url.Host + Request.Url.PathAndQuery);
|
|
//}
|
|
else if (GetMENUPAGES.Where(w => (w.pageurl ?? "").ToUpper().Equals(Request.Url.AbsolutePath.ToUpper())).OrderByDescending(od => od.pdepth).FirstOrDefault() != null
|
|
//&& !Request.Url.AbsolutePath.ToUpper().StartsWith("/CDMS/PLAY")
|
|
//&& !Request.Url.AbsolutePath.ToUpper().StartsWith("/CONTENTS")
|
|
)
|
|
{
|
|
filterContext.Result = new RedirectResult("/Account/Index?fobase=1&ru=" + Request.Url.AbsolutePath, true);
|
|
SetError("fobaseerror:path=" + Request.Url.AbsolutePath + "&urlrefer=" + Request.UrlReferrer + "&userinfo=" + SUserInfo.UserNo + "&ssuer=" + ViewBag.SSUserNo);
|
|
//학습창 등이 안뜨고 로그인창으로 갈 경우 여기에 urlreferrer suserinfo, viewbag.ssuser~, GetMENUPAGES 등의 값들을 로깅해본다.
|
|
//~~
|
|
//Response.Redirect("/Account/Index?ru=" + Request.Url.AbsolutePath, true);
|
|
}
|
|
else if (!Request.Url.AbsolutePath.ToUpper().StartsWith("/OPEN/") &&
|
|
!Request.Url.AbsolutePath.ToUpper().StartsWith("/HOME/POPUP") &&
|
|
!Request.Url.AbsolutePath.ToUpper().StartsWith("/ACCOUNT/ERROR") &&
|
|
!Request.Url.AbsolutePath.ToUpper().StartsWith("/ACCOUNT/CERTOK3") &&
|
|
Request.Url.AbsolutePath.ToUpper() != "/ACCOUNT/ADMINEE")
|
|
{
|
|
filterContext.Result = new RedirectResult("/Account/Error");
|
|
}
|
|
//if (Request.IsSecureConnection &&
|
|
//!Request.Url.AbsolutePath.ToUpper().StartsWith("/ACCOUNT/") &&
|
|
//!Request.Url.AbsolutePath.ToUpper().StartsWith("/OPEN/"))
|
|
//{
|
|
// //Redirect("http://" + Request.Url.Host + Request.Url.PathAndQuery);
|
|
// filterContext.Result = new RedirectResult("http://" + Request.Url.Host + Request.Url.PathAndQuery);
|
|
//}
|
|
}
|
|
}
|
|
private static IList<NP.Model.Popup> POPUPS { get; set; }
|
|
public IList<NP.Model.Popup> GetPOPUPS
|
|
{
|
|
get
|
|
{
|
|
if (POPUPS == null)
|
|
{
|
|
POPUPS = Dao.Get<Popup>("mm.popups", new System.Collections.Hashtable() { { "isopen", 1} });
|
|
POPUP = null;
|
|
}
|
|
return POPUPS;
|
|
}
|
|
set
|
|
{
|
|
POPUPS = value;
|
|
}
|
|
}
|
|
private static String POPUP { get; set; }
|
|
public String GetPOPUP
|
|
{
|
|
get
|
|
{
|
|
if (POPUP == null)
|
|
{
|
|
var popups = GetPOPUPS;
|
|
POPUP = "";
|
|
if (GetPOPUPS.Count() > 0)
|
|
{
|
|
POPUP = string.Join("nptechpopuplistseparator", GetPOPUPS.Select(s => string.Format("{0}nptechpopupseparator{1}nptechpopupseparator{2}nptechpopupseparator{3}nptechpopupseparator{4}nptechpopupseparator{5}nptechpopupseparator{6}nptechpopupseparator{7}nptechpopupseparator{8}"
|
|
, s.pno, s.ptitle, "", s.toppx, s.leftpx, s.pwidth, s.pheight+37, s.purl, s.zindex + 100)));
|
|
}
|
|
}
|
|
return POPUP;
|
|
}
|
|
set
|
|
{
|
|
POPUP = value;
|
|
}
|
|
}
|
|
private static IList<NP.Model.Banner> BANNERS { get; set; }
|
|
public IList<NP.Model.Banner> GetBANNERS
|
|
{
|
|
get
|
|
{
|
|
if (BANNERS == null)
|
|
{
|
|
BANNERS = Dao.Get<Banner>("mm.banners", new System.Collections.Hashtable() { { "isopen", 1 } });
|
|
BANNER = null;
|
|
BANNERCROOM = null;
|
|
}
|
|
return BANNERS;
|
|
}
|
|
set
|
|
{
|
|
BANNERS = value;
|
|
}
|
|
}
|
|
private static String BANNER { get; set; }
|
|
public String GetBANNER
|
|
{
|
|
get
|
|
{
|
|
if (BANNER == null)
|
|
{
|
|
//var banners = GetBANNERS;
|
|
BANNER = "";
|
|
if (GetBANNERS.Where(w => w.ismain == 0).Count() > 0)
|
|
{
|
|
BANNER = string.Join("", GetBANNERS.Where(w => w.ismain == 0).Select(s =>
|
|
string.Format("<div {2} class=\"mpgsdCont\" style=\"{3}background:url({0})no-repeat left center;\"><img src=\"{1}\" alt=\"\" /></div>",
|
|
(new BaseModel()).rootfolder + s.fileurl,
|
|
(new BaseModel()).rootfolder + s.fileurl2,
|
|
string.IsNullOrEmpty(s.burl)?"": s.burl.ToLower().StartsWith("http")? ("onclick=\"window.open('" + s.burl + "')\"") : ("onclick=\"location.href='" + s.burl + "'\""),
|
|
string.IsNullOrEmpty(s.burl)?"":"cursor:pointer;"
|
|
)));
|
|
}
|
|
}
|
|
return BANNER;
|
|
}
|
|
set
|
|
{
|
|
BANNER = value;
|
|
}
|
|
}
|
|
private static String BANNERCROOM { get; set; }
|
|
public String GetBANNERCROOM
|
|
{
|
|
get
|
|
{
|
|
if (BANNERCROOM == null)
|
|
{
|
|
//var banners = GetBANNERS;
|
|
BANNERCROOM = "";
|
|
if (GetBANNERS.Where(w => w.ismain == 1).Count() > 0)
|
|
{
|
|
//BANNERCROOM = string.Join("", GetBANNERS.Where(w => w.ismain == 1).Select(s =>
|
|
// string.Format("<div class=\"mpgsdCont\" style=\"background:url({0})no-repeat left center;\"><img src=\"{1}\" alt=\"\" /></div>"
|
|
// , (new BaseModel()).rootfolder + s.fileurl, (new BaseModel()).rootfolder + s.fileurl2)));
|
|
}
|
|
}
|
|
return BANNERCROOM;
|
|
}
|
|
set
|
|
{
|
|
BANNERCROOM = value;
|
|
}
|
|
}
|
|
|
|
|
|
private static IList<NP.Model.MenuPage> MENUPAGES { get; set; }
|
|
public IList<NP.Model.MenuPage> GetMENUPAGES
|
|
{
|
|
get
|
|
{
|
|
if (MENUPAGES == null)
|
|
{
|
|
MENUPAGES = Dao.Get<NP.Model.MenuPage>("mm.pages", new System.Collections.Hashtable() { { "isopen", 9 } });
|
|
GNBTOP = null;
|
|
}
|
|
return MENUPAGES.ToList();
|
|
}
|
|
set
|
|
{
|
|
MENUPAGES = value;
|
|
}
|
|
}
|
|
private static String GNBTOP { get; set; }
|
|
private static String GNBTOPAUTH { get; set; }
|
|
private static String GNBTOP2 { get; set; }
|
|
private static String GNBTOP2AUTH { get; set; }
|
|
private static String GNBTOP3 { get; set; }
|
|
private static String GNBTOP3AUTH { get; set; }
|
|
private static String GNBTOPM { get; set; }
|
|
private static String GNBTOPMAUTH { get; set; }
|
|
public String GetGnbTop(int usertype)
|
|
{
|
|
if (GNBTOP == null)
|
|
{
|
|
System.Text.StringBuilder sb = new System.Text.StringBuilder("");
|
|
System.Text.StringBuilder sbauth = new System.Text.StringBuilder("");
|
|
System.Text.StringBuilder sb2 = new System.Text.StringBuilder("");
|
|
System.Text.StringBuilder sb2auth = new System.Text.StringBuilder("");
|
|
System.Text.StringBuilder sbm = new System.Text.StringBuilder("");
|
|
System.Text.StringBuilder sbmauth = new System.Text.StringBuilder("");
|
|
var tops = "";
|
|
var topsauth = "";
|
|
sbmauth.Append("<li><a class=\"mlink\" href=\"/My/Index\">Home</a></li>");
|
|
foreach (var m in GetMENUPAGES.Where(w => w.pdepth == 0 && w.isopen == 1))
|
|
{
|
|
var mp = m.pagetype == 0 ? GetMENUPAGES.Where(w => w.pagetype > 0 && (w.m0 == m.pno || w.m1 == m.pno || w.m2 == m.pno || w.m3 == m.pno || w.m4 == m.pno)).FirstOrDefault() ?? new Model.MenuPage() { } : m;
|
|
sbauth.Append(string.Format("<li class=\"topmenu{5}\"><a href=\"#\" onclick=\"gomenu({0},{1}, '{2}', this)\" data-refcode=\"{3}\">{4}</a>", mp.pno, mp.pagetype, mp.pageurl ?? "", m.refcode??"", m.pagename, m.pno));
|
|
topsauth += string.Format("<li class=\"topmenu{1}\"><h5>{0}</h5></li>", m.pagename, m.pno);
|
|
if (m.usertype == 0)
|
|
{
|
|
sb.Append(string.Format("<li><a href=\"#\" onclick=\"gomenu({0},{1}, '{2}', this)\" data-refcode=\"{3}\">{4}</a>", mp.pno, mp.pagetype, mp.pageurl ?? "", m.refcode ?? "", m.pagename));
|
|
tops += string.Format("<li><h5>{0}</h5></li>", m.pagename);
|
|
}
|
|
sb2.Append("<li><ul>");
|
|
sb2auth.Append("<li><ul>");
|
|
foreach (var m2 in GetMENUPAGES.Where(w => w.pdepth == 1 && w.isopen == 1 && w.ppno == m.pno && w.pagetype != 4))
|
|
{
|
|
sb2auth.Append(string.Format("<li class=\"topsubmenu{4}\"><a href=\"#\" onclick=\"gomenu({0}, {1}, '{2}', this)\">{3}</a></li>", m2.pno, m2.pagetype, m2.pageurl ?? "", m2.pagename, m2.pno));
|
|
if (m.usertype == 0 && m2.usertype == 0)
|
|
{
|
|
sb2.Append(string.Format("<li class=\"topsubmenu{4}\"><a href=\"#\" onclick=\"gomenu({0}, {1}, '{2}', this)\">{3}</a></li>", m2.pno, m2.pagetype, m2.pageurl ?? "", m2.pagename, m2.pno));
|
|
}
|
|
}
|
|
sb2.Append("</ul></li>");
|
|
sb2auth.Append("</ul></li>");
|
|
var menu = GetMENUPAGES.Where(w => w.pdepth == 1 && w.isopen == 1 && w.ppno == m.pno && w.pagetype != 4).FirstOrDefault();
|
|
sbmauth.Append(string.Format("<li class=\"topmenu{1}" + (m.pno == 16 ? "style=\"display:none;\"" : string.Empty) + "\"><a href=\"#\" onclick=\"gomenu({2}, {3}, '{4}', this)\">{0}</a><span></span><ul>", m.pagename, m.pno,menu.pno,menu.pagetype,menu.pageurl));
|
|
if (m.usertype == 0)
|
|
{
|
|
sbm.Append(string.Format("<li class=\"topmenu{1}" + (m.pno == 16 ? "style=\"display:none;\"" : string.Empty) + "\"><a href=\"#\" onclick=\"gomenu({2}, {3}, '{4}', this)\">{0}</a><span></span><ul>", m.pagename, m.pno, menu.pno, menu.pagetype, menu.pageurl));
|
|
}
|
|
foreach (var m2 in GetMENUPAGES.Where(w => w.pdepth == 1 && w.isopen == 1 && w.ppno == m.pno && w.pagetype != 4))
|
|
{
|
|
sbmauth.Append(string.Format("<li class=\"topsubmenu{4}\"><a href=\"#\" onclick=\"gomenu({0}, {1}, '{2}', this)\">{3}</a></li>", m2.pno, m2.pagetype, m2.pageurl ?? "", m2.pagename, m2.pno));
|
|
if (m.usertype == 0)
|
|
{
|
|
sbm.Append(string.Format("<li class=\"topsubmenu{4}\"><a href=\"#\" onclick=\"gomenu({0}, {1}, '{2}', this)\">{3}</a></li>", m2.pno, m2.pagetype, m2.pageurl ?? "", m2.pagename, m2.pno));
|
|
}
|
|
}
|
|
sbmauth.Append("</ul></li>");
|
|
if (m.usertype == 0)
|
|
{
|
|
sbm.Append("</ul></li>");
|
|
}
|
|
}
|
|
GNBTOP = sb.ToString();
|
|
GNBTOPAUTH = sbauth.ToString();
|
|
GNBTOP2 = tops;
|
|
GNBTOP2AUTH = topsauth;
|
|
GNBTOP3 = sb2.ToString();
|
|
GNBTOP3AUTH = sb2auth.ToString();
|
|
GNBTOPM = sbm.ToString();
|
|
GNBTOPMAUTH = sbmauth.ToString();
|
|
}
|
|
return usertype < 1 ? GNBTOP : GNBTOPAUTH;
|
|
}
|
|
|
|
protected void ResetMenu()
|
|
{
|
|
MENUPAGES = null;
|
|
}
|
|
protected void ResetPopup()
|
|
{
|
|
POPUPS = null;
|
|
}
|
|
protected void ResetBanner()
|
|
{
|
|
BANNERS = null;
|
|
}
|
|
private System.Security.Authentication.SslProtocols ExtractSslProtocol(System.IO.Stream stream)
|
|
{
|
|
if (stream is null) return System.Security.Authentication.SslProtocols.None;
|
|
System.Reflection.BindingFlags bindingFlags = System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic;
|
|
System.IO.Stream metaStream = stream;
|
|
if (stream.GetType().BaseType == typeof(System.IO.Compression.GZipStream))
|
|
{
|
|
metaStream = (stream as System.IO.Compression.GZipStream).BaseStream;
|
|
}
|
|
else if (stream.GetType().BaseType == typeof(System.IO.Compression.DeflateStream))
|
|
{
|
|
metaStream = (stream as System.IO.Compression.DeflateStream).BaseStream;
|
|
}
|
|
var connection = metaStream.GetType().GetProperty("Connection", bindingFlags).GetValue(metaStream);
|
|
if (!(bool)connection.GetType().GetProperty("UsingSecureStream", bindingFlags).GetValue(connection))
|
|
{
|
|
// Not a Https connection
|
|
return System.Security.Authentication.SslProtocols.None;
|
|
}
|
|
var tlsStream = connection.GetType().GetProperty("NetworkStream", bindingFlags).GetValue(connection);
|
|
var tlsState = tlsStream.GetType().GetField("m_Worker", bindingFlags).GetValue(tlsStream);
|
|
return (System.Security.Authentication.SslProtocols)tlsState.GetType().GetProperty("SslProtocol", bindingFlags).GetValue(tlsState);
|
|
}
|
|
protected void PayAll(VMPay vm)
|
|
{
|
|
//ViewBag.IsOldTLS = false;
|
|
//try
|
|
//{
|
|
// if (Request.IsSecureConnection)
|
|
// {
|
|
// System.Net.Security.SslStream sss = new System.Net.Security.SslStream(Request.UrlReferrer.);
|
|
// Console.WriteLine(sss.SslProtocol);
|
|
// //if (ssp.SslProtocol != System.Security.Authentication.SslProtocols.Tls12)
|
|
// //{
|
|
// // ViewBag.IsOldTLS = true;
|
|
// //}
|
|
// }
|
|
//}
|
|
//catch (Exception ex)
|
|
//{
|
|
// Console.WriteLine(ex.Message);
|
|
//}
|
|
vm.PayItems = new List<PayItem>() { };
|
|
if (vm.ispaycart)
|
|
{
|
|
//장바구니에서 결제 진입
|
|
vm.PayItems = Dao.Get<PayItem>("pay.payitems.forcartpay", new System.Collections.Hashtable() { { "userno", SUserInfo.UserNo } });
|
|
vm.User = Dao.Get<Users>("users.users", new System.Collections.Hashtable() { { "userno", SUserInfo.UserNo } }).First();
|
|
}
|
|
else if (vm.ispaycert && vm.payno > 0)
|
|
{
|
|
//자격증강좌는 신청 시점에는 금액이 0이므로 결제시점에 현재가격으로 갱신해준다.
|
|
vm.PayItems = Dao.Get<PayItem>("pay.payitems.forcertpay", new System.Collections.Hashtable() { { "payno", vm.payno }, { "userno", SUserInfo.UserNo} });
|
|
vm.User = Dao.Get<Users>("users.users", new System.Collections.Hashtable() { { "userno", SUserInfo.UserNo } }).First();
|
|
}
|
|
else if (vm.ispayexam)
|
|
{
|
|
vm.PayItems = Dao.Get<PayItem>("pay.payitems.forexampay", new System.Collections.Hashtable() { { "exno", vm.exno }, { "userno", SUserInfo.UserNo } });
|
|
vm.User = Dao.Get<Users>("users.users", new System.Collections.Hashtable() { { "userno", SUserInfo.UserNo } }).First();
|
|
}
|
|
else
|
|
{
|
|
//구매상품데이터를 추출한다.
|
|
foreach (var d in vm.items.Split(';'))
|
|
{
|
|
var dd = d.Split(':');
|
|
vm.PayItems.Add(new PayItem() { ptype = GetInt(dd[0]), itemno = GetLong(dd[1]), pcnt = GetInt(dd[2]), userno = vm.isgroup == 0 ? SUserInfo.UserNo : GetInt(dd[3]), isrebate = GetInt(dd[4]), fgno = dd[5] == "0" ? (Int64?)null : GetLong(dd[5]) });
|
|
}
|
|
var pis = Dao.Get<PayItem>("pay.payitems.forpay", new System.Collections.Hashtable(){
|
|
{"userno", SUserInfo.UserNo },
|
|
{ "cmnos0", string.Join(",", vm.PayItems.Where(w=>w.ptype == 0).Select(s=>s.itemno).Distinct()) },
|
|
{"bknos", string.Join(",", vm.PayItems.Where(w=>w.ptype == 2).Select(s=>s.itemno)) }
|
|
});
|
|
vm.User = Dao.Get<Users>("users.users", new System.Collections.Hashtable() { { "userno", SUserInfo.UserNo } }).First();
|
|
foreach(var pi in vm.PayItems)
|
|
{
|
|
var item = pis.Where(w => w.ptype == pi.ptype && w.itemno == pi.itemno).First();
|
|
pi.days = item.days;
|
|
pi.itemname = item.itemname;
|
|
pi.orgamt = item.orgamt;
|
|
pi.discamt = item.discamt;
|
|
pi.payamt = item.payamt;
|
|
pi.cshape = item.cshape;
|
|
}
|
|
}
|
|
vm.pginfo = GetConfig("pginfo");
|
|
vm.pginfomobile = GetConfig("pginfomobile");
|
|
vm.signkey = ComputeHash(vm.pginfo.Split('|')[2]);
|
|
|
|
//vm.payitemname = Utf8ToEuckr();
|
|
vm.viewname5 = GetConfig("fronturl") + "/Course/PayClose";
|
|
vm.previewname = vm.previewname ?? "/My/Cart";
|
|
vm.deliveramt = GetInt(GetConfig("deliveramt"));
|
|
}
|
|
//private String Utf8ToEuckr(String s)
|
|
//{
|
|
// byte[] pbSource = System.Text.Encoding.UTF8.GetBytes(s);
|
|
// byte[] pbDest = System.Text.Encoding.Convert(
|
|
// System.Text.Encoding.UTF8, System.Text.Encoding.GetEncoding("euc-kr"), pbSource);
|
|
// pbSource = System.Text.Encoding.Convert(System.Text.Encoding.GetEncoding("euc-kr"), System.Text.Encoding.UTF8, pbDest);
|
|
// char[] psUnicode = System.Text.UTF8Encoding.UTF8.GetChars(pbSource);
|
|
// return new string(psUnicode);
|
|
//}
|
|
protected ActionResult PayReturn(VMPay vm)
|
|
{
|
|
if (vm.payno > 0 && (vm.absptype == 6 || vm.absptype == 7))
|
|
{
|
|
//0원강좌 결제
|
|
vm.Pay = new Pay() { payno = vm.payno, pstatus = 1, ptype = vm.absptype, oid2 = (vm.absptype == 6 ? "free" : string.Empty) + vm.payno };
|
|
vm.Pay.payresult = "1:무료결제완료";
|
|
vm.PayItemResults = Dao.Get<PayItemResult>("pay.payitems", vm.Pay.payno);
|
|
vm.CM = Dao.Get<CM>("cm.cms", new System.Collections.Hashtable() { { "cmno", vm.PayItemResults.First().itemno } }).FirstOrDefault();
|
|
}
|
|
else
|
|
{
|
|
vm.Pay = new Pay();
|
|
/* ※ 중요
|
|
* 환경설정 파일의 경우 반드시 외부에서 접근이 가능한 경로에 두시면 안됩니다.
|
|
* 해당 환경파일이 외부에 노출이 되는 경우 해킹의 위험이 존재하므로 반드시 외부에서 접근이 불가능한 경로에 두시기 바랍니다.
|
|
* 예) [Window 계열] C:\inetpub\wwwroot\lgdacom ==> 절대불가(웹 디렉토리)
|
|
*/
|
|
String configPath = GetConfig("lgdacomConfigPath"); //토스페이먼츠에서 제공한 환경파일 위치를 지정해 주세요.
|
|
|
|
/*
|
|
* [최종결제요청 페이지(STEP2-2)]
|
|
*
|
|
* 매뉴얼 "5.1. XPay 결제 요청 페이지 개발"의 "단계 5. 최종 결제 요청 및 요청 결과 처리" 참조
|
|
*
|
|
* 토스페이먼츠으로 부터 내려받은 LGD_PAYKEY(인증Key)를 가지고 최종 결제요청.(파라미터 전달시 POST를 사용하세요)
|
|
*/
|
|
|
|
/*
|
|
*************************************************
|
|
* 1.최종결제 요청(수정하지 마세요) - BEGIN
|
|
* (단, 최종 금액체크를 원하시는 경우 금액체크 부분 주석을 제거 하시면 됩니다.)
|
|
*************************************************
|
|
*/
|
|
String CST_PLATFORM = Request.Params.Get("CST_PLATFORM");
|
|
String CST_MID = Request.Params.Get("CST_MID");
|
|
String LGD_MID = (("test".Equals(CST_PLATFORM.Trim())) ? "t" : "") + CST_MID;
|
|
String LGD_PAYKEY = Request.Params.Get("LGD_PAYKEY");
|
|
String LGD_CLOSEDATE = Request.Params.Get("LGD_CLOSEDATE");
|
|
//String DB_AMOUNT = ""; //반드시 위변조가 불가능한 곳(DB나 세션)에서 금액을 가져오십시요.
|
|
|
|
// (1) XpayClient의 사용을 위한 xpay 객체 생성
|
|
XPayClient xpay = new XPayClient();
|
|
|
|
// (2) Init: XPayClient 초기화(환경설정 파일 로드)
|
|
// configPath: 설정파일
|
|
// CST_PLATFORM: - test, service 값에 따라 lgdacom.conf의 test_url(test) 또는 url(srvice) 사용
|
|
// - test, service 값에 따라 테스트용 또는 서비스용 아이디 생성
|
|
xpay.Init(configPath, CST_PLATFORM);
|
|
|
|
try
|
|
{
|
|
// (3) Init_TX: 메모리에 mall.conf, lgdacom.conf 할당 및 트랜잭션의 고유한 키 TXID 생성
|
|
xpay.Init_TX(LGD_MID);
|
|
xpay.Set("LGD_TXNAME", "PaymentByKey");
|
|
xpay.Set("LGD_PAYKEY", LGD_PAYKEY);
|
|
|
|
//금액을 체크하시기 원하는 경우 아래 주석을 풀어서 이용하십시요.
|
|
//xpay.Set("LGD_AMOUNTCHECKYN", "Y");
|
|
//xpay.Set("LGD_AMOUNT", DB_AMOUNT);
|
|
|
|
}
|
|
catch (Exception err)
|
|
{
|
|
SetError("환경파일의 경로가 잘못 되었습니다. configPath의 경로를 확인해 주시기 바랍니다." + "|" + err.StackTrace);
|
|
vm.Pay.payresult = "0:호출실패";
|
|
vm.Pay.cancelresult = "환경파일의 경로가 잘못 되었습니다. configPath의 경로를 확인해 주시기 바랍니다.";
|
|
}
|
|
/*
|
|
*************************************************
|
|
* 1.최종결제 요청(수정하지 마세요) - END
|
|
*************************************************
|
|
*/
|
|
|
|
/*
|
|
* 2. 최종결제 요청 결과 처리
|
|
*
|
|
* 최종 결제요청 결과 리턴 파라미터는 연동메뉴얼을 참고하시기 바랍니다.
|
|
*/
|
|
// (4) TX: lgdacom.conf에 설정된 URL로 소켓 통신하여 최종 인증요청, 결과값으로 true, false 리턴
|
|
if (xpay.TX())
|
|
{
|
|
Int64 payno = GetLong(xpay.Response("LGD_OID", 0).Substring(2));
|
|
//1)결제결과 화면처리(성공,실패 결과 처리를 하시기 바랍니다.
|
|
vm.Pay = new Pay() { payno = payno, uno = SUserInfo.UserNo, uip = GetUserIP() };
|
|
String cancelMsg = "결제오류|" + payno;
|
|
|
|
// (5) DB에 인증요청 결과 처리
|
|
if ("0000".Equals(xpay.m_szResCode))
|
|
{
|
|
try
|
|
{
|
|
//통신상의 문제가 없을시
|
|
//최종결제요청 결과 성공 DB처리(LGD_RESPCODE 값에 따라 결제가 성공인지, 실패인지 DB처리)
|
|
vm.Pay = Dao.Get<Pay>("pay.pay", new System.Collections.Hashtable() { { "payno", payno }, { "userno", SUserInfo.UserNo }, { "pstatus21", 0 } }).FirstOrDefault();
|
|
if (vm.Pay == null)
|
|
{
|
|
vm.Pay = new Pay() { payno = payno, uno = SUserInfo.UserNo, uip = GetUserIP() };
|
|
vm.Pay.payresult = "0:결제상품 오류(E1)";
|
|
cancelMsg += "|결제상품 오류(E1)";
|
|
vm.Pay = new Pay() { payno = payno, uno = SUserInfo.UserNo, uip = GetUserIP() };
|
|
throw new Exception("결제상품 오류(E1)");
|
|
}
|
|
else
|
|
{
|
|
vm.Pay.uno = SUserInfo.UserNo;
|
|
vm.Pay.uip = GetUserIP();
|
|
if (vm.Pay.payamt != GetInt((xpay.Response("LGD_AMOUNT", 0) ?? "").Replace(",", "")))
|
|
{
|
|
vm.Pay.payresult = "0:결제금액 오류(E3)";
|
|
cancelMsg += "|결제금액 오류(E3)";
|
|
throw new Exception("결제금액 오류(E3)");
|
|
}
|
|
else
|
|
{
|
|
if (vm.Pay.ptype == 3)
|
|
{ //가상계좌
|
|
vm.Pay.vactnum = xpay.Response("LGD_ACCOUNTNUM", 0);
|
|
vm.Pay.vactbankcode = xpay.Response("LGD_FINANCECODE", 0);
|
|
vm.Pay.vactbankname = xpay.Response("LGD_FINANCENAME", 0);
|
|
vm.Pay.vactname = xpay.Response("LGD_SAOWNER", 0);
|
|
vm.Pay.vactinname = xpay.Response("LGD_PAYER", 0);
|
|
//vm.Pay.paylimit = Convert.ToDateTime(xpay.Response("LGD_CLOSEDATE", 0));
|
|
}
|
|
else if (vm.Pay.ptype == 2)
|
|
{ //실시간계좌이체
|
|
vm.Pay.vactbankcode = xpay.Response("LGD_FINANCECODE", 0);
|
|
vm.Pay.cshrtype = xpay.Response("LGD_CASHRECEIPTKIND", 0);
|
|
vm.Pay.cshrauthno = xpay.Response("LGD_CASHRECEIPTNUM", 0);
|
|
}
|
|
else
|
|
{//카드
|
|
vm.Pay.cardquota = xpay.Response("LGD_CARDINSTALLMONTH", 0);
|
|
if (!"00".Equals(xpay.Response("LGD_CARDINSTALLMONTH", 0)) && "1".Equals(xpay.Response("LGD_CARDNOINTYN", 0)))
|
|
{
|
|
vm.Pay.cardquotatype = 1;
|
|
}
|
|
vm.Pay.cardnum = xpay.Response("LGD_CARDNUM", 0);
|
|
vm.Pay.iscardpoint = vm.Pay.cardquota.Count() == 4 ? 1 : 0; // 포인트 사용 시 할부개월 + 포인트별로 숫자 두개가 붙음, 즉 4개면 포인트 사용했다는 뜻
|
|
vm.Pay.cardcode = xpay.Response("LGD_FINANCECODE", 0);
|
|
vm.Pay.cardbankcode = xpay.Response("LGD_CARDACQUIRER", 0);
|
|
vm.Pay.cardprtccode = xpay.Response("LGD_PCANCELFLAG", 0);
|
|
vm.Pay.checkflag = xpay.Response("LGD_CARDGUBUN2", 0);
|
|
}
|
|
vm.Pay.payresult = xpay.Response("LGD_RESPCODE", 0);
|
|
vm.Pay.payresultmsg = xpay.Response("LGD_RESPMSG", 0);
|
|
vm.Pay.pgkey = xpay.Response("LGD_TID", 0);
|
|
vm.Pay.mid = LGD_MID;
|
|
vm.Pay.uno = SUserInfo.UserNo;
|
|
vm.Pay.uip = GetUserIP();
|
|
//상품구매완료 처리 (최소 3건 업데이트 (pay, paydata, payitem)
|
|
if (Dao.Save("pay.paylect", vm.Pay) < 3)
|
|
{
|
|
vm.Pay.payresult = "0:구매완료 실패(E4)";
|
|
cancelMsg += "|구매완료 실패(E4)";
|
|
throw new Exception("구매완료 실패(E4)");
|
|
}
|
|
vm.Pay.payresult = "1:결제완료";
|
|
try
|
|
{
|
|
vm.Pay.oid2 = GetConfig("PAYMENT_CLASSIFICATION") + vm.Pay.payno;
|
|
vm.PayItemResults = Dao.Get<PayItemResult>("pay.payitems", vm.Pay.payno);
|
|
vm.PayItem = Dao.Get<PayItem>("pay.payresult", new System.Collections.Hashtable() { { "payno", vm.Pay.payno }, { "userno", SUserInfo.UserNo } }).First();
|
|
vm.Pay.pstatus = vm.Pay.ptype == 1 ? 1 : 22;
|
|
vm.CM = Dao.Get<CM>("cm.cms", new System.Collections.Hashtable() { { "cmno", vm.PayItemResults.First().itemno } }).FirstOrDefault();
|
|
}
|
|
catch (Exception exresult)
|
|
{
|
|
SetError(exresult.StackTrace);
|
|
}
|
|
#region 영수증 출력 관련
|
|
String authdata = vm.Pay.mid + vm.Pay.pgkey + GetConfig("LGD_MERTKEY");
|
|
HashAlgorithm hash;
|
|
byte[] authdataTextBytes = Encoding.UTF8.GetBytes(authdata);
|
|
hash = new MD5CryptoServiceProvider();
|
|
byte[] hashed = hash.ComputeHash(authdataTextBytes);
|
|
for (int i = 0; i < hashed.Length; i++)
|
|
{
|
|
vm.Pay.authdata += string.Format("{0:x2}", hashed[i]);
|
|
}
|
|
#endregion
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//망취소
|
|
xpay.Rollback("상점 DB처리 실패로 인하여 Rollback 처리 [TID:" + xpay.Response("LGD_TID", 0) + ",MID:" + xpay.Response("LGD_MID", 0) + ",OID:" + xpay.Response("LGD_OID", 0) + "]");
|
|
|
|
if ("0000".Equals(xpay.m_szResCode))
|
|
{
|
|
try
|
|
{
|
|
// 자동취소가 정상적으로 완료 되었을때
|
|
vm.Pay.cancelresult = (vm.Pay.cancelresult ?? "") + "|" + xpay.Response("LGD_RESPMSG", 0);
|
|
vm.Pay.pstatus = 66;
|
|
Dao.Save("pay.pay.fail", vm.Pay);
|
|
SetError(cancelMsg += "|" + xpay.Response("LGD_RESPMSG", 0) + "|" + ex.StackTrace);
|
|
}
|
|
catch (Exception ex2)
|
|
{
|
|
SetError(cancelMsg += "|" + xpay.Response("LGD_RESPMSG", 0) + "|" + ex2.StackTrace);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// 자동취소가 정상적으로 처리되지 않았을때
|
|
vm.Pay.cancelresult = (vm.Pay.cancelresult ?? "") + "|" + xpay.Response("LGD_RESPMSG", 0);
|
|
vm.Pay.pstatus = 66;
|
|
Dao.Save("pay.pay.fail", vm.Pay);
|
|
SetError(cancelMsg += "|" + xpay.Response("LGD_RESPCODE", 0) + "|" + xpay.Response("LGD_RESPMSG", 0));
|
|
}
|
|
|
|
vm.Pay.payresult = "0:결제중 오류(E101)";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//통신상의 문제 발생(최종결제요청 결과 실패 DB처리)
|
|
vm.Pay.payresult = "0:통신상의 문제 발생(" + xpay.Response("LGD_RESPCODE", 0) + ")";
|
|
vm.Pay.cancelresult = xpay.Response("LGD_RESPMSG", 0);
|
|
if ("S007".Equals(xpay.m_szResCode))
|
|
{
|
|
vm.Pay.cancelresult = "이미 거래시도된 내역입니다.";
|
|
}
|
|
else
|
|
{
|
|
try
|
|
{
|
|
Dao.Save("pay.pay.fail", new System.Collections.Hashtable() { {"payno", payno },{"pstatus", 66 },
|
|
{ "payresult", xpay.Response("LGD_RESPCODE", 0)},
|
|
{ "payresultmsg", xpay.Response("LGD_RESPMSG", 0) },
|
|
{ "uno", SUserInfo.UserNo},{"uip", GetUserIP() } });
|
|
}
|
|
catch (Exception ex2)
|
|
{
|
|
SetError(cancelMsg += "|" + (cancelMsg ?? "") + "|" + ex2.StackTrace);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//2)API 요청실패 화면처리
|
|
vm.Pay.payresult = "0:결제요청실패(" + xpay.m_szResCode + ")";
|
|
vm.Pay.cancelresult = xpay.m_szResMsg;
|
|
}
|
|
}
|
|
return View("ApplyComplete", vm);
|
|
}
|
|
}
|
|
}
|
|
|