钉钉查询NCC薪资
2024-02-15 本文已影响0人
更真实
功能效果
1.jpg2.jpg
3.jpg
根据钉钉code单点NCC
1. 根据钉钉code查询钉钉用户信息
/**
* @description 通过编码获取用户信息
* @param code
* @return
*/
public DingTalkUser getUser(String code) {
String token=this.getToken();
String url=String.format(dingTalkConfig.getUserinfoUrl(), token);
Map<String,String> param=new HashMap<String,String>();
param.put("code", code);
ResponseEntity<Response<DingTalkUser>> userInfo=restTemplate.exchange(url,HttpMethod.POST, new HttpEntity<>(param), new ParameterizedTypeReference<Response<DingTalkUser>>(){});
if(userInfo.getBody()!=null&&userInfo.getBody().getErrcode()==ERROR_CODE_SUCCESS) {
return userInfo.getBody().getResult();
}else {
Logger.error("获取钉钉用户信息失败:"+code);
throw new BusinessException("获取钉钉用户信息失败:code="+code+",token="+token);
}
}
2.根据钉钉userid生成NCC accessToken
/**根据钉钉code生成NCC accessToken
* 前提 钉钉LoginId与NCC userCode一致
* @author
*/
public class DingtalkLoginStrategy implements IMobLoginStrategy{
public String mobLogin(IMobHttpOperator operator) {
String token = null;
String str = operator.getRequest().read();
IJson json = JsonFactory.create();
DingtalkLoginVO dingtalkLoginVO = (DingtalkLoginVO) json.fromJson(str, DingtalkLoginVO.class);
try {
IBusiCenterManageService bcmService = (IBusiCenterManageService) ServiceLocator.find(IBusiCenterManageService.class);
BusiCenterVO busiVO = bcmService.getBusiCenterByCode(dingtalkLoginVO.getBusiCenterCode());
if (busiVO == null) {
throw new MobileException("找不到" + dingtalkLoginVO.getBusiCenterCode() + "对应的账套,请检查在钉钉配置的地址");
}
IUserService userService = (IUserService) ServiceLocator.find(IUserService.class);
DingTalkUser dingTalkUser=userService.getUser(dingtalkLoginVO.getDingtalkCode());
// 如果钉钉和NCC手机号一致,需要使用BaseDAO 通过手机号查询NCC userCode
UserVO userVO = ((INCUserQueryService) ServiceLocator.find(INCUserQueryService.class)).findUserVO(busiVO.getDataSourceName(), dingTalkUser.getLoginId());
if(userVO==null) {
throw new MobileException("NCC未查询到用户:"+dingtalkLoginVO.getUserCode()+",请先在NCC创建用户");
}
Map<String, String> userObject = new HashMap<String, String>();
// userObject.put(MobNCCloudAccessToken.tenantId, "123");
userObject.put(MobNCCloudAccessToken.yhtUserId, userVO.getUser_code());
// userObject.put(MobNCCloudAccessToken.userPhone, "12345678910");
token = MobTokenUtil.generateMobToken(busiVO, userVO, operator, userObject);
} catch (Exception e) {
ExceptionUtils.wrapException(e);
}
return token;
}
public MobLoginType getLoginType() {
return null;
}
}