Ejemplo n.º 1
0
        protected override SHaiRequestInfo ResolveRequestInfo(ArraySegment <byte> header, byte[] bodyBuffer, int offset, int length)
        {
            SHaiRequestInfo request = new SHaiRequestInfo();

            request.FixedContent = header.Array.Take(2).ToArray();
            request.MessageType  = header.Array.ToArray()[2];
            byte[] data = bodyBuffer.Skip(offset).Take(length).ToArray();
            if (request.MessageType == 3)
            {
                request.Key  = "ENERGYDATA";
                request.Data = AESHelper.AESDecrypt(data, Runtime.m_AESValue, Runtime.m_AESValue);
            }
            else
            {
                if (request.MessageType == 1)
                {
                    request.Key = "VALIDATE";
                }
                else
                {
                    request.Key = "HEARTBEAT";
                }

                request.Data = Encoding.UTF8.GetString(data);
            }


            return(request);
        }
        void UpdateAccount(Dictionary <string, object> cinfo, string opSrc)
        {
            string acc = cinfo["n1"].ToString();

            if (string.IsNullOrEmpty(acc))
            {
                Response.Write("err_data_error");//号码错误
                return;
            }

            string[] field = { "pwd" };
            Dictionary <string, object> data = MongodbAccount.Instance.ExecuteGetBykey("AccountTable", "acc", acc, field);

            if (data == null)
            {
                Response.Write("err_not_acc");//找不到账号
            }
            else
            {
                // 玩家账号密码不能在游戏客户端修改,但可以通过API接口来改
                if (opSrc != CC.RESET_MODIFY_BY_API)
                {
                    DyOpModifyPlayerPwd dy = new DyOpModifyPlayerPwd();
                    bool canModify         = dy.canModifyPwd(acc);
                    if (!canModify)
                    {
                        Response.Write("err_cannot_modify"); // 不能修改密码
                        return;
                    }

                    string oldpwd = AESHelper.AESDecrypt(cinfo["n2"].ToString(), AES_KEY);//password
                    if (oldpwd != data["pwd"].ToString())
                    {
                        Response.Write("err_pwd_error");//验证码错误
                        return;
                    }
                }

                string spwd = AESHelper.AESDecrypt(cinfo["n3"].ToString(), AES_KEY); //password
                if (spwd.Length != 32)                                               //md5
                {
                    Response.Write("err_pwd_error");                                 //密码错误
                    return;
                }

                Dictionary <string, object> updata = new Dictionary <string, object>();
                updata["pwd"]       = spwd;
                updata["updatepwd"] = true;
                string ret = MongodbAccount.Instance.ExecuteUpdate("AccountTable", "acc", acc, updata);
                if (ret == "")
                {
                    Response.Write("err_success");
                }
                else
                {
                    Response.Write("err_system_error");
                }
            }
        }
Ejemplo n.º 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string phoneNum = Request.QueryString["phonenum"];

            if (string.IsNullOrEmpty(phoneNum))
            {
                Response.Write(Helper.buildLuaReturn(-2, "err_not_phone"));//号码错误
                return;
            }
            string phoneCode = Request.QueryString["phonecode"];

            if (string.IsNullOrEmpty(phoneCode))
            {
                Response.Write(Helper.buildLuaReturn(-2, "err_not_phone"));//号码错误
                return;
            }
            phoneNum  = Encoding.Default.GetString(Convert.FromBase64String(phoneNum));
            phoneNum  = AESHelper.AESDecrypt(phoneNum, AES_KEY);  //aes解密
            phoneCode = Encoding.Default.GetString(Convert.FromBase64String(phoneCode));
            phoneCode = AESHelper.AESDecrypt(phoneCode, AES_KEY); //aes解密

            List <IMongoQuery> lmq = new List <IMongoQuery>();

            lmq.Add(Query.EQ("phoneNum", phoneNum));
            lmq.Add(Query.EQ("phoneCode", phoneCode));

            Dictionary <string, object> data = MongodbAccount.Instance.ExecuteGetByQuery("BaiduPhoneCode", Query.And(lmq), new string[] { "lastSendTime" });

            if (data == null)
            {
                Response.Write(Helper.buildLuaReturn(-2, "err_not_phone"));//号码错误
                return;
            }
            //获取帐号信息
            List <string> accounts = getAccountInfos(phoneNum);

            //没有帐号
            if (accounts.Count == 0)
            {
                Response.Write(Helper.buildLuaReturn(-2, "err_not_phone"));//号码错误
                return;
            }
            else
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("local ret = {{}};");
                sb.Append("ret.code = 0;");
                sb.Append("ret.msg = \"\";");
                sb.Append("ret.data = {{}};");
                for (int i = 0; i < accounts.Count; i++)
                {
                    sb.AppendFormat("ret.data[{0}] = {{acc=\"{1}\"}};", i + 1, accounts[i]);
                }
                sb.Append("return ret;");
                Response.Write(sb.ToString());
            }
        }
Ejemplo n.º 4
0
 private void FormSetup_Load(object sender, EventArgs e)
 {
     if (!(ConfigurationManager.AppSettings["RunTime"] == null || ConfigurationManager.AppSettings["RunTime"] == "0"))
     {
         comboBoxDatabase.Items.Add(AESHelper.AESDecrypt(ConfigurationManager.AppSettings["DatabaseName"].ToString(), "adsfadsfadfadsfasasdfads"));
         textBoxDbUser.Text = AESHelper.AESDecrypt(ConfigurationManager.AppSettings["DatabaseUser"].ToString(), "adsfadsfadfadsfasasdfads");
         textBoxDBPwd.Text  = AESHelper.AESDecrypt(ConfigurationManager.AppSettings["DatabasePassword"].ToString(), "adsfadsfadfadsfasasdfads");
     }
 }
        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"));
            }
        }
