| | |
| | | import com.dingtalk.api.response.OapiUserListidResponse; |
| | | import com.dingtalk.api.response.OapiV2UserGetbymobileResponse; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.exception.base.BaseException; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | |
| | | */ |
| | | public Map<String, Object> noLogin(String authCode) { |
| | | try { |
| | | String params = "access_token=" + dingTalkProxyClient.getAccessToken() + "&code=" + authCode; |
| | | // 复用同一个 accessToken,避免重复请求 |
| | | String accessToken = dingTalkProxyClient.getAccessToken(); |
| | | |
| | | // 第一步:authCode 换 userid |
| | | String params = "access_token=" + accessToken + "&code=" + authCode; |
| | | String result = HttpUtils.sendPost("https://oapi.dingtalk.com/topapi/v2/user/getuserinfo", params); |
| | | ObjectMapper objectMapper = new ObjectMapper(); |
| | | Map<String, Object> map = objectMapper.readValue(result, Map.class); |
| | | return map; |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage()); |
| | | new BaseException("登录出异常了,请联系管理员处理"); |
| | | if (!Integer.valueOf(0).equals(map.get("errcode"))) { |
| | | throw new BaseException("钉钉登录失败:" + map.get("errmsg")); |
| | | } |
| | | return null; |
| | | Map<String, Object> resultMap = (Map<String, Object>) map.get("result"); |
| | | String userid = (String) resultMap.get("userid"); |
| | | |
| | | // 第二步:userid 换用户详情(含手机号) |
| | | String params2 = "access_token=" + accessToken + "&userid=" + userid + "&language=zh_CN"; |
| | | String result2 = HttpUtils.sendPost("https://oapi.dingtalk.com/topapi/v2/user/get", params2); |
| | | Map<String, Object> map2 = objectMapper.readValue(result2, Map.class); |
| | | if (!Integer.valueOf(0).equals(map2.get("errcode"))) { |
| | | throw new BaseException("获取用户详情失败:" + map2.get("errmsg")); |
| | | } |
| | | Map<String, Object> userDetail = (Map<String, Object>) map2.get("result"); |
| | | |
| | | return userDetail; |
| | | } catch (BaseException e) { |
| | | throw e; |
| | | } catch (Exception e) { |
| | | log.error("noLogin 异常:{}", e); |
| | | throw new BaseException("登录出异常了,请联系管理员处理"); |
| | | } |
| | | } |
| | | |
| | | @Override |