/// <summary> /// 发送短信 /// </summary> /// <param name="mobile"></param> /// <returns></returns> public static bool SendMesssage(string mobile, string Content) { string url = string.Format("{0}:{1}/inter/sendSingleSMS", EMayConfig.Host, EMayConfig.Port); SingMessage entity = new SingMessage() { content = Content, mobile = mobile, customsmsid = DateTime.Now.ToString("yyyyMMddHHmmsss"), extendedcode = "", requesttime = DateTime.Now.Ticks, timertime = "", requestvalidperiod = EMayConfig.ValidPeriod }; HttpWebResponse response = null; string json = SerializerJson.SerializeObject(entity); byte[] byteArray = EMayConfig.IsCompress ? AESHelper.AESEncrypt(GzipHelper.GZipCompressString(json), EMayConfig.SecretKey) : AESHelper.AESEncrypt(json, EMayConfig.SecretKey); byte[] result = HttpHelper.SendRequestData(url, byteArray, ref response); string code = response.GetResponseHeader("result").ToString(); if (code == "SUCCESS") { string res = AESHelper.AESDecryptString(result, EMayConfig.SecretKey); return(true); } else { return(false); } }
private string modifyPwd(ParamModifyPlayerPwd p) { RSAHelper rsa = new RSAHelper(); rsa.init(); Dictionary <string, object> data = new Dictionary <string, object>(); data["n1"] = p.m_playerAcc; string old = Tool.getMD5Hash(p.m_oldPwd); data["n2"] = AESHelper.AESEncrypt(old, AES_KEY); string newPwd = Tool.getMD5Hash(p.m_newPwd); data["n3"] = AESHelper.AESEncrypt(newPwd, AES_KEY); string jsonstr = JsonHelper.ConvertToStr(data); string md5 = AESHelper.MD5Encrypt(jsonstr + AES_KEY); string urlstr = Convert.ToBase64String(Encoding.Default.GetBytes(jsonstr)); string fmt = CONST.URL_MODIFY_PLAYER_PWD; string aspx = string.Format(fmt, urlstr, md5); var ret = HttpPost.Get(new Uri(aspx)); if (ret != null) { string retStr = Encoding.UTF8.GetString(ret); return(retStr); } return(""); }
private bool isCompress = false;//是否压缩,默认否 public SMSResponseBody BatchSend(SMSRequestBody body) { SMSResponseBody responseBody = new SMSResponseBody(); string result = ""; Hashtable headerhs = new Hashtable(); Byte[] byteArray = null; string jsondata = ""; string url = "http://" + host + "/inter/sendPersonalitySMS"; headerhs.Add("appId", appId); //jsondata = "{\"smses\":[{\"mobile\":15500000000,\"customSmsId\":null,\"content\":\"【短信签名】短信内容\"},{\"mobile\":15500000001,\"customSmsId\":null,\"content\":\"【短信签名】短信内容\"}],\"timerTime\":\"\",\"extendedCode\":112,\"requestTime\":" + DateTime.Now.Ticks.ToString() + ",\"requestValidPeriod\":30}"; jsondata = JsonConvertEx.ObjectToJson(body); if (isCompress) { headerhs.Add("gzip", "on");//先压缩成byte再加密 //byteArray = HttpHelper.postdata(url, AESHelper.AESEncrypt(GzipHelper.GZipCompressString(jsondata), secretKey), headerhs, Encoding.UTF8, secretKey); } else { byteArray = HttpHelper.postdata(url, AESHelper.AESEncrypt(jsondata, secretKey), headerhs, Encoding.UTF8, secretKey); } if (byteArray != null) { if (isCompress) { //result = GzipHelper.DecompressString(AESHelper.AESDecrypt(byteArray, secretKey)); } else { result = AESHelper.AESDecryptString(byteArray, secretKey); } if (result != "") { if (result.IndexOf("ERROR") != -1) { responseBody.flag = false; responseBody.resultCode = result; } else { responseBody.flag = true; responseBody.resultCode = ""; responseBody.smses = JsonConvertEx.JsonToList <SMSResponseEntity>(result); } return(responseBody); } } AsyncHelper.RunSync <bool>(() => Manager.Instance.WriteLogFile("亿美发送msg出现问题")); return(null); }
public void LoginSucceedHandle(User user) { //登录成功 user.LastLoginTime = user.LoginTime; user.LoginTime = DateTime.Now; //写入缓存 Cache.Default.Add("LoginContext.User." + user.UserId, user); //写cookie Cookie.Default.SetCookie("login-uid", MyEncoding.UrlEncode(AESHelper.AESEncrypt(user.UserId))); }
public byte[] EnPwd_UTF8(List <byte[]> data) { try { return(AESHelper.AESEncrypt(data[0], data[1], data[2])); } catch (Exception) { return(Encoding.UTF8.GetBytes("")); } }
void checkAccount(BaiduResult result, string channelID) { Random rd = new Random(); DateTime now = DateTime.Now; int randkey = rd.Next(); Dictionary <string, object> savedata = new Dictionary <string, object>(); string acc = "bd_" + result.data.userid; savedata["acc"] = acc; savedata["username"] = result.data.username; savedata["randkey"] = randkey; savedata["lasttime"] = now.Ticks; savedata["ip"] = Request.ServerVariables.Get("Remote_Addr").ToString(); savedata["channelID"] = channelID; if (MongodbAccount.Instance.KeyExistsBykey("baiduview_login", "acc", acc) == false) { 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["channel"] = channelID; MongodbAccount.Instance.ExecuteInsert("RegisterLog", savelog); } string msg = MongodbAccount.Instance.ExecuteStoreBykey("baiduview_login", "acc", acc, savedata); if (msg == "") { 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["channel"] = channelID; MongodbAccount.Instance.ExecuteInsert("LoginLog", savelog); } string clientkey = randkey.ToString() + ":" + now.Ticks.ToString(); string loginKey = AESHelper.AESEncrypt(clientkey, AES_LOGINKEY); StringBuilder sb = new StringBuilder(); sb.AppendFormat("local ret = {{code = 0, msg=\"{0}\"}};", loginKey); sb.AppendFormat("ret.userid = \"{0}\";", AESHelper.AESEncrypt(acc, AES_KEY)); sb.AppendFormat("ret.username = \"{0}\";", AESHelper.AESEncrypt(result.data.username, AES_KEY)); sb.Append("return ret;"); Response.Write(sb.ToString()); }
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); }
private void BtnSave_Click(object sender, EventArgs e) { BtnSave.Enabled = false; if (this.txtServer.Text == "") { MessageBox.Show("服务器名称不能为空!"); return; } if (this.txtUserName.Text == "") { MessageBox.Show("用户名不能为空!"); return; } if (this.txtPwd.Text == "") { MessageBox.Show("登录密码不能为空!"); return; } if (this.txtDBName.Text == "") { MessageBox.Show("数据库名称不能为空!"); return; } string SaveSer = AESHelper.AESEncrypt(this.txtServer.Text); string SaveUid = AESHelper.AESEncrypt(this.txtUserName.Text); string SavePwd = AESHelper.AESEncrypt(this.txtPwd.Text); string SaveDBN = AESHelper.AESEncrypt(this.txtDBName.Text); try { CommentController comm = new CommentController(); comm.IniDataBase(SaveSer, SaveUid, SavePwd, SaveDBN); MessageBox.Show("数据库连接初始化配置成功!"); BtnSave.Enabled = true; } catch (Exception ex) { MessageBox.Show("初始化失败!错误原因:" + ex.Message); BtnSave.Enabled = true; } }
private bool createAccToServer(string accName, string pwd, ref string error) { RSAHelper rsa = new RSAHelper(); rsa.init(); Dictionary <string, object> data = new Dictionary <string, object>(); data["n1"] = accName; string md5Pwd = Tool.getMD5Hash(pwd); data["n2"] = AESHelper.AESEncrypt(md5Pwd, AES_KEY); data["n3"] = rsa.getModulus(); string jsonstr = JsonHelper.ConvertToStr(data); string md5 = AESHelper.MD5Encrypt(jsonstr + AES_KEY); string urlstr = Convert.ToBase64String(Encoding.Default.GetBytes(jsonstr)); string fmt = WebConfigurationManager.AppSettings["createAccount"]; string aspx = string.Format(fmt, urlstr, md5); var ret = HttpPost.Get(new Uri(aspx)); if (ret != null) { string retStr = Encoding.UTF8.GetString(ret); string oriStr = Encoding.Default.GetString(Convert.FromBase64String(retStr)); Dictionary <string, object> retData = JsonHelper.ParseFromStr <Dictionary <string, object> >(oriStr); if (retData.ContainsKey("result")) { if (retData.ContainsKey("error")) { error = Convert.ToString(retData["error"]); } return(Convert.ToBoolean(retData["result"])); } } return(false); }
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> /// post方法 /// </summary> /// <param name="postUrl">地址</param> /// <param name="paramData">参数</param> /// <param name="Header">请求头</param> /// <param name="dataEncode">编码</param> /// <returns></returns> public static byte[] postdata(string postUrl, Byte[] paramData, Hashtable Header, Encoding dataEncode, string secretKey) { string reuslt = ""; byte[] backstr = null; try { byte[] byteArray = paramData; HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(new Uri(postUrl)); webReq.Method = "POST"; webReq.ContentType = "application/x-www-form-urlencoded"; webReq.ContentLength = byteArray.Length; if (Header != null) { foreach (DictionaryEntry de in Header) { webReq.Headers.Add(de.Key.ToString(), de.Value.ToString()); } } Stream newStream = webReq.GetRequestStream(); newStream.Write(byteArray, 0, byteArray.Length); newStream.Close(); HttpWebResponse response = (HttpWebResponse)webReq.GetResponse(); if (response != null) { Stream stream = response.GetResponseStream(); string code = response.GetResponseHeader("result").ToString(); if (code == "SUCCESS") { if (stream.CanRead) { //将基础流写入内存流 MemoryStream memoryStream = new MemoryStream(); const int bufferLength = 1024; int actual; byte[] buffer = new byte[bufferLength]; while ((actual = stream.Read(buffer, 0, bufferLength)) > 0) { memoryStream.Write(buffer, 0, actual); } memoryStream.Position = 0; backstr = StreamToBytes(memoryStream); memoryStream.Close(); } stream.Close(); } else { backstr = AESHelper.AESEncrypt(code, secretKey); } } response.Close(); newStream.Close(); if (backstr != null) { return(backstr); } } catch (Exception e) { reuslt = e.ToString(); //错误日志 } return(null); }
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; } string password = BuildAccount.getAutoPassword(6); string passwordMD5 = AESHelper.MD5Encrypt(password); updateAccountInfos(phoneNum, passwordMD5); //获取帐号信息 List <AccountInfo> 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++) { string pwd = AESHelper.AESEncrypt(password, AES_KEY); sb.AppendFormat("ret.data[{0}] = {{acc=\"{1}\",pwd=\"{2}\"}};", i + 1, accounts[i].account, pwd); } sb.Append("return ret;"); Response.Write(sb.ToString()); } }
static void Main(string[] args) { string pattern = @"^[0-9a-zA-z][^_]{6,20}$"; if (!Regex.IsMatch("1234556547", pattern)) { int i = 0; } TalkingGame.get_vca("3"); //TalkingGame tg = new TalkingGame(); //tg.adddata("test", "PB585615090914221334621",1,10); //tg.PostToTG(); int time1 = Environment.TickCount; string result = Encoding.UTF8.GetString(HttpPost.Get(new Uri("http://192.168.1.11:26004/ServerList.aspx"), true)); int time2 = Environment.TickCount; Console.WriteLine("time:" + (time2 - time1)); if (result.StartsWith("error")) { Console.WriteLine(result); } else { Console.WriteLine(result); Console.WriteLine(""); } ///////////////////////////////////////////////////////////// RSAHelper rsa = new RSAHelper(); rsa.init(); Dictionary <string, object> data = new Dictionary <string, object>(); data["n1"] = "test1"; data["n2"] = AESHelper.AESEncrypt("123456", AES_KEY); data["n3"] = rsa.getModulus(); string jsonstr = JsonHelper.ConvertToStr(data); string md5 = AESHelper.MD5Encrypt(jsonstr + AES_KEY); NameValueCollection nvc = new NameValueCollection(); string urlstr = Convert.ToBase64String(Encoding.Default.GetBytes(jsonstr)); nvc.Add("data", urlstr); nvc.Add("sign", md5); nvc.Add("platform", "default"); urlstr = string.Format("http://localhost:33820/SwitchLogin.aspx?data={0}&sign={1}&platform={2}", urlstr, md5, "default"); time1 = Environment.TickCount; result = Encoding.Default.GetString(HttpPost.Get(new Uri(urlstr))); time2 = Environment.TickCount; Console.WriteLine("time:" + (time2 - time1)); if (result.StartsWith("error")) { Console.WriteLine(result); } else { string jstr = Encoding.Default.GetString(Convert.FromBase64String(result)); Console.WriteLine("login:"******""); Dictionary <string, object> retdata = JsonHelper.ParseFromStr <Dictionary <string, object> >(jstr); if (!Convert.ToBoolean(retdata["result"])) { Console.Read(); return; } string logindata = rsa.RSADecryptStr(retdata["data"].ToString()); Console.WriteLine("data:" + logindata); Console.WriteLine(""); ////////////////////////////////////////////////////////////// bool isok = Convert.ToBoolean(retdata["result"]); if (isok) { nvc.Clear(); nvc.Add("acc", "test1"); time1 = Environment.TickCount; result = Encoding.Default.GetString(HttpPost.Get(new Uri("http://192.168.1.11:12345/AccCheck.aspx?acc=test1"))); time2 = Environment.TickCount; Console.WriteLine("time:" + (time2 - time1)); jstr = Encoding.Default.GetString(Convert.FromBase64String(result)); Console.WriteLine("check:" + jstr); Dictionary <string, object> retdata2 = JsonHelper.ParseFromStr <Dictionary <string, object> >(jstr); if (!Convert.ToBoolean(retdata2["result"])) { Console.Read(); return; } Dictionary <string, object> retdata3 = JsonHelper.ParseFromStr <Dictionary <string, object> >(retdata2["data"].ToString()); } } Console.Read(); }
protected void Page_Load(object sender, EventArgs e) { NameValueCollection req = Request.Form; string args = ""; foreach (string key in req.AllKeys) { args += key + "=" + req[key] + "&"; } args = args.Substring(0, args.Length - 1); LoginInfo loginInfo = null; try { loginInfo = JsonHelper.ParseFromStr <LoginInfo>(req["server_ext_for_login"]); } catch (Exception) { } string msg = ""; try { Uri uri = new Uri(login); HttpWebRequest requester = WebRequest.Create(uri) as HttpWebRequest; requester.Method = "POST"; requester.Timeout = 3000; byte[] bs = Encoding.UTF8.GetBytes(args); requester.ContentType = "application/x-www-form-urlencoded"; requester.ContentLength = bs.Length; using (Stream reqStream = requester.GetRequestStream()) { reqStream.Write(bs, 0, bs.Length); } HttpWebResponse responser = requester.GetResponse() as HttpWebResponse; StreamReader reader = new StreamReader(responser.GetResponseStream(), Encoding.UTF8); msg = reader.ReadToEnd(); JavaScriptSerializer serializer = new JavaScriptSerializer(); Dictionary <string, object> rets = serializer.Deserialize <Dictionary <string, object> >(msg); if (rets["status"].ToString() == "ok") { Dictionary <string, object> commondata = (Dictionary <string, object>)rets["common"]; Dictionary <string, object> savedata = new Dictionary <string, object>(); Random rd = new Random(); DateTime now = DateTime.Now; int randkey = rd.Next(); string tempacc = "anysdk_" + commondata["channel"].ToString() + "_" + commondata["uid"].ToString(); string channelID = commondata["channel"].ToString(); string remoteIP = Common.Helper.getRemoteIP(Request); savedata["acc"] = tempacc; savedata["randkey"] = randkey; savedata["regedittime"] = now; savedata["regeditip"] = remoteIP; savedata["updatepwd"] = false; savedata["platform"] = "anysdk"; savedata["channelID"] = channelID; savedata["lasttime"] = now.Ticks; savedata["lastip"] = remoteIP; string clientkey = randkey.ToString() + ":" + now.Ticks.ToString(); rets["ext"] = AESHelper.AESEncrypt(clientkey, AES_KEY); if (MongodbAccount.Instance.KeyExistsBykey("AccountTable", "acc", tempacc) == false) { Dictionary <string, object> savelog = new Dictionary <string, object>(); savelog["acc"] = tempacc; savelog["acc_real"] = tempacc; savelog["ip"] = remoteIP; savelog["time"] = now; savelog["channel"] = channelID; MongodbAccount.Instance.ExecuteInsert("RegisterLog", savelog); } msg = MongodbAccount.Instance.ExecuteStoreBykey("AccountTable", "acc", tempacc, savedata); if (msg == "") { msg = serializer.Serialize(rets); Dictionary <string, object> savelog = new Dictionary <string, object>(); savelog["acc"] = tempacc; savelog["acc_real"] = tempacc; if (loginInfo != null && !string.IsNullOrEmpty(loginInfo.deviceID)) { savelog["acc_dev"] = loginInfo.deviceID; } savelog["ip"] = remoteIP; savelog["time"] = now; savelog["channel"] = channelID; MongodbAccount.Instance.ExecuteInsert("LoginLog", savelog); } } } catch (Exception ex) { msg = ex.Message; } Response.Write(msg); }
private void buttonSave_Click(object sender, EventArgs e) { if (comboBoxDatabase.SelectedItem == null) { MessageBox.Show("未输入数据库名"); return; } if (textBoxDbUser.Text == "") { MessageBox.Show("未输入数据库用户名"); return; } if (comboBoxDatabase.SelectedItem.ToString() == "") { MessageBox.Show("未输入数据库"); return; } AppSetingHelper.UpdateAppString("DatabaseName", AESHelper.AESEncrypt(GlobleVariable.DatabaseName, "adsfadsfadfadsfasasdfads")); AppSetingHelper.UpdateAppString("DatabaseUser", AESHelper.AESEncrypt(GlobleVariable.DatabaseUser, "adsfadsfadfadsfasasdfads")); AppSetingHelper.UpdateAppString("DatabasePassword", AESHelper.AESEncrypt(GlobleVariable.DatabasePassword, "adsfadsfadfadsfasasdfads")); AppSetingHelper.UpdateAppString("LocalKeepDay", "-" + numericUpDownLocalKeepDay.Value.ToString()); AppSetingHelper.UpdateAppString("BackupTime", numericUpDownBackupTime.Value.ToString()); AppSetingHelper.UpdateAppString("RunTime", "1"); GlobleVariable.LocalKeeyDay = -1 * (int)numericUpDownLocalKeepDay.Value; string outFangyouClient, outFangyouVer; GetFangyouInfo(out outFangyouVer, out outFangyouClient); GlobleVariable.FangyouClient = outFangyouClient; GlobleVariable.FangyouVer = outFangyouVer; AppSetingHelper.UpdateAppString("FangyouVer", outFangyouVer); AppSetingHelper.UpdateAppString("FangyouClient", outFangyouClient); var sqlBase = new SqlBase(); GlobleVariable.SqlServerType = sqlBase.GetSqlVersion(); AppSetingHelper.UpdateAppString("SqlType", GlobleVariable.SqlServerType.ToString()); AppSetingHelper.UpdateAppString("LocalKeeyDay", GlobleVariable.LocalKeeyDay.ToString()); var result = MessageBox.Show("是否立即执行备份工作?", "提示", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { var checkSql = new SqlBase(); GlobleVariable.Progress = true; switch (checkSql.GetSqlVersion()) { case SqlTypeEnum.Sql2000: var backup2000 = new Sql2000(); backup2000.Backup(); break; case SqlTypeEnum.Sql2005: var backup2005 = new Sql2005(); backup2005.Backup(); break; case SqlTypeEnum.Sql2008: var backup2008 = new Sql2008(); backup2008.Backup(); break; } } this.Close(); }
protected void Page_Load(object sender, EventArgs e) { NameValueCollection req = Request.Form; string args = ""; foreach (string key in req.AllKeys) { args += key + "=" + req[key] + "&"; } args = args.Substring(0, args.Length - 1); string msg = ""; try { Uri uri = new Uri(login); HttpWebRequest requester = WebRequest.Create(uri) as HttpWebRequest; requester.Method = "POST"; requester.Timeout = 3000; byte[] bs = Encoding.UTF8.GetBytes(args); requester.ContentType = "application/x-www-form-urlencoded"; requester.ContentLength = bs.Length; using (Stream reqStream = requester.GetRequestStream()) { reqStream.Write(bs, 0, bs.Length); } HttpWebResponse responser = requester.GetResponse() as HttpWebResponse; StreamReader reader = new StreamReader(responser.GetResponseStream(), Encoding.UTF8); msg = reader.ReadToEnd(); JavaScriptSerializer serializer = new JavaScriptSerializer(); Dictionary <string, object> rets = serializer.Deserialize <Dictionary <string, object> >(msg); if (rets["status"].ToString() == "ok") { Dictionary <string, object> savedata = (Dictionary <string, object>)rets["common"]; Random rd = new Random(); DateTime now = DateTime.Now; int randkey = rd.Next(); savedata["randkey"] = randkey; savedata["lasttime"] = now.Ticks; savedata["ip"] = Request.ServerVariables.Get("Remote_Addr").ToString(); string clientkey = randkey.ToString() + ":" + now.Ticks.ToString(); rets["ext"] = AESHelper.AESEncrypt(clientkey, AES_KEY); string tempacc = savedata["channel"].ToString() + "_" + savedata["uid"].ToString(); msg = MongodbAccount.Instance.ExecuteStoreBykey("anysdk_login", "acc", tempacc, savedata); if (msg == "") { msg = serializer.Serialize(rets); Dictionary <string, object> savelog = new Dictionary <string, object>(); savelog["acc"] = tempacc; savelog["ip"] = Request.ServerVariables.Get("Remote_Addr").ToString(); savelog["time"] = now; MongodbAccount.Instance.ExecuteInsert("LoginLog", savelog); } } } catch (Exception ex) { msg = ex.Message; } Response.Write(msg); }
protected void Page_Load(object sender, EventArgs e) { string platform = Request.Params["platform"]; if (string.IsNullOrEmpty(platform)) { Response.Write("local ret = {code = -1}; return ret;"); return; } string table = ConfigurationManager.AppSettings["acc_" + platform]; if (string.IsNullOrEmpty(table)) { Response.Write("local ret = {code = -15}; return ret;"); return; } string acc = BuildAccount.getAutoAccount(table); if (string.IsNullOrEmpty(acc)) { Response.Write("local ret = {code = -12}; return ret;"); return; } string encrypt = Request.Params["encrypt"]; bool pwd_encrypt = false; if (!string.IsNullOrEmpty(encrypt) && encrypt == "true") { pwd_encrypt = true; } string pwd = null; string out_pwd = null; string save_pwd = null; if (pwd_encrypt) { pwd = BuildAccount.getAutoPassword(6); out_pwd = AESHelper.AESEncrypt(pwd, AES_KEY); save_pwd = AESHelper.MD5Encrypt(pwd); } else { out_pwd = BuildAccount.getAutoPassword(20); pwd = string.Format("{0}{1}{2}{3}{4}{5}", out_pwd[8], out_pwd[16], out_pwd[4], out_pwd[11], out_pwd[2], out_pwd[9]);//password save_pwd = AESHelper.MD5Encrypt(pwd); } string deviceID = Request.Params["deviceID"]; Random rd = new Random(); int randkey = rd.Next(); Dictionary <string, object> updata = new Dictionary <string, object>(); updata["acc"] = acc; updata["pwd"] = save_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(table, "acc", acc, updata); if (strerr != "") { Response.Write("local ret = {code = -11}; return ret;"); } else { string channelID = Request.Params["channelID"]; Dictionary <string, object> savelog = new Dictionary <string, object>(); savelog["acc"] = acc; savelog["acc_real"] = acc; 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("RegisterLog", savelog); //渠道每日注册 if (string.IsNullOrEmpty(channelID) == false) { MongodbAccount.Instance.ExecuteIncBykey("day_regedit", "date", DateTime.Now.Date, channelID, 0); } string ret = string.Format("local ret = {{code = 0, acc=\"{0}\", pwd=\"{1}\"}}; return ret;", acc, out_pwd); Response.Write(ret); } //Response.Write("local ret = {code = 0, acc=\"fish000001\", pwd=\"123456\"};"); }
public ActionResult SavePostInfoEncode(FormCollection saveForm) { NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger(); InvokeResult result = new InvokeResult(); #region 构建数据 var formKeys = saveForm.AllKeys; string tbName = formKeys.Contains("tbName") ? saveForm["tbName"] : PageReq.GetForm("tbName"); string queryStr = formKeys.Contains("queryStr") ? saveForm["queryStr"] : PageReq.GetForm("queryStr"); string dataStr = formKeys.Contains("dataStr") ? saveForm["dataStr"] : PageReq.GetForm("dataStr"); string encodeColumns = formKeys.Contains("encodeColumns") ? saveForm["encodeColumns"] : PageReq.GetForm("encodeColumns"); TableRule rule = new TableRule(tbName); BsonDocument dataBson = new BsonDocument(); bool columnNeedConvert = false; if (dataStr.Trim() == "") { if (saveForm.AllKeys.Contains("fileObjId")) { columnNeedConvert = true; } foreach (var tempKey in saveForm.AllKeys) { if (tempKey == "tbName" || tempKey == "queryStr" || tempKey.Contains("fileList[") || tempKey.Contains("param.")) { continue; } //2016.1.25添加数据转换过滤, //由于前端通用TableManage需要上传可能会内置tableName字段,如果表中页游tableName字段可能会冲突保存不了 //目前做法前段替换,后端转化COLUMNNEEDCONVERT_ var curFormValue = saveForm[tempKey]; var curColumnName = tempKey; if (columnNeedConvert && tempKey.Contains("COLUMNNEEDCONVERT_")) { curColumnName = curColumnName.Replace("COLUMNNEEDCONVERT_", string.Empty); } dataBson.Set(curColumnName, curFormValue); } } else { dataBson = TypeConvert.ParamStrToBsonDocument(dataStr); } #endregion #region 加密数据 var AesHelp = new AESHelper(); var encodeColumnList = encodeColumns.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList(); var bson = queryStr != "" ? dataOp.FindOneByQuery(tbName, TypeConvert.NativeQueryToQuery(queryStr)) : new BsonDocument(); foreach (var encodeColumn in encodeColumnList) { if (dataBson.String(encodeColumn) != bson.String(encodeColumn) && !string.IsNullOrEmpty(dataBson.String(encodeColumn))) { dataBson.Set(encodeColumn, AESHelper.AESEncrypt(dataBson.String(encodeColumn), dataBson.String("customerCode"))); } } #endregion #region 保存数据 result = dataOp.Save(tbName, queryStr != "" ? TypeConvert.NativeQueryToQuery(queryStr) : Query.Null, dataBson); #endregion #region 文件上传 int primaryKey = 0; ColumnRule columnRule = rule.ColumnRules.Where(t => t.IsPrimary == true).FirstOrDefault(); string keyName = columnRule != null ? columnRule.Name : ""; if (!string.IsNullOrEmpty(queryStr)) { var query = TypeConvert.NativeQueryToQuery(queryStr); var recordDoc = dataOp.FindOneByQuery(tbName, query); saveForm["keyValue"] = result.BsonInfo.Text(keyName); if (recordDoc != null) { primaryKey = recordDoc.Int(keyName); } } if (primaryKey == 0)//新建 { if (saveForm["tableName"] != null) { saveForm["keyValue"] = result.BsonInfo.Text(keyName); } } else//编辑 { #region 除文件 string delFileRelIds = saveForm["delFileRelIds"] != null ? saveForm["delFileRelIds"] : ""; if (!string.IsNullOrEmpty(delFileRelIds)) { FileOperationHelper opHelper = new FileOperationHelper(); try { string[] fileArray; if (delFileRelIds.Length > 0) { fileArray = delFileRelIds.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); if (fileArray.Length > 0) { var fileRelIdList = fileArray.Select(t => (BsonValue)t).ToList(); var result1 = opHelper.DeleteFileByRelIdList(fileRelIdList); } } } catch (Exception ex) { result.Status = Status.Failed; result.Message = ex.Message; return(Json(TypeConvert.InvokeResultToPageJson(result))); } } #endregion saveForm["keyValue"] = primaryKey.ToString(); } result.FileInfo = SaveMultipleUploadFiles(saveForm); #endregion return(Json(TypeConvert.InvokeResultToPageJson(result))); }
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); } } } }
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; //} }
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()); } }
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)); } }
string encryptUrl(string src) { string dec = AESHelper.AESEncrypt(src, AES_KEY); return(Convert.ToBase64String(Encoding.Default.GetBytes(dec))); }