protected void Page_Load(object sender, EventArgs e)
        {
            string platform  = Request.QueryString["platform"];
            string channelID = Request.QueryString["channelID"];
            string loginKey  = Request.QueryString["loginkey"];

            if (string.IsNullOrEmpty(loginKey))
            {
                Response.Write(BuildAccount.buildLuaReturn(-1, "data error"));
                return;
            }
            if (string.IsNullOrEmpty(loginKey))
            {
                Response.Write(BuildAccount.buildLuaReturn(-1, "data error"));
                return;
            }
            if (string.IsNullOrEmpty(channelID))
            {
                Response.Write(BuildAccount.buildLuaReturn(-1, "data error"));
                return;
            }
            loginKey = Encoding.Default.GetString(Convert.FromBase64String(loginKey));
            string decryptStr = AESHelper.AESDecrypt(loginKey, AES_KEY);

            string[] subString = decryptStr.Split(':');
            if (subString.Length < 2)
            {
                Response.Write(BuildAccount.buildLuaReturn(-1, "data error"));
                return;
            }
            string token    = subString[0];
            string sign     = subString[1];
            string remoteIP = Request.ServerVariables.Get("Remote_Addr").ToString();

            string url = string.Format("http://zhibo.v.baidu.com/token/tokencheck/?token={0}&ip={1}&sign={2}", token, remoteIP, sign);

            byte[] bytes = HttpPost.Get(new Uri(url));
            if (bytes == null)
            {
                Response.Write(BuildAccount.buildLuaReturn(-2, "http error"));
                return;
            }
            string result = Encoding.UTF8.GetString(bytes);

            BaiduResult baiduResult = JsonHelper.ParseFromStr <BaiduResult>(result);

            if (baiduResult.result == 0)
            {
                checkAccount(baiduResult, channelID);
            }
            else
            {
                Response.Write(BuildAccount.buildLuaReturn(-3, "check error"));
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            string platform  = Request.Form["platform"];
            string acc       = Request.Form["acc"];
            string logintime = Request.Form["logintime"];
            string deviceID  = Request.Form["deviceID"];
            string channelID = Request.Form["channelID"];

            if (string.IsNullOrEmpty(platform))
            {
                Response.Write(Helper.buildLuaReturn(-1, "platform is empty"));
                return;
            }
            if (string.IsNullOrEmpty(acc))
            {
                Response.Write(Helper.buildLuaReturn(-1, "acc is empty"));
                return;
            }
            if (string.IsNullOrEmpty(logintime))
            {
                Response.Write(Helper.buildLuaReturn(-1, "logintime is empty"));
                return;
            }
            //if (string.IsNullOrEmpty(deviceID))
            //{
            //    Response.Write(Helper.buildLuaReturn(-1, "deviceID is empty"));
            //    return;
            //}

            //string rsakey = Encoding.Default.GetString(Convert.FromBase64String(loginkey));
            //rsakey = AESHelper.AESDecrypt(rsakey, AES_KEY);

            //string source = string.Format("username={0}&appkey=3f2fadb37dd503fe686cdfb33ab8c095&logintime={1}", acc, logintime);
            //if (Helper.checkMD5(source, sign))
            {
                string acc_table = "shuanglong_acc";
                string pwd       = Helper.getMD5("123456");
                //判断是否存在帐号
                if (MongodbAccount.Instance.KeyExistsBykey(acc_table, "acc", acc))
                {
                    //检测帐号是否能登陆
                    int retCode = tryLogin(acc, pwd, acc_table);
                    if (retCode == 0)
                    {
                        Random rd      = new Random();
                        int    randkey = rd.Next();
                        Dictionary <string, object> updata = new Dictionary <string, object>();
                        DateTime now = DateTime.Now;
                        updata["randkey"]  = randkey;
                        updata["lasttime"] = now.Ticks;
                        updata["lastip"]   = Request.ServerVariables.Get("Remote_Addr").ToString();
                        string strerr = MongodbAccount.Instance.ExecuteUpdate(acc_table, "acc", acc, updata);
                        if (strerr != "")
                        {
                            Response.Write(BuildAccount.buildLuaReturn(-11, "server error"));
                        }
                        else
                        {
                            RSAHelper rsa = new RSAHelper();
                            //rsa.setModulus(rsakey);

                            string clientkey = randkey.ToString() + ":" + now.Ticks.ToString();
                            Response.Write(BuildAccount.buildLuaReturn(0, AESHelper.AESEncrypt(clientkey, AES_KEY)));

                            Dictionary <string, object> savelog = new Dictionary <string, object>();
                            savelog["acc"]       = acc;
                            savelog["acc_real"]  = acc;
                            savelog["ip"]        = Request.ServerVariables.Get("Remote_Addr").ToString();
                            savelog["time"]      = now;
                            savelog["acc_dev"]   = deviceID;
                            savelog["channelID"] = channelID;
                            MongodbAccount.Instance.ExecuteInsert("LoginLog", savelog);
                        }
                    }
                    else
                    {
                        Response.Write(BuildAccount.buildLuaReturn(retCode, "acc error"));
                    }
                }
                else
                {
                    //注册新帐号
                    Random rd      = new Random();
                    int    randkey = rd.Next();
                    Dictionary <string, object> updata = new Dictionary <string, object>();
                    updata["acc"] = acc;
                    updata["pwd"] = pwd;
                    DateTime now = DateTime.Now;
                    updata["randkey"]     = randkey;
                    updata["lasttime"]    = now.Ticks;
                    updata["regedittime"] = now;
                    updata["regeditip"]   = Request.ServerVariables.Get("Remote_Addr").ToString();
                    updata["updatepwd"]   = false;
                    updata["platform"]    = platform;

                    string strerr = MongodbAccount.Instance.ExecuteStoreBykey(acc_table, "acc", acc, updata);
                    if (strerr != "")
                    {
                        Response.Write(BuildAccount.buildLuaReturn(-11, "server error"));
                    }
                    else
                    {
                        RSAHelper rsa = new RSAHelper();
                        //rsa.setModulus(rsakey);

                        string clientkey = randkey.ToString() + ":" + now.Ticks.ToString();
                        Response.Write(BuildAccount.buildLuaReturn(0, AESHelper.AESEncrypt(clientkey, AES_KEY)));

                        Dictionary <string, object> savelog = new Dictionary <string, object>();
                        savelog["acc"]       = acc;
                        savelog["acc_real"]  = acc;
                        savelog["ip"]        = Request.ServerVariables.Get("Remote_Addr").ToString();
                        savelog["time"]      = now;
                        savelog["acc_dev"]   = deviceID;
                        savelog["channelID"] = channelID;
                        MongodbAccount.Instance.ExecuteInsert("RegisterLog", savelog);

                        MongodbAccount.Instance.ExecuteInsert("LoginLog", savelog);
                    }
                }
            }
            //else
            //{
            //    Response.Write(Helper.buildLuaReturn(-2, "sign is error"));
            //    return;
            //}
        }
示例#3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                string platform = Request.Form["platform"];
                string loginKey = Request.Form["loginkey"];
                string deviceID = Request.Form["DeviceID"];
                if (string.IsNullOrEmpty(deviceID))
                {
                    deviceID = "";
                }
                if (string.IsNullOrEmpty(loginKey))
                {
                    Response.Write(BuildAccount.buildLuaReturn(-1, "data error"));
                    return;
                }
                string dataStr = Encoding.Default.GetString(Convert.FromBase64String(loginKey));
                dataStr = AESHelper.AESDecrypt(dataStr, AES_KEY);
                string[] data = dataStr.Split(':');
                if (data.Length < 3)
                {
                    Response.Write(BuildAccount.buildLuaReturn(-2, "data error"));
                    return;
                }

                string acc    = data[0];
                string pwd    = data[1];
                string rsakey = data[2];

                //帐号表
                string acc_table = "cgamebt_acc";//ConfigurationManager.AppSettings["acc_cgamebt"];

                //List<IMongoQuery> imqs = new List<IMongoQuery>();
                //imqs.Add(Query.EQ("acc", acc));
                //imqs.Add(Query.EQ("platform", platform));

                //判断是否存在帐号
                if (MongodbAccount.Instance.KeyExistsBykey(acc_table, "acc", acc))
                {
                    //检测帐号是否能登陆
                    int retCode = tryLogin(acc, pwd, acc_table);
                    if (retCode == 0)
                    {
                        Random rd      = new Random();
                        int    randkey = rd.Next();
                        Dictionary <string, object> updata = new Dictionary <string, object>();
                        DateTime now = DateTime.Now;
                        updata["randkey"]  = randkey;
                        updata["lasttime"] = now.Ticks;
                        updata["lastip"]   = Request.ServerVariables.Get("Remote_Addr").ToString();
                        string strerr = MongodbAccount.Instance.ExecuteUpdate(acc_table, "acc", acc, updata);
                        if (strerr != "")
                        {
                            Response.Write(BuildAccount.buildLuaReturn(-11, "server error"));
                        }
                        else
                        {
                            RSAHelper rsa = new RSAHelper();
                            rsa.setModulus(rsakey);

                            string clientkey = randkey.ToString() + ":" + now.Ticks.ToString();
                            Response.Write(BuildAccount.buildLuaReturn(0, AESHelper.AESEncrypt(clientkey, AES_KEY)));

                            Dictionary <string, object> savelog = new Dictionary <string, object>();
                            savelog["acc"]      = acc;
                            savelog["acc_real"] = acc;
                            savelog["ip"]       = Request.ServerVariables.Get("Remote_Addr").ToString();
                            savelog["time"]     = now;
                            savelog["DeviceID"] = deviceID;
                            MongodbAccount.Instance.ExecuteInsert("LoginLog", savelog);
                        }
                    }
                    else
                    {
                        Response.Write(BuildAccount.buildLuaReturn(retCode, "acc error"));
                    }
                }
                else
                {
                    //注册新帐号
                    Random rd      = new Random();
                    int    randkey = rd.Next();
                    Dictionary <string, object> updata = new Dictionary <string, object>();
                    updata["acc"] = acc;
                    updata["pwd"] = pwd;
                    DateTime now = DateTime.Now;
                    updata["randkey"]     = randkey;
                    updata["lasttime"]    = now.Ticks;
                    updata["regedittime"] = now;
                    updata["regeditip"]   = Request.ServerVariables.Get("Remote_Addr").ToString();
                    updata["updatepwd"]   = false;
                    updata["platform"]    = platform;

                    string strerr = MongodbAccount.Instance.ExecuteStoreBykey(acc_table, "acc", acc, updata);
                    if (strerr != "")
                    {
                        Response.Write(BuildAccount.buildLuaReturn(-11, "server error"));
                    }
                    else
                    {
                        RSAHelper rsa = new RSAHelper();
                        rsa.setModulus(rsakey);

                        string clientkey = randkey.ToString() + ":" + now.Ticks.ToString();
                        Response.Write(BuildAccount.buildLuaReturn(0, AESHelper.AESEncrypt(clientkey, AES_KEY)));

                        Dictionary <string, object> savelog = new Dictionary <string, object>();
                        savelog["acc"]      = acc;
                        savelog["acc_real"] = acc;
                        savelog["ip"]       = Request.ServerVariables.Get("Remote_Addr").ToString();
                        savelog["time"]     = now;
                        savelog["DeviceID"] = deviceID;
                        MongodbAccount.Instance.ExecuteInsert("LoginLog", savelog);
                    }
                }
            }
            catch (Exception ex)
            {
                Response.Write(BuildAccount.buildLuaReturn(-1, ex.Message));
            }
        }