Ejemplo n.º 1
0
        private void RegisterCcbUser()
        {
            string userid    = Request["userid"];
            string userdata  = Request["userdata"];
            string timestamp = Request["timestamp"];
            string source    = Request["source"];

            if (string.IsNullOrWhiteSpace(userid) ||
                string.IsNullOrWhiteSpace(userdata) ||
                string.IsNullOrWhiteSpace(timestamp) ||
                string.IsNullOrWhiteSpace(source))
            {
                Response.Write("fail,缺少必要参数");
                Response.End();
            }

            string mobile = Request["mobile"];
            string email  = Request["email"];

            string key = ConfigurationManager.AppSettings["Key_CCB"];
            string iv  = ConfigurationManager.AppSettings["IV_CCB"];

            string dataKey     = Cryptographer.DESDecrypt(userdata, key, iv);
            string deUserId    = Cryptographer.DESDecrypt(userid, dataKey, iv);
            string deTimestamp = Cryptographer.DESDecrypt(timestamp, dataKey, iv);
            string deMobile    = Cryptographer.DESDecrypt(mobile, dataKey, iv);
            string deEmail     = Cryptographer.DESDecrypt(email, dataKey, iv);

            if (string.IsNullOrWhiteSpace(dataKey) ||
                string.IsNullOrWhiteSpace(deUserId) ||
                string.IsNullOrWhiteSpace(deTimestamp))
            {
                Response.Write("fail,请求参数无效");
                Response.End();
            }

            DateTime time = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)).Add(new TimeSpan(long.Parse(deTimestamp + "0000000")));
            TimeSpan span = DateTime.Now - time;

            if (span.TotalSeconds > 60)
            {
                Response.Write("fail,请求已过期");
                Response.End();
            }

            // 注册用户,与微信类似,将deUserId写到aspnet_Users的CCBOpenId字段上
            // success,将在海美生活注册一个新的用户,与userid关联
            IUser user;
            bool  isExists = UserHelper.CreateCcbUsersMemberUsersInRoles(deUserId, deMobile, deEmail, UserHelper.GenerateSalt(), GetProvinceId(), out user);

            if (isExists)
            {
                Response.Write("fail,用户已存在");
                Response.End();
            }

            if (user != null)
            {
                Response.Write("success");
                Response.End();
            }
            // fail,返回原因
            Response.Write("fail,创建用户失败");
            Response.End();
        }
Ejemplo n.º 2
0
        private void Login()
        {
            string userid    = Request["userid"];
            string userdata  = Request["userdata"];
            string timestamp = Request["timestamp"];
            string source    = Request["source"];

            if (string.IsNullOrWhiteSpace(userid) ||
                string.IsNullOrWhiteSpace(userdata) ||
                string.IsNullOrWhiteSpace(timestamp) ||
                string.IsNullOrWhiteSpace(source))
            {
                Response.Write("fail,缺少必要参数");
                Response.End();
            }

            string key = ConfigurationManager.AppSettings["Key_CCB"];
            string iv  = ConfigurationManager.AppSettings["IV_CCB"];

            string dataKey     = Cryptographer.DESDecrypt(userdata, key, iv);
            string deUserId    = Cryptographer.DESDecrypt(userid, dataKey, iv);
            string deTimestamp = Cryptographer.DESDecrypt(timestamp, dataKey, iv);

            if (string.IsNullOrWhiteSpace(dataKey) ||
                string.IsNullOrWhiteSpace(deUserId) ||
                string.IsNullOrWhiteSpace(deTimestamp))
            {
                Response.Write("fail,请求参数无效");
                Response.End();
            }

            DateTime time = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)).Add(new TimeSpan(long.Parse(deTimestamp + "0000000")));
            TimeSpan span = DateTime.Now - time;

            if (span.TotalSeconds > 60)
            {
                Response.Write("fail,请求已过期");
                Response.End();
            }

            Member member = Users.GetUserByCcbOpenId(deUserId) as Member;

            if (member == null)
            {
                // fail,返回原因
                Response.Write("fail,用户不存在");
                Response.End();
            }

            System.Web.HttpCookie authCookie = System.Web.Security.FormsAuthentication.GetAuthCookie(member.Username, false);
            IUserCookie           userCookie = member.GetUserCookie();

            userCookie.WriteCookie(authCookie, 30, false);
            ShoppingCartInfo cookieShoppingCart = ShoppingCartProcessor.GetCookieShoppingCart();

            HiContext.Current.User = member;
            if (cookieShoppingCart != null)
            {
                ShoppingCartProcessor.ConvertShoppingCartToDataBase(cookieShoppingCart);
                ShoppingCartProcessor.ClearCookieShoppingCart();
            }

            // 登录成功跳转到海美生活用户中心
            Response.Redirect("/User/UserDefault.aspx");
        }
