package com.stylefeng.guns.modular.api;
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.google.code.kaptcha.Constants;
|
import com.stylefeng.guns.core.common.constant.JwtConstants;
|
import com.stylefeng.guns.core.common.exception.InvalidKaptchaException;
|
import com.stylefeng.guns.core.support.HttpKit;
|
import com.stylefeng.guns.core.util.ToolUtil;
|
import com.stylefeng.guns.modular.system.model.UserInfo;
|
import com.stylefeng.guns.modular.system.service.IReportLossService;
|
import com.stylefeng.guns.modular.system.service.ISmsrecordService;
|
import com.stylefeng.guns.modular.system.service.IUserInfoService;
|
import com.stylefeng.guns.modular.system.service.IVerifiedService;
|
import com.stylefeng.guns.modular.system.util.*;
|
import com.stylefeng.guns.modular.system.warpper.LoginWarpper;
|
import com.stylefeng.guns.modular.system.warpper.UserInfoWarpper;
|
import com.stylefeng.guns.modular.system.warpper.UserInviteInfoWarpper;
|
import com.stylefeng.guns.modular.system.warpper.VerifiedWarpper;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParams;
|
import io.swagger.annotations.ApiOperation;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpSession;
|
import java.util.*;
|
|
/**
|
* 用户控制器
|
*/
|
@Api
|
@CrossOrigin
|
@RestController
|
@RequestMapping("")
|
public class UserInfoController {
|
|
@Autowired
|
private IUserInfoService userInfoService;
|
|
@Autowired
|
private IVerifiedService verifiedService;
|
|
@Autowired
|
private ISmsrecordService smsrecordService;
|
|
@Autowired
|
private RedisUtil redisUtil;
|
|
@Autowired
|
private IReportLossService reportLossService;
|
|
|
|
|
@ResponseBody
|
@PostMapping("/base/isEnterEmergencyContact")
|
@ApiOperation(value = "是否输入紧急联系人", tags = {"用户端-登录"}, notes = "")
|
public ResultUtil isEnterEmergencyContact(){
|
try {
|
Integer type = userInfoService.getAppOpenInfo(2);
|
Map<String,Object> map = new HashMap<>();
|
map.put("isEnterEmergencyContact",type==1);
|
return ResultUtil.success(map);
|
}catch (Exception e){
|
e.printStackTrace();
|
return ResultUtil.runErr();
|
}
|
}
|
|
/**
|
* 获取短信验证码
|
* @param phone
|
* @return
|
*/
|
@ResponseBody
|
@PostMapping("/base/authentication")
|
@ApiOperation(value = "实名认证", tags = {"用户端-登录"}, notes = "")
|
@ApiImplicitParams({
|
@ApiImplicitParam(value = "手机号码", name = "phone", required = true, dataType = "String"),
|
@ApiImplicitParam(value = "身份证号", name = "idCard", required = true, dataType = "String")
|
})
|
public ResultUtil authentication(String phone, String idCard){
|
if(ToolUtil.isNotEmpty(phone)){
|
try {
|
//return ResultUtil.success(aLiApiUtil.authentication(phone,idCard));
|
return ResultUtil.success(true);
|
}catch (Exception e){
|
e.printStackTrace();
|
return ResultUtil.runErr();
|
}
|
}else{
|
return ResultUtil.paranErr();
|
}
|
}
|
|
|
|
/**
|
* 获取短信验证码
|
* @param phone
|
* @return
|
*/
|
@ResponseBody
|
@PostMapping("/base/queryCaptcha")
|
@ApiOperation(value = "获取短信验证码", tags = {"用户端-登录"}, notes = "")
|
@ApiImplicitParams({
|
@ApiImplicitParam(value = "手机号码", name = "phone", required = true, dataType = "String"),
|
@ApiImplicitParam(value = "图片验证码", name = "kaptcha", required = true, dataType = "String"),
|
@ApiImplicitParam(value = "场景类型(1=身份验证,2=登录确认,3=用户注册,4=修改密码)", name = "type", required = true, dataType = "String")
|
})
|
public ResultUtil queryCaptcha(HttpServletRequest request,String phone, Integer type,String kaptcha){
|
if(ToolUtil.isNotEmpty(phone)){
|
try {
|
/* HttpSession session = request.getSession();
|
String code = (String)session.getAttribute(Constants.KAPTCHA_SESSION_KEY);*/
|
String code = redisUtil.getValue(phone+"_Code");
|
System.out.println("缓存中验证码为:"+code);
|
if (ToolUtil.isEmpty(kaptcha) || !kaptcha.equalsIgnoreCase(code)) {
|
return ResultUtil.error("图形验证码错误");
|
}
|
return userInfoService.queryCaptcha(phone, type);
|
}catch (Exception e){
|
e.printStackTrace();
|
return ResultUtil.runErr();
|
}
|
}else{
|
return ResultUtil.paranErr();
|
}
|
}
|
|
@ResponseBody
|
@PostMapping("/base/sedEmail")
|
@ApiOperation(value = "获取邮箱验证码【1.0】", tags = {"用户端-登录"}, notes = "")
|
@ApiImplicitParams({
|
@ApiImplicitParam(value = "邮箱地址", name = "email", required = true, dataType = "String")
|
})
|
public ResultUtil sedEmail(String email){
|
try {
|
if(ToolUtil.isEmpty(email)){
|
return ResultUtil.error("邮箱地址不能为空");
|
}
|
Random random = new Random();
|
StringBuffer sb = new StringBuffer();
|
for(int i = 0; i < 4; i++){
|
sb.append((int) (random.nextDouble() * 10));
|
}
|
String authCode = sb.toString();
|
redisUtil.setStrValue(email, authCode, 5 * 60);
|
EmailUtil.getMimeMessage(email, "验证码", "您的验证码:<span style=\"color:red;\">" + authCode + "</span>");
|
return ResultUtil.success();
|
}catch (Exception e){
|
e.printStackTrace();
|
return ResultUtil.runErr();
|
}
|
}
|
|
|
|
|
/**
|
* 手机验证码登录
|
* @param phone
|
* @param code
|
* @param registIp
|
* @param registAreaCode
|
* @return
|
*/
|
@ResponseBody
|
@PostMapping("/base/user/captchaLogin")
|
@ApiOperation(value = "手机验证码登录", tags = {"用户端-登录"}, notes = "")
|
@ApiImplicitParams({
|
@ApiImplicitParam(value = "手机号码", name = "phone", required = true, dataType = "String"),
|
@ApiImplicitParam(value = "短信验证码", name = "code", required = true, dataType = "String"),
|
@ApiImplicitParam(value = "ip地址", name = "registIp", required = false, dataType = "String"),
|
@ApiImplicitParam(value = "当前定位区县行政编号", name = "registAreaCode", required = false, dataType = "String")
|
})
|
public ResultUtil<LoginWarpper> captchaLogin(String phone, String code, String registIp, String registAreaCode){
|
try {
|
return userInfoService.captchaLogin(phone, code, registIp, registAreaCode,null,null,null);
|
}catch (Exception e){
|
e.printStackTrace();
|
return ResultUtil.runErr();
|
}
|
}
|
|
|
|
/**
|
* 手机验证码登录
|
* @param phone
|
* @param code
|
* @return
|
*/
|
@ResponseBody
|
@PostMapping("/base/user/captchaLogin_")
|
@ApiOperation(value = "手机验证码登录", tags = {"分享专用"}, notes = "")
|
@ApiImplicitParams({
|
@ApiImplicitParam(value = "手机号码", name = "phone", required = true, dataType = "String"),
|
@ApiImplicitParam(value = "短信验证码", name = "code", required = true, dataType = "String"),
|
@ApiImplicitParam(value = "分享的用户id", name = "uid", required = true, dataType = "int"),
|
@ApiImplicitParam(value = "用户类型(1=用户,2=司机)", name = "type", required = true, dataType = "int"),
|
@ApiImplicitParam(value = "注册类型(1=司机注册,2=用户注册)", name = "userType", required = true, dataType = "int")
|
})
|
public ResultUtil<LoginWarpper> captchaLogin_(String phone, String code, Integer uid, Integer type, Integer userType){
|
try {
|
return userInfoService.captchaLogin(phone, code, uid, type, userType);
|
}catch (Exception e){
|
e.printStackTrace();
|
return ResultUtil.runErr();
|
}
|
}
|
|
|
|
|
|
/**
|
* 账号密码登录
|
* @param phone
|
* @param password
|
* @return
|
*/
|
@ResponseBody
|
@PostMapping("/base/user/userLogin")
|
@ApiOperation(value = "账号密码登录", tags = {"用户端-登录"}, notes = "")
|
@ApiImplicitParams({
|
@ApiImplicitParam(value = "手机号码", name = "phone", required = true, dataType = "String"),
|
@ApiImplicitParam(value = "登录密码", name = "password", required = true, dataType = "String")
|
})
|
public ResultUtil<LoginWarpper> userLogin(String phone, String password){
|
if(ToolUtil.isNotEmpty(phone) && ToolUtil.isNotEmpty(password)){
|
try {
|
return userInfoService.userLogin(phone, password);
|
}catch (Exception e){
|
e.printStackTrace();
|
return ResultUtil.runErr();
|
}
|
}else{
|
return ResultUtil.paranErr();
|
}
|
}
|
|
|
/**
|
* 忘记密码
|
* @param phone
|
* @param code
|
* @param password
|
* @return
|
*/
|
@ResponseBody
|
@PostMapping("/base/user/forgetPassword")
|
@ApiOperation(value = "忘记密码操作", tags = {"用户端-登录"}, notes = "")
|
@ApiImplicitParams({
|
@ApiImplicitParam(value = "手机号码", name = "phone", required = true, dataType = "String"),
|
@ApiImplicitParam(value = "验证码", name = "code", required = true, dataType = "String"),
|
@ApiImplicitParam(value = "新密码", name = "password", required = true, dataType = "String")
|
})
|
public ResultUtil forgetPassword(String phone, String code, String password){
|
if(ToolUtil.isNotEmpty(phone) && ToolUtil.isNotEmpty(code) && ToolUtil.isNotEmpty(password)){
|
try {
|
return userInfoService.forgetPassword(phone, code, password);
|
}catch (Exception e){
|
e.printStackTrace();
|
return ResultUtil.runErr();
|
}
|
}else{
|
return ResultUtil.paranErr();
|
}
|
}
|
|
|
/**
|
* 微信授权登录
|
* @param type 登录端口(1:APP登录,2:小程序)
|
* @param openid 微信openid
|
* @param unionid 微信unionid
|
* @param jscode 小程序登录时的jscode临时凭证
|
* @param registIp ip地址
|
* @param registAreaCode 当前定位区县行政编号(6位)
|
* @return
|
*/
|
@ResponseBody
|
@PostMapping("/base/user/wxLogin")
|
@ApiOperation(value = "微信授权登录", tags = {"用户端-登录"}, notes = "")
|
@ApiImplicitParams({
|
@ApiImplicitParam(value = "登录端口(1:APP,2:小程序)", name = "type", required = true, dataType = "int"),
|
@ApiImplicitParam(value = "微信openid(APP登录上传)", name = "openid", required = false, dataType = "String"),
|
@ApiImplicitParam(value = "encryptedData", name = "encryptedData", required = false, dataType = "String"),
|
@ApiImplicitParam(value = "iv", name = "iv", required = false, dataType = "String"),
|
@ApiImplicitParam(value = "微信unionid(APP登录上传)", name = "unionid", required = false, dataType = "String"),
|
@ApiImplicitParam(value = "微信jscode(小程序登录上传)", name = "jscode", required = false, dataType = "String"),
|
@ApiImplicitParam(value = "ip地址", name = "registIp", required = false, dataType = "String"),
|
@ApiImplicitParam(value = "当前定位区县行政编号", name = "registAreaCode", required = true, dataType = "String"),
|
@ApiImplicitParam(value = "头像", name = "avatar", required = false, dataType = "String"),
|
@ApiImplicitParam(value = "昵称", name = "nickName", required = false, dataType = "String"),
|
@ApiImplicitParam(value = "登录端口-小程序传Applets", name = "loginType", required = false, dataType = "String"),
|
@ApiImplicitParam(value = "分享的用户id", name = "uid", required = false, dataType = "int"),
|
@ApiImplicitParam(value = "性别(1=男,2=女)", name = "sex", required = false, dataType = "int")
|
})
|
public ResultUtil<LoginWarpper> wxLogin(Integer uid,String encryptedData, String iv,Integer type, String openid, String unionid, String jscode, String registIp, String registAreaCode, Integer sex, String nickName, String avatar,String loginType){
|
try {
|
return userInfoService.wxLogin(type, openid, unionid, jscode, registIp, registAreaCode, sex, nickName, avatar,loginType,encryptedData,iv,uid);
|
}catch (Exception e){
|
e.printStackTrace();
|
return ResultUtil.runErr();
|
}
|
}
|
|
@ResponseBody
|
@PostMapping("/base/user/wxIsLogin")
|
@ApiOperation(value = "微信小程序是否登录", tags = {"用户端-登录"}, notes = "")
|
@ApiImplicitParams({
|
@ApiImplicitParam(value = "微信jscode(小程序登录上传)", name = "jscode", required = false, dataType = "String")
|
})
|
public ResultUtil<LoginWarpper> wxIsLogin( String jscode){
|
try {
|
return userInfoService.wxIsLogin(jscode);
|
}catch (Exception e){
|
e.printStackTrace();
|
return ResultUtil.runErr();
|
}
|
}
|
|
|
@ResponseBody
|
@PostMapping("/base/user/facebookLogin")
|
@ApiOperation(value = "FaceBook授权登录【1.0】", tags = {"用户端-登录"}, notes = "")
|
@ApiImplicitParams({
|
@ApiImplicitParam(value = "FaceBook用户id", name = "id", required = true, dataType = "String"),
|
@ApiImplicitParam(value = "FaceBook用户名称", name = "name", required = true, dataType = "String"),
|
@ApiImplicitParam(value = "FaceBook绑定的email", name = "email", required = false, dataType = "String"),
|
@ApiImplicitParam(value = "当前定位区县行政编号", name = "registAreaCode", required = true, dataType = "String"),
|
@ApiImplicitParam(value = "分享的用户id", name = "uid", required = false, dataType = "int"),
|
})
|
public ResultUtil facebookLogin(String id, String name, String email, String registAreaCode, Integer uid){
|
try {
|
return userInfoService.facebookLogin(id, name, email, registAreaCode, uid);
|
}catch (Exception e){
|
e.printStackTrace();
|
return ResultUtil.runErr();
|
}
|
}
|
|
|
|
|
/**
|
* 设置电话号码
|
* @param phone
|
* @param code
|
* @param request
|
* @return
|
*/
|
@ResponseBody
|
@PostMapping("/api/user/bindingPhone")
|
@ApiOperation(value = "设置电话号码", tags = {"用户端-登录"}, notes = "")
|
@ApiImplicitParams({
|
@ApiImplicitParam(value = "电话号码", name = "phone", required = true, dataType = "String"),
|
@ApiImplicitParam(value = "验证码", name = "code", required = false, dataType = "String"),
|
@ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
|
})
|
public ResultUtil<LoginWarpper> bindingPhone(String phone, String code, HttpServletRequest request){
|
try {
|
Integer uid = userInfoService.getUserIdFormRedis(request);
|
if(null == uid){
|
return ResultUtil.tokenErr();
|
}
|
return userInfoService.bindingPhone(uid, phone, code);
|
}catch (Exception e){
|
e.printStackTrace();
|
return ResultUtil.runErr();
|
}
|
}
|
|
|
@ResponseBody
|
@PostMapping("/api/user/bindingEmail")
|
@ApiOperation(value = "设置邮箱地址【1.0】", tags = {"用户端-登录"}, notes = "")
|
@ApiImplicitParams({
|
@ApiImplicitParam(value = "绑定类型(1=注册账号绑定,2=个人中心绑定)", name = "type", required = true, dataType = "int"),
|
@ApiImplicitParam(value = "邮箱地址", name = "email", required = true, dataType = "String"),
|
@ApiImplicitParam(value = "验证码", name = "code", required = true, dataType = "String"),
|
@ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
|
})
|
public ResultUtil<LoginWarpper> bindingEmail(Integer type, String email, String code, HttpServletRequest request){
|
try {
|
Integer uid = userInfoService.getUserIdFormRedis(request);
|
if(null == uid){
|
return ResultUtil.tokenErr();
|
}
|
return userInfoService.bindingEmail(uid, type, email, code);
|
}catch (Exception e){
|
e.printStackTrace();
|
return ResultUtil.runErr();
|
}
|
}
|
|
|
/**
|
* 获取用户个人信息
|
* @param request
|
* @return
|
*/
|
@ResponseBody
|
@PostMapping("/api/user/queryUserInfo")
|
@ApiOperation(value = "获取用户详情【1.0】", tags = {"用户端-个人中心"}, notes = "")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
|
})
|
public ResultUtil<UserInfoWarpper> queryUserInfo(HttpServletRequest request){
|
try {
|
Integer uid = userInfoService.getUserIdFormRedis(request);
|
if(null == uid){
|
return ResultUtil.tokenErr();
|
}
|
Map<String, Object> map = userInfoService.queryUserInfo(uid);
|
return ResultUtil.success(UserInfoWarpper.getUserInfoWarpper(map));
|
}catch (Exception e){
|
e.printStackTrace();
|
return ResultUtil.runErr();
|
}
|
}
|
|
|
/**
|
* 手机号码获取用户
|
* @param phone
|
* @return
|
*/
|
@ResponseBody
|
@PostMapping("/api/user/queryUser")
|
@ApiOperation(value = "手机号码获取用户", tags = {"用户端-个人中心"}, notes = "")
|
@ApiImplicitParams({
|
@ApiImplicitParam(value = "电话号码", name = "phone", required = true, dataType = "String"),
|
@ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
|
})
|
public ResultUtil<Object> queryUser(String phone){
|
try {
|
Map<String, Object> map = userInfoService.queryUser(phone);
|
if(null != map){
|
return ResultUtil.success(UserInfoWarpper.getUserInfoWarpper(map));
|
}
|
return ResultUtil.success(new JSONObject());
|
}catch (Exception e){
|
e.printStackTrace();
|
return ResultUtil.runErr();
|
}
|
}
|
|
|
/**
|
* 实名认证操作
|
* @param verifiedWarpper
|
* @param request
|
* @return
|
*/
|
@ResponseBody
|
@PostMapping("/api/user/verified")
|
@ApiOperation(value = "实名认证操作", tags = {"用户端-个人中心"}, notes = "")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
|
})
|
public ResultUtil verified(VerifiedWarpper verifiedWarpper, HttpServletRequest request){
|
try {
|
Integer uid = userInfoService.getUserIdFormRedis(request);
|
if(null == uid){
|
return ResultUtil.tokenErr();
|
}
|
return verifiedService.verified(VerifiedWarpper.getVerified(verifiedWarpper), uid);
|
}catch (Exception e){
|
e.printStackTrace();
|
return ResultUtil.runErr();
|
}
|
}
|
|
|
/**
|
* 设置紧急联系人
|
* @param name
|
* @param phone
|
* @param request
|
* @return
|
*/
|
@ResponseBody
|
@PostMapping("/api/user/setUrgentUser")
|
@ApiOperation(value = "设置紧急联系人", tags = {"用户端-个人中心"}, notes = "")
|
@ApiImplicitParams({
|
@ApiImplicitParam(value = "姓名,没有传空字符串", name = "name", required = true, dataType = "String"),
|
@ApiImplicitParam(value = "电话号码,没有传空字符串", name = "phone", required = true, dataType = "String"),
|
@ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
|
})
|
public ResultUtil setUrgentUser(String name, String phone, HttpServletRequest request){
|
try {
|
Integer uid = userInfoService.getUserIdFormRedis(request);
|
if(null == uid){
|
return ResultUtil.tokenErr();
|
}
|
userInfoService.setUrgentUser(name, phone, uid);
|
return ResultUtil.success();
|
}catch (Exception e){
|
e.printStackTrace();
|
return ResultUtil.runErr();
|
}
|
}
|
|
|
/**
|
* 用户充值余额
|
* @param payType
|
* @param money
|
* @param request
|
* @return
|
*/
|
@ResponseBody
|
@PostMapping("/api/user/depositBalance")
|
@ApiOperation(value = "余额充值", tags = {"用户端-个人中心"}, notes = "")
|
@ApiImplicitParams({
|
@ApiImplicitParam(value = "支付方式(1=微信,2=支付宝)", name = "payType", required = true, dataType = "int"),
|
@ApiImplicitParam(value = "充值金额", name = "money", required = true, dataType = "double"),
|
@ApiImplicitParam(value = "支付端(1=用户APP端,2=司机APP端,3=用户小程序端)", name = "type", required = false, dataType = "int"),
|
@ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
|
})
|
public ResultUtil depositBalance(Integer payType, Double money, Integer type, HttpServletRequest request){
|
try {
|
Integer uid = userInfoService.getUserIdFormRedis(request);
|
if(null == uid){
|
return ResultUtil.tokenErr();
|
}
|
return userInfoService.depositBalance(payType, money, uid, type);
|
}catch (Exception e){
|
e.printStackTrace();
|
return ResultUtil.runErr();
|
}
|
}
|
|
|
/**
|
* 修改手机号码
|
* @param code
|
* @param phone
|
* @param request
|
* @return
|
*/
|
@ResponseBody
|
@PostMapping("/api/user/updatePhone")
|
@ApiOperation(value = "修改手机号码", tags = {"用户端-个人中心"}, notes = "")
|
@ApiImplicitParams({
|
@ApiImplicitParam(value = "验证码", name = "code", required = true, dataType = "string"),
|
@ApiImplicitParam(value = "新手机号", name = "phone", required = true, dataType = "string"),
|
@ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
|
})
|
public ResultUtil updatePhone(String code, String phone, HttpServletRequest request){
|
try {
|
Integer uid = userInfoService.getUserIdFormRedis(request);
|
if(null == uid){
|
return ResultUtil.tokenErr();
|
}
|
return userInfoService.updatePhone(code, phone, uid);
|
}catch (Exception e){
|
e.printStackTrace();
|
return ResultUtil.runErr();
|
}
|
}
|
|
@ResponseBody
|
@PostMapping("/api/user/checkCaptcha")
|
@ApiOperation(value = "验证短信验证码", tags = {"用户端-个人中心"}, notes = "1=正确,0=错误")
|
@ApiImplicitParams({
|
@ApiImplicitParam(value = "电话号码", name = "phone", required = true, dataType = "string"),
|
@ApiImplicitParam(value = "短信验证码", name = "code", required = true, dataType = "string"),
|
@ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
|
})
|
public ResultUtil checkCaptcha(String phone, String code, HttpServletRequest request){
|
try {
|
Integer uid = userInfoService.getUserIdFormRedis(request);
|
if(null == uid){
|
return ResultUtil.tokenErr();
|
}
|
UserInfo userInfo = userInfoService.selectById(uid);
|
smsrecordService.saveData(4, userInfo.getPhone(), code, "短信验证码【" + code + "】已发到您的手机,验证码将在5分钟后失效,请及时登录!");
|
boolean b = userInfoService.checkCaptcha(phone, code);
|
Map<String, Object> map = new HashMap<>();
|
map.put("ok", b ? 1 : 0);
|
return ResultUtil.success(map);
|
}catch (Exception e){
|
e.printStackTrace();
|
return ResultUtil.runErr();
|
}
|
}
|
|
|
|
/**
|
* 修改登录密码
|
* @param password
|
* @param request
|
* @return
|
*/
|
@ResponseBody
|
@PostMapping("/api/user/updatePassword")
|
@ApiOperation(value = "修改登录密码", tags = {"用户端-个人中心"}, notes = "")
|
@ApiImplicitParams({
|
@ApiImplicitParam(value = "新密码", name = "password", required = true, dataType = "string"),
|
@ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
|
})
|
public ResultUtil updatePassword(String password, HttpServletRequest request){
|
try {
|
Integer uid = userInfoService.getUserIdFormRedis(request);
|
if(null == uid){
|
return ResultUtil.tokenErr();
|
}
|
return userInfoService.updatePass(password, uid);
|
}catch (Exception e){
|
e.printStackTrace();
|
return ResultUtil.runErr();
|
}
|
}
|
|
|
/**
|
* 修改个人信息
|
* @param avatar
|
* @param nickname
|
* @param sex
|
* @param birthday
|
* @param request
|
* @return
|
*/
|
@ResponseBody
|
@PostMapping("/api/user/updateInfo")
|
@ApiOperation(value = "修改个人信息", tags = {"用户端-个人中心"}, notes = "")
|
@ApiImplicitParams({
|
@ApiImplicitParam(value = "头像", name = "avatar", required = false, dataType = "string"),
|
@ApiImplicitParam(value = "昵称", name = "nickname", required = false, dataType = "string"),
|
@ApiImplicitParam(value = "性别(1=男,2=女)", name = "sex", required = false, dataType = "int"),
|
@ApiImplicitParam(value = "生日(2020-06-15)", name = "birthday", required = false, dataType = "string"),
|
@ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
|
})
|
public ResultUtil updateInfo(String avatar, String nickname, Integer sex, Date birthday, HttpServletRequest request){
|
try {
|
Integer uid = userInfoService.getUserIdFormRedis(request);
|
if(null == uid){
|
return ResultUtil.tokenErr();
|
}
|
userInfoService.updateInfo(avatar, nickname, sex, birthday, uid);
|
return ResultUtil.success();
|
}catch (Exception e){
|
e.printStackTrace();
|
return ResultUtil.runErr();
|
}
|
}
|
|
|
@ResponseBody
|
@PostMapping("/api/user/queryRealName")
|
@ApiOperation(value = "获取实名认证的数据", tags = {"用户端-个人中心"}, notes = "")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
|
})
|
public ResultUtil queryRealName(HttpServletRequest request){
|
try {
|
Integer uid = userInfoService.getUserIdFormRedis(request);
|
if(null == uid){
|
return ResultUtil.tokenErr();
|
}
|
Map<String, Object> map = userInfoService.queryRealName(uid);
|
return ResultUtil.success(null != map ? map : new HashMap<>());
|
}catch (Exception e){
|
e.printStackTrace();
|
return ResultUtil.runErr();
|
}
|
}
|
|
|
/**
|
* 后台调用禁用用户
|
* @param uid
|
* @return
|
*/
|
@ResponseBody
|
@PostMapping("/base/user/freeze")
|
public ResultUtil freeze(Integer uid){
|
try {
|
UserInfo userInfo = userInfoService.selectById(uid);
|
String value = redisUtil.getValue(userInfo.getPhone());
|
redisUtil.remove(value);
|
redisUtil.remove(userInfo.getPhone());
|
return ResultUtil.success();
|
}catch (Exception e){
|
e.printStackTrace();
|
return ResultUtil.runErr();
|
}
|
}
|
|
|
/**
|
* 仿socket接口(单点登录)
|
* @param request
|
* @return
|
*/
|
@ResponseBody
|
@PostMapping("/api/user/comparisonToken")
|
@ApiOperation(value = "单点登录", tags = {"用户端-仿socket接口"}, notes = "match=1(匹配),match=2(不匹配)")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
|
})
|
public ResultUtil comparisonToken(HttpServletRequest request){
|
try {
|
Integer uid = userInfoService.getUserIdFormRedis(request);
|
if(null == uid){
|
return ResultUtil.tokenErr();
|
}
|
String requestHeader = request.getHeader(JwtConstants.AUTH_HEADER);
|
requestHeader = requestHeader.substring(requestHeader.indexOf(" ") + 1);
|
String value = redisUtil.getValue("USER_" + uid);
|
Map<String, Object> map = new HashMap<>();
|
map.put("match", requestHeader.equals(value) ? 1 : 2);
|
return ResultUtil.success(map);
|
}catch (Exception e){
|
e.printStackTrace();
|
return ResultUtil.runErr();
|
}
|
}
|
|
/**
|
* 注销账号
|
* @param request
|
* @return
|
*/
|
@ResponseBody
|
@PostMapping("/api/user/cancellation")
|
@ApiOperation(value = "注销账号", tags = {"用户端-个人中心"}, notes = "")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
|
})
|
public ResultUtil cancellation(HttpServletRequest request){
|
try {
|
Integer uid = userInfoService.getUserIdFormRedis(request);
|
if(null == uid){
|
return ResultUtil.tokenErr();
|
}
|
UserInfo userInfo = userInfoService.selectById(uid);
|
userInfo.setState(2);
|
userInfoService.updateById(userInfo);
|
//开始验证当前账号是否在别处登录
|
String value = redisUtil.getValue("USER_" + uid);
|
if(ToolUtil.isNotEmpty(value)){//将另外设备上的强迫下线
|
//开始清除redis中无效的数据
|
String key = redisUtil.getValue("USER_" + userInfo.getPhone());
|
redisUtil.remove(key);//删除个人信息数据
|
redisUtil.remove("USER_" + userInfo.getPhone());//删除后台冻结相关缓存
|
redisUtil.remove("USER_" + uid);//清除存储的token
|
}
|
return ResultUtil.success();
|
}catch (Exception e){
|
e.printStackTrace();
|
return ResultUtil.runErr();
|
}
|
}
|
|
@ResponseBody
|
@PostMapping("/api/user/getInviteList")
|
@ApiOperation(value = "获取邀请司机/乘客列表", tags = {"用户端-个人中心"}, notes = "")
|
@ApiImplicitParams({
|
@ApiImplicitParam(value = "类型[1:乘客,2:司机]", name = "type", required = true, dataType = "int"),
|
@ApiImplicitParam(value = "页码,首页1", name = "pageNum", required = true, dataType = "int"),
|
@ApiImplicitParam(value = "页条数", name = "size", required = true, dataType = "int"),
|
@ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
|
})
|
public ResultUtil getInviteList(Integer type,Integer pageNum, Integer size, HttpServletRequest request){
|
try {
|
Integer uid = userInfoService.getUserIdFormRedis(request);
|
if(null == uid){
|
return ResultUtil.tokenErr();
|
}
|
List<Map<String,Object>> list = userInfoService.queryMyInviteList(type,uid, pageNum, size);
|
return ResultUtil.success(UserInviteInfoWarpper.getDriverInviteInfoWarpper(list));
|
}catch (Exception e){
|
e.printStackTrace();
|
return ResultUtil.runErr();
|
}
|
}
|
|
|
|
@ResponseBody
|
@PostMapping("/api/user/editLanguage")
|
@ApiOperation(value = "修改多语言配置", tags = {"用户端-个人中心"}, notes = "")
|
@ApiImplicitParams({
|
@ApiImplicitParam(value = "1=中文,2=英文,3=法语", name = "language", required = true, dataType = "int"),
|
@ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
|
})
|
public ResultUtil editLanguage(Integer language, HttpServletRequest request){
|
try {
|
Integer uid = userInfoService.getUserIdFormRedis(request);
|
if(null == uid){
|
return ResultUtil.tokenErr();
|
}
|
UserInfo userInfo = userInfoService.selectById(uid);
|
userInfo.setLanguage(language);
|
userInfoService.updateById(userInfo);
|
return ResultUtil.success();
|
}catch (Exception e){
|
e.printStackTrace();
|
return ResultUtil.runErr();
|
}
|
}
|
|
|
@ResponseBody
|
@PostMapping("/base/user/addReportLoss")
|
@ApiOperation(value = "提交报失", tags = {"用户端-个人中心"}, notes = "")
|
@ApiImplicitParams({
|
@ApiImplicitParam(value = "订单类型(1=专车,2=出租车,3=跨城出行,4=同城小件物流,5=跨城小件物流)", name = "orderType", required = true, dataType = "int"),
|
@ApiImplicitParam(value = "订单id", name = "orderId", required = true, dataType = "int"),
|
@ApiImplicitParam(value = "提交内容", name = "remark", required = true, dataType = "int"),
|
@ApiImplicitParam(value = "提交图片", name = "image", required = true, dataType = "int"),
|
})
|
public ResultUtil addReportLoss(Integer orderType, Integer orderId, String remark, String image){
|
try {
|
reportLossService.addReportLoss(orderType, orderId, remark, image);
|
return ResultUtil.success();
|
}catch (Exception e){
|
e.printStackTrace();
|
return ResultUtil.runErr();
|
}
|
}
|
}
|