Ejemplo n.º 6
0
        public void TestAES()
        {
            var str = "123456@xs";

            str = AESHelper.AESEncrypt(str);
            str = AESHelper.AESDecrypt(str);

            var key = GuidTool.GetGuid();

            str = AESHelper.AESEncrypt(str, key);
            str = AESHelper.AESDecrypt(str, key);
        }
Ejemplo n.º 7
0
        void UpdateAccount(Dictionary <string, object> cinfo)
        {
            string acc = cinfo["n1"].ToString();

            if (string.IsNullOrEmpty(acc))
            {
                Response.Write("err_data_error");//号码错误
                return;
            }

            string[] field = { "pwd" };
            Dictionary <string, object> data = MongodbAccount.Instance.ExecuteGetBykey("AccountTable", "acc", acc, field);

            if (data == null)
            {
                Response.Write("err_not_acc");//找不到账号
            }
            else
            {
                string oldpwd = AESHelper.AESDecrypt(cinfo["n2"].ToString(), AES_KEY);//password
                if (oldpwd != data["pwd"].ToString())
                {
                    Response.Write("err_pwd_error");//验证码错误
                    return;
                }

                string spwd = AESHelper.AESDecrypt(cinfo["n3"].ToString(), AES_KEY); //password
                if (spwd.Length != 32)                                               //md5
                {
                    Response.Write("err_pwd_error");                                 //密码错误
                    return;
                }

                Dictionary <string, object> updata = new Dictionary <string, object>();
                updata["pwd"]       = spwd;
                updata["updatepwd"] = true;
                string ret = MongodbAccount.Instance.ExecuteUpdate("AccountTable", "acc", acc, updata);
                if (ret == "")
                {
                    Response.Write("err_success");
                }
                else
                {
                    Response.Write("err_system_error");
                }
            }
        }
        void UpdateAccount(Dictionary <string, object> cinfo)
        {
            string strphone = cinfo["n1"].ToString();

            if (strphone.Length != 11 || !Regex.IsMatch(strphone, @"^\d{11}$"))
            {
                Response.Write("err_not_phone");//号码错误
                return;
            }

            string[] field = { "acc", "pwdcode" };
            Dictionary <string, object> data = MongodbAccount.Instance.ExecuteGetBykey("AccountTable", "bindPhone", strphone, field);

            if (data == null || data.Count != 2)
            {
                Response.Write("err_not_bind");//未绑定
            }
            else
            {
                if (cinfo["n2"].ToString() != data["pwdcode"].ToString())
                {
                    Response.Write("err_code_error");//验证码错误
                    return;
                }

                string spwd = AESHelper.AESDecrypt(cinfo["n3"].ToString(), AES_KEY); //password
                if (spwd.Length != 32)                                               //md5
                {
                    Response.Write("err_pwd_error");                                 //密码错误
                    return;
                }

                Dictionary <string, object> updata = new Dictionary <string, object>();
                updata["pwd"]     = spwd;
                updata["pwdcode"] = "";
                string ret = MongodbAccount.Instance.ExecuteUpdate("AccountTable", "acc", data["acc"].ToString(), updata);
                if (ret == "")
                {
                    sendMsgToPhone(strphone, data["acc"].ToString());
                    Response.Write("err_success");
                }
                else
                {
                    Response.Write("err_system_error");
                }
            }
        }
Ejemplo n.º 9
0
        public User GetUser()
        {
            string userid = Cookie.Default.GetCookieValue("login-uid");

            if (!string.IsNullOrEmpty(userid))
            {
                return(null);
            }
            userid = AESHelper.AESDecrypt(MyEncoding.UrlDecode(userid));

            User user = Cache.Default.Get <User>(userid);

            if (user == null)
            {
                user = GetUserById(userid);
            }

            return(user);
        }
Ejemplo n.º 10
0
        protected string GetJson(string methodName, Dictionary <string, string> args, bool decode = true)
        {
            var queryUrl = BaseUri + "/" +
                           methodName + "?" + args.ToQueryString();

            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(queryUrl);

            request.Method  = "GET";
            request.Timeout = 5000;
            try {
                using (HttpWebResponse respose = (HttpWebResponse)request.GetResponse()) {
                    using (StreamReader sr = new StreamReader(respose.GetResponseStream(), Encoder)) {
                        string json = sr.ReadToEnd();
                        //// base 64 解码
                        //{
                        //var base64EncodedBytes = System.Convert.FromBase64String(json);
                        //json =  System.Text.Encoding.UTF8.GetString(base64EncodedBytes);
                        //}
                        //// aes解码
                        //{

                        // clsCrypto aes = new clsCrypto();
                        //  aes.IV = "this is your IV";     // your IV
                        //  aes.KEY = "this is your KEY";    // your KEY
                        //  json = aes.Decrypt(json, CipherMode.CBC);
                        //}
                        if (decode)
                        {
                            // 解密
                            AESHelper helper = new AESHelper();
                            json = helper.AESDecrypt(json);
                        }
                        return(json);
                    }
                }
            } catch (Exception e) {
                //log.Fatal("HttpService Fail:", e);
                throw;
            }
        }
