Commit 66200d6e authored by hezhen's avatar hezhen

修改上传

parent 2546f4d1
...@@ -18,6 +18,8 @@ public class AppUserLogin { ...@@ -18,6 +18,8 @@ public class AppUserLogin {
private int id; private int id;
@Column(name = "im_userid") @Column(name = "im_userid")
private Integer imUserid; private Integer imUserid;
@Column(name = "im_password")
private String imPassword;
@Column(name = "username") @Column(name = "username")
private String username; private String username;
private String password; private String password;
......
...@@ -40,6 +40,11 @@ ...@@ -40,6 +40,11 @@
<artifactId>xx-universal-api</artifactId> <artifactId>xx-universal-api</artifactId>
<version>2.0-SNAPSHOT</version> <version>2.0-SNAPSHOT</version>
</dependency> </dependency>
<dependency>
<groupId>com.xxfc.platform</groupId>
<artifactId>xx-im-api</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId> <artifactId>spring-boot-starter-data-redis</artifactId>
......
...@@ -33,7 +33,7 @@ import java.util.List; ...@@ -33,7 +33,7 @@ import java.util.List;
@EnableDiscoveryClient @EnableDiscoveryClient
@EnableCircuitBreaker @EnableCircuitBreaker
@SpringBootApplication @SpringBootApplication
@EnableFeignClients({"com.github.wxiaoqi.security.auth.client.feign", "com.xxfc.platform.universal.feign"}) @EnableFeignClients({"com.github.wxiaoqi.security.auth.client.feign","com.xxfc.platform"})
@EnableScheduling @EnableScheduling
@EnableAceAuthClient @EnableAceAuthClient
@EnableAceCache @EnableAceCache
......
...@@ -78,6 +78,7 @@ public class AppUserRest { ...@@ -78,6 +78,7 @@ public class AppUserRest {
mobilecode, null, null,0); mobilecode, null, null,0);
} }
/** /**
* 微信注册/微信绑定 * 微信注册/微信绑定
* @param username * @param username
......
...@@ -9,12 +9,14 @@ import com.github.wxiaoqi.security.admin.constant.RedisKey; ...@@ -9,12 +9,14 @@ import com.github.wxiaoqi.security.admin.constant.RedisKey;
import com.github.wxiaoqi.security.admin.entity.*; import com.github.wxiaoqi.security.admin.entity.*;
import com.github.wxiaoqi.security.api.vo.authority.PermissionInfo; import com.github.wxiaoqi.security.api.vo.authority.PermissionInfo;
import com.github.wxiaoqi.security.api.vo.user.AppUserInfo; import com.github.wxiaoqi.security.api.vo.user.AppUserInfo;
import com.github.wxiaoqi.security.common.msg.BaseResponse;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse; import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.util.EmojiFilter; import com.github.wxiaoqi.security.common.util.EmojiFilter;
import com.github.wxiaoqi.security.common.util.VerificationUtils; import com.github.wxiaoqi.security.common.util.VerificationUtils;
import com.github.wxiaoqi.security.common.util.process.ResultCode; import com.github.wxiaoqi.security.common.util.process.ResultCode;
import com.github.wxiaoqi.security.common.util.process.SystemConfig; import com.github.wxiaoqi.security.common.util.process.SystemConfig;
import com.github.wxiaoqi.security.common.util.result.JsonResultUtil; import com.github.wxiaoqi.security.common.util.result.JsonResultUtil;
import com.xxfc.platform.im.feign.ImFeign;
import com.xxfc.platform.universal.feign.ThirdFeign; import com.xxfc.platform.universal.feign.ThirdFeign;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
...@@ -23,9 +25,10 @@ import org.springframework.data.redis.core.RedisTemplate; ...@@ -23,9 +25,10 @@ import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
/** /**
...@@ -44,6 +47,9 @@ public class AppPermissionService { ...@@ -44,6 +47,9 @@ public class AppPermissionService {
@Autowired @Autowired
ThirdFeign thirdFeign; ThirdFeign thirdFeign;
@Autowired
ImFeign imFeign;
private BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(12); private BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(12);
@Autowired @Autowired
private RedisTemplate userRedisTemplate; private RedisTemplate userRedisTemplate;
...@@ -56,9 +62,9 @@ public class AppPermissionService { ...@@ -56,9 +62,9 @@ public class AppPermissionService {
public AppUserInfo validate(String username, String password) { public AppUserInfo validate(String username, String password) {
AppUserInfo info = new AppUserInfo(); AppUserInfo info = new AppUserInfo();
AppUserLogin user = appUserLoginBiz.checkeUserLogin(username); AppUserLogin user = appUserLoginBiz.checkeUserLogin(username);
if (user!=null&&encoder.matches(password, user.getPassword())) { if (user != null && encoder.matches(password, user.getPassword())) {
info.setUsername(user.getUsername()); info.setUsername(user.getUsername());
info.setId(user.getId()+""); info.setId(user.getId() + "");
} }
return info; return info;
} }
...@@ -128,10 +134,10 @@ public class AppPermissionService { ...@@ -128,10 +134,10 @@ public class AppPermissionService {
return JsonResultUtil.createFailedResult(ResultCode.EXIST_CODE, "手机号未注册"); return JsonResultUtil.createFailedResult(ResultCode.EXIST_CODE, "手机号未注册");
} }
// String sms = PassportUtil.SendSMS(phone, SystemConfig.SENDSMS_TITLE); // String sms = PassportUtil.SendSMS(phone, SystemConfig.SENDSMS_TITLE);
String mobilecode=null; String mobilecode = null;
JSONObject data=thirdFeign.send(phone); JSONObject data = thirdFeign.send(phone);
if(data!=null&&data.getInteger("status")== ResultCode.SUCCESS_CODE){ if (data != null && data.getInteger("status") == ResultCode.SUCCESS_CODE) {
mobilecode=data.getString("data"); mobilecode = data.getString("data");
} }
log.info("调用短信发送接口返回值为:{}", mobilecode); log.info("调用短信发送接口返回值为:{}", mobilecode);
// 判断返回值是否为空,并且是否可以转换成JSONObject // 判断返回值是否为空,并且是否可以转换成JSONObject
...@@ -139,10 +145,10 @@ public class AppPermissionService { ...@@ -139,10 +145,10 @@ public class AppPermissionService {
return JsonResultUtil.createDefaultFail(); return JsonResultUtil.createDefaultFail();
try { try {
result.put("mobilecode", mobilecode); result.put("mobilecode", mobilecode);
String redisLockKey = RedisKey.CONSTANT_CODE_PREFIX+phone+mobilecode; String redisLockKey = RedisKey.CONSTANT_CODE_PREFIX + phone + mobilecode;
Boolean suc = userRedisTemplate.opsForValue().setIfAbsent(redisLockKey, mobilecode); Boolean suc = userRedisTemplate.opsForValue().setIfAbsent(redisLockKey, mobilecode);
if(suc){ if (suc) {
userRedisTemplate.expire(redisLockKey,5, TimeUnit.MINUTES);//5分钟内过期 userRedisTemplate.expire(redisLockKey, 5, TimeUnit.MINUTES);//5分钟内过期
} }
} catch (Exception e) { } catch (Exception e) {
return JsonResultUtil.createFailedResult(ResultCode.EXCEPTION_CODE, "出现异常"); return JsonResultUtil.createFailedResult(ResultCode.EXCEPTION_CODE, "出现异常");
...@@ -160,13 +166,13 @@ public class AppPermissionService { ...@@ -160,13 +166,13 @@ public class AppPermissionService {
*/ */
@Transactional @Transactional
public JSONObject register(String username, String password, String headimgurl, public JSONObject register(String username, String password, String headimgurl,
String nickname, String mobilecode,String openId, String unionid,Integer type) { String nickname, String mobilecode, String openId, String unionid, Integer type) {
// 判断参数和验证码 // 判断参数和验证码
if (StringUtils.isBlank(username) || StringUtils.isBlank(password) || StringUtils.isBlank(mobilecode)) { if (StringUtils.isBlank(username) || StringUtils.isBlank(password) || StringUtils.isBlank(mobilecode)) {
return JsonResultUtil.createFailedResult(ResultCode.NULL_CODE, "参数为空"); return JsonResultUtil.createFailedResult(ResultCode.NULL_CODE, "参数为空");
} }
String redisLockKey = RedisKey.CONSTANT_CODE_PREFIX+username+mobilecode; String redisLockKey = RedisKey.CONSTANT_CODE_PREFIX + username + mobilecode;
String mobilecodeRedis=userRedisTemplate.opsForValue().get(redisLockKey)==null?"":userRedisTemplate.opsForValue().get(redisLockKey).toString(); String mobilecodeRedis = userRedisTemplate.opsForValue().get(redisLockKey) == null ? "" : userRedisTemplate.opsForValue().get(redisLockKey).toString();
log.error("注册接口,获取redis中的验证码:" + mobilecodeRedis); log.error("注册接口,获取redis中的验证码:" + mobilecodeRedis);
// 获取到缓存的验证码后要先清空缓存对应键的值 // 获取到缓存的验证码后要先清空缓存对应键的值
userRedisTemplate.delete(redisLockKey); userRedisTemplate.delete(redisLockKey);
...@@ -174,7 +180,7 @@ public class AppPermissionService { ...@@ -174,7 +180,7 @@ public class AppPermissionService {
return JsonResultUtil.createFailedResult(ResultCode.NOTEXIST_CODE, "验证码错误"); return JsonResultUtil.createFailedResult(ResultCode.NOTEXIST_CODE, "验证码错误");
} }
// 是否已存在 // 是否已存在
AppUserLogin user = appUserLoginBiz.checkeUserLogin(username); AppUserLogin user = appUserLoginBiz.checkeUserLogin(username);
if (null != user) { if (null != user) {
return JsonResultUtil.createFailedResult(ResultCode.EXIST_CODE, "用户已存在"); return JsonResultUtil.createFailedResult(ResultCode.EXIST_CODE, "用户已存在");
} }
...@@ -187,9 +193,9 @@ public class AppPermissionService { ...@@ -187,9 +193,9 @@ public class AppPermissionService {
appUserLogin.setIsdel(0); appUserLogin.setIsdel(0);
appUserLogin.setStatus(0); appUserLogin.setStatus(0);
//QQ //QQ
if(type==1&&StringUtils.isNotBlank(openId)){ if (type == 1 && StringUtils.isNotBlank(openId)) {
appUserLogin.setOpenid(openId); appUserLogin.setOpenid(openId);
}else{ } else {
if (StringUtils.isNotBlank(openId)) { if (StringUtils.isNotBlank(openId)) {
appUserLogin.setWxOpenid(openId); appUserLogin.setWxOpenid(openId);
} }
...@@ -200,7 +206,7 @@ public class AppPermissionService { ...@@ -200,7 +206,7 @@ public class AppPermissionService {
appUserLogin.setCreatetime(now); appUserLogin.setCreatetime(now);
appUserLogin.setUpdatetime(now); appUserLogin.setUpdatetime(now);
appUserLoginBiz.insertSelective(appUserLogin); appUserLoginBiz.insertSelective(appUserLogin);
Integer userid=appUserLogin.getId(); Integer userid = appUserLogin.getId();
log.error("注册:新增登陆用户信息: " + userid); log.error("注册:新增登陆用户信息: " + userid);
// 新增用户详情 // 新增用户详情
AppUserDetail rsUserDetail = new AppUserDetail(); AppUserDetail rsUserDetail = new AppUserDetail();
...@@ -214,9 +220,20 @@ public class AppPermissionService { ...@@ -214,9 +220,20 @@ public class AppPermissionService {
log.error("注册:新增用户详情: " + userid); log.error("注册:新增用户详情: " + userid);
// 登录结果要做做统一处理 // 登录结果要做做统一处理
JSONObject data = autoLogin(userid, username, headimgurl, nickname); JSONObject data = autoLogin(userid, username, headimgurl, nickname);
/* // 到im注册,获取返回结果 // 到im注册,获取返回结果
Map<String,Object> map=registerIm(username,appUserLogin.getPassword(),nickname);
if(map!=null){
Integer imUserId=Integer.parseInt(map.get("userId").toString());
String access_token=map.get("access_token").toString();
String imPassword=map.get("password").toString();
if(imUserId!=null&&imUserId>0&&StringUtils.isNotBlank(imPassword)){
AppUserLogin userLogin = new AppUserLogin();
userLogin.setId(userid);
userLogin.setImPassword(imPassword);
userLogin.setImUserid(imUserId);
}
}
*/
if (data != null) { if (data != null) {
return JsonResultUtil.createSuccessResultWithObj(data); return JsonResultUtil.createSuccessResultWithObj(data);
} else { } else {
...@@ -233,26 +250,26 @@ public class AppPermissionService { ...@@ -233,26 +250,26 @@ public class AppPermissionService {
*/ */
public JSONObject autoLogin(Integer userid, String username, String headimgurl, String nickname) { public JSONObject autoLogin(Integer userid, String username, String headimgurl, String nickname) {
JSONObject data = new JSONObject(); JSONObject data = new JSONObject();
AppUserLogin userLoign = appUserLoginBiz.selectById(userid); AppUserLogin userLoign = appUserLoginBiz.selectById(userid);
if (userLoign!=null) { if (userLoign != null) {
data.put("nickname", nickname); data.put("nickname", nickname);
data.put("headerurl",headimgurl); data.put("headerurl", headimgurl);
AppUserDetail appUserDetail=appUserDetailBiz.getUserByUserid(userid); AppUserDetail appUserDetail = appUserDetailBiz.getUserByUserid(userid);
if(appUserDetail!=null){ if (appUserDetail != null) {
if(StringUtils.isNotBlank(appUserDetail.getNickname())){ if (StringUtils.isNotBlank(appUserDetail.getNickname())) {
data.put("nickname", appUserDetail.getNickname()); data.put("nickname", appUserDetail.getNickname());
} }
if(StringUtils.isNotBlank(appUserDetail.getHeadimgurl())){ if (StringUtils.isNotBlank(appUserDetail.getHeadimgurl())) {
data.put("headerurl", appUserDetail.getHeadimgurl()); data.put("headerurl", appUserDetail.getHeadimgurl());
} }
} }
// 缓存操作 // 缓存操作
String token=""; String token = "";
String imtoken_=""; String imtoken_ = "";
//userRedisTemplate.opsForValue().set("token_" + userid,token, SystemConfig.REDISTOKENTIME, TimeUnit.SECONDS); //userRedisTemplate.opsForValue().set("token_" + userid,token, SystemConfig.REDISTOKENTIME, TimeUnit.SECONDS);
//userRedisTemplate.opsForValue().set("imtoken_" + userid,imtoken_,SystemConfig.REDISTOKENTIME, TimeUnit.SECONDS); //userRedisTemplate.opsForValue().set("imtoken_" + userid,imtoken_,SystemConfig.REDISTOKENTIME, TimeUnit.SECONDS);
// 返回结果 // 返回结果
// data.put("token", token); // data.put("token", token);
data.put("username", username); data.put("username", username);
data.put("userid", userid); data.put("userid", userid);
...@@ -262,6 +279,7 @@ public class AppPermissionService { ...@@ -262,6 +279,7 @@ public class AppPermissionService {
/** /**
* 微信绑定/注册 * 微信绑定/注册
*
* @param username * @param username
* @param password * @param password
* @param openId * @param openId
...@@ -274,7 +292,7 @@ public class AppPermissionService { ...@@ -274,7 +292,7 @@ public class AppPermissionService {
*/ */
@Transactional @Transactional
public JSONObject weCahtRegister(String username, String password, String openId, public JSONObject weCahtRegister(String username, String password, String openId,
String unionid, String nickname,String headimgurl, int type, String mobilecode,Integer isQQ) { String unionid, String nickname, String headimgurl, int type, String mobilecode, Integer isQQ) {
// 校验参数和验证码 // 校验参数和验证码
if (StringUtils.isBlank(username) || StringUtils.isBlank(mobilecode)) { if (StringUtils.isBlank(username) || StringUtils.isBlank(mobilecode)) {
return JsonResultUtil.createFailedResult(ResultCode.NULL_CODE, "参数为空"); return JsonResultUtil.createFailedResult(ResultCode.NULL_CODE, "参数为空");
...@@ -287,7 +305,7 @@ public class AppPermissionService { ...@@ -287,7 +305,7 @@ public class AppPermissionService {
try { try {
// 获取缓存用户信息 // 获取缓存用户信息
log.error("weCahtRegister:" + openId); log.error("weCahtRegister:" + openId);
if(StringUtils.isNotBlank(openId)) { if (StringUtils.isNotBlank(openId)) {
if (StringUtils.isNotBlank(nickname)) { if (StringUtils.isNotBlank(nickname)) {
// 转换特殊字符 // 转换特殊字符
nickname = EmojiFilter.filterEmoji(nickname); nickname = EmojiFilter.filterEmoji(nickname);
...@@ -299,24 +317,24 @@ public class AppPermissionService { ...@@ -299,24 +317,24 @@ public class AppPermissionService {
} }
if (type == 1) { // 绑定 if (type == 1) { // 绑定
Long now = System.currentTimeMillis() / 1000; Long now = System.currentTimeMillis() / 1000;
AppUserLogin userLogin = appUserLoginBiz.checkeUserLogin(username); AppUserLogin userLogin = appUserLoginBiz.checkeUserLogin(username);
if ((isQQ==1&&StringUtils.isNotBlank(userLogin.getOpenid()))||(isQQ==0&&StringUtils.isNotBlank(userLogin.getWxOpenid()))) { if ((isQQ == 1 && StringUtils.isNotBlank(userLogin.getOpenid())) || (isQQ == 0 && StringUtils.isNotBlank(userLogin.getWxOpenid()))) {
// 已绑定微信 // 已绑定微信
return JsonResultUtil.createFailedResultMsg(ResultCode.WX_BIND_CODE); return JsonResultUtil.createFailedResultMsg(ResultCode.WX_BIND_CODE);
} }
Integer userid = userLogin.getId(); Integer userid = userLogin.getId();
if(isQQ==1){ if (isQQ == 1) {
userLogin.setOpenid(openId); userLogin.setOpenid(openId);
}else{ } else {
userLogin.setWxOpenid(openId); userLogin.setWxOpenid(openId);
// 添加unionid // 添加unionid
userLogin.setUnionid(unionid); userLogin.setUnionid(unionid);
} }
userLogin.setUpdatetime(now); userLogin.setUpdatetime(now);
appUserLoginBiz.updateSelectiveById(userLogin); appUserLoginBiz.updateSelectiveById(userLogin);
AppUserDetail userDetail=appUserDetailBiz.getUserByUserid(userid); AppUserDetail userDetail = appUserDetailBiz.getUserByUserid(userid);
if(userDetail==null){ if (userDetail == null) {
userDetail=new AppUserDetail(); userDetail = new AppUserDetail();
userDetail.setUserid(userid); userDetail.setUserid(userid);
userDetail.setHeadimgurl(headimgurl); userDetail.setHeadimgurl(headimgurl);
userDetail.setNickname(nickname); userDetail.setNickname(nickname);
...@@ -324,7 +342,7 @@ public class AppPermissionService { ...@@ -324,7 +342,7 @@ public class AppPermissionService {
userDetail.setUpdatetime(now); userDetail.setUpdatetime(now);
userDetail.setIsdel(0); userDetail.setIsdel(0);
appUserDetailBiz.insertSelective(userDetail); appUserDetailBiz.insertSelective(userDetail);
}else { } else {
userDetail.setHeadimgurl(headimgurl); userDetail.setHeadimgurl(headimgurl);
userDetail.setNickname(nickname); userDetail.setNickname(nickname);
appUserDetailBiz.updateSelectiveById(userDetail); appUserDetailBiz.updateSelectiveById(userDetail);
...@@ -336,7 +354,7 @@ public class AppPermissionService { ...@@ -336,7 +354,7 @@ public class AppPermissionService {
} }
} else if (type == 2) { // 新增 } else if (type == 2) { // 新增
JSONObject register = register(username, password, headimgurl, nickname, mobilecode, JSONObject register = register(username, password, headimgurl, nickname, mobilecode,
openId, unionid,isQQ); openId, unionid, isQQ);
if (register.getInteger("status") != ResultCode.SUCCESS_CODE) { if (register.getInteger("status") != ResultCode.SUCCESS_CODE) {
if (register.getInteger("status") == ResultCode.EXIST_CODE) { if (register.getInteger("status") == ResultCode.EXIST_CODE) {
return JsonResultUtil.createFailedResult(ResultCode.EXIST_CODE, "用户已存在"); return JsonResultUtil.createFailedResult(ResultCode.EXIST_CODE, "用户已存在");
...@@ -385,54 +403,55 @@ public class AppPermissionService { ...@@ -385,54 +403,55 @@ public class AppPermissionService {
/** /**
* 微信登录 * 微信登录
*
* @param openId * @param openId
* @return * @return
*/ */
@Transactional @Transactional
public JSONObject weCahtLogin(String openId,Integer isQQ) { public JSONObject weCahtLogin(String openId, Integer isQQ) {
if (StringUtils.isBlank(openId)) { if (StringUtils.isBlank(openId)) {
return JsonResultUtil.createFailedResult(ResultCode.NULL_CODE, "参数为空"); return JsonResultUtil.createFailedResult(ResultCode.NULL_CODE, "参数为空");
} }
AppUserLogin userLogin = appUserLoginBiz.getUserByOpenid(openId,isQQ); AppUserLogin userLogin = appUserLoginBiz.getUserByOpenid(openId, isQQ);
if(userLogin==null){ if (userLogin == null) {
return JsonResultUtil.createFailedResult(ResultCode.WXNOTEXIST_CODE, "该微信号尚未绑定手机号"); return JsonResultUtil.createFailedResult(ResultCode.WXNOTEXIST_CODE, "该微信号尚未绑定手机号");
} }
if(userLogin.getStatus()==1){ if (userLogin.getStatus() == 1) {
return JsonResultUtil.createFailedResult(ResultCode.EXIST_CODE, "用户已被禁用"); return JsonResultUtil.createFailedResult(ResultCode.EXIST_CODE, "用户已被禁用");
} }
Integer userid=userLogin.getId(); Integer userid = userLogin.getId();
AppUserDetail userDetail=appUserDetailBiz.getUserByUserid(userid); AppUserDetail userDetail = appUserDetailBiz.getUserByUserid(userid);
String headimgurl=""; String headimgurl = "";
String nickname=""; String nickname = "";
if(userDetail!=null){ if (userDetail != null) {
headimgurl=userDetail.getHeadimgurl(); headimgurl = userDetail.getHeadimgurl();
nickname=userDetail.getNickname(); nickname = userDetail.getNickname();
} }
JSONObject data = autoLogin(userid,userLogin.getUsername(),headimgurl,nickname); JSONObject data = autoLogin(userid, userLogin.getUsername(), headimgurl, nickname);
if (data != null) { if (data != null) {
return JsonResultUtil.createSuccessResultWithObj(data); return JsonResultUtil.createSuccessResultWithObj(data);
} }
return JsonResultUtil.createDefaultFail(); return JsonResultUtil.createDefaultFail();
} }
public JSONObject login(String username, String password,String mobilecode,int type) { public JSONObject login(String username, String password, String mobilecode, int type) {
if (StringUtils.isBlank(username) || ((StringUtils.isBlank(password)&&type==1)|| (StringUtils.isBlank(mobilecode)&&type==2))) { if (StringUtils.isBlank(username) || ((StringUtils.isBlank(password) && type == 1) || (StringUtils.isBlank(mobilecode) && type == 2))) {
return JsonResultUtil.createFailedResult(ResultCode.NULL_CODE, "请求参数为空"); return JsonResultUtil.createFailedResult(ResultCode.NULL_CODE, "请求参数为空");
} }
try { try {
AppUserLogin user = appUserLoginBiz.checkeUserLogin(username); AppUserLogin user = appUserLoginBiz.checkeUserLogin(username);
if(type==1){ if (type == 1) {
if (user==null||!encoder.matches(password,user.getPassword())) if (user == null || !encoder.matches(password, user.getPassword()))
return JsonResultUtil.createFailedResult(ResultCode.EXIST_CODE, "用户名或密码错误"); return JsonResultUtil.createFailedResult(ResultCode.EXIST_CODE, "用户名或密码错误");
}else { } else {
String redisLockKey = RedisKey.CONSTANT_CODE_PREFIX+username+mobilecode; String redisLockKey = RedisKey.CONSTANT_CODE_PREFIX + username + mobilecode;
String mobilecodeRedis=userRedisTemplate.opsForValue().get(redisLockKey)==null?"":userRedisTemplate.opsForValue().get(redisLockKey).toString(); String mobilecodeRedis = userRedisTemplate.opsForValue().get(redisLockKey) == null ? "" : userRedisTemplate.opsForValue().get(redisLockKey).toString();
log.error("验证码登录接口,获取redis中的验证码:" + mobilecodeRedis); log.error("验证码登录接口,获取redis中的验证码:" + mobilecodeRedis);
// 获取到缓存的验证码后要先清空缓存对应键的值 // 获取到缓存的验证码后要先清空缓存对应键的值
userRedisTemplate.delete(redisLockKey); userRedisTemplate.delete(redisLockKey);
if (StringUtils.isBlank(mobilecodeRedis)) if (StringUtils.isBlank(mobilecodeRedis))
return JsonResultUtil.createFailedResult(ResultCode.NOTEXIST_CODE, "验证码错误"); return JsonResultUtil.createFailedResult(ResultCode.NOTEXIST_CODE, "验证码错误");
if (user==null) if (user == null)
return JsonResultUtil.createFailedResult(ResultCode.NOTEXIST_CODE, "用户不存在"); return JsonResultUtil.createFailedResult(ResultCode.NOTEXIST_CODE, "用户不存在");
} }
...@@ -441,79 +460,141 @@ public class AppPermissionService { ...@@ -441,79 +460,141 @@ public class AppPermissionService {
return JsonResultUtil.createFailedResult(ResultCode.EXIST_CODE, "用户已被禁用"); return JsonResultUtil.createFailedResult(ResultCode.EXIST_CODE, "用户已被禁用");
} }
Integer userid = user.getId(); Integer userid = user.getId();
String nickname=SystemConfig.USER_NIKENAME_DEFAULT+(int)((Math.random()*9+1)*100000); String nickname = SystemConfig.USER_NIKENAME_DEFAULT + (int) ((Math.random() * 9 + 1) * 100000);
JSONObject data = autoLogin(userid,user.getUsername(),SystemConfig.USER_HEADER_URL_DEFAULT,nickname); JSONObject data = autoLogin(userid, user.getUsername(), SystemConfig.USER_HEADER_URL_DEFAULT, nickname);
if (data != null) { if (data != null) {
return JsonResultUtil.createSuccessResultWithObj(data); return JsonResultUtil.createSuccessResultWithObj(data);
} }
return JsonResultUtil.createDefaultFail(); return JsonResultUtil.createDefaultFail();
}catch (Exception e) { } catch (Exception e) {
log.error("userlogin->error:{}", e.getMessage(), e); log.error("userlogin->error:{}", e.getMessage(), e);
return JsonResultUtil.createFailedResult(ResultCode.EXCEPTION_CODE, "出现异常"); return JsonResultUtil.createFailedResult(ResultCode.EXCEPTION_CODE, "出现异常");
} }
} }
@Transactional @Transactional
public JSONObject reset(String username, String mobilecode, String password) { public JSONObject reset(String username, String mobilecode, String password) {
if (StringUtils.isBlank(username) || StringUtils.isBlank(mobilecode)|| StringUtils.isBlank(password)) { if (StringUtils.isBlank(username) || StringUtils.isBlank(mobilecode) || StringUtils.isBlank(password)) {
return JsonResultUtil.createFailedResult(ResultCode.NULL_CODE, "请求参数为空"); return JsonResultUtil.createFailedResult(ResultCode.NULL_CODE, "请求参数为空");
} }
try { try {
String redisLockKey = RedisKey.CONSTANT_CODE_PREFIX+username+mobilecode; String redisLockKey = RedisKey.CONSTANT_CODE_PREFIX + username + mobilecode;
String mobilecodeRedis=userRedisTemplate.opsForValue().get(redisLockKey)==null?"":userRedisTemplate.opsForValue().get(redisLockKey).toString(); String mobilecodeRedis = userRedisTemplate.opsForValue().get(redisLockKey) == null ? "" : userRedisTemplate.opsForValue().get(redisLockKey).toString();
log.error("验证码登录接口,获取redis中的验证码:" + mobilecodeRedis); log.error("验证码登录接口,获取redis中的验证码:" + mobilecodeRedis);
// 获取到缓存的验证码后要先清空缓存对应键的值 // 获取到缓存的验证码后要先清空缓存对应键的值
userRedisTemplate.delete(redisLockKey); userRedisTemplate.delete(redisLockKey);
if (StringUtils.isBlank(mobilecodeRedis)){ if (StringUtils.isBlank(mobilecodeRedis)) {
return JsonResultUtil.createFailedResult(ResultCode.NOTEXIST_CODE, "验证码错误"); return JsonResultUtil.createFailedResult(ResultCode.NOTEXIST_CODE, "验证码错误");
} }
AppUserLogin user = appUserLoginBiz.checkeUserLogin(username); AppUserLogin user = appUserLoginBiz.checkeUserLogin(username);
if(user==null){ if (user == null) {
return JsonResultUtil.createFailedResult(ResultCode.NOTEXIST_CODE, "用户不存在"); return JsonResultUtil.createFailedResult(ResultCode.NOTEXIST_CODE, "用户不存在");
}
user.setPassword(password);
appUserLoginBiz.updatePasswordById(user);
Integer userid = user.getId();
String nickname = SystemConfig.USER_NIKENAME_DEFAULT + (int) ((Math.random() * 9 + 1) * 100000);
JSONObject data = autoLogin(userid, user.getUsername(), SystemConfig.USER_HEADER_URL_DEFAULT, nickname);
if (data != null) {
return JsonResultUtil.createSuccessResultWithObj(data);
}
return JsonResultUtil.createDefaultFail();
} catch (Exception e) {
log.error("userlogin->error:{}", e.getMessage(), e);
return JsonResultUtil.createFailedResult(ResultCode.EXCEPTION_CODE, "出现异常");
} }
user.setPassword(password);
appUserLoginBiz.updatePasswordById(user);
Integer userid=user.getId();
String nickname=SystemConfig.USER_NIKENAME_DEFAULT+(int)((Math.random()*9+1)*100000);
JSONObject data = autoLogin(userid,user.getUsername(),SystemConfig.USER_HEADER_URL_DEFAULT,nickname);
if (data != null) {
return JsonResultUtil.createSuccessResultWithObj(data);
}
return JsonResultUtil.createDefaultFail();
}catch (Exception e) {
log.error("userlogin->error:{}", e.getMessage(), e);
return JsonResultUtil.createFailedResult(ResultCode.EXCEPTION_CODE, "出现异常");
}
} }
//实名认证 //实名认证
@Transactional @Transactional
public ObjectRestResponse upAuthentication(Integer userid, String idNumber, Integer status) { public ObjectRestResponse upAuthentication(Integer userid, String idNumber, Integer status) {
if(userid==null||userid==0||(status==1&&StringUtils.isBlank(idNumber))){ if (userid == null || userid == 0 || (status == 1 && StringUtils.isBlank(idNumber))) {
return ObjectRestResponse.createFailedResult(ResultCode.NULL_CODE, "参数为空"); return ObjectRestResponse.createFailedResult(ResultCode.NULL_CODE, "参数为空");
} }
try { try {
AppUserLogin user=appUserLoginBiz.getUserById(userid); AppUserLogin user = appUserLoginBiz.getUserById(userid);
if(user==null){ if (user == null) {
return ObjectRestResponse.createFailedResult(ResultCode.NOTEXIST_CODE, "用户不存在"); return ObjectRestResponse.createFailedResult(ResultCode.NOTEXIST_CODE, "用户不存在");
} }
if(user.getCertificationStatus()==1){ if (user.getCertificationStatus() == 1) {
return ObjectRestResponse.createFailedResultWithObj(ResultCode.EXIST_CODE, "用户已认证",user.getIdNumber()); return ObjectRestResponse.createFailedResultWithObj(ResultCode.EXIST_CODE, "用户已认证", user.getIdNumber());
} }
if(status==1){ if (status == 1) {
String username=user.getUsername(); String username = user.getUsername();
user=new AppUserLogin(); user = new AppUserLogin();
user.setId(userid); user.setId(userid);
user.setUsername(username); user.setUsername(username);
user.setIdNumber(idNumber); user.setIdNumber(idNumber);
user.setCertificationStatus(1); user.setCertificationStatus(1);
appUserLoginBiz.updateSelectiveById(user); appUserLoginBiz.updateSelectiveById(user);
} }
return ObjectRestResponse.succ(); return ObjectRestResponse.succ();
}catch (Exception e) { } catch (Exception e) {
log.error("upAuthentication->error:{}", e.getMessage(), e); log.error("upAuthentication->error:{}", e.getMessage(), e);
return ObjectRestResponse.createFailedResult(ResultCode.EXCEPTION_CODE, "出现异常"); return ObjectRestResponse.createFailedResult(ResultCode.EXCEPTION_CODE, "出现异常");
} }
} }
//注册im
public Map<String, Object> registerIm(String username, String password, String nickname) {
log.error("------注册registerIm----username====="+username+"-----password==="+password+"---nickname==="+nickname);
Map<String, Object> map = new HashMap<>();
map.put("telephone", username);
map.put("password", password);
map.put("nickname", nickname);
BaseResponse response = imFeign.register(map);
log.error("registerIm->response:{}", response);
if (response.getStatus() == ResultCode.SUCCESS_CODE) {
String result = response.getMessage();
log.error("------im注册----result======"+result);
if (StringUtils.isNotBlank(result)) {
JSONObject object = JSONObject.parseObject(result);
password = object.getString("password");
if (StringUtils.isNotBlank(result)) {
map.put("password", password);
}
JSONObject data = object.getJSONObject("data");
log.error("------im注册----data======"+data);
if (data != null) {
map.put("userId", data.getString("userId"));
map.put("access_token", data.getString("access_token"));
} else {
map.put("userId", "");
map.put("access_token", "");
}
}
}
return map;
}
//登录im
public String loginIm(String username, String password, String userId) {
log.error("------登录loginIm----username====="+username+"-----password==="+password+"---userId==="+userId);
Map<String, Object> map = new HashMap<>();
map.put("telephone", username);
map.put("password", password);
map.put("userId", userId);
BaseResponse response = imFeign.login(map);
log.error("registerIm->response:{}", response);
String access_token = "";
if (response.getStatus() == ResultCode.SUCCESS_CODE) {
String result = response.getMessage();
log.error("------im登录----result======"+result);
if (StringUtils.isNotBlank(result)) {
JSONObject object = JSONObject.parseObject(result);
JSONObject data = object.getJSONObject("data");
log.error("------im登录----data======"+data);
if (data != null) {
access_token = data.getString("access_token");
}
}
}
log.error("------im登录----access_token======"+access_token);
return access_token;
}
} }
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
<version>2.0-SNAPSHOT</version> <version>2.0-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.xxfc.platform</groupId>
<artifactId>xx-im-api</artifactId> <artifactId>xx-im-api</artifactId>
......
...@@ -45,7 +45,7 @@ public class UploadController{ ...@@ -45,7 +45,7 @@ public class UploadController{
return JsonResultUtil.createSuccessResultWithObj(uploadService.uploadFile(file,prefix)); return JsonResultUtil.createSuccessResultWithObj(uploadService.uploadFile(file,prefix));
} }
@RequestMapping(value = "/admin/upload", method = RequestMethod.POST) @RequestMapping(value = "/app/unauth/admin/upload", method = RequestMethod.POST)
public JSONObject uploads( public JSONObject uploads(
@RequestParam("file") MultipartFile file, @RequestParam("file") MultipartFile file,
@RequestParam(value = "prefix",defaultValue = "admin")String prefix @RequestParam(value = "prefix",defaultValue = "admin")String prefix
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment