| | |
| | | if (serverHttpRequest instanceof ServletServerHttpRequest) { |
| | | HttpServletRequest request = ((ServletServerHttpRequest) serverHttpRequest).getServletRequest(); |
| | | Object appAuth = request.getAttribute("appAuth"); |
| | | if (appAuth != null) { |
| | | if (o instanceof R) { |
| | | String appkey = request.getHeader("appkey"); |
| | | Object reqCache = request.getAttribute("cache"); |
| | | if (!Cools.isEmpty(appkey)) { |
| | | boolean success = String.valueOf(((R) o).get("code")).equalsIgnoreCase("200"); |
| | | if (success){ |
| | | // 保存接口日志 |
| | | apiLogService.save( |
| | | String.valueOf(appAuth), |
| | | request.getRequestURI(), |
| | | appkey, |
| | | IpTools.gainRealIp(request), |
| | | reqCache==null?"": JSON.toJSONString(reqCache), |
| | | JSON.toJSONString(o), |
| | | success |
| | | ); |
| | | } else { |
| | | beforeBodyWriteCallApiLogSave( |
| | | String.valueOf(appAuth), |
| | | request.getRequestURI(), |
| | | appkey, |
| | | IpTools.gainRealIp(request), |
| | | reqCache==null?"": JSON.toJSONString(reqCache), |
| | | JSON.toJSONString(o), |
| | | success); |
| | | } |
| | | } |
| | | if (appAuth != null && o instanceof R) { |
| | | String appkey = request.getHeader("appkey"); |
| | | if (Cools.isEmpty(appkey)) { |
| | | appkey = "-"; |
| | | } |
| | | Object reqCache = request.getAttribute("cache"); |
| | | boolean success = String.valueOf(((R) o).get("code")).equalsIgnoreCase("200"); |
| | | if (success) { |
| | | apiLogService.save( |
| | | String.valueOf(appAuth), |
| | | request.getRequestURI(), |
| | | appkey, |
| | | IpTools.gainRealIp(request), |
| | | reqCache == null ? "" : JSON.toJSONString(reqCache), |
| | | JSON.toJSONString(o), |
| | | success |
| | | ); |
| | | } else { |
| | | beforeBodyWriteCallApiLogSave( |
| | | String.valueOf(appAuth), |
| | | request.getRequestURI(), |
| | | appkey, |
| | | IpTools.gainRealIp(request), |
| | | reqCache == null ? "" : JSON.toJSONString(reqCache), |
| | | JSON.toJSONString(o), |
| | | success); |
| | | } |
| | | } else if (o instanceof R && isInboundThirdPartyUri(request.getRequestURI())) { |
| | | String appkey = request.getHeader("appkey"); |
| | | if (Cools.isEmpty(appkey)) { |
| | | appkey = "-"; |
| | | } |
| | | Object reqCache = request.getAttribute("cache"); |
| | | boolean success = String.valueOf(((R) o).get("code")).equalsIgnoreCase("200"); |
| | | String ns = inboundNamespace(request.getRequestURI()); |
| | | if (success) { |
| | | apiLogService.save( |
| | | ns, |
| | | request.getRequestURI(), |
| | | appkey, |
| | | IpTools.gainRealIp(request), |
| | | reqCache == null ? "" : JSON.toJSONString(reqCache), |
| | | JSON.toJSONString(o), |
| | | success |
| | | ); |
| | | } else { |
| | | beforeBodyWriteCallApiLogSave( |
| | | ns, |
| | | request.getRequestURI(), |
| | | appkey, |
| | | IpTools.gainRealIp(request), |
| | | reqCache == null ? "" : JSON.toJSONString(reqCache), |
| | | JSON.toJSONString(o), |
| | | success); |
| | | } |
| | | } |
| | | } |
| | | return o; |
| | | } |
| | | |
| | | private static boolean isInboundThirdPartyUri(String uri) { |
| | | if (uri == null) { |
| | | return false; |
| | | } |
| | | return uri.contains("/open/asrs") || uri.contains("/wcs/openapi/report"); |
| | | } |
| | | |
| | | private static String inboundNamespace(String uri) { |
| | | if (uri != null && uri.contains("/wcs/openapi/report")) { |
| | | return "WCS回写"; |
| | | } |
| | | return "开放接口"; |
| | | } |
| | | |
| | | public void beforeBodyWriteCallApiLogSave(String name, String url, String appkey, String ip, String request, String response, boolean success) { |
| | | ApiLogService apiLogService = SpringUtils.getBean(ApiLogService.class); |
| | | String memo = response; |