提交 f270c419 authored 作者: 李秋林's avatar 李秋林

勤策登录接口

上级 3078caab
package com.sfa.auth.controller;
import com.sfa.auth.service.SysLoginService;
import com.sfa.auth.util.QinCeUtil;
import com.sfa.common.security.service.TokenService;
import com.sfa.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
/**
* @author : liqiulin
* @date : 2025-03-25 17
* @describe : 勤策登录
*/
@RestController
public class QcTokenController {
@Autowired
private TokenService tokenService;
@Autowired
private QinCeUtil qinCeUtil;
@Autowired
private SysLoginService sysLoginService;
@GetMapping("/qc/login")
public Map<String, Object> login(String code){
String accessToken = qinCeUtil.getAccessToken();
String employeeNo = qinCeUtil.getUserInfo(accessToken, code);
LoginUser loginUser = sysLoginService.fsLogin(employeeNo);
return tokenService.createToken(loginUser);
}
}
......@@ -26,27 +26,27 @@ public class LoginBody
/**
* 飞书免登code
* 飞书 / 勤策
* 免登code
*/
private String code;
public String getUsername()
{
return username;
}
public void setUsername(String username)
{
this.username = username;
}
public String getPassword()
{
return password;
}
public void setPassword(String password)
{
this.password = password;
}
/**
* 勤策登录-固定值:STATE
*/
private String state;
/**
* 勤策登录 tenant_id
*/
private String tenantId;
/**
* 勤策登录 app_id
*/
private String appId;
}
package com.sfa.auth.util;
import com.alibaba.fastjson2.JSONObject;
import com.lark.oapi.okhttp.*;
import com.sfa.common.core.enums.ECode;
import com.sfa.common.core.exception.auth.NotLoginException;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.util.HashMap;
/**
* @author : liqiulin
* @date : 2025-03-26 11
* @describe :
*/
@Component
public class QinCeUtil {
private static final String QINCE_OSS_URL = "https://sso.qince.com/service/oauth";
private static final String APP_ID = "app1742881477251";
private static final String APP_SECRET = "wr87Ozn7Dp10rR656xRCxfuxOxYs9OR0";
private static final String TENANT_ID = "6035565720566270399";
public String getAccessToken() {
try {
String ossUrl = QINCE_OSS_URL+"/token";
HashMap<String, String> bodyMap = new HashMap<>();
bodyMap.put("app_id", APP_ID);
bodyMap.put("app_secret", APP_SECRET);
bodyMap.put("tenant_id", TENANT_ID);
OkHttpClient client = new OkHttpClient();
RequestBody body = RequestBody.create(MediaType.parse("application/json"), JSONObject.toJSONString(bodyMap));
Request request = new Request.Builder().url(ossUrl).post(body).build();
Response execute = client.newCall(request).execute();
JSONObject rj = JSONObject.parseObject(execute.body().string());
Integer returnCode = rj.getInteger("return_code");
if (returnCode != 0){
throw new NotLoginException(ECode.QC_ACCESS_TOKEN_ERROR);
}
return rj.getJSONObject("return_data").getString("access_token");
} catch (IOException e) {
throw new RuntimeException(e);
}
}
/**
* 获取当前登录人的登录账号
* @param accessToken
* @param code
* @return
*/
public String getUserInfo(String accessToken, String code) {
try {
String ossUrl = QINCE_OSS_URL + "/userinfo?access_token=" + accessToken + "&code=" + code;
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder().url(ossUrl).get().build();
Response execute = client.newCall(request).execute();
JSONObject rj = JSONObject.parseObject(execute.body().string());
Integer returnCode = rj.getInteger("return_code");
if (returnCode != 0){
throw new NotLoginException(ECode.QC_ACCESS_TOKEN_ERROR);
}
return rj.getJSONObject("return_data").getString("code");
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论