Ejemplo n.º 11
0
        void CheckAccount(Dictionary <string, object> data)
        {
            string sacc = data["n1"].ToString();                                //account
            string spwd = AESHelper.AESDecrypt(data["n2"].ToString(), AES_KEY); //password

            if (spwd.Length != 32)                                              //md5
            {
                buildReturnMsg("-14");                                          //pwd error
                return;
            }

            string platform = Request.Params["platform"];

            string table = ConfigurationManager.AppSettings["acc_" + platform];

            if (string.IsNullOrEmpty(table))
            {
                buildReturnMsg("-15");//platform error
                return;
            }

            string retacc  = string.Empty;
            int    retCode = tryLogin(sacc, spwd, table, ref retacc);

            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();

                if (string.IsNullOrEmpty(retacc))
                {
                    retacc             = Guid.NewGuid().ToString().Replace("-", "");
                    updata["acc_real"] = retacc;
                }

                string strerr = MongodbAccount.Instance.ExecuteUpdate(table, "acc", sacc, updata);
                if (strerr != "")
                {
                    buildReturnMsg("-11");//server error
                }
                else
                {
                    RSAHelper rsa = new RSAHelper();
                    rsa.setModulus(data["n3"].ToString());

                    string clientkey = randkey.ToString() + ":" + now.Ticks.ToString();
                    buildReturnMsg(rsa.RSAEncryptStr(clientkey), true, retacc);//login success

                    string channelID = null;
                    if (data.ContainsKey("n4"))
                    {
                        channelID = data["n4"].ToString();
                    }

                    Dictionary <string, object> savelog = new Dictionary <string, object>();
                    savelog["acc"]      = sacc;
                    savelog["acc_real"] = retacc;
                    string deviceID = Request.Params["deviceID"];
                    if (!string.IsNullOrEmpty(deviceID))
                    {
                        savelog["acc_dev"] = deviceID;
                    }
                    savelog["ip"]      = Request.ServerVariables.Get("Remote_Addr").ToString();
                    savelog["time"]    = now;
                    savelog["channel"] = channelID;
                    MongodbAccount.Instance.ExecuteInsert("LoginLog", savelog);
                }
            }
            else
            {
                // ReturnMsg("-10");//acc or pwd error
                buildReturnMsg(retCode.ToString());
            }
        }
Ejemplo n.º 12
0
    public override string doDyop(object param)
    {
        ParamPlayerSelfRegAcc p = (ParamPlayerSelfRegAcc)param;
        int code = p.isParamValid();

        if (code != 0)
        {
            return(returnMsg(code.ToString()));
        }

        Dictionary <string, object> data = p.getData();

        string acc = Convert.ToString(data["n1"]);

        if (!Regex.IsMatch(acc, Exp.ACCOUNT_PLAYER))
        {
            return(returnMsg(HttpRetCode.RET_ACC_ERROR.ToString()));
        }

        string pwd = AESHelper.AESDecrypt(data["n2"].ToString(), AES_KEY);

        if (pwd.Length != 32)
        {
            return(returnMsg(HttpRetCode.RET_PWD_ERROR.ToString()));
        }

        MySqlDbServer sqlDb = new MySqlDbServer(CC.MYSQL_IP);

        string cmd = string.Format(SQL_CMD, TableName.GM_ACCOUNT, p.m_gmId - ConstDef.GM_ID_OFFSET);
        Dictionary <string, object> agentData = sqlDb.queryOne(cmd, MySqlDbName.DB_XIANXIA);

        if (agentData == null)
        {
            return(returnMsg(HttpRetCode.RET_AGENT_ACC_ERROR.ToString()));
        }

        int accType = Convert.ToInt32(agentData["accType"]);

        if (accType != AccType.ACC_AGENCY) // Íæ¼ÒÕ˺ÅÖ»ÄÜÒÔ´úÀíºÅ×÷Ϊ´´½¨Õß
        {
            return(returnMsg(HttpRetCode.RET_AGENT_ACC_ERROR.ToString()));
        }

        string creator    = Convert.ToString(agentData["acc"]);
        string createCode = Convert.ToString(agentData["createCode"]);

        code = createAccToMySql(acc, creator, createCode, sqlDb);
        if (code == HttpRetCode.RET_ACC_EXISTS || code == 0)
        {
            RSAHelper rsa = new RSAHelper();
            rsa.setModulus(Convert.ToString(data["n3"]));
            string clientKey = "";
            code = createAccToMongo(acc, pwd, p.m_ip, sqlDb, ref clientKey);

            if (code == 0)
            {
                return(returnMsg(rsa.RSAEncryptStr(clientKey), true));
            }
        }

        return(returnMsg(code.ToString()));
    }
Ejemplo n.º 13
0
        static void Main()
        {
            // 设置应用程序处理异常方式:ThreadException处理
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
            //处理UI线程异常
            Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
            //处理非UI线程异常
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            GlobleVariable.RunLog = new StringBuilder();
            int runTime      = 0;
            var firstRunBool = int.TryParse(ConfigurationManager.AppSettings["runTime"].ToString(), out runTime);

            GlobleVariable.InfoLogger  = log4net.LogManager.GetLogger("loginfo");
            GlobleVariable.ErrorLogger = log4net.LogManager.GetLogger("logerror");

            log4net.Config.XmlConfigurator.Configure();



            int BackupTime = 0;

            if (int.TryParse(ConfigurationManager.AppSettings["BackupTime"].ToString(), out BackupTime))
            {
                GlobleVariable.BackupTime = BackupTime;
            }
            else
            {
                GlobleVariable.BackupTime = 1;
            }

            GlobleVariable.DatabaseAddress = ConfigurationManager.AppSettings["DatabaseAddress"];
            if (string.IsNullOrEmpty(GlobleVariable.DatabaseAddress))
            {
                GlobleVariable.DatabaseAddress = "127.0.0.1";
            }
            if (ConfigurationManager.AppSettings["RunTime"] == null || ConfigurationManager.AppSettings["RunTime"] == "0")
            {
                var setup = new FormSetup();
                setup.ShowDialog();
            }
            else
            {
                GlobleVariable.DatabaseAddress  = ConfigurationManager.AppSettings["DatabaseAddress"].ToString();
                GlobleVariable.DatabaseName     = AESHelper.AESDecrypt(ConfigurationManager.AppSettings["DatabaseName"].ToString(), "adsfadsfadfadsfasasdfads");
                GlobleVariable.DatabaseUser     = AESHelper.AESDecrypt(ConfigurationManager.AppSettings["DatabaseUser"], "adsfadsfadfadsfasasdfads");
                GlobleVariable.DatabasePassword = AESHelper.AESDecrypt(ConfigurationManager.AppSettings["DatabasePassword"], "adsfadsfadfadsfasasdfads");

                int outLocalKeepDay = -1;
                if (int.TryParse(ConfigurationManager.AppSettings["LocalKeepDay"], out outLocalKeepDay))
                {
                    GlobleVariable.LocalKeeyDay = outLocalKeepDay;
                }
                else
                {
                    GlobleVariable.LocalKeeyDay = -1;
                }



                FluentScheduler.JobManager.Initialize(new BackupJobFactory());
            }

            //DateTime lasttime = DateTime.Now;
            //DateTime.TryParse(ConfigurationManager.AppSettings["LastBackupTime"].ToString(), out lasttime);
            //GlobleVariable.LastBackupTime = lasttime;

            GlobleVariable.StartTime     = DateTime.Now;
            GlobleVariable.FangyouClient = ConfigurationManager.AppSettings["FangyouClient"];
            GlobleVariable.FangyouVer    = ConfigurationManager.AppSettings["FangyouVer"];



            Application.Run(new FormMain());
        }
