protected void Application_Error(object sender, EventArgs e) { Exception ex = this.Context.Server.GetLastError(); if (ex != null) { Log4Net.WriteErrorLog(ex); } }
public void ProcessRequest(HttpContext context) { //允许跨站请求域名 context.Response.AddHeader("Access-Control-Allow-Origin", AppConfig.MoblieInterfaceDomain); //接口返回数据格式 context.Response.ContentType = "application/json"; //接口请求类型 string action = GameRequest.GetQueryString("action").ToLower(); try { lock (lockobj) { System.IO.Stream s = context.Request.InputStream; StreamReader sr = new StreamReader(s, System.Text.ASCIIEncoding.UTF8); string ret = sr.ReadToEnd(); //Log4Net.WriteInfoLog("ret:" + ret); string userid = context.Request.Form["userid"]; //string log = context.Request.Form["logtext"]; int platformType = GameRequest.GetInt("platformType", 0); string TypeName = ""; if (platformType == 1) { TypeName = "Android"; } else if (platformType == 2) { TypeName = "IOS"; } Writelog(ret, userid, TypeName); context.Response.Write("true"); } } catch (Exception ex) { Log4Net.WriteInfoLog("下面一条为接口故障信息", "LogInterface"); Log4Net.WriteErrorLog(ex, "LogInterface"); context.Response.Write(ex); } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "application/json"; string action = GameRequest.GetString("action").ToLower(); int version = GameRequest.GetInt("version", 2); #region Version 2.0 Router if (version == 2) { try { //不需要认证的action string[] unNeedAuthActions = { "agentauth", "gettoken" }; string token = GameRequest.GetString("token"); string gameid = GameRequest.GetString("gameid"); string authheader = context.Request.Headers["Authorization"]; _ajv = new AjaxJsonValid(); _ajv.SetDataItem("apiVersion", 20180316); if (!string.IsNullOrEmpty(gameid)) { unNeedAuthActions[1] = "setpassword"; } //排除不需要认证后判断认证是否正确 if (!unNeedAuthActions.Contains(action)) { if (string.IsNullOrEmpty(token) && (string.IsNullOrEmpty(authheader) || !authheader.Contains("Bearer"))) { _ajv.code = (int)ApiCode.VertyParamErrorCode; _ajv.msg = string.Format(EnumHelper.GetDesc(ApiCode.VertyParamErrorCode), " token 缺失"); context.Response.Write(_ajv.SerializeToJson()); return; } string authToken = !string.IsNullOrEmpty(token) ? token : authheader.Replace("Bearer ", ""); AgentTokenInfo authInfo = FacadeManage.aideAgentFacade.VerifyAgentToken(authToken); if (authInfo == null) { _ajv.code = (int)ApiCode.Unauthorized; _ajv.msg = EnumHelper.GetDesc(ApiCode.Unauthorized); context.Response.Write(_ajv.SerializeToJson()); return; } //认证完成后 设置到全局 _agentInfo = FacadeManage.aideAgentFacade.GetAgentInfo(authInfo.AgentID, authInfo.UserID); } switch (action) { case "agentauth": //1.0 AgentAuth(GameRequest.GetString("gameid"), GameRequest.GetString("pass")); break; case "getinfo": //1.1 GetAgentInfo(); break; case "gettoken": //1.0 Gettoken(); break; case "getnicknamebygameid": //1.2 GetNickNameByGameID(GameRequest.GetInt("gameid", 0)); break; case "getrecord": //1.3 GetRecord(GameRequest.GetString("type")); break; case "getbelowlist": //1.4 GetBelowList(GameRequest.GetString("type"), GameRequest.GetString("query")); break; case "getawardinfo": //1.5 GetAwardInfo(); break; case "presentscore": //1.6 TakeScoreORDiamond(GameRequest.GetInt("gameid", 0), GameRequest.GetString("password"), GameRequest.GetInt("count", 0), Convert.ToByte(GameRequest.GetInt("type", 0))); break; case "presentdiamondorscore": PresentDiamondOrScore(GameRequest.GetInt("gameid", 0), GameRequest.GetString("password"), GameRequest.GetInt("count", 0), Convert.ToByte(GameRequest.GetInt("type", 0))); break; case "setpassword": //1.7 SetSafePass(GameRequest.GetString("password")); break; case "updatepassword": //1.8 UpdateSafePass(GameRequest.GetString("oldPassword"), GameRequest.GetString("newPassword")); break; case "updateinfo": //1.9 UpdateAgentInfo(GameRequest.GetString("address"), GameRequest.GetString("phone"), GameRequest.GetString("qq")); break; case "addagent": //1.10 AddBelowAgent(GameRequest.GetInt("gameid", 0), GameRequest.GetString("agentDomain"), GameRequest.GetString("compellation"), "", GameRequest.GetString("phone"), "" ); break; default: _ajv.code = (int)ApiCode.VertyParamErrorCode; _ajv.msg = string.Format(EnumHelper.GetDesc(ApiCode.VertyParamErrorCode), " action 对应接口不存在"); break; } context.Response.Write(_ajv.SerializeToJson()); } catch (Exception ex) { Log4Net.WriteInfoLog("下面一条为接口故障信息", "Agent_DataHandler"); Log4Net.WriteErrorLog(ex, "Agent_DataHandler"); _ajv = new AjaxJsonValid { code = (int)ApiCode.LogicErrorCode, msg = EnumHelper.GetDesc(ApiCode.LogicErrorCode) }; context.Response.Write(_ajv.SerializeToJson()); } } #endregion }
/// <summary> /// 统一处理入口(主要验证) /// </summary> /// <param name="context"></param> public void ProcessRequest(HttpContext context) { try { //允许跨站请求域名 context.Response.AddHeader("Access-Control-Allow-Origin", AppConfig.MoblieInterfaceDomain); //接口返回数据格式 context.Response.ContentType = "application/json"; //接口请求类型 string action = GameRequest.GetQueryString("action").ToLower(); //获取参数 _userid = GameRequest.GetQueryInt("userid", 0); _device = GameRequest.GetString("device"); _ajv = new AjaxJsonValid(); #if !DEBUG //DEBUG情况下不验证 string time = GameRequest.GetQueryString("time"); string sign = GameRequest.GetQueryString("sign"); //签名验证 _ajv = Fetch.VerifySignData((context.Request.QueryString["userid"] == null ? "" : _userid.ToString()) + AppConfig.MoblieInterfaceKey + time, sign); // Log4Net.WriteInfoLog("signStr:"+(context.Request.QueryString["userid"] == null ? "" : _userid.ToString()) + AppConfig.MoblieInterfaceKey + time + " sign:"+sign); if (_ajv.code == (int)ApiCode.VertySignErrorCode) { context.Response.Write(_ajv.SerializeToJson()); return; } #endif //参数验证 if (context.Request.QueryString["userid"] != null && _userid <= 0) { _ajv.code = (int)ApiCode.VertyParamErrorCode; _ajv.msg = string.Format(EnumHelper.GetDesc(ApiCode.VertyParamErrorCode), " userid 错误"); context.Response.Write(_ajv.SerializeToJson()); return; } //获取其他参数 int configid = GameRequest.GetQueryInt("configid", 0); int typeid = GameRequest.GetQueryInt("typeid", 0); switch (action) { case "webversion": _ajv.SetDataItem("apiVersion", 20171220); _ajv.SetDataItem("webVersion", "V1.1.8"); _ajv.SetDataItem("updateAt", "2018/02/03"); _ajv.SetValidDataValue(true); break; //获取手机端登录数据 case "getmobilelogindata": _ajv.SetDataItem("apiVersion", 20171017); GetMobileLoginData(); break; //获取手机端登录后数据 case "getmobileloginlater": _ajv.SetDataItem("apiVersion", 20171213); GetMobileLoginLater(); break; //获取充值产品列表 case "getpayproduct": _ajv.SetDataItem("apiVersion", 20171028); //获取参数 int typeId = GameRequest.GetQueryInt("typeid", 0); GetPayProduct(typeId); break; //领取推广有效好友奖励 case "receivespreadaward": //参数验证 if (configid <= 0) { _ajv.code = (int)ApiCode.VertyParamErrorCode; _ajv.msg = string.Format(EnumHelper.GetDesc(ApiCode.VertyParamErrorCode), " configid 错误"); context.Response.Write(_ajv.SerializeToJson()); return; } ReceiveSpreadAward(configid); break; case "getgameintrolist": _ajv.SetDataItem("apiVersion", 20171107); GetGameIntroList(); break; //钻石充值下单 case "createpayorder": _ajv.SetDataItem("apiVersion", 20171123); //获取参数 string paytype = GameRequest.GetQueryString("paytype"); string openid = GameRequest.GetQueryString("openid"); string subtype = GameRequest.GetQueryString("subtype"); //参数验证 if (configid <= 0 || paytype.Equals("")) { _ajv.code = (int)ApiCode.VertyParamErrorCode; _ajv.msg = string.Format(EnumHelper.GetDesc(ApiCode.VertyParamErrorCode), ""); context.Response.Write(_ajv.SerializeToJson()); return; } context.Response.Write(CreatePayOrder(configid, paytype, openid, subtype).SerializeToJson()); return; //获取排行榜数据 case "getrankingdata": _ajv.SetDataItem("apiVersion", 20171129); //参数验证 if (typeid <= 0 || typeid > 7) { _ajv.code = (int)ApiCode.VertyParamErrorCode; _ajv.msg = string.Format(EnumHelper.GetDesc(ApiCode.VertyParamErrorCode), " typeid 错误"); context.Response.Write(_ajv.SerializeToJson()); return; } GetRankingData(typeid); break; //获取财富信息 case "getuserwealth": GetUserWealth(); break; //获取玩家信息 case "getuserinfo": _ajv.SetDataItem("apiVersion", 20171208); GetUserInfo(); break; //领取排行奖励 case "receiverankingaward": _ajv.SetDataItem("apiVersion", 20171213); //获取参数 int dateid = GameRequest.GetQueryInt("dateid", 0); //参数验证 if (dateid <= 0 || typeid <= 0) { _ajv.code = (int)ApiCode.VertyParamErrorCode; _ajv.msg = string.Format(EnumHelper.GetDesc(ApiCode.VertyParamErrorCode), ""); context.Response.Write(_ajv.SerializeToJson()); return; } ReceiveRankingAward(dateid, typeid); break; //获取游戏列表 case "getgamelist": GetGameList(); break; //领取注册赠送奖励 case "receiveregistergrant": _ajv.SetDataItem("apiVersion", 20171213); ReceiveRegisterGrant(); break; //金币流水记录 case "recordtreasuretrade": RecordTreasureTrade(); break; //钻石流水记录 case "recorddiamondstrade": RecordDiamondsTrade(); break; //钻石兑换金币 case "diamondexchgold": _ajv.SetDataItem("apiVersion", 20171213); //for 响应规范 if (configid <= 0 || typeid < 0) { _ajv.code = (int)ApiCode.VertyParamErrorCode; _ajv.msg = string.Format(EnumHelper.GetDesc(ApiCode.VertyParamErrorCode), " configid或typeid 错误"); context.Response.Write(_ajv.SerializeToJson()); return; } DiamondExchGold(configid, typeid); break; case "getpayorderstatus": _ajv.SetDataItem("apiVersion", 20171127); string orderid = GameRequest.GetString("orderid"); if (string.IsNullOrEmpty(orderid)) { _ajv.code = (int)ApiCode.VertyParamErrorCode; _ajv.msg = string.Format(EnumHelper.GetDesc(ApiCode.VertyParamErrorCode), " orderid 错误"); context.Response.Write(_ajv.SerializeToJson()); return; } GetPayOrderStatus(orderid); break; case "getquestionandanswerlist": _ajv.SetDataItem("apiVersion", 20180125); GetQuestionAndAnswerList(); break; default: _ajv.code = (int)ApiCode.VertyParamErrorCode; _ajv.msg = string.Format(EnumHelper.GetDesc(ApiCode.VertyParamErrorCode), " action 错误"); break; } context.Response.Write(_ajv.SerializeToJson()); } catch (Exception ex) { Log4Net.WriteInfoLog("下面一条为手机接口故障信息", "MobileInterface"); Log4Net.WriteErrorLog(ex); _ajv = new AjaxJsonValid { code = 500, msg = "手机接口短暂故障,请联系管理员!" }; context.Response.Write(_ajv.SerializeToJson()); } context.Response.End(); }