public override void ProcessRequest(System.Web.HttpContext context) { string json = LocalCacheManager <string> .Find(_apimethodname + "_json", () => { StringBuilder sb = new StringBuilder(); sb.AppendFormat("接口地址:<span style=\"color:blue;\"><a href=\"###\">{0}</a></span><br/><p/>", new Regex("/json$", RegexOptions.IgnoreCase).Replace(context.Request.Url.AbsolutePath, "")); sb.AppendFormat("接口功能:<span style=\"color:blue;\">{0}</span><br/><p/>", _hander.ApiMethodProp.Function ?? string.Empty); sb.Append("<font>接口数据序列化格式:json</font><br/><p/>"); sb.Append("请求参数:<br/>"); sb.Append("<table style=\"border:solid 1px yellow;\" border=\"1\">"); sb.AppendFormat("<tr><th>参数名</th><th>参数类型</th><th>备注</th></tr>"); EntityBufCore.GetPropToTable(_hander._requestType, sb); sb.Append("</table>"); //context.Response.Write(string.Format("{0}", sb.ToString())); sb.Append("<br/>"); sb.Append("响应类型:<br/>"); sb.Append("<table style=\"border:solid 1px yellow;\" border=\"1\">"); sb.AppendFormat("<tr><th>参数名</th><th>参数类型</th><th>备注</th></tr>"); var apiType = typeof(APIResult <>); var apiResultType = (_hander.ApiMethodProp.OutPutContentType == OutPutContentType.apiObject || !_hander.ApiMethodProp.StandApiOutPut) ? _hander._responseType : apiType.MakeGenericType(new[] { _hander._responseType }); EntityBufCore.GetPropToTable(apiResultType, sb); sb.Append("</table>"); if (!string.IsNullOrWhiteSpace(_ipLimit)) { sb.Append("<br/>"); sb.AppendFormat("<div style='font-weight:bold;color:red;'>ip限制:{0}</div>", _ipLimit); } return(sb.ToString()); }, 1440); context.Response.Write(json); }
public override bool Process(HttpServer server, HttpRequest request, HttpResponse response) { string json = LocalCacheManager <string> .Find(_apimethodname + "_json", () => { StringBuilder sb = new StringBuilder(); sb.Append("<html>"); sb.Append(@"<head><title>接口文档</title><style>.heading1{background:#003366;margin-top:0px; color:#fff; padding-top:5px; line-height:40px; width:100%;display:block;} table,pre{ background:#e5e5cc;} table{border-left:solid 1px #ccc;font-size:11px;width:98%;margin-left:5px;border-bottom:none;border-top:solid 1px #ccc;border-right:none;} td,th{border-top:none;border-right:solid 1px #ccc;border-bottom:solid 1px #ccc;} iframe{width:100%; background:#e5e5cc; margin-bottom:15px;} </style></head>"); sb.Append("<body style='width:100%;margin:0px;padding:0px;'>"); sb.Append("<h1 class=\"heading1\">" + (this._hander.ApiMethodProp.Aliname ?? this._apimethodname) + "接口文档</h1>"); sb.AppendFormat("<span class='title'>接口地址:</span><span style=\"color:blue;\"><a href=\"###\">{0}</a></span><br/><p/>", new Regex("/json$", RegexOptions.IgnoreCase).Replace(request.Url, "")); sb.AppendFormat("<span class='title'>接口功能:</span><span style=\"color:blue;\">{0}</span><br/><p/>", _hander.ApiMethodProp.Function ?? string.Empty); sb.Append("<span class='title'><font>接口数据序列化格式:json</font></span><br/><p/>"); sb.AppendFormat("<span class='title'>接口请求json示例:</span><span style=\"color:blue;display:none;\"><a href=\"{0}\" target=\"_blank\">{0}</a></span><br/><p/>", new Regex("/json$", RegexOptions.IgnoreCase).Replace(request.Url, "") + "/req"); sb.AppendFormat("<iframe id=\"req\" frameborder=\"no\" border=\"0\" marginwidth=\"0\" marginheight=\"0\" src=\"{0}/req\"></iframe>", new Regex("/json$", RegexOptions.IgnoreCase).Replace(request.Url, "")); sb.AppendFormat("<span class='title'>接口响应json示例:</span><span style=\"color:blue;display:none;\"><a href=\"{0}\" target=\"_blank\">{0}</a></span><br/><p/>", new Regex("/json$", RegexOptions.IgnoreCase).Replace(request.Url, "") + "/resp"); sb.AppendFormat("<iframe id=\"resp\" frameborder=\"no\" border=\"0\" marginwidth=\"0\" marginheight=\"0\" src=\"{0}/resp\"></iframe>", new Regex("/json$", RegexOptions.IgnoreCase).Replace(request.Url, "")); sb.Append("<span class='title'>请求参数说明:</span><p/>"); sb.Append("<table cellpadding=0 cellspacing=0 border=\"0\">"); sb.AppendFormat("<tr><th>参数名</th><th>参数类型</th><th>备注</th></tr>"); EntityBufCore.GetPropToTable(_hander._requestType, sb); sb.Append("</table>"); //context.Response.Write(string.Format("{0}", sb.ToString())); sb.Append("<br/>"); sb.Append("响应类型:<p/>"); sb.Append("<table cellpadding=0 cellspacing=0 border=\"0\">"); sb.AppendFormat("<tr><th>参数名</th><th>参数类型</th><th>备注</th></tr>"); var apiType = typeof(APIResult <>); var apiResultType = (_hander.ApiMethodProp.OutPutContentType == OutPutContentType.apiObject || !_hander.ApiMethodProp.StandApiOutPut) ? _hander._responseType : apiType.MakeGenericType(new[] { _hander._responseType }); EntityBufCore.GetPropToTable(apiResultType, sb); sb.Append("</table>"); sb.Append("<br/>"); sb.AppendFormat("<a href=\"{0}\">接口调用测试</a>", new Regex("/json$", RegexOptions.IgnoreCase).Replace(request.Url, "") + "/invoke"); if (!string.IsNullOrWhiteSpace(_ipLimit)) { sb.Append("<br/>"); sb.AppendFormat("<div style='font-weight:bold;color:red;'>ip限制:{0}</div>", _ipLimit); } sb.Append("<p/></p>"); sb.Append("</body>"); sb.Append("</html>"); return(sb.ToString()); }, 1440); response.Content = json; response.ReturnCode = 200; return(true); }
public override bool Process(HttpServer server, HttpRequest request, HttpResponse response) { string json = LocalCacheManager <string> .Find(_apimethodname + "_invoke", () => { StringBuilder sb = new StringBuilder(); sb.Append("<html>"); sb.Append(@"<head><title>接口调用</title><style> .heading1{background:#003366;margin-top:0px; color:#fff; padding-top:5px; line-height:40px; width:100%;display:block;} #datacontainer table { width:98%; font-family: verdana,arial,sans-serif; font-size:11px; color:#333333; border-width: 1px; border-color: #ccc; border-collapse: collapse; } #datacontainer table th { border-width: 1px; padding: 8px; border-style: solid; border-color: #ccc; background-color: #dedede; } #datacontainer table td { vertical-align:top; border-width: 1px; padding: 8px; border-style: solid; border-color: #ccc; background-color: #ffffff; } .spanbutton{ cursor:pointer; margin-right:5px; font-weight:bold; font-size:18px; color:#10bd86; } h2{margin:0;padding:0;} #overlay{position:absolute;top:0;left:0;width:100%;height:100%;background: rgba(0, 0, 0, 0.5);display:none;} #win{position:absolute;top:10%;left:10%;width:80%;height:80%;background:#fff;border:4px solid #ccc;opacity:1;filter:alpha(opacity=100);} h2{font-size:12px;text-align:right;background:#ccc;border-bottom:3px solid #ccc;padding:5px;} h2 span{color:#f90;cursor:pointer;background:#fff;border:1px solid #ccc;padding:0 2px;} #tab1,#tab2 {float:left; width:120px; line-height:25px; margin-right:5px;margin-top:4px; color:#333; background:#eee; text-align:center; cursor:pointer; font-weight:bold;} #tab1.on,#tab2.on {background:#333; color:#fff;} textarea {border:0px;} </style></head>"); sb.Append("<body style='width:100%;margin:0px;'>"); sb.Append("<h1 class=\"heading1\">" + (this._hander.ApiMethodProp.Aliname ?? this._apimethodname) + "接口调用</h1>"); sb.Append("<div id='datacontainer' style=\"width:90%;margin:0 auto;\">"); EntityBufCore.GetInvokeHtml(_hander._requestType, false, sb); //context.Response.Write(string.Format("{0}", sb.ToString())); sb.Append("<div style=\"clear:both;\"></div>"); sb.Append("<div style=\"float:right;margin-top:15px;margin-bottom:50px;padding-right:20px;\"><input type=\"button\" value=\"提 交\" style='width:200px;line-height:30px;' onclick=\"submit()\"/></div>"); sb.Append("</div>"); sb.Append("<div id =\"overlay\" >"); sb.Append("<div id=\"win\"><span id=\"tab1\" onclick=\"changetab('tab1','page1','tab2','page2')\" style='margin-left:10px;'>请求</span><span class='on' onclick=\"changetab('tab2','page2','tab1','page1')\" id=\"tab2\">结果</span><h2><span id =\"close\"> x </span></h2><div id='page1' style=\"width:100%;height:90%;display:none;\"><textarea id=\"sendjsondata\" style=\"width:100%;height:100%;\"></textarea></div><div id='page2' style=\"width:100%;height:90%;\"><textarea id=\"jsondata\" style=\"width:100%;height:100%;\"></textarea></div></div>"); sb.Append("</div>"); sb.Append(Functions(new Regex("/invoke$", RegexOptions.IgnoreCase).Replace(request.Url, ""))); sb.Append("</body>"); sb.Append("</html>"); return(sb.ToString()); }, 1440); response.Content = json; response.ReturnCode = 200; return(true); }