public Response testapi(dynamic _) { ReqParameter <string> req = this.Bind <ReqParameter <string> >(); LoginModel loginModel = this.GetReqData <LoginModel>(); return(Response.AsText("hello")); }
/// <summary> /// 前置拦截器 /// </summary> /// <param name="ctx"></param> /// <returns></returns> private Response BeforeRequest(NancyContext ctx) { string path = ctx.ResolvedRoute.Description.Path; //验证登录状态 ReqParameter req = this.Bind <ReqParameter>(); loginMark = req.loginMark; token = req.token; if (path == "/learun/adms/user/login" || path == "/" || path == "/bgimg") {// 登录接口,默认页面接口不做权限验证处理 return(null); } OperatorResult res = OperatorHelper.Instance.IsOnLine(req.token, req.loginMark); if (res.stateCode == -1) { return(this.Fail("未找到登录信息")); } if (res.stateCode == 0) { return(this.Fail("登录信息已过期")); } else { // 获取登录者信息 userInfo = res.userInfo; } return(null); }
/// <summary> /// 获取请求数据 /// </summary> /// <returns></returns> public string GetReqData() { try { ReqParameter <string> req = this.Bind <ReqParameter <string> >(); return(req.data); } catch (Exception) { throw; } }
/// <summary> /// 获取请求数据 /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public T GetReqData <T>() where T : class { try { ReqParameter <string> req = this.Bind <ReqParameter <string> >(); return(req.data.ToObject <T>()); } catch (Exception) { throw; } }
/// <summary> /// 前置拦截器 /// </summary> /// <param name="ctx"></param> /// <returns></returns> private Response BeforeRequest(NancyContext ctx) { string path = ctx.ResolvedRoute.Description.Path; //验证登录状态 ReqParameter <string> req = this.Bind <ReqParameter <string> >(); loginMark = req.loginMark; token = req.token; var dicParam = new Dictionary <string, string>(); var ignoreUrl = new List <string>() { "/ayma/adms/user/login", "/", "/bgimg", "/webapi/openoauth/onlogin", "/webapi/openoauth/registeruserinfo", "/webapi/openoauth/verificode", "/webapi/openoauth/sendphonecode", "/webapi/orders/cancelorder", "/webapi/test/getca", "/ayma/api/productorder/syncorder", "/api/facerecording/getuserinfo", "/getuserinfo", "/webapi/scanrecord/getbarcodeinfo" }; if (ignoreUrl.Contains(path.ToLower()))// 登录接口,默认页面接口不做权限验证处理 { WriterInfaceLog(ctx, req); return(null); } //if (string.IsNullOrEmpty(req.token)) //{ // return Fail("缺少token"); //} //if (string.IsNullOrEmpty(req.loginMark)) //{ // return Fail("缺少loginMark"); //} WriterInfaceLog(ctx, req); //switch (currentOper.stateCode) //{ // case -1: // return this.Fail("未找到登录信息"); // case 0: // return this.Fail("登录信息已过期"); // default: // break; //} return(null); }
public void ReqServer(object reqData) { // 优先使用热更新的代码 if (ILRuntimeUtil.getInstance().checkDllClassHasFunc("NetUtil_hotfix", "ReqServer")) { ILRuntimeUtil.getInstance().getAppDomain().Invoke("HotFix_Project.NetUtil_hotfix", "ReqServer", null, reqData); return; } ReqParameter reqParameter = (ReqParameter)reqData; try { Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); iPEndPoint = new IPEndPoint(ipAddress, ipPort); socket.Connect(iPEndPoint); Console.WriteLine("连接服务器成功"); // 发送消息 sendmessage(socket, reqParameter.m_reqData); Console.WriteLine("发送消息:" + reqParameter.m_reqData); // 接收消息 string reces = receive(socket); //Console.WriteLine("收到服务端消息:" + reces); // 调用回调 if (reqParameter.m_netListen != null) { reqParameter.m_netListen.onNetListen(reqParameter.m_tag, reces); } socket.Close(); } catch (SocketException ex) { Console.WriteLine("异常:" + ex.Message); // 调用回调 if (reqParameter.m_netListen != null) { reqParameter.m_netListen.onNetListenError(reqParameter.m_tag); } } }
void ReqServer(object reqData) { ReqParameter reqParameter = (ReqParameter)reqData; try { Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); iPEndPoint = new IPEndPoint(ipAddress, ipPort); socket.Connect(iPEndPoint); Debug.Log("连接服务器成功"); // 发送消息 sendmessage(socket, reqParameter.m_reqData); // 接收消息 string reces = receive(socket); //Debug.Log("收到服务端消息:" + reces); // 调用回调 if (reqParameter.m_netListen != null) { reqParameter.m_netListen.onNetListen(reqParameter.m_tag, reces); } else { Debug.Log("m_netListen为空"); } socket.Close(); } catch (SocketException ex) { Debug.LogException(ex); // 调用回调 if (reqParameter.m_netListen != null) { reqParameter.m_netListen.onNetListenError(reqParameter.m_tag); } } }
/// <summary> /// 添加接口访问记录 /// </summary> public void WriterInfaceLog(NancyContext context, ReqParameter <string> req) { try { var logMessage = new LogMessage() { OperationTime = DateTime.Now }; logMessage.Url = context.Request.Url.Path; logMessage.Class = context.NegotiationContext.ModuleName; logMessage.Ip = Net.Ip; logMessage.Content = req.ToJson(); var message = new LogFormat().InfoFormat(logMessage); Logger.Info(message); } catch (Exception ex) { WriteLog(context, ex); } }
/// <summary> /// 验证登录票据 /// </summary> /// <param name="ctx">上下文数据</param> /// <returns></returns> private Response BeforeRequest(NancyContext ctx) { //验证登录状态 ReqParameter req = this.Bind <ReqParameter>(); OperatorResult res = OperatorHelper.Instance.IsOnLine(req.token, req.loginMark); if (res.stateCode == -1) { return(this.Fail("未找到登录信息")); } if (res.stateCode == 0) { return(this.Fail("登录信息已过期")); } else { // 获取登录者信息 userInfo = res.userInfo; } return(null); }
public List <RespNews> GetDomainNewsListLessThan72Hour(ReqParameter req) { return(Call <List <RespNews>, ReqParameter>(req, "GetDomainNewsListLessThan72Hour")); }
public List <RespNews> GetNews(ReqParameter req) { return(this.Call <List <RespNews>, ReqParameter>(req, "GetNews")); }