示例#1
0
        private void SetInfo(HttpContext context)
        {
            string vouchers = context.Request["vouchers"];

            if (string.IsNullOrEmpty(vouchers))
            {
                context.Response.Write(string.Format("{{\"error\":{0},\"msg\":\"{1}\"}}", 5, "Hãy nhập gói cước"));
                return;
            }

            var oUser = (CustomerGateInfo)context.Session[Config.GetSessionUser];

            if (oUser == null)
            {
                context.Response.Write(string.Format("{{\"error\":{0},\"msg\":\"{1}\"}}", 6, "Hết phiên làm việc, hãy thực hiện lại"));
                return;
            }

            if (!Utility.isOnlyNumber(vouchers))
            {
                context.Response.Write(string.Format("{{\"error\":{0},\"msg\":\"{1}\"}}", 7, "Gói cước không phù hợp"));
                return;
            }

            List <voucher> list     = oUser.vouchers;
            voucher        oVoucher = null;

            foreach (voucher item in list)
            {
                if (vouchers == item.vouchervalue)
                {
                    oVoucher = item;
                    break;
                }
            }

            if (oVoucher == null)
            {
                context.Response.Write(string.Format("{{\"error\":{0},\"msg\":\"{1}\"}}", 8, "Gói cước không phù hợp"));
                return;
            }

            string Good_Code = string.Format("{0:yyMMddHHmmssfff}", DateTime.Now) + oVoucher.duration;

            Good_Code = Security.GetMD5Hash(Good_Code);
            Good_Code = "THAV-" + Good_Code.Substring(0, 15).ToUpper();

            string sSuccess = context.Request.Url.Scheme + "://" + context.Request.Url.Authority + "/Banknet/success.aspx?code=" + Good_Code;
            string sFail    = context.Request.Url.Scheme + "://" + context.Request.Url.Authority + "/Banknet/fail.aspx?code=" + Good_Code;

            SendGoodInfo sendInfo = new SendGoodInfo()
            {
                UserId          = oUser.subnum,
                vouchers        = oVoucher.vouchervalue + " - " + oVoucher.vouchername + " - " + oVoucher.duration + " " + oVoucher.durationuomaltcode,
                Good_code       = Good_Code,
                Xml_description = Config.Desc,
                Url_success     = sSuccess,
                Url_fail        = sFail,
                CreateDate      = DateTime.Now
            };

            try
            {
                string s = BanknetHelper.Send_GoodInfo(Good_Code, Config.Desc, vouchers, "0", "0", sSuccess, sFail, ref sendInfo);

                if (BanknetHelper.getCodeResult(s) != "010")
                {
                    context.Response.Write(string.Format("{{\"error\":{0},\"msg\":\"{1}\"}}", 9, "Kết nối với cổng thanh toán Banknet gặp sự cố"));
                    return;
                }

                string sUrl      = "";
                string sTrans_Id = "";
                int    iResult   = BanknetHelper.GetUrlRedirection(s, out sUrl);
                if (iResult != 0)
                {
                    context.Response.Write(string.Format("{{\"error\":{0},\"msg\":\"{1}\"}}", 10, "Kết nối với cổng thanh toán Banknet gặp sự cố"));
                    return;
                }
                sTrans_Id         = BanknetHelper.getTransIdFromUrl(sUrl);
                sendInfo.Trans_Id = sTrans_Id;
                //save cached
                CacheInfo oCacheInfo = new CacheInfo()
                {
                    Voucher           = oVoucher,
                    sTrans_Id         = sTrans_Id,
                    Good_Code         = Good_Code,
                    User              = oUser,
                    Merchant_trans_id = sendInfo.Merchant_trans_id
                };

                CacheProvider.AddWithTimeOut(string.Format(KeyCache.KeyUserBanknet, Good_Code), oCacheInfo, 720);
                //
                context.Response.Write(string.Format("{{\"error\":{0},\"msg\":\"{1}\"}}", 0, sUrl));
                return;
            }
            catch (Exception ex)
            {
                sendInfo.ResultId  = ex.GetHashCode().ToString();
                sendInfo.OutString = ex.Message;
                context.Response.Write(string.Format("{{\"error\":{0},\"msg\":\"{1}\"}}", sendInfo.ResultId, sendInfo.OutString));
            }
            finally
            {
                SendGoodData.instance.Add(sendInfo);
            }
        }