Ejemplo n.º 14
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));
            }
        }
        void BindAccount(Dictionary <string, object> data)
        {
            string HardwareID = data["n4"].ToString();//HardwareID

            if (string.IsNullOrEmpty(HardwareID))
            {
                buildReturnMsg("-12");//account error
                return;
            }

            string platform = Request.Params["platform"];

            string table = ConfigurationManager.AppSettings["acc_" + platform];

            if (string.IsNullOrEmpty(table))
            {
                buildReturnMsg("-15");//platform error
                return;
            }

            var retdata = MongodbAccount.Instance.ExecuteGetByQuery(table, Query.EQ("acc_dev", HardwareID), new string[] { "acc", "lasttime" });

            if (retdata != null)
            {
                string sacc = data["n1"].ToString();//account

                string pattern = @"^[0-9a-zA-Z]{6,30}$";

                if (!Regex.IsMatch(sacc, pattern))
                {
                    buildReturnMsg("-12");//account error
                    return;
                }

                //判断此账号已经被注册
                if (MongodbAccount.Instance.KeyExistsBykey(table, "acc", sacc))
                {
                    buildReturnMsg("-13");//account exists
                    return;
                }

                string spwd = AESHelper.AESDecrypt(data["n2"].ToString(), AES_KEY); //password
                if (spwd.Length != 32)                                              //md5
                {
                    buildReturnMsg("-14");                                          //pwd error
                    return;
                }

                //判断是否绑定过
                if (retdata.ContainsKey("acc"))
                {
                    string findacc = retdata["acc"].ToString();
                    if (!string.IsNullOrEmpty(findacc))
                    {
                        buildReturnMsg("-13");//account is error
                        return;
                    }
                }

                //校验玩家必须登录成功后才能绑定
                string token = data["n3"].ToString();
                if (retdata.ContainsKey("lasttime"))
                {
                    string lasttime = retdata["lasttime"].ToString();
                    lasttime = AESHelper.MD5Encrypt(lasttime + ACC_CHECK);
                    token    = AESHelper.AESDecrypt(token, ACC_CHECK);
                    if (token != lasttime || string.IsNullOrEmpty(lasttime))
                    {
                        buildReturnMsg("-14");//pwd error
                        return;
                    }
                }
                else
                {
                    buildReturnMsg("-14");//pwd error
                    return;
                }


                Dictionary <string, object> updata = new Dictionary <string, object>();
                DateTime now = DateTime.Now;
                updata["acc"]      = sacc;
                updata["pwd"]      = spwd;
                updata["bindtime"] = now;
                string strerr = MongodbAccount.Instance.ExecuteUpdate(table, "acc_dev", HardwareID, updata);
                if (strerr != "")
                {
                    buildReturnMsg("-11");//server error
                }
                else
                {
                    buildReturnMsg("ok", true);//login success

                    Dictionary <string, object> savelog = new Dictionary <string, object>();
                    savelog["acc_dev"] = HardwareID;
                    savelog["acc"]     = sacc;
                    savelog["time"]    = now;
                    savelog["ip"]      = Request.ServerVariables.Get("Remote_Addr").ToString();
                    MongodbAccount.Instance.ExecuteInsert("BindLog", savelog);
                }
            }
            else
            {
                // ReturnMsg("-10");//acc or pwd error
                buildReturnMsg("-12");
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            string platform  = Request.Form["platform"];
            string acc       = Request.Form["acc"];
            string logintime = Request.Form["logintime"];
            string sign      = Request.Form["sign"];
            string loginkey  = Request.Form["loginkey"];

            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(sign))
            {
                Response.Write(Helper.buildLuaReturn(-1, "sign is empty"));
                return;
            }
            if (string.IsNullOrEmpty(loginkey))
            {
                Response.Write(Helper.buildLuaReturn(-1, "loginkey 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 = "wanke_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;
                            string deviceID = Request.Params["deviceID"];
                            if (!string.IsNullOrEmpty(deviceID))
                            {
                                savelog["acc_dev"] = deviceID;
                            }
                            savelog["ip"]   = Request.ServerVariables.Get("Remote_Addr").ToString();
                            savelog["time"] = now;
                            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;
                        string deviceID = Request.Params["deviceID"];
                        if (!string.IsNullOrEmpty(deviceID))
                        {
                            savelog["acc_dev"] = deviceID;
                        }
                        savelog["ip"]   = Request.ServerVariables.Get("Remote_Addr").ToString();
                        savelog["time"] = now;
                        MongodbAccount.Instance.ExecuteInsert("LoginLog", savelog);
                    }
                }
            }
            else
            {
                Response.Write(Helper.buildLuaReturn(-2, "sign is error"));
                return;
            }
        }
