|
@@ -1,34 +1,70 @@
|
|
package com.rtrh.projects.web.controller.passport.api;
|
|
package com.rtrh.projects.web.controller.passport.api;
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.rtrh.projects.outapi.result.JsonResult;
|
|
import com.rtrh.projects.web.controller.BaseController;
|
|
import com.rtrh.projects.web.controller.BaseController;
|
|
import com.rtrh.projects.web.util.JwtUtil;
|
|
import com.rtrh.projects.web.util.JwtUtil;
|
|
import com.team.security.TeamShiroUser;
|
|
import com.team.security.TeamShiroUser;
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
+import org.apache.http.HttpEntity;
|
|
|
|
+import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
|
+import org.apache.http.client.methods.HttpGet;
|
|
|
|
+import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
|
+import org.apache.http.impl.client.HttpClients;
|
|
|
|
+import org.apache.http.util.EntityUtils;
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.util.ResourceBundle;
|
|
|
|
|
|
@RestController
|
|
@RestController
|
|
-@RequestMapping("/switch")
|
|
|
|
|
|
+@RequestMapping("/app/switch")
|
|
public class SwitchApiController extends BaseController {
|
|
public class SwitchApiController extends BaseController {
|
|
|
|
|
|
/**
|
|
/**
|
|
* 切换到发改委系统
|
|
* 切换到发改委系统
|
|
|
|
+ *
|
|
* @param request
|
|
* @param request
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- @GetMapping("/toFgw")
|
|
|
|
- public String switchToFgw(HttpServletRequest request) {
|
|
|
|
-
|
|
|
|
- //获取当前用户信息
|
|
|
|
|
|
+ @PostMapping("/toFgw")
|
|
|
|
+ public Object switchToFgw() {
|
|
|
|
+ // 获取当前用户信息
|
|
TeamShiroUser curUser = getCurUser();
|
|
TeamShiroUser curUser = getCurUser();
|
|
- //使用jwt生成token
|
|
|
|
|
|
+ // 使用jwt生成token
|
|
String token = JwtUtil.generateToken(curUser.getLoginName());
|
|
String token = JwtUtil.generateToken(curUser.getLoginName());
|
|
-
|
|
|
|
|
|
+ if (token == null || token.isEmpty()) {
|
|
|
|
+ // 处理token生成失败的情况
|
|
|
|
+ throw new RuntimeException("token生成失败"); // 或者抛出异常,由全局异常处理器处理
|
|
|
|
+ }
|
|
|
|
+ ResourceBundle resourceBundle = ResourceBundle.getBundle("config");
|
|
|
|
+ String url = resourceBundle.getString("app.fgw.url");
|
|
// 拼接 B 系统的 URL
|
|
// 拼接 B 系统的 URL
|
|
- String targetUrl = "http://localhost:8090/projects/api/login?token=" + token;
|
|
|
|
- return "redirect:" + targetUrl;
|
|
|
|
|
|
+ // 获取B系统的登录token
|
|
|
|
+ String targetUrl = url+"/projects/outApi/auth/fgwLogin?token=" + token;
|
|
|
|
+
|
|
|
|
+ // 创建一个HttpClient实例
|
|
|
|
+ // 创建一个HttpClient实例
|
|
|
|
+ try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
|
|
|
|
+ // 创建一个HttpGet请求
|
|
|
|
+ HttpGet request = new HttpGet(targetUrl);
|
|
|
|
+ // 发送请求并获取响应
|
|
|
|
+ try (CloseableHttpResponse response = httpClient.execute(request)) {
|
|
|
|
+ // 获取响应实体
|
|
|
|
+ HttpEntity entity = response.getEntity();
|
|
|
|
+ // 如果响应实体不为空,则输出响应内容
|
|
|
|
+ if (entity != null) {
|
|
|
|
+ String responseBody = EntityUtils.toString(entity);
|
|
|
|
+ System.out.println("Response body: " + responseBody);
|
|
|
|
+ JsonResult result = JSONObject.parseObject(responseBody, JsonResult.class);
|
|
|
|
+ result.setMsg(url);
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|