|
|
@ -2,6 +2,7 @@ package com.yxt.supervise.system.sysuser; |
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.yxt.supervise.system.config.DictCommonType; |
|
|
@ -26,18 +27,21 @@ import com.yxt.common.core.result.ResultBean; |
|
|
|
import com.yxt.common.core.vo.PagerVo; |
|
|
|
import com.yxt.supervise.system.sysuser.app.AppUserOrgInfoVo; |
|
|
|
import com.yxt.supervise.system.sysuser.app.OrgList; |
|
|
|
import com.yxt.supervise.system.sysuser.wx.WxHomePageVo; |
|
|
|
import com.yxt.supervise.system.sysuser.wx.WxMySysUserInfoVo; |
|
|
|
import com.yxt.supervise.system.sysuser.wx.WxSysUserVo; |
|
|
|
import com.yxt.supervise.system.sysuser.wx.*; |
|
|
|
import com.yxt.supervise.system.sysuserwxauth.SysUserWxAuth; |
|
|
|
import org.apache.ibatis.annotations.Param; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.http.ResponseEntity; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.web.bind.annotation.PathVariable; |
|
|
|
import org.springframework.web.client.RestTemplate; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
import java.util.*; |
|
|
|
import java.util.concurrent.ScheduledExecutorService; |
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
import java.util.logging.Logger; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
import static java.util.concurrent.Executors.newScheduledThreadPool; |
|
|
@ -75,6 +79,10 @@ public class SysUserService extends MybatisBaseService<SysUserMapper, SysUser> { |
|
|
|
* 手机短信登录验证码时效(秒) |
|
|
|
*/ |
|
|
|
static final long APP_LOGIN_CODE_TIME_LIMIT = 300L; |
|
|
|
String APP_ID = "wx05604ce2a8bede05"; |
|
|
|
String SECRET = "3d36e8a61212cf773a2fa4e6c9a83334"; |
|
|
|
private static final String WX_URL_LOGIN = "https://api.weixin.qq.com/sns/jscode2session?appid=APPID&secret=SECRET&js_code=JSCODE&grant_type=authorization_code "; |
|
|
|
private static final String WX_EMPOWER_URL_LOGIN = "https://api.weixin.qq.com/sns/jscode2session?appid=APPID&secret=SECRET&js_code=JSCODE&grant_type=authorization_code"; |
|
|
|
@Autowired |
|
|
|
private SysStaffinfoService sysStaffinfoService; |
|
|
|
@Autowired |
|
|
@ -554,12 +562,14 @@ public class SysUserService extends MybatisBaseService<SysUserMapper, SysUser> { |
|
|
|
public ResultBean sendVerificationCodeForApp(String mobile, String type) { |
|
|
|
Date date = new Date(); |
|
|
|
String redisKey = ""; |
|
|
|
if (type.equals("1")) { |
|
|
|
if (type.equals("1")) { |
|
|
|
redisKey = "loginCode"; |
|
|
|
} else if (type.equals("2")) { |
|
|
|
redisKey = "updatePwdCode"; |
|
|
|
} else if (type.equals("3")) { |
|
|
|
redisKey = "resetPwdCode"; |
|
|
|
}else if(type.equals("4")){ |
|
|
|
redisKey = "binding"; |
|
|
|
} |
|
|
|
String codeRedis = redisUtil.get(redisKey + mobile); |
|
|
|
if (StringUtils.isNotEmpty(codeRedis)) { |
|
|
@ -581,13 +591,16 @@ public class SysUserService extends MybatisBaseService<SysUserMapper, SysUser> { |
|
|
|
} |
|
|
|
String content = ""; |
|
|
|
if (type.equals("1")) { |
|
|
|
content = "登录验证码:" + verificationCode + ",用于登录App,有效期5分钟,如非本人操作,请忽略该短信。"; |
|
|
|
} else { |
|
|
|
content = "登录验证码:" + verificationCode + ",有效期5分钟,如非本人操作,请忽略。"; |
|
|
|
} else if(type.equals("4")){ |
|
|
|
content = "账户绑定验证码:" + verificationCode + ",有效期5分钟,如非本人操作,请忽略。"; |
|
|
|
}else { |
|
|
|
content = "修改密码验证码:" + verificationCode + ",用于修改登录密码,有效期5分钟,如非本人操作,请忽略该短信。"; |
|
|
|
} |
|
|
|
String res = MsgWs.SendWaitWorkMsg(mobile, content); |
|
|
|
String res = com.yxt.supervise.utils.MsgWs.SendWaitWorkMsg(mobile, content); |
|
|
|
// String res = "1";
|
|
|
|
if (res.equals("1")) { |
|
|
|
System.out.println("发送消息"); |
|
|
|
redisUtil.set(redisKey + mobile, verificationCode + date.getTime(), APP_LOGIN_CODE_TIME_LIMIT); |
|
|
|
} |
|
|
|
return ResultBean.fireSuccess().setMsg("发送短信验证码成功"); |
|
|
@ -755,13 +768,13 @@ public class SysUserService extends MybatisBaseService<SysUserMapper, SysUser> { |
|
|
|
/** |
|
|
|
* @param mobile 手机号 |
|
|
|
* @param verificationCode 验证码 |
|
|
|
* @description: 客户端注册验证验证码是否正确 |
|
|
|
* @description: 绑定微信验证验证码是否正确 |
|
|
|
* @return: |
|
|
|
* @Author: dimengzhe |
|
|
|
* @Date: 2021/10/6 11:02 |
|
|
|
*/ |
|
|
|
public Map<String, Object> mobileValidateWxRegister(String mobile, String verificationCode) { |
|
|
|
String key = DictCommonType.WX_REGIST + mobile; |
|
|
|
String key = "binding" + mobile; |
|
|
|
String code = redisUtil.get(key); |
|
|
|
if (StringUtils.isNotBlank(code)) { |
|
|
|
code = code.substring(0, 4); |
|
|
@ -1121,4 +1134,218 @@ public class SysUserService extends MybatisBaseService<SysUserMapper, SysUser> { |
|
|
|
public List<String> getPost(String staffSid) { |
|
|
|
return sysStaffPostService.getPost(staffSid); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 微信静默登录 |
|
|
|
* @param wxCode 临时凭证code值 |
|
|
|
* @return ResultBean data:Token |
|
|
|
* 登陆成功后data返回用户Sid |
|
|
|
* 聂金毅 2022/6/8 20:30 创建 |
|
|
|
*/ |
|
|
|
public ResultBean<SysUserLoginVo> wxSilentLogin(String wxCode) { |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
// 通过wxCode获取unionid,失败返回微信的错误提示。
|
|
|
|
ResultBean<JSONObject> rbJsonObject = wxLogin(wxCode,APP_ID,SECRET); |
|
|
|
if (!rbJsonObject.getSuccess()){ |
|
|
|
JSONObject jsonObject = rbJsonObject.getData(); |
|
|
|
String errcode = jsonObject.get("errcode").toString(); |
|
|
|
String errmsg = jsonObject.get("errmsg").toString(); |
|
|
|
return rb.setMsg(errmsg).setCode(errcode); |
|
|
|
} |
|
|
|
// 判断存在不存在unionid,用户在开放平台的唯一标识符,若当前小程序已绑定到微信开放平台帐号下会返回,详见 UnionID 机制说明。、
|
|
|
|
JSONObject jsonObject = rbJsonObject.getData(); |
|
|
|
if (!jsonObject.containsKey("openid")){ |
|
|
|
return rb.setMsg("未获得openid,请参见auth.code2Session"); |
|
|
|
} |
|
|
|
//String unionid = jsonObject.get("unionid").toString();
|
|
|
|
String openid = jsonObject.get("openid").toString(); |
|
|
|
// 判断用户登陆授权表是否存在该用户unionid和openid,如果不存在就增加一条返回
|
|
|
|
SysUser sysUser=baseMapper.selectOne(new QueryWrapper<SysUser>().eq("appletOpenid",openid)); |
|
|
|
|
|
|
|
if(sysUser==null){ |
|
|
|
return rb.setMsg("此微信没有绑定用户").setCode("100").setData(openid); |
|
|
|
}else{ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// 重置Token失效时间
|
|
|
|
// {写代码}
|
|
|
|
SysUserVo sysUserVo=setUserRedisSessionToken(sysUser); |
|
|
|
SysUserLoginVo sysUserLoginVo = new SysUserLoginVo(); |
|
|
|
sysUserLoginVo.setSysUserSid(sysUser.getSid()); |
|
|
|
sysUserLoginVo.setToken(sysUserVo.getToken()); |
|
|
|
sysUserLoginVo.setIsLogin(true); |
|
|
|
sysUser.setToken(sysUserVo.getToken()); |
|
|
|
return rb.success().setData(sysUser); |
|
|
|
} |
|
|
|
/** |
|
|
|
* 授权登录 |
|
|
|
* @param wxCode 临时凭证code值 |
|
|
|
* @return ResultBean data:Token |
|
|
|
* 登陆成功后data返回用户Sid |
|
|
|
* 聂金毅 2022/6/8 20:30 创建 |
|
|
|
*/ |
|
|
|
public ResultBean<SysUserLoginVo> wxAuthLogin(String wxCode) { |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
// 通过wxCode获取unionid,失败返回微信的错误提示。
|
|
|
|
ResultBean<JSONObject> rbJsonObject = wxAuthLogin(wxCode,APP_ID,SECRET); |
|
|
|
if (!rbJsonObject.getSuccess()){ |
|
|
|
JSONObject jsonObject = rbJsonObject.getData(); |
|
|
|
String errcode = jsonObject.get("errcode").toString(); |
|
|
|
String errmsg = jsonObject.get("errmsg").toString(); |
|
|
|
return rb.setMsg(errmsg).setCode(errcode); |
|
|
|
} |
|
|
|
// 判断存在不存在unionid,用户在开放平台的唯一标识符,若当前小程序已绑定到微信开放平台帐号下会返回,详见 UnionID 机制说明。、
|
|
|
|
JSONObject jsonObject = rbJsonObject.getData(); |
|
|
|
if (!jsonObject.containsKey("openid")){ |
|
|
|
return rb.setMsg("未获得openid,请参见auth.code2Session"); |
|
|
|
} |
|
|
|
//String unionid = jsonObject.get("unionid").toString();
|
|
|
|
String openid = jsonObject.get("openid").toString(); |
|
|
|
// 判断用户登陆授权表是否存在该用户unionid和openid,如果不存在就增加一条返回
|
|
|
|
SysUser sysUser=baseMapper.selectOne(new QueryWrapper<SysUser>().eq("appletOpenid",openid)); |
|
|
|
|
|
|
|
if(sysUser==null){ |
|
|
|
return rb.setMsg("此微信没有绑定用户").setCode("100").setData(openid); |
|
|
|
}else{ |
|
|
|
|
|
|
|
} |
|
|
|
// //SysUserWxAuth sysUserWxAuth = sysUserWxAuthService.fetchByUnionidAndOpenid(unionid,openid);
|
|
|
|
// if (null == sysUser) {
|
|
|
|
// // 添加一个新用户授权记录
|
|
|
|
// //sysUser.setUnionid(unionid);
|
|
|
|
// //sysUser.setOpenid(openid);
|
|
|
|
// int isSave = baseMapper.insert(sysUser);
|
|
|
|
// if ( isSave==0 ){
|
|
|
|
// return rb.setMsg("登陆:新增用户授权表失败");
|
|
|
|
// }
|
|
|
|
// return rb.setMsg(SysUserWxAuth_Not_Exist.getMsg()).setCode(SysUserWxAuth_Not_Exist.getCode());
|
|
|
|
// }
|
|
|
|
// // 如果用户Sid为空返回
|
|
|
|
// String sysUserSid = sysUserWxAuth.getSysUserSid();
|
|
|
|
// if(com.baomidou.mybatisplus.core.toolkit.StringUtils.isBlank(sysUserSid) || sysUserSid == null){
|
|
|
|
// return rb.setMsg(SysUser_Sid_IsEmpty.getMsg()).setCode(SysUser_Sid_IsEmpty.getCode());
|
|
|
|
// }
|
|
|
|
// // 如果未找到用户记录返回
|
|
|
|
// SysUser sysUser = fetchBySid(sysUserSid);
|
|
|
|
// if (sysUser == null){
|
|
|
|
// return rb.setMsg(SysUser_Not_Exist.getMsg()).setCode(SysUser_Not_Exist.getCode());
|
|
|
|
// }
|
|
|
|
// // 如果未绑定手机号返回
|
|
|
|
// String mobile = sysUser.getMobile();
|
|
|
|
// if(com.baomidou.mybatisplus.core.toolkit.StringUtils.isBlank(mobile) || mobile == null){
|
|
|
|
// return rb.setMsg(SysUser_Mobile_Not_Bind.getMsg()).setCode(SysUser_Mobile_Not_Bind.getCode());
|
|
|
|
// }
|
|
|
|
// // 如果设置为未登陆返回
|
|
|
|
// int isLogin = sysUser.getIsLogin();
|
|
|
|
// if (isLogin !=1){
|
|
|
|
// return rb.setMsg(SysUser_Not_Login.getMsg()).setCode(SysUser_Not_Login.getCode());
|
|
|
|
// }
|
|
|
|
// 获得Token
|
|
|
|
// String token = sysUser.getToken();
|
|
|
|
// if(com.baomidou.mybatisplus.core.toolkit.StringUtils.isBlank(token) || token == null){
|
|
|
|
// return rb.setMsg("登陆:token为空").setCode("122016");
|
|
|
|
// }
|
|
|
|
// 重置Token失效时间
|
|
|
|
// {写代码}
|
|
|
|
SysUserLoginVo sysUserLoginVo = new SysUserLoginVo(); |
|
|
|
sysUserLoginVo.setSysUserSid(sysUser.getSid()); |
|
|
|
// sysUserLoginVo.setToken(token);
|
|
|
|
sysUserLoginVo.setIsLogin(true); |
|
|
|
return rb.success().setData(sysUser); |
|
|
|
} |
|
|
|
public ResultBean<JSONObject> wxLogin( String jsCode,String appid, String secret) { |
|
|
|
ResultBean rb=new ResultBean(); |
|
|
|
String url = WX_URL_LOGIN.replace("APPID", appid).replace("SECRET", secret).replace("JSCODE",jsCode).replace("authorization_code","authorization_code"); |
|
|
|
RestTemplate restTemplate = new RestTemplate(); |
|
|
|
ResponseEntity<String> forEntity = restTemplate.getForEntity(url,String.class); |
|
|
|
JSONObject jsonObject = JSONObject.parseObject(forEntity.getBody()); |
|
|
|
System.out.println(jsonObject); |
|
|
|
return rb.success().setData(jsonObject); |
|
|
|
} |
|
|
|
public ResultBean<JSONObject> wxAuthLogin( String code,String appid, String secret) { |
|
|
|
ResultBean rb=new ResultBean(); |
|
|
|
String url = WX_EMPOWER_URL_LOGIN.replace("APPID", appid).replace("SECRET", secret).replace("CODE",code).replace("authorization_code","authorization_code"); |
|
|
|
RestTemplate restTemplate = new RestTemplate(); |
|
|
|
ResponseEntity<String> forEntity = restTemplate.getForEntity(url,String.class); |
|
|
|
JSONObject jsonObject = JSONObject.parseObject(forEntity.getBody()); |
|
|
|
System.out.println(jsonObject); |
|
|
|
return rb.success().setData(jsonObject); |
|
|
|
} |
|
|
|
public ResultBean wxBindMobile(SysUserWxBindMobileDto sysUserWxBindMobileDto) { |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
String mobile = sysUserWxBindMobileDto.getMobile(); |
|
|
|
// 校验手机验证码
|
|
|
|
String code = sysUserWxBindMobileDto.getCode(); |
|
|
|
Map<String, Object> vali = mobileValidateWxRegister(mobile,code); |
|
|
|
// if (!rb.getSuccess()){
|
|
|
|
// return rb;
|
|
|
|
// }
|
|
|
|
if(!vali.get("code").equals("200")){ |
|
|
|
return rb.setMsg(vali.get("details").toString()); |
|
|
|
} |
|
|
|
String sysUserSid = ""; |
|
|
|
// 通过手机号查询及添加用户信息
|
|
|
|
SysUser sysUser = baseMapper.selectOne(new QueryWrapper<SysUser>().eq("mobile",mobile)); |
|
|
|
if (sysUser != null) { |
|
|
|
sysUserSid = sysUser.getSid(); |
|
|
|
sysUser.setAppletOpenid(sysUserWxBindMobileDto.getOpenid()); |
|
|
|
int i= baseMapper.updateById(sysUser); |
|
|
|
if (i>0){ |
|
|
|
return rb.success().setMsg("绑定成功").setData(sysUser); |
|
|
|
} |
|
|
|
else{ |
|
|
|
return rb.setMsg("绑定失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
// 当用户Sid不为空时更新
|
|
|
|
// if(!com.baomidou.mybatisplus.core.toolkit.StringUtils.isBlank(sysUserWxAuth.getSysUserSid()) && sysUserWxAuth.getSysUserSid() != null){
|
|
|
|
// sysUserSid = sysUserWxAuth.getSysUserSid();
|
|
|
|
// sysUser = fetchBySid(sysUserSid);
|
|
|
|
// if (sysUser != null){
|
|
|
|
// sysUser.setMobile(mobile);
|
|
|
|
// boolean isUpdate = updateById(sysUser);
|
|
|
|
// if (isUpdate){
|
|
|
|
// return rb.success().setMsg("绑定成功").setData(sysUserSid);
|
|
|
|
// }
|
|
|
|
// else{
|
|
|
|
// return rb.setMsg("绑定失败");
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
// // 添加用户信息表
|
|
|
|
// SysUserInfoDto sysUserInfoDto = sysUserInfoService.setSysUserInfoDefaultValue();
|
|
|
|
// sysUserInfoDto.setMobile(mobile);
|
|
|
|
// ResultBean isSave = sysUserInfoService.saveSysUserInfo(sysUserInfoDto);
|
|
|
|
// if (!isSave.getSuccess()){
|
|
|
|
// return rb.setMsg("绑定用户新增用户信息表失败");
|
|
|
|
// }
|
|
|
|
// String sysUserInfoSid = isSave.getData().toString();
|
|
|
|
// sysUser = new SysUser();
|
|
|
|
// sysUser.setSysUserInfoSid(sysUserInfoSid);
|
|
|
|
// sysUser.setMobile(mobile);
|
|
|
|
// // 设置登陆名
|
|
|
|
// String timeNow = String.valueOf(System.currentTimeMillis());
|
|
|
|
// sysUser.setLoginName("user" + timeNow);
|
|
|
|
// sysUser.setIsLogin(1);
|
|
|
|
// sysUser.setIsAdmin(2);
|
|
|
|
// sysUser.setOnlineState(1);
|
|
|
|
// boolean isSaveSysUser = this.save(sysUser);
|
|
|
|
// if (!isSaveSysUser){
|
|
|
|
// return rb.setMsg("用户表保存失败");
|
|
|
|
// }
|
|
|
|
// // 更新用户微信授权表
|
|
|
|
// sysUserSid = sysUser.getSid();
|
|
|
|
// sysUserWxAuth.setSysUserSid(sysUserSid);
|
|
|
|
// boolean isUpdate = sysUserWxAuthService.updateById(sysUserWxAuth);
|
|
|
|
// if (isUpdate){
|
|
|
|
// return rb.success().setMsg("绑定成功").setData(sysUserSid);
|
|
|
|
// }
|
|
|
|
// else{
|
|
|
|
// return rb.setMsg("绑定失败");
|
|
|
|
// }
|
|
|
|
return rb; |
|
|
|
} |
|
|
|
} |