Ejemplo n.º 17
0
        void CheckAccount(Dictionary <string, object> data)
        {
            string sacc = data["n1"].ToString();                                //account
            string spwd = AESHelper.AESDecrypt(data["n2"].ToString(), AES_KEY); //password

            if (spwd.Length != 32)                                              //md5
            {
                buildReturnMsg("-14");                                          //pwd error
                return;
            }

            string platform = Request.Params["platform"];

            string table = ConfigurationManager.AppSettings["acc_" + platform];

            if (string.IsNullOrEmpty(table))
            {
                buildReturnMsg("-15");//platform error
                return;
            }

            string pattern = @"^[0-9a-zA-Z]{6,30}$";

            if (!Regex.IsMatch(sacc, pattern))
            {
                buildReturnMsg("-15");//account error
                return;
            }
            string             remoteIP = Common.Helper.getRemoteIP(Request);
            List <IMongoQuery> imqs     = new List <IMongoQuery>();

            imqs.Add(Query.EQ("acc", sacc));
            imqs.Add(Query.EQ("pwd", spwd));
            int retCode = tryLogin(sacc, spwd, table);

            //if (MongodbAccount.Instance.KeyExistsByQuery(table, Query.And(imqs)))
            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;
                //List<IMongoQuery> imqs2 = new List<IMongoQuery>();
                //imqs2.Add(Query.EQ("acc", sacc));
                //imqs2.Add(Query.EQ("platform", Platform));
                updata["lastip"] = remoteIP;
                string strerr = MongodbAccount.Instance.ExecuteUpdate(table, "acc", sacc, updata);
                if (strerr != "")
                {
                    buildReturnMsg("-11");//server error
                }
                else
                {
                    RSAHelper rsa = new RSAHelper();
                    rsa.setModulus(data["n3"].ToString());

                    string clientkey = randkey.ToString() + ":" + now.Ticks.ToString();
                    buildReturnMsg(rsa.RSAEncryptStr(clientkey), true);//login success

                    string channelID = null;
                    if (data.ContainsKey("n4"))
                    {
                        channelID = data["n4"].ToString();
                    }

                    Dictionary <string, object> savelog = new Dictionary <string, object>();
                    savelog["acc"]      = sacc;
                    savelog["acc_real"] = sacc;
                    string deviceID = Request.Params["deviceID"];
                    if (!string.IsNullOrEmpty(deviceID))
                    {
                        savelog["acc_dev"] = deviceID;
                    }
                    savelog["ip"]      = remoteIP;
                    savelog["time"]    = now;
                    savelog["channel"] = channelID;
                    MongodbAccount.Instance.ExecuteInsert("LoginLog", savelog);
                }
            }
            else
            {
                // ReturnMsg("-10");//acc or pwd error
                buildReturnMsg(retCode.ToString());
            }
        }
        void CheckAccount(Dictionary <string, object> data)
        {
            string sacc = data["n1"].ToString();                                //account
            string spwd = AESHelper.AESDecrypt(data["n2"].ToString(), AES_KEY); //password

            if (spwd.Length != 32)                                              //md5
            {
                ReturnLuaMsg("-14");                                            //pwd error
                return;
            }

            string platform = Request.Params["platform"];

            string table = ConfigurationManager.AppSettings["acc_" + platform];

            if (string.IsNullOrEmpty(table))
            {
                ReturnLuaMsg("-15");//platform error
                return;
            }

            List <IMongoQuery> imqs = new List <IMongoQuery>();

            imqs.Add(Query.EQ("acc", sacc));
            imqs.Add(Query.EQ("pwd", spwd));
            int retCode = tryLogin(sacc, spwd, table);

            //if (MongodbAccount.Instance.KeyExistsByQuery(table, Query.And(imqs)))
            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(table, "acc", sacc, updata);
                if (strerr != "")
                {
                    ReturnLuaMsg("-11");//server error
                }
                else
                {
                    string channelID = null;
                    if (data.ContainsKey("n4"))
                    {
                        channelID = data["n4"].ToString();
                    }

                    Dictionary <string, object> savelog = new Dictionary <string, object>();
                    savelog["acc"]      = sacc;
                    savelog["acc_real"] = sacc;
                    string deviceID = Request.Params["deviceID"];
                    if (!string.IsNullOrEmpty(deviceID))
                    {
                        savelog["acc_dev"] = deviceID;
                    }
                    savelog["ip"]      = Request.ServerVariables.Get("Remote_Addr").ToString();
                    savelog["time"]    = now;
                    savelog["channel"] = channelID;
                    MongodbAccount.Instance.ExecuteInsert("LoginLog", savelog);

                    string clientkey = randkey.ToString() + ":" + now.Ticks.ToString();
                    string loginKey  = AESHelper.AESEncrypt(clientkey, AES_KEY);
                    ReturnLuaMsg(loginKey, true);
                }
            }
            else
            {
                // ReturnMsg("-10");//acc or pwd error
                ReturnLuaMsg(retCode.ToString());
            }
        }
        void CheckAccount(Dictionary <string, object> data)
        {
            string platform = Request.Params["platform"];

            if (string.IsNullOrEmpty(platform))
            {
                buildReturnMsg("-1");//data error
                return;
            }

            string table = ConfigurationManager.AppSettings["acc_" + platform];

            if (string.IsNullOrEmpty(table))
            {
                buildReturnMsg("-15");//platform error
                return;
            }

            string acc_reg = data["n1"].ToString();//account

            string pattern = @"^[0-9a-zA-Z]{6,30}$";

            if (!Regex.IsMatch(acc_reg, pattern))
            {
                buildReturnMsg("-12");//account error
                return;
            }

            if (MongodbAccount.Instance.KeyExistsBykey(table, "acc", acc_reg))
            {
                buildReturnMsg("-12");//account exists
                return;
            }

            string spwd = AESHelper.AESDecrypt(data["n2"].ToString(), AES_KEY); //password

            if (spwd.Length != 32)                                              //md5
            {
                buildReturnMsg("-14");                                          //pwd error
                return;
            }

            Random rd      = new Random();
            int    randkey = rd.Next();
            Dictionary <string, object> updata = new Dictionary <string, object>();

            updata["acc"]      = acc_reg;
            updata["acc_real"] = Guid.NewGuid().ToString().Replace("-", "");
            updata["pwd"]      = spwd;
            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(table, "acc", acc_reg, updata);

            if (strerr != "")
            {
                buildReturnMsg("-11");//server error
            }
            else
            {
                RSAHelper rsa = new RSAHelper();
                rsa.setModulus(data["n3"].ToString());

                string clientkey = randkey.ToString() + ":" + now.Ticks.ToString();
                buildReturnMsg(rsa.RSAEncryptStr(clientkey), true, updata["acc_real"].ToString());//login success

                string channelID = null;
                if (data.ContainsKey("n4"))
                {
                    channelID = data["n4"].ToString();
                }

                Dictionary <string, object> savelog = new Dictionary <string, object>();
                savelog["acc_real"] = updata["acc_real"].ToString();
                savelog["acc"]      = acc_reg;
                string deviceID = Request.Params["deviceID"];
                if (!string.IsNullOrEmpty(deviceID))
                {
                    savelog["acc_dev"] = deviceID;
                }
                savelog["ip"]      = Request.ServerVariables.Get("Remote_Addr").ToString();
                savelog["time"]    = now;
                savelog["channel"] = channelID;
                MongodbAccount.Instance.ExecuteInsert("LoginLog", savelog);
                MongodbAccount.Instance.ExecuteInsert("RegisterLog", savelog);

                //渠道每日注册
                if (data.ContainsKey("n4"))
                {
                    MongodbAccount.Instance.ExecuteIncBykey("day_regedit", "date", DateTime.Now.Date, data["n4"].ToString(), 0);
                }
            }
        }
