|
@@ -0,0 +1,79 @@
|
|
|
+package com.persagy.ibms.data.sdk.service.rest;
|
|
|
+
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
|
+import com.persagy.ibms.core.util.LogUtil;
|
|
|
+import com.persagy.ibms.data.sdk.util.ConfigRedirect;
|
|
|
+import com.persagy.ibms.data.sdk.util.Constant;
|
|
|
+import com.persagy.ibms.data.sdk.util.HttpClientUtil;
|
|
|
+
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+
|
|
|
+@ApiOperation(value = "重定向接口")
|
|
|
+@RestController
|
|
|
+@Slf4j
|
|
|
+public class RedirectApi {
|
|
|
+
|
|
|
+ @PostMapping(path = { "/redirect", "/zkt-sdk/redirect" }, produces = "application/json;charset=UTF-8")
|
|
|
+ public String redirect(@RequestBody String param) {
|
|
|
+ String result;
|
|
|
+ JSONObject sql_json = JSON.parseObject(param);
|
|
|
+ String code = sql_json.getString("code");
|
|
|
+ ConfigRedirect ConfigRedirect = Constant.ConfigRedirectMap.get(code);
|
|
|
+ if (ConfigRedirect == null) {
|
|
|
+ JSONObject resultJSON = new JSONObject();
|
|
|
+ resultJSON.put("Result", "failure");
|
|
|
+ resultJSON.put("ResultMsg", "code: " + code + " not exist");
|
|
|
+ resultJSON.put("ResultCode", 250);
|
|
|
+ return JSONObject.toJSONString(resultJSON, SerializerFeature.WriteMapNullValue);
|
|
|
+ }
|
|
|
+ String url = ConfigRedirect.url;
|
|
|
+ JSONObject urlParams = sql_json.getJSONObject("urlParams");
|
|
|
+ if (urlParams != null) {
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
+ for (String key : urlParams.keySet()) {
|
|
|
+ if (sb.length() > 0) {
|
|
|
+ sb.append("&");
|
|
|
+ }
|
|
|
+ sb.append(key + "=" + urlParams.get(key));
|
|
|
+ }
|
|
|
+ url = url + "?" + sb.toString();
|
|
|
+ }
|
|
|
+ String urlSuffix = sql_json.getString("urlSuffix");
|
|
|
+ if (urlSuffix != null) {
|
|
|
+ url = url + urlSuffix;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ if (ConfigRedirect.http_request_type.equals("get")) {
|
|
|
+ result = HttpClientUtil.get(url);
|
|
|
+ } else {
|
|
|
+ Object postBody = sql_json.get("postBody");
|
|
|
+ String postString;
|
|
|
+ if (postBody instanceof JSONObject) {
|
|
|
+ postString = JSONObject.toJSONString((JSONObject) postBody, SerializerFeature.WriteMapNullValue);
|
|
|
+ } else if (postBody instanceof JSONArray) {
|
|
|
+ postString = JSONArray.toJSONString((JSONArray) postBody, SerializerFeature.WriteMapNullValue);
|
|
|
+ } else {
|
|
|
+ postString = postBody.toString();
|
|
|
+ }
|
|
|
+ result = HttpClientUtil.post(url, postString);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ JSONObject resultJSON = new JSONObject();
|
|
|
+ resultJSON.put("Result", "failure");
|
|
|
+ String message = LogUtil.GetExceptionStackTrace(e);
|
|
|
+ resultJSON.put("ResultMsg", message);
|
|
|
+ resultJSON.put("ResultCode", 250);
|
|
|
+ result = JSONObject.toJSONString(resultJSON, SerializerFeature.WriteMapNullValue);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+}
|