Ejemplo n.º 3
0
        private void BalanceRecharge()
        {
            string userid    = Request["userid"];
            string userdata  = Request["userdata"];
            string timestamp = Request["timestamp"];
            string source    = Request["source"];
            string amount    = Request["amount"];
            string tradeno   = Request["tradeno"];

            if (string.IsNullOrWhiteSpace(userid) ||
                string.IsNullOrWhiteSpace(userdata) ||
                string.IsNullOrWhiteSpace(timestamp) ||
                string.IsNullOrWhiteSpace(source) ||
                string.IsNullOrWhiteSpace(amount) ||
                string.IsNullOrWhiteSpace(tradeno))
            {
                Response.Write("fail,缺少必要参数");
                Response.End();
            }

            string key = ConfigurationManager.AppSettings["Key_CCB"];
            string iv  = ConfigurationManager.AppSettings["IV_CCB"];

            string dataKey     = Cryptographer.DESDecrypt(userdata, key, iv);
            string deUserId    = Cryptographer.DESDecrypt(userid, dataKey, iv);
            string deTimestamp = Cryptographer.DESDecrypt(timestamp, dataKey, iv);
            string deAmount    = Cryptographer.DESDecrypt(amount, dataKey, iv);
            string deTradeno   = Cryptographer.DESDecrypt(tradeno, dataKey, iv);

            if (string.IsNullOrWhiteSpace(dataKey) ||
                string.IsNullOrWhiteSpace(deUserId) ||
                string.IsNullOrWhiteSpace(deTimestamp) ||
                string.IsNullOrWhiteSpace(deAmount) ||
                string.IsNullOrWhiteSpace(deTradeno))
            {
                Response.Write("fail,请求参数无效");
                Response.End();
            }

            DateTime time = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)).Add(new TimeSpan(long.Parse(deTimestamp + "0000000")));
            TimeSpan span = DateTime.Now - time;

            if (span.TotalSeconds > 60)
            {
                Response.Write("fail,请求已过期");
                Response.End();
            }

            decimal money = 0;

            if (!decimal.TryParse(deAmount, out money))
            {
                Response.Write("fail,充值金额只能是数值");
                Response.End();
            }

            money = money / 100;
            if (money <= 0 || money > 10000000m)
            {
                Response.Write("fail,充值金额必须大于0且小于等于1000万元");
                Response.End();
            }

            Member member = Users.GetUserByCcbOpenId(deUserId) as Member;

            if (member == null || !member.IsOpenBalance)
            {
                // fail,返回原因
                Response.Write("fail,该用户不存在或还没有开通预付款账户");
                Response.End();
            }

            deTradeno = "CCB" + deTradeno;//加上ccb前缀以区分是建行的充值。
            // 检查交易号是否重复
            if (MemberHelper.IsTradeNoExists(deTradeno))
            {
                Response.Write("fail,交易号已失效");
                Response.End();
            }

            BalanceDetailInfo balanceDetailInfo = new BalanceDetailInfo();

            balanceDetailInfo.UserId    = member.UserId;
            balanceDetailInfo.UserName  = member.Username;
            balanceDetailInfo.TradeDate = DateTime.Now;
            balanceDetailInfo.TradeType = TradeTypes.CcbRecharge;
            balanceDetailInfo.Income    = money;
            balanceDetailInfo.Balance   = money + member.Balance;
            balanceDetailInfo.Remark    = "建行预付款充值";
            balanceDetailInfo.InpourId  = deTradeno;

            // success: 充值成功,将金额充值到用户预存款帐户上
            if (MemberHelper.AddBalance(balanceDetailInfo, money))
            {
                //Response.Redirect("/User/UserDefault.aspx", true);
                Response.Write("success,充值成功");
                Response.End();
            }

            // fail,返回原因
            Response.Write("fail,充值失败,请稍后重试");
            Response.End();
        }