Ejemplo n.º 20
0
        void CheckAccount(Dictionary <string, object> data)
        {
            string platform = Request.Params["platform"];

            if (string.IsNullOrEmpty(platform))
            {
                ReturnMsg(HttpRetCode.RET_PARAM_NOT_VALID.ToString());//data error
                return;
            }

            string table = ConfigurationManager.AppSettings["acc_" + platform];

            if (string.IsNullOrEmpty(table))
            {
                ReturnMsg(HttpRetCode.RET_PLATFORM_ERROR.ToString());//platform error
                return;
            }

            string sacc = data["n1"].ToString();//account

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

            // string pattern = @"^[0-9a-zA-Z]{6,30}$";

            if (!Regex.IsMatch(sacc, Exp.ACCOUNT_PLAYER))
            {
                ReturnMsg(HttpRetCode.RET_ACC_ERROR.ToString());//account error
                return;
            }

            if (MongodbAccount.Instance.KeyExistsBykey(table, "acc", sacc))
            {
                ReturnMsg(HttpRetCode.RET_ACC_EXISTS.ToString());//account exists
                return;
            }

            string spwd = AESHelper.AESDecrypt(data["n2"].ToString(), AES_KEY); //password

            if (spwd.Length != 32)                                              //md5
            {
                ReturnMsg(HttpRetCode.RET_PWD_ERROR.ToString());                //pwd error
                return;
            }

            Random rd      = new Random();
            int    randkey = rd.Next();
            Dictionary <string, object> updata = new Dictionary <string, object>();

            updata["acc"] = sacc;
            updata["pwd"] = spwd;
            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(table, "acc", sacc, updata);

            if (strerr != "")
            {
                ReturnMsg(HttpRetCode.RET_DB_ERROR.ToString());//server error
            }
            else
            {
                RSAHelper rsa = new RSAHelper();
                rsa.setModulus(data["n3"].ToString());

                string clientkey = randkey.ToString() + ":" + now.Ticks.ToString();
                ReturnMsg(rsa.RSAEncryptStr(clientkey), true);//login success

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

                //渠道每日注册
                if (data.ContainsKey("n4"))
                {
                    MongodbAccount.Instance.ExecuteIncBykey("day_regedit", "date", DateTime.Now.Date, data["n4"].ToString(), 0);
                }
            }
        }
        void CheckAccount(Dictionary <string, object> data)
        {
            string sacc       = data["n1"].ToString();                                //account
            string sphonecode = AESHelper.AESDecrypt(data["n2"].ToString(), AES_KEY); //password

            string platform = Request.Params["platform"];

            string table = ConfigurationManager.AppSettings["acc_" + platform];

            if (string.IsNullOrEmpty(table))
            {
                ReturnLuaMsg("-15");//platform error
                return;
            }
            string remoteIP = Common.Helper.getRemoteIP(Request);
            int    retCode  = tryLogin(sacc, sphonecode, 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"]   = remoteIP;
                string strerr = MongodbAccount.Instance.ExecuteUpdate(table, "acc", sacc, updata);
                if (strerr != "")
                {
                    ReturnLuaMsg("-11");//server error
                }
                else
                {
                    string channelID = null;
                    if (data.ContainsKey("n4"))
                    {
                        channelID = data["n4"].ToString();
                    }

                    Dictionary <string, object> savelog = new Dictionary <string, object>();
                    savelog["acc"]      = sacc;
                    savelog["acc_real"] = sacc;
                    string deviceID = Request.Params["deviceID"];
                    if (!string.IsNullOrEmpty(deviceID))
                    {
                        savelog["acc_dev"] = deviceID;
                    }
                    savelog["ip"]      = remoteIP;
                    savelog["time"]    = now;
                    savelog["channel"] = channelID;
                    MongodbAccount.Instance.ExecuteInsert("LoginLog", savelog);

                    string clientkey = randkey.ToString() + ":" + now.Ticks.ToString();
                    string loginKey  = AESHelper.AESEncrypt(clientkey, AES_KEY);
                    ReturnLuaMsg(loginKey, true);
                }
            }
            else
            {
                // ReturnMsg("-10");//acc or pwd error
                ReturnLuaMsg(retCode.ToString());
            }
        }
        /// <summary>
        /// 描述:家校登陆
        /// <para>作    者:蔡亚康</para>
        /// <para>创建时间:2019-03-06</para>
        /// </summary>
        /// <param name="request">用户登陆的手机号和验证码等信息</param>
        /// <exception>
        /// 异常ID:2->手机号码在系统不存在
        /// 异常ID:1->验证码有误
        /// 异常ID:6->微信号已被其他手机号绑定
        /// 异常ID:7->用户信息数据解密失败
        /// </exception>
        /// <returns>登陆结果</returns>
        public StudentLoginResponse SignIn(StudentLoginRequest request)
        {
            TblHssPassport       passport = _repository.Value.GetByUserCode(request.Mobile);
            StudentLoginResponse result   = new StudentLoginResponse();

            //1、验证账户是否存在
            this.ValidateUserExist(passport);

            //2、短信验证码校验
            this.ValidateSmsCode(request.Mobile, request.SmsCode);

            //3、获取openid
            Code2SessionService wxService = new Code2SessionService();
            OpenIdResponse      openid    = wxService.GetOpenId(request.WxCode);


            //4、检查openid是否已经被其他手机号绑定
            TblHssPassport passport2 = _repository.Value.GetByOpenId(openid.OpenId);

            if (passport2 != null && passport2.OpenId == openid.OpenId && passport2.UserCode != request.Mobile)
            {
                throw new BussinessException(ModelType.Hss, 6);
            }

            //5、用户数据解密
            try
            {
                string  data       = AESHelper.AESDecrypt(request.EncryptedData, openid.Session_Key, request.Iv);
                JObject wxUserInfo = (JObject)JsonConvert.DeserializeObject(data);

                //检查返回值是否包含unionID,防止出现异常。
                JToken jtoke = null;
                if (wxUserInfo.TryGetValue("unionId", out jtoke))
                {
                    passport.UnionId = jtoke.ToString();
                }
                else
                {
                    LogWriter.Write(this, "解密数据没有unionID,原数据如下:" + GetDecryptData(request, openid), LoggerType.Warn);
                }
            }
            catch (Exception ex)
            {
                LogWriter.Write(this, "小程序解密失败,原数据如下:" + GetDecryptData(request, openid), LoggerType.Error);
                throw new BussinessException(ModelType.Hss, 7);
            }
            //获取到的unionID为空,有可能是用户未允许访问授权
            if (string.IsNullOrEmpty(passport.UnionId))
            {
                throw new BussinessException(ModelType.Hss, 8);
            }

            //6、绑定openid 并更新最新登陆信息,包括最新的openid
            passport.OpenId           = openid.OpenId;//openid.OpenId;   //如果在另外一个微信上登陆将会被新的替换
            passport.LastLoginIp      = passport.CurrentLoginIp;
            passport.LastLoginDate    = passport.CurrentLoginDate;
            passport.CurrentLoginIp   = request.IpAddress;
            passport.CurrentLoginDate = DateTime.Now;
            passport.LoginTimes       = passport.LoginTimes + 1;
            _repository.Value.Update(passport);

            //6、记录登陆日记
            AddOperationLog(passport);

            //7、返回登陆结果
            JwtTokenService tokenService = new JwtTokenService();

            result.Token = tokenService.CreateToken(passport);

            return(result);
        }
