提交修改
This commit is contained in:
commit
c0950a7282
@ -8,14 +8,18 @@ import com.dingtalk.api.DingTalkClient;
|
||||
import com.dingtalk.api.request.*;
|
||||
import com.dingtalk.api.response.*;
|
||||
import com.lz.modules.app.entity.StaffEntity;
|
||||
import com.lz.modules.app.service.StaffService;
|
||||
import com.lz.modules.job.model.responseBo.DepartmentInfosBo;
|
||||
import com.lz.modules.job.model.responseBo.DepartmentStaffBo;
|
||||
import com.lz.modules.sys.entity.SysUserEntity;
|
||||
import com.lz.modules.sys.service.SysUserTokenService;
|
||||
import com.lz.modules.third.entity.ThirdAppConfig;
|
||||
import com.lz.modules.third.entity.ThirdMsgSendRecord;
|
||||
import com.lz.modules.third.service.ThirdAppConfigService;
|
||||
import com.lz.modules.third.service.ThirdMsgSendRecordService;
|
||||
import com.lz.modules.third.service.impl.ThirdAppConfigServiceImpl;
|
||||
import com.taobao.api.ApiException;
|
||||
import net.bytebuddy.implementation.bytecode.Throw;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
@ -62,6 +66,12 @@ public class DingTalkUtil {
|
||||
@Autowired
|
||||
ThirdMsgSendRecordService thirdMsgSendRecordService;
|
||||
|
||||
@Autowired
|
||||
StaffService staffService;
|
||||
|
||||
@Autowired
|
||||
private SysUserTokenService sysUserTokenService;
|
||||
|
||||
|
||||
|
||||
CloseableHttpClient getHttpClient(){
|
||||
@ -80,18 +90,24 @@ public class DingTalkUtil {
|
||||
try {
|
||||
|
||||
ThirdAppConfig thirdAppConfig = thirdAppConfigService.getByAppId(appid);
|
||||
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken");
|
||||
OapiGettokenRequest req = new OapiGettokenRequest();
|
||||
req.setAppkey(thirdAppConfig.getAppKey());
|
||||
req.setAppsecret(thirdAppConfig.getAppSecret());
|
||||
req.setHttpMethod("GET");
|
||||
OapiGettokenResponse rsp = client.execute(req);
|
||||
String resultStr = rsp.getBody();
|
||||
JSONObject dataObj = JSON.parseObject(resultStr);
|
||||
String tenant_access_token = dataObj.getString("access_token");
|
||||
return tenant_access_token;
|
||||
} catch (ApiException e) {
|
||||
if(thirdAppConfig != null){
|
||||
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken");
|
||||
OapiGettokenRequest req = new OapiGettokenRequest();
|
||||
req.setAppkey(thirdAppConfig.getAppKey());
|
||||
req.setAppsecret(thirdAppConfig.getAppSecret());
|
||||
req.setHttpMethod("GET");
|
||||
OapiGettokenResponse rsp = client.execute(req);
|
||||
String resultStr = rsp.getBody();
|
||||
JSONObject dataObj = JSON.parseObject(resultStr);
|
||||
String tenant_access_token = dataObj.getString("access_token");
|
||||
return tenant_access_token;
|
||||
}else{
|
||||
logger.info("appid不存在,数据库未配置appid");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.info("获取token异常{}", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -142,7 +158,7 @@ public class DingTalkUtil {
|
||||
logger.info("获取部门详情异常{}", rsp.getBody());
|
||||
}
|
||||
return list;
|
||||
} catch (ApiException e) {
|
||||
} catch (Exception e) {
|
||||
logger.info("获取部门详情异常{}", e);
|
||||
}
|
||||
return null;
|
||||
@ -209,8 +225,9 @@ public class DingTalkUtil {
|
||||
}
|
||||
|
||||
return list;
|
||||
} catch (ApiException e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.info("获取部门用户详情异常{}", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -301,4 +318,40 @@ public class DingTalkUtil {
|
||||
thirdMsgSendRecordService.insert(thirdMsgSendRecord);
|
||||
return msg;
|
||||
}
|
||||
|
||||
public R getUserIdByCode(String code, String token) {
|
||||
try {
|
||||
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/user/getuserinfo");
|
||||
OapiUserGetuserinfoRequest req = new OapiUserGetuserinfoRequest();
|
||||
req.setCode(code);
|
||||
req.setHttpMethod("GET");
|
||||
OapiUserGetuserinfoResponse rsp = client.execute(req, token);
|
||||
JSONObject json = JSONObject.parseObject(rsp.getBody());
|
||||
if(json.getIntValue("errcode") == 0){
|
||||
String employeeId = json.getString("userid");
|
||||
StaffEntity staffEntity = staffService.selectStaffByEmployeeId(employeeId);
|
||||
if(staffEntity != null){
|
||||
//登录操作
|
||||
SysUserEntity user = new SysUserEntity();
|
||||
user.setPassword(staffEntity.getPassword());
|
||||
user.setMobile(staffEntity.getMobile());
|
||||
user.setUserId(staffEntity.getId());
|
||||
user.setEmail(staffEntity.getEmail());
|
||||
user.setSalt(staffEntity.getSalt());
|
||||
user.setStatus(1);
|
||||
user.setType(1);
|
||||
user.setRealName(staffEntity.getName());
|
||||
user.setUserNo(staffEntity.getMobile());
|
||||
return sysUserTokenService.createToken(user);
|
||||
}
|
||||
return R.error("用户不存在");
|
||||
}
|
||||
return R.error("请求钉钉异常:" + json.getString("errmsg"));
|
||||
|
||||
} catch (ApiException e) {
|
||||
e.printStackTrace();
|
||||
return R.error(e.getErrMsg());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,6 +62,7 @@ public class ShiroConfig {
|
||||
filterMap.put("/swagger-resources/**", "anon");
|
||||
filterMap.put("/captcha.jpg", "anon");
|
||||
filterMap.put("/aaa.txt", "anon");
|
||||
filterMap.put("/dtlg/login", "anon");
|
||||
filterMap.put("/**", "oauth2");
|
||||
shiroFilter.setFilterChainDefinitionMap(filterMap);
|
||||
|
||||
|
||||
@ -73,4 +73,5 @@ public interface StaffDao extends BaseMapper<StaffEntity> {
|
||||
|
||||
StaffEntity selectByPhone(@Param("phone") String phone);
|
||||
|
||||
StaffEntity selectStaffByEmployeeId(@Param("employeeId") String employeeId);
|
||||
}
|
||||
|
||||
@ -69,5 +69,7 @@ public interface StaffService extends IService<StaffEntity> {
|
||||
int deleteStaffById(Long id);
|
||||
|
||||
StaffEntity selectByPhone(String userName);
|
||||
|
||||
StaffEntity selectStaffByEmployeeId(String employeeId);
|
||||
}
|
||||
|
||||
|
||||
@ -87,6 +87,11 @@ public class StaffServiceImpl extends ServiceImpl<StaffDao, StaffEntity> impleme
|
||||
return staffDao.selectByPhone(phone);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StaffEntity selectStaffByEmployeeId(String employeeId){
|
||||
return staffDao.selectStaffByEmployeeId(employeeId);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PageUtils queryPage(Map<String, Object> params) {
|
||||
|
||||
@ -10,6 +10,7 @@ import com.google.common.collect.Lists;
|
||||
import com.lz.common.emun.WorkMsgTypeEnum;
|
||||
import com.lz.common.utils.DateUtils;
|
||||
import com.lz.common.utils.DingTalkUtil;
|
||||
import com.lz.common.utils.R;
|
||||
import com.lz.modules.app.dao.StaffDao;
|
||||
import com.lz.modules.app.dto.StaffBaseInfoDto;
|
||||
import com.lz.modules.app.entity.StaffEntity;
|
||||
@ -195,4 +196,12 @@ public class DingtalkBusiness {
|
||||
return "无相关人员信息";
|
||||
|
||||
}
|
||||
|
||||
public R login(String code, String appid) {
|
||||
String token = dingTalkUtil.getAccessToken(appid);
|
||||
if(token != null && token.length() > 0){
|
||||
return dingTalkUtil.getUserIdByCode(code, token);
|
||||
}
|
||||
return R.error("授权失败,未授权");
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,26 @@
|
||||
package com.lz.modules.third.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.lz.common.utils.DingTalkUtil;
|
||||
import com.lz.common.utils.R;
|
||||
import com.lz.modules.job.business.DingtalkBusiness;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
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;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/dtlg")
|
||||
public class DingTalkLoginController {
|
||||
@Autowired
|
||||
DingtalkBusiness dingtalkBusiness;
|
||||
static String appid = "855818566";
|
||||
@PostMapping("/login")
|
||||
public R login(@RequestBody String body){
|
||||
JSONObject json = JSONObject.parseObject(body);
|
||||
return dingtalkBusiness.login(json.getString("code"), appid);
|
||||
|
||||
}
|
||||
}
|
||||
@ -39,7 +39,7 @@ public class ThirdAppConfig implements java.io.Serializable {
|
||||
//程序入口,如果有
|
||||
private String appUrl;
|
||||
//企业的钉钉corpId
|
||||
private Long corpId;
|
||||
private String corpId;
|
||||
//备注说明
|
||||
private String remark;
|
||||
/**
|
||||
@ -207,18 +207,11 @@ public class ThirdAppConfig implements java.io.Serializable {
|
||||
this.appUrl = appUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* 企业的钉钉corpId
|
||||
* @return
|
||||
*/
|
||||
public Long getCorpId() {
|
||||
public String getCorpId() {
|
||||
return corpId;
|
||||
}
|
||||
/**
|
||||
* 企业的钉钉corpId
|
||||
* @param corpId
|
||||
*/
|
||||
public void setCorpId(Long corpId) {
|
||||
|
||||
public void setCorpId(String corpId) {
|
||||
this.corpId = corpId;
|
||||
}
|
||||
|
||||
|
||||
@ -433,4 +433,8 @@
|
||||
select * from lz_staff where is_delete = 0 and ( mobile = #{phone} or mobile = concat('+86',#{phone},'')) limit 1
|
||||
</select>
|
||||
|
||||
<select id="selectStaffByEmployeeId" resultType="com.lz.modules.app.entity.StaffEntity">
|
||||
select * from lz_staff where is_delete = 0 and employee_id = #{employeeId} limit 1
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user