add oa单点登录
This commit is contained in:
+31
@@ -0,0 +1,31 @@
|
||||
package com.jero.modules.docking.oa.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.jero.common.api.vo.Result;
|
||||
import com.jero.modules.docking.oa.service.OAService;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
|
||||
/**
|
||||
* @author lijiarao
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/oa")
|
||||
@Slf4j
|
||||
public class OALoginController {
|
||||
@Resource
|
||||
private OAService oaService;
|
||||
|
||||
@ApiOperation("OA单点登录")
|
||||
@PostMapping("/login")
|
||||
public Result<JSONObject> login(@RequestBody JSONObject jsonObject){
|
||||
return oaService.login(jsonObject);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.jero.modules.docking.oa.service;
|
||||
|
||||
import cn.hutool.http.Header;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.jero.common.api.vo.Result;
|
||||
import com.jero.modules.system.service.ILoginService;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* @author liJiaRao
|
||||
* @date 2024-02-26 17:20
|
||||
*/
|
||||
@Service
|
||||
public class OAService {
|
||||
@Resource
|
||||
private ILoginService loginService;
|
||||
|
||||
public static final String TICKET = "ticket";
|
||||
public static final String APP_ID = "appId";
|
||||
public static final String APP_SECRET = "appSecret";
|
||||
public static final String ACCESS_TOKEN = "accessToken";
|
||||
public static final String USER_NAME = "userName";
|
||||
|
||||
@Value("${oa.getAccessTokenUrl}")
|
||||
private String getAccessTokenUrl;
|
||||
@Value("${oa.getTicketInfoUrl}")
|
||||
private String getTicketInfoUrl;
|
||||
@Value("${oa.appId}")
|
||||
private String appId;
|
||||
@Value("${oa.appSecret}")
|
||||
private String appSecret;
|
||||
|
||||
|
||||
public Result<JSONObject> login(JSONObject jsonObject) {
|
||||
String ticket = jsonObject.getString(TICKET);
|
||||
JSONObject body = new JSONObject();
|
||||
body.put(APP_ID, appId);
|
||||
body.put(APP_SECRET, appSecret);
|
||||
|
||||
String post = HttpRequest.post(getAccessTokenUrl)
|
||||
.header(Header.CONTENT_TYPE, "application/json")
|
||||
.body(body.toJSONString())
|
||||
.execute().body();
|
||||
JSONObject responseJson = JSONObject.parseObject(post);
|
||||
|
||||
String accessToken = responseJson.getString(ACCESS_TOKEN);
|
||||
JSONObject body1 = new JSONObject();
|
||||
body1.put(ACCESS_TOKEN, accessToken);
|
||||
body1.put(TICKET, ticket);
|
||||
String post1 = HttpRequest.post(getTicketInfoUrl)
|
||||
.header(Header.CONTENT_TYPE, "application/json")
|
||||
.body(body1.toJSONString())
|
||||
.execute().body();
|
||||
JSONObject responseJson1 = JSONObject.parseObject(post1);
|
||||
String userName = responseJson1.getString(USER_NAME);
|
||||
|
||||
return loginService.loginByUserName(userName);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user