Ejemplo n.º 23
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string phoneNum = Request.QueryString["phonenum"];

            if (string.IsNullOrEmpty(phoneNum))
            {
                Response.Write(Helper.buildLuaReturn(-2, "err_not_phone"));//号码错误
                return;
            }
            phoneNum = Encoding.Default.GetString(Convert.FromBase64String(phoneNum));
            phoneNum = AESHelper.AESDecrypt(phoneNum, AES_KEY);//aes解密
            if (phoneNum.Length != 11 || !Regex.IsMatch(phoneNum, @"^\d{11}$"))
            {
                Response.Write(Helper.buildLuaReturn(-2, "err_not_phone"));//号码错误
                return;
            }

            int sendCount = 0;

            string[] field = { "lastSendTime", "sendCount" };
            Dictionary <string, object> data = MongodbAccount.Instance.ExecuteGetBykey("BaiduPhoneCode", "phoneNum", phoneNum, field);

            if (data != null)
            {
                DateTime last = DateTime.MinValue;
                if (data.ContainsKey("lastSendTime"))
                {
                    last = Convert.ToDateTime(data["lastSendTime"]).ToLocalTime();
                }
                DateTime now      = DateTime.Now;
                TimeSpan span     = now - last;
                int      interval = Convert.ToInt32(ConfigurationManager.AppSettings["send_interval"]);
                if (span.TotalSeconds < interval)
                {
                    Response.Write(Helper.buildLuaReturn(-3, "err_timecd"));//验证码cd时间
                    return;
                }

                if (data.ContainsKey("SendCount"))
                {
                    sendCount = Convert.ToInt32(data["SendCount"]);
                }

                if (last.DayOfYear != now.DayOfYear)
                {
                    sendCount = 0;
                }

                int limitCount = Convert.ToInt32(ConfigurationManager.AppSettings["send_count"]);
                if (sendCount >= limitCount)
                {
                    Response.Write(Helper.buildLuaReturn(-4, "err_maxcount"));//当日次数已满
                    return;
                }
            }

            string pwdcode = m_rd.Next(100000, 999999).ToString();

            Dictionary <string, object> savedata = new Dictionary <string, object>();

            savedata["sendCount"]    = ++sendCount;
            savedata["lastSendTime"] = DateTime.Now;
            savedata["phoneCode"]    = pwdcode;
            if (data == null)
            {
                savedata["phoneNum"] = phoneNum;
                MongodbAccount.Instance.ExecuteInsert("BaiduPhoneCode", savedata);
            }
            else
            {
                MongodbAccount.Instance.ExecuteUpdate("BaiduPhoneCode", "phoneNum", phoneNum, savedata);
            }

            string ret = sendMsgToPhone(phoneNum, pwdcode);

            Response.Write(Helper.buildLuaReturn(0, ret));
        }
