update hiwork单点登录 增加log

This commit is contained in:
lijiarao
2024-03-01 14:55:41 +08:00
parent 9071dddb90
commit fd35a90c2d
@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
import com.jero.common.api.vo.Result;
import com.jero.modules.docking.hiwork.entity.HiworkUserInfo;
import com.jero.modules.system.service.ILoginService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@@ -14,6 +15,7 @@ import javax.annotation.Resource;
* @author liJiaRao
* @date 2024-03-01 14:02
*/
@Slf4j
@Service
public class HiworkService {
@Resource
@@ -26,17 +28,24 @@ public class HiworkService {
public Result<JSONObject> login(JSONObject jsonObject) {
//根据appkey和appsecret获取accessToken
String body = HttpRequest.get("https://oapi.dingtalk.com/gettoken?appkey=" + appkey + "&appsecret=" + appsecret)
String url1 = "https://oapi.dingtalk.com/gettoken?appkey=" + appkey + "&appsecret=" + appsecret;
log.info("url:"+url1);
String body = HttpRequest.get(url1)
.execute().body();
JSONObject responseJson = JSONObject.parseObject(body);
log.info("responseJson:"+responseJson.toJSONString());
String accessToken = responseJson.getString("access_token");
//根据accessToken和前端传过来的jsonObject获得用户信息
String body1 = HttpRequest.post("https://oapi.dingtalk.com/topapi/v2/user/getuserinfo?access_token=" + accessToken)
String url2 = "https://oapi.dingtalk.com/topapi/v2/user/getuserinfo?access_token=" + accessToken;
log.info("url:"+url2);
String body1 = HttpRequest.post(url2)
//jsonObject中有code
.body(jsonObject.toJSONString())
.execute().body();
HiworkUserInfo hiworkUserInfo = JSONObject.parseObject(body1, HiworkUserInfo.class);
log.info("response:"+hiworkUserInfo.toString());
String userid = hiworkUserInfo.getResult().getUserid();
log.info("userid:"+userid);
return loginService.loginByUserName(userid);
}
}