|
@@ -2,12 +2,18 @@ package com.usoftchina.smartschool.school.wxschool.basic.controller;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.github.kevinsawicki.http.HttpRequest;
|
|
import com.github.kevinsawicki.http.HttpRequest;
|
|
|
|
|
+import com.usoftchina.smartschool.auth.dto.TokenDTO;
|
|
|
|
|
+import com.usoftchina.smartschool.auth.jwt.JwtHelper;
|
|
|
|
|
+import com.usoftchina.smartschool.auth.jwt.JwtInfo;
|
|
|
|
|
+import com.usoftchina.smartschool.auth.jwt.JwtToken;
|
|
|
|
|
+import com.usoftchina.smartschool.school.po.ParentsDO;
|
|
|
import com.usoftchina.smartschool.school.po.SchoolDO;
|
|
import com.usoftchina.smartschool.school.po.SchoolDO;
|
|
|
import com.usoftchina.smartschool.school.po.TeacherDO;
|
|
import com.usoftchina.smartschool.school.po.TeacherDO;
|
|
|
import com.usoftchina.smartschool.school.wxschool.basic.service.WxSchoolService;
|
|
import com.usoftchina.smartschool.school.wxschool.basic.service.WxSchoolService;
|
|
|
import com.usoftchina.smartschool.school.wxschool.basic.service.WxUserService;
|
|
import com.usoftchina.smartschool.school.wxschool.basic.service.WxUserService;
|
|
|
import com.usoftchina.smartschool.school.wxschool.utils.ObjectUtils;
|
|
import com.usoftchina.smartschool.school.wxschool.utils.ObjectUtils;
|
|
|
import com.usoftchina.smartschool.school.wxschool.utils.ResultBean;
|
|
import com.usoftchina.smartschool.school.wxschool.utils.ResultBean;
|
|
|
|
|
+import com.usoftchina.smartschool.utils.BeanMapper;
|
|
|
import org.apache.ibatis.annotations.Param;
|
|
import org.apache.ibatis.annotations.Param;
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -48,6 +54,11 @@ public class WxUserController {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private WxSchoolService schoolService;
|
|
private WxSchoolService schoolService;
|
|
|
|
|
|
|
|
|
|
+ @Value("${auth.private-key}")
|
|
|
|
|
+ private String privateKeyPath;
|
|
|
|
|
+
|
|
|
|
|
+ @Value("${auth.expire:72000}")
|
|
|
|
|
+ private int expire;
|
|
|
|
|
|
|
|
@Value("${smartschool.domain.wechat}")
|
|
@Value("${smartschool.domain.wechat}")
|
|
|
private String wechatUrl;
|
|
private String wechatUrl;
|
|
@@ -79,6 +90,16 @@ public class WxUserController {
|
|
|
Assert.notNull(code,"请输入验证码");
|
|
Assert.notNull(code,"请输入验证码");
|
|
|
Assert.notNull(openid,"openid不能为空");
|
|
Assert.notNull(openid,"openid不能为空");
|
|
|
Map<String, Object> map = userService.bindOpenid(userPhone, code, openid,headimgurl);
|
|
Map<String, Object> map = userService.bindOpenid(userPhone, code, openid,headimgurl);
|
|
|
|
|
+ Object teacherDOS = map.get("teacherDOS");
|
|
|
|
|
+ Object parentsDOS = map.get("parentsDOS");
|
|
|
|
|
+ TokenDTO tokenDTO = null;
|
|
|
|
|
+ //如果家长存在,APP进入后默认是家长身份
|
|
|
|
|
+ if (ObjectUtils.isNotEmpty(parentsDOS)) {
|
|
|
|
|
+ tokenDTO = generateToken(((List<ParentsDO>) parentsDOS).get(0));
|
|
|
|
|
+ }else {
|
|
|
|
|
+ tokenDTO = generateToken(((List<TeacherDO>) teacherDOS).get(0));
|
|
|
|
|
+ }
|
|
|
|
|
+ map.put("token", tokenDTO);
|
|
|
return new ResultBean(map);
|
|
return new ResultBean(map);
|
|
|
}catch (Exception e){
|
|
}catch (Exception e){
|
|
|
return new ResultBean(e);
|
|
return new ResultBean(e);
|
|
@@ -95,6 +116,14 @@ public class WxUserController {
|
|
|
if (ObjectUtils.isEmpty(teacherDOS)&&ObjectUtils.isEmpty(parentsDOS)){
|
|
if (ObjectUtils.isEmpty(teacherDOS)&&ObjectUtils.isEmpty(parentsDOS)){
|
|
|
return new ResultBean(false);
|
|
return new ResultBean(false);
|
|
|
}else {
|
|
}else {
|
|
|
|
|
+ TokenDTO tokenDTO = null;
|
|
|
|
|
+ //如果家长存在,APP进入后默认是家长身份
|
|
|
|
|
+ if (ObjectUtils.isNotEmpty(parentsDOS)) {
|
|
|
|
|
+ tokenDTO = generateToken(((List<ParentsDO>) parentsDOS).get(0));
|
|
|
|
|
+ }else {
|
|
|
|
|
+ tokenDTO = generateToken(((List<TeacherDO>) teacherDOS).get(0));
|
|
|
|
|
+ }
|
|
|
|
|
+ map.put("token", tokenDTO);
|
|
|
return new ResultBean(map);
|
|
return new ResultBean(map);
|
|
|
}
|
|
}
|
|
|
}catch (Exception e){
|
|
}catch (Exception e){
|
|
@@ -102,6 +131,45 @@ public class WxUserController {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 身份切换
|
|
|
|
|
+ * @param personId 用户ID
|
|
|
|
|
+ * @param type 1: 教师 0:家长
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ @PostMapping("/switchIdentity")
|
|
|
|
|
+ public ResultBean switchIdentify(Long personId, Long type){
|
|
|
|
|
+ return new ResultBean(userService.switchIdentify(personId, type, privateKeyPath, expire));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 创建token
|
|
|
|
|
+ * @param object
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ private TokenDTO generateToken(Object object){
|
|
|
|
|
+ Long schoolId = -1L, userId = -1L;
|
|
|
|
|
+ String username = null, mobile = null;
|
|
|
|
|
+ if (object instanceof ParentsDO) {
|
|
|
|
|
+ ParentsDO parentsDO = ((ParentsDO) object);
|
|
|
|
|
+ schoolId = parentsDO.getSchoolId();
|
|
|
|
|
+ userId = parentsDO.getUserId();
|
|
|
|
|
+ username = parentsDO.getParentsName();
|
|
|
|
|
+ mobile = parentsDO.getPaPhone();
|
|
|
|
|
+ }else if (object instanceof TeacherDO) {
|
|
|
|
|
+ TeacherDO teacherDO = ((TeacherDO) object);
|
|
|
|
|
+ schoolId = teacherDO.getSchoolId();
|
|
|
|
|
+ userId = teacherDO.getUserId();
|
|
|
|
|
+ username = teacherDO.getTeacherName();
|
|
|
|
|
+ mobile = teacherDO.getTeacherPhone();
|
|
|
|
|
+ }else {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ JwtInfo jwtInfo = new JwtInfo("school", schoolId, userId, username, mobile);
|
|
|
|
|
+ JwtToken jwtToken = JwtHelper.generateToken(jwtInfo, privateKeyPath, expire);
|
|
|
|
|
+ return BeanMapper.map(jwtToken, TokenDTO.class);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 首页数据
|
|
* 首页数据
|
|
|
* @param schoolId
|
|
* @param schoolId
|