Ejemplo n.º 24
0
        void CheckAccount(Dictionary <string, object> data)
        {
            string platform = Request.Params["platform"];

            if (string.IsNullOrEmpty(platform))
            {
                buildReturnMsg("-1");//data error
                return;
            }

            string table = ConfigurationManager.AppSettings["acc_" + platform];

            if (string.IsNullOrEmpty(table))
            {
                buildReturnMsg("-15");//platform error
                return;
            }

            string HardwareID = data["n1"].ToString();//HardwareID

            if (string.IsNullOrEmpty(HardwareID))
            {
                buildReturnMsg("-12");//account error
                return;
            }

            //特殊校验
            string spwd = AESHelper.AESDecrypt(data["n2"].ToString(), AES_KEY);//password

            spwd = spwd.Replace("\n", "");
            string tmp = AESHelper.AESEncrypt(AES_KEY + HardwareID + ACC_CHECK, ACC_CHECK);

            if (spwd != tmp)           //md5
            {
                buildReturnMsg("-14"); //pwd error
                return;
            }


            string retacc    = "";
            string strerr    = "";
            bool   isregedit = false;

            Random   rd      = new Random();
            int      randkey = rd.Next();
            DateTime now     = DateTime.Now;
            Dictionary <string, object> updata = new Dictionary <string, object>();

            updata["randkey"]  = randkey;
            updata["lasttime"] = now.Ticks;
            updata["lastip"]   = Request.ServerVariables.Get("Remote_Addr").ToString();

            if (!MongodbAccount.Instance.KeyExistsBykey(table, "acc_dev", HardwareID))
            {
                retacc = BuildAccount.getAutoAccount(table);
                //注册
                updata["acc_dev"]     = HardwareID;
                updata["acc"]         = retacc;
                updata["regedittime"] = now;
                updata["updatepwd"]   = false;

                strerr = MongodbAccount.Instance.ExecuteStoreBykey(table, "acc_dev", HardwareID, updata);

                isregedit = true;
            }
            else
            {
                var fdata = MongodbAccount.Instance.ExecuteGetBykey(table, "acc_dev", HardwareID, new string[] { "acc" });
                if (fdata != null)
                {
                    retacc = fdata["acc"].ToString();
                }

                //登陆
                strerr = MongodbAccount.Instance.ExecuteUpdate(table, "acc_dev", HardwareID, updata);
            }

            if (strerr != "")
            {
                buildReturnMsg("-11");//server error
            }
            else
            {
                RSAHelper rsa = new RSAHelper();
                rsa.setModulus(data["n3"].ToString());

                string clientkey = randkey.ToString() + ":" + now.Ticks.ToString();
                buildReturnMsg(AESHelper.AESEncrypt(clientkey, AES_KEY), true, retacc);//login success

                string channelID = null;
                if (data.ContainsKey("n4"))
                {
                    channelID = data["n4"].ToString();
                }

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

                if (isregedit)
                {
                    MongodbAccount.Instance.ExecuteInsert("RegisterLog", savelog);

                    //渠道每日注册
                    if (data.ContainsKey("n4"))
                    {
                        MongodbAccount.Instance.ExecuteIncBykey("day_regedit", "date", DateTime.Now.Date, data["n4"].ToString(), 0);
                    }
                }
            }
        }
Ejemplo n.º 25
0
        void CheckAccount(Dictionary <string, object> data)
        {
            string sacc = data["n1"].ToString();                                //account
            string spwd = AESHelper.AESDecrypt(data["n2"].ToString(), AES_KEY); //password

            if (spwd.Length != 32)                                              //md5
            {
                ReturnMsg(HttpRetCode.RET_PWD_ERROR.ToString());                //pwd error
                return;
            }

            string platform = Request.Params["platform"];

            string table = ConfigurationManager.AppSettings["acc_" + platform];

            if (string.IsNullOrEmpty(table))
            {
                ReturnMsg(HttpRetCode.RET_PLATFORM_ERROR.ToString());//platform error
                return;
            }

            List <IMongoQuery> imqs = new List <IMongoQuery>();

            imqs.Add(Query.EQ("acc", sacc));
            imqs.Add(Query.EQ("pwd", spwd));
            int retCode = tryLogin(sacc, spwd, table);

            //if (MongodbAccount.Instance.KeyExistsByQuery(table, Query.And(imqs)))
            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;
                //List<IMongoQuery> imqs2 = new List<IMongoQuery>();
                //imqs2.Add(Query.EQ("acc", sacc));
                //imqs2.Add(Query.EQ("platform", Platform));
                updata["lastip"] = Request.ServerVariables.Get("Remote_Addr").ToString();
                string strerr = MongodbAccount.Instance.ExecuteUpdate(table, "acc", sacc, updata);
                if (strerr != "")
                {
                    ReturnMsg(HttpRetCode.RET_DB_ERROR.ToString());//server error
                }
                else
                {
                    RSAHelper rsa = new RSAHelper();
                    rsa.setModulus(data["n3"].ToString());

                    string clientkey = randkey.ToString() + ":" + now.Ticks.ToString();
                    ReturnMsg(rsa.RSAEncryptStr(clientkey), true);//login success

                    Dictionary <string, object> savelog = new Dictionary <string, object>();
                    savelog["acc"]  = sacc;
                    savelog["ip"]   = Request.ServerVariables.Get("Remote_Addr").ToString();
                    savelog["time"] = now;
                    MongodbAccount.Instance.ExecuteInsert("LoginLog", savelog);
                }
            }
            else
            {
                // ReturnMsg("-10");//acc or pwd error
                ReturnMsg(retCode.ToString());
            }
        }