From b99c66a7f0a333af463e3891c187fdb83dd43bf3 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 28 Mar 2023 12:11:31 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B7=B3=E8=BD=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/idc/controller/IdcController.java | 88 +++++++++++++++++++ .../glxp/sale/admin/util/RedirectUtils.java | 3 +- 2 files changed, 90 insertions(+), 1 deletion(-) diff --git a/api-admin/src/main/java/com/glxp/sale/admin/idc/controller/IdcController.java b/api-admin/src/main/java/com/glxp/sale/admin/idc/controller/IdcController.java index a10c1e3..eaab010 100644 --- a/api-admin/src/main/java/com/glxp/sale/admin/idc/controller/IdcController.java +++ b/api-admin/src/main/java/com/glxp/sale/admin/idc/controller/IdcController.java @@ -1,17 +1,28 @@ package com.glxp.sale.admin.idc.controller; +import java.io.BufferedReader; +import java.io.IOException; +import java.util.Enumeration; +import java.util.HashMap; import java.util.Map; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; +import org.apache.commons.lang3.StringUtils; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.RestTemplate; import org.springframework.web.multipart.MultipartFile; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.glxp.sale.admin.idc.dao.DbDao; import com.glxp.sale.admin.idc.service.IdcService; import com.glxp.sale.common.res.BaseResponse; @@ -71,4 +82,81 @@ public class IdcController { public BaseResponse success(HttpServletRequest request,@RequestBody Map params) { return idcService.downlaodSuccess(request,params); } + + @RequestMapping("/mapi/**") + public JSONObject mapi(HttpServletRequest request) { + + return redirect(request); + } + @RequestMapping("/zapi/**") + public JSONObject zapi(HttpServletRequest request) { + + return redirect(request); + } + private JSONObject redirect(HttpServletRequest request) { + String uri = parseUri(request.getRequestURL().toString()); + RestTemplate restTemplate = new RestTemplate(); + + + Map headerParam = getAllReaderParam(request); + Map bodyParam = new HashMap(); + Enumeration pNames=request.getParameterNames(); + while(pNames.hasMoreElements()){ + String name=(String)pNames.nextElement(); + String value=request.getParameter(name); + bodyParam.put(name, value); + } + + HttpHeaders headers = new HttpHeaders(); + //headers.add("Content-Type", "application/json;charset=UTF-8"); + for(String key : headerParam.keySet()){ + headers.add(key, headerParam.get(key).toString()); + } + System.out.print(JSON.toJSONString(headerParam)); + System.out.print(JSON.toJSONString(bodyParam)); + HttpEntity http = new HttpEntity<>(JSON.toJSONString(bodyParam), headers); + ResponseEntity responseBody = restTemplate.postForEntity("http://127.0.0.1:8090/"+uri, http, JSONObject.class); + JSONObject result = responseBody.getBody(); + return result; + } + + + private Map getAllReaderParam(HttpServletRequest request) { + Map result = new HashMap<>(); + BufferedReader br; + try { + br = request.getReader(); + if(br!=null) { + System.out.print("-----------------------"); + System.out.print(br.readLine()); + } + String str, wholeStr = ""; + while((str = br.readLine()) != null){ + wholeStr += str; + System.out.print(str); + } + if(!StringUtils.isEmpty(wholeStr)) { + result = JSON.parseObject(wholeStr); + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return result; + } + private String parseUri(String url) { + String uri = url; + int a1 = uri.indexOf("://"); + int a2 = 0; + if(a1>0) { + a2 = uri.indexOf("/",a1 +4); + if(a2>0) { + uri = uri.substring(a2 +1); + } + } + return uri; + } + + } diff --git a/api-admin/src/main/java/com/glxp/sale/admin/util/RedirectUtils.java b/api-admin/src/main/java/com/glxp/sale/admin/util/RedirectUtils.java index cc82a76..60d2ff5 100644 --- a/api-admin/src/main/java/com/glxp/sale/admin/util/RedirectUtils.java +++ b/api-admin/src/main/java/com/glxp/sale/admin/util/RedirectUtils.java @@ -1,5 +1,6 @@ package com.glxp.sale.admin.util; public class RedirectUtils { - + + }