// POST: api/GameServer public object Post([FromBody] string jsonStr) { RetValue ret = new RetValue(); JsonData jsonData = JsonMapper.ToObject(jsonStr); //时间戳 long t = Convert.ToInt64(jsonData["t"].ToString()); string deviceIdentifier = jsonData["deviceIdentifier"].ToString(); string deviceModel = jsonData["deviceModel"].ToString(); string sign = jsonData["sign"].ToString(); //1.判断时间戳 如果大于3秒 直接返回错误 if (MFDSAUtil.GetTimestamp() - t > 3) { ret.HasError = true; ret.ErrorCode = ProtoCode.RequestDelay; //"请求无效"; //return ret; } //2.验证签名 string signServer = MFEncryptUtil.Md5(string.Format("{0}:{1}", t, deviceIdentifier)); if (!signServer.Equals(sign, StringComparison.CurrentCultureIgnoreCase)) { ret.HasError = true; ret.ErrorCode = ProtoCode.SignatureInvalid; //"请求无效"; return(ret); } int type = Convert.ToInt32(jsonData["Type"].ToString()); if (type == 0) { string channelId = jsonData["ChannelId"].ToString(); string innerVersion = jsonData["InnerVersion"].ToString(); //先获取渠道状态 根据渠道状态 来加载不同的区服 ChannelEntity entity = ChannelCacheModel.Instance.GetEntity(string.Format("[ChannelId]={0} and [InnerVersion]={1}", channelId, innerVersion)); if (entity == null) { ret.HasError = true; ret.ErrorCode = ProtoCode.ChannelNumberNoExist; //"渠道号不存在"; } //获取页签 return(GameServerCacheModel.Instance.GetGameServerPageList(string.Format("[ChannelStatus]={0}", entity.ChannelStatus))); } else if (type == 1) { string channelId = jsonData["ChannelId"].ToString(); string innerVersion = jsonData["InnerVersion"].ToString(); //先获取渠道状态 根据渠道状态 来加载不同的区服 ChannelEntity entity = ChannelCacheModel.Instance.GetEntity(string.Format("[ChannelId]={0} and [InnerVersion]={1}", channelId, innerVersion)); if (entity == null) { ret.HasError = true; ret.ErrorCode = ProtoCode.ChannelNumberNoExist; //"渠道号不存在"; } int pageIndex = int.Parse(jsonData["pageIndex"].ToString()); //获取区服列表 return(GameServerCacheModel.Instance.GetGameServerList(pageIndex, string.Format("[ChannelStatus]={0}", entity.ChannelStatus))); } else if (type == 2) { //更新最后登录信息 int userId = int.Parse(jsonData["userId"].ToString()); int lastServerId = int.Parse(jsonData["lastServerId"].ToString()); string lastServerName = jsonData["lastServerName"].ToString(); Dictionary <string, object> dic = new Dictionary <string, object>(); dic["Id"] = userId; dic["LastLogOnServerId"] = lastServerId; dic["LastLogOnServerName"] = lastServerName; dic["LastLogOnServerTime"] = DateTime.Now; AccountCacheModel.Instance.Update("LastLogOnServerId=@LastLogOnServerId, LastLogOnServerName=@LastLogOnServerName, LastLogOnServerTime=@LastLogOnServerTime", "Id=@Id", dic); } return(ret); }
public RetValue Post([FromBody] string jsonStr) { RetValue ret = new RetValue(); JsonData jsonData = JsonMapper.ToObject(jsonStr); //时间戳 long t = Convert.ToInt64(jsonData["t"].ToString()); string deviceIdentifier = jsonData["deviceIdentifier"].ToString(); string deviceModel = jsonData["deviceModel"].ToString(); string sign = jsonData["sign"].ToString(); //1.判断时间戳 如果大于3秒 直接返回错误 if (MFDSAUtil.GetTimestamp() - t > 3) { ret.HasError = true; ret.ErrorMsg = "请求无效"; return(ret); } //2.验证签名 string signServer = MFEncryptUtil.Md5(string.Format("{0}:{1}", t, deviceIdentifier)); if (!signServer.Equals(sign, StringComparison.CurrentCultureIgnoreCase)) { ret.HasError = true; ret.ErrorMsg = "请求无效"; return(ret); } //订单号 付费服务器识别码_玩家账号_要充值到哪个GameServerId_角色ID_充值的产品Id_时间 string orderId = jsonData["orderId"].ToString(); string[] arr = orderId.Split('_'); if (arr.Length == 6) { //1.记录充值日志 RechargeLogEntity rechargeLogEntity = new RechargeLogEntity(); rechargeLogEntity.AccountId = arr[1].ToInt(); string channelId = AccountCacheModel.Instance.GetEntity(rechargeLogEntity.AccountId).ChannelId; rechargeLogEntity.ChannelId = channelId; rechargeLogEntity.GameServerId = arr[2].ToInt(); rechargeLogEntity.RoldId = arr[3].ToInt(); rechargeLogEntity.RechargeProductId = arr[4].ToString(); rechargeLogEntity.OrderId = orderId; rechargeLogEntity.CreateTime = DateTime.Now; RechargeLogCacheModel.Instance.Create(rechargeLogEntity); //2.找到对应的游戏服 int gameServerId = arr[2].ToInt(); GameServerEntity entity = GameServerCacheModel.Instance.GetEntity(gameServerId); if (entity != null) { //发送socket请求 给游戏服 Socket rechargeServer = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); rechargeServer.Connect(new IPEndPoint(IPAddress.Parse(entity.Ip), entity.Port)); string str = string.Format("{0}_{1}_{2}", channelId, arr[3], arr[4]); rechargeServer.Send(System.Text.UTF8Encoding.UTF8.GetBytes(str)); } else { ret.HasError = true; ret.ErrorMsg = "充值失败"; } } else { ret.HasError = true; ret.ErrorMsg = "充值失败"; } return(ret); }
// POST: api/Account public RetValue Post([FromBody] string jsonStr) { RetValue ret = new RetValue(); JsonData jsonData = JsonMapper.ToObject(jsonStr); //时间戳 long t = Convert.ToInt64(jsonData["t"].ToString()); string deviceIdentifier = jsonData["deviceIdentifier"].ToString(); string deviceModel = jsonData["deviceModel"].ToString(); string sign = jsonData["sign"].ToString(); //1.判断时间戳 如果大于3秒 直接返回错误 if (MFDSAUtil.GetTimestamp() - t > 3) { ret.HasError = true; ret.ErrorMsg = "请求无效"; return(ret); } //// 2.验证签名 string signServer = MFEncryptUtil.Md5(string.Format("{0}:{1}", t, deviceIdentifier)); if (!signServer.Equals(sign, StringComparison.CurrentCultureIgnoreCase)) { ret.HasError = true; ret.ErrorMsg = "请求无效"; return(ret); } int type = Convert.ToInt32(jsonData["Type"].ToString()); string userName = jsonData["UserName"].ToString(); string pwd = jsonData["Pwd"].ToString(); if (type == 0) { string channelId = jsonData["ChannelId"].ToString(); ret.Type = "0"; //注册 MFReturnValue <int> retValue = AccountCacheModel.Instance.Register(userName, pwd, channelId, deviceIdentifier, deviceModel); ret.HasError = retValue.HasError; ret.ErrorMsg = retValue.Message; int userID = retValue.Value; AccountEntity entity = AccountCacheModel.Instance.GetEntity(userID); RetAccountEntity retAccountEntity = new RetAccountEntity(entity); ret.Value = JsonMapper.ToJson(retAccountEntity); } else { ret.Type = "1"; //登录 AccountEntity entity = AccountCacheModel.Instance.LogOn(userName, pwd, deviceIdentifier, deviceModel); if (entity != null) { RetAccountEntity rect = new RetAccountEntity(entity); ret.objValue = rect; } else { // 登录失败 ret.HasError = true; ret.ErrorMsg = "帐户取出来为空"; } } return(ret); }
public long Get() { return(MFDSAUtil.GetTimestamp()); }
public RetValue Post([FromBody] string jsonStr) { RetValue ret = new RetValue(); JsonData jsonData = JsonMapper.ToObject(jsonStr); //时间戳 long t = Convert.ToInt64(jsonData["t"].ToString()); string deviceIdentifier = jsonData["deviceIdentifier"].ToString(); string deviceModel = jsonData["deviceModel"].ToString(); string sign = jsonData["sign"].ToString(); //1.判断时间戳 如果大于3秒 直接返回错误 if (MFDSAUtil.GetTimestamp() - t > 3) { ret.HasError = true; ret.ErrorCode = 1002;// "请求无效"; return(ret); } //2.验证签名 string signServer = MFEncryptUtil.Md5(string.Format("{0}:{1}", t, deviceIdentifier)); if (!signServer.Equals(sign, StringComparison.CurrentCultureIgnoreCase)) { ret.HasError = true; ret.ErrorCode = 1002; //"请求无效"; return(ret); } //苹果回执 string receipt = jsonData["receipt"].ToString(); string strJosn = string.Format("{{\"receipt-data\":\"{0}\"}}", receipt); // 请求验证 string strResult = CreatePostHttpResponse(strJosn, true); JsonData retJson = LitJson.JsonMapper.ToObject(strResult); int status = int.Parse(retJson["status"].ToString()); if (status == 0) { //成功 string retreceipt = retJson["receipt"].ToJson(); JsonData retReceiptJson = JsonMapper.ToObject(retreceipt); string rechargeProductId = retReceiptJson["product_id"].ToString(); ret.Value = rechargeProductId; //把充值产品编号传递给客户端 //订单号 付费服务器识别码_玩家账号_要充值到哪个GameServerId_角色ID_充值的产品Id_时间 string orderId = jsonData["orderId"].ToString(); string[] arr = orderId.Split('_'); if (arr.Length == 6) { //1.记录充值日志 RechargeLogEntity rechargeLogEntity = new RechargeLogEntity(); rechargeLogEntity.AccountId = arr[1].ToInt(); short channelId = AccountCacheModel.Instance.GetEntity(rechargeLogEntity.AccountId).ChannelId; rechargeLogEntity.Status = Mmcoy.Framework.AbstractBase.EnumEntityStatus.Released; rechargeLogEntity.ChannelId = channelId; rechargeLogEntity.GameServerId = arr[2].ToInt(); rechargeLogEntity.RoldId = arr[3].ToInt(); rechargeLogEntity.RechargeProductId = short.Parse(rechargeProductId); rechargeLogEntity.OrderId = orderId; rechargeLogEntity.CreateTime = DateTime.Now; RechargeLogCacheModel.Instance.Create(rechargeLogEntity); //2.找到对应的游戏服 int gameServerId = arr[2].ToInt(); GameServerEntity entity = GameServerCacheModel.Instance.GetEntity(gameServerId); if (entity != null) { //发送socket请求 给游戏服 Socket rechargeServer = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); rechargeServer.Connect(new IPEndPoint(IPAddress.Parse(entity.Ip), entity.Port)); string str = string.Format("{0}_{1}_{2}", channelId, arr[3], arr[4]); rechargeServer.Send(System.Text.UTF8Encoding.UTF8.GetBytes(str)); } else { ret.HasError = true; ret.ErrorCode = 1004; //"充值失败"; } } else { ret.HasError = true; ret.ErrorCode = 1004; //"充值失败"; } } else { ret.HasError = true; ret.ErrorCode = 1004; //"充值失败"; } return(ret); }
// POST: api/Account public RetValue Post([FromBody] string jsonStr) { RetValue ret = new RetValue(); JsonData jsonData = JsonMapper.ToObject(jsonStr); //时间戳 long t = Convert.ToInt64(jsonData["t"].ToString()); string deviceIdentifier = jsonData["deviceIdentifier"].ToString(); string deviceModel = jsonData["deviceModel"].ToString(); string sign = jsonData["sign"].ToString(); //1.判断时间戳 如果大于3秒 直接返回错误 if (MFDSAUtil.GetTimestamp() - t > 3) { ret.HasError = true; ret.ErrorCode = ProtoCode.RequestDelay;//"url请求无效"; return(ret); } //2.验证签名 string signServer = MFEncryptUtil.Md5(string.Format("{0}:{1}", t, deviceIdentifier)); if (!signServer.Equals(sign, StringComparison.CurrentCultureIgnoreCase)) { ret.HasError = true; ret.ErrorCode = ProtoCode.SignatureInvalid;//"签名无效"; return(ret); } int type = Convert.ToInt32(jsonData["Type"].ToString()); string userName = jsonData["UserName"].ToString(); string pwd = jsonData["Pwd"].ToString(); if (type == 0) { short channelId = jsonData["ChannelId"].ToString().ToShort(); //注册 MFReturnValue <int> retValue = AccountCacheModel.Instance.Register(userName, pwd, channelId, deviceIdentifier, deviceModel); ret.HasError = retValue.HasError; //ret.ErrorMsg = retValue.Message; ret.ErrorCode = ProtoCode.AccountRegistrationFailed; int userID = retValue.Value; AccountEntity entity = AccountCacheModel.Instance.GetEntity(userID); ret.Value = JsonMapper.ToJson(new RetAccountEntity(entity)); } else { //登录 AccountEntity entity = AccountCacheModel.Instance.LogOn(userName, pwd, deviceIdentifier, deviceModel); if (entity != null) { ret.Value = JsonMapper.ToJson(new RetAccountEntity(entity)); } else { ret.HasError = true; ret.ErrorCode = ProtoCode.AccountDoesNotExist; //"帐户不存在"; } } return(ret); }