/// <summary> /// 获取支付信息 /// </summary> /// <param name="prepay_id"></param> /// <returns></returns> private string GetPayReqInfo(SDK_Weixin_Config config, string prepay_id) { //随机字符串 string nonceStr = new Random(1).Next(0, 99999).ToString(); //时间戳 long timeStamp = MFDSAUtil.GetTimestamp(); string package = "Sign=WXPay"; string temp = string.Format("appid={0}&noncestr={1}&package={2}&partnerid={3}&prepayid={4}×tamp={5}&key={6}", config.appid, nonceStr, package, config.mch_id, prepay_id, timeStamp, config.payKey); //签名 string sign = MFEncryptUtil.Md5(temp).ToUpper(); //签名是MD5大写形式 JsonData data = new JsonData(); data["partnerId"] = config.mch_id; //商户号 data["prepayId"] = prepay_id; //统一下单编号 data["nonceStr"] = nonceStr; //随机字符串 data["timeStamp"] = timeStamp; //时间戳 data["package"] = package; // data["sign"] = sign; //签名 return(JsonMapper.ToJson(data)); }
public RetValue Post([FromBody] string jsonStr) { RetValue ret = new RetValue(); JsonData jsonData = JsonMapper.ToObject(jsonStr); 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.ErrorMsg = "渠道号不存在"; } else { JsonData data = new JsonData(); data["ServerTime"] = MFDSAUtil.GetTimestamp(); data["SourceUrl"] = entity.SourceUrl; data["RechargeUrl"] = entity.RechargeUrl; data["TDAppId"] = entity.TDAppId; data["IsOpenTD"] = entity.IsOpenTD; data["PayServerNo"] = entity.PayServerNo; ret.Value = JsonMapper.ToJson(data); } return(ret); }
public RetValue Post([FromBody] string jsonStr) { RetValue ret = new RetValue(); JsonData jsonData = JsonMapper.ToObject(jsonStr); string channelId = jsonData["ChannelId"].ToString(); string innerVersion = jsonData["InnerVersion"].ToString(); //ConnectionString "Data Source=.;Initial Catalog=DBAccount;Persist Security Info=True;User ID=youyou;Password=123456" string ChannelEntity entity = ChannelCacheModel.Instance.GetEntity(string.Format("[ChannelId]={0} and [InnerVersion]={1}", channelId, innerVersion)); if (entity == null) { ret.HasError = true; ret.ErrorCode = 1001;//"渠道号不存在"; } else { JsonData data = new JsonData(); data["ServerTime"] = MFDSAUtil.GetTimestamp(); data["SourceVersion"] = entity.SourceVersion; data["SourceUrl"] = entity.SourceUrl; data["RechargeUrl"] = entity.RechargeUrl; data["TDAppId"] = entity.TDAppId; data["IsOpenTD"] = entity.IsOpenTD; data["PayServerNo"] = entity.PayServerNo; ret.Value = JsonMapper.ToJson(data); } return(ret); }
// POST: api/Account public RetValue Post([FromBody] string value) { RetValue ret = new RetValue(); JsonData jsonData = JsonMapper.ToObject(value); //1.验证时间戳 //2.验证签名 int type = Convert.ToInt32(jsonData["Type"].ToString()); string userName = jsonData["UserName"].ToString(); string pwd = jsonData["Pwd"].ToString(); //客户端时间戳 long t = Convert.ToInt64(jsonData["t"].ToString()); //签名 string sign = jsonData["sign"].ToString(); //客户端驱动id string deviceIdentifier = jsonData["deviceIdentifier"].ToString(); string deviceModel = jsonData["DeviceModel"].ToString(); long st = MFDSAUtil.GetTimestamp(); //第一重检验 //if (st - t > 300) //{ // ret.IsError = true; // ret.ErrorMsg = "请求失败"; // return ret; //} //第二重检验 if (string.Format("{0},{1}", deviceIdentifier, t) != sign) { ret.IsError = true; ret.ErrorMsg = "请求失败"; return(ret); } if (type == 0) { string ChannelId = JsonMapper.ToObject(value)["Channelld"].ToString(); MFReturnValue <int> ret2 = AccountCacheModel.Instance.Register(userName, pwd, ChannelId, deviceIdentifier, deviceModel); ret.IsError = ret2.HasError; ret.ErrorMsg = ret2.Message; AccountEntity entity = AccountCacheModel.Instance.GetEntity(ret2.Value); ret.RetData = JsonMapper.ToJson(new RetAccountEntity(entity)); } else { AccountEntity entity = AccountCacheModel.Instance.LogOn(userName, pwd, deviceIdentifier, deviceModel); if (entity != null) { ret.IsError = false; ret.RetData = entity.Id; } else { ret.IsError = true; ret.ErrorMsg = "账号或者密码错误"; } RetAccountEntity retEnitity = new RetAccountEntity(entity); ret.RetData = JsonMapper.ToJson(retEnitity); } 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.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 sdkName = jsonData["SDKName"].ToString(); string actionName = jsonData["ActionName"].ToString(); string userData = jsonData["UserData"].ToString(); IChannelSDK sdk = null; m_SDKDic.TryGetValue(sdkName, out sdk); if (sdk == null) { Type m_SdkType = Type.GetType(string.Format("WebAccount.Models.SDK.{0}", sdkName)); sdk = Activator.CreateInstance(m_SdkType) as IChannelSDK; m_SDKDic[sdkName] = sdk; } return(sdk.DoAction(actionName, userData, new string[] { deviceIdentifier, deviceModel })); }
// POST: api/GameServer public object Post([FromBody] string value) { RetValue ret = new RetValue(); JsonData jsonData = JsonMapper.ToObject(value); //1.验证时间戳 //2.验证签名 //客户端时间戳 long t = Convert.ToInt64(jsonData["t"].ToString()); //签名 string sign = jsonData["sign"].ToString(); //客户端驱动id string deviceIdentifier = jsonData["deviceIdentifier"].ToString(); string deviceModel = jsonData["DeviceModel"].ToString(); long st = MFDSAUtil.GetTimestamp(); //第一重检验 //if (st - t > 300) //{ // ret.IsError = true; // ret.ErrorMsg = "请求失败"; // return ret; //} //第二重检验 if (string.Format("{0},{1}", deviceIdentifier, t) != sign) { ret.IsError = true; ret.ErrorMsg = "请求失败"; return(ret); } //0.获取页签列表 1.获取服务器列表 int type = Convert.ToInt32(jsonData["Type"].ToString()); if (type == 0) { int pageIndex = Convert.ToInt32(jsonData["PageIndex"].ToString()); List <RetGameserverEntity> gameServerList = GameServerCacheModel.Instance.GetGameServerList(pageIndex); return(gameServerList); } else if (type == 1) { List <RetGameServerPageEntity> pageList = GameServerCacheModel.Instance.GetGameServerPageList(); return(pageList); } //更新登录结果 else if (type == 2) { IDictionary <string, object> dic = new Dictionary <string, object>(); int userID = Convert.ToInt32(jsonData["UserID"].ToString()); int lastServerId = Convert.ToInt32(jsonData["LastServerId"].ToString()); string lastServerName = jsonData["LastServerName"].ToString(); 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); } ret.IsError = true; ret.ErrorMsg = "请求失败"; return(ret); }
public long Get() { return(MFDSAUtil.GetTimestamp()); }
// 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 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); }