| | |
| | | package com.stylefeng.guns.modular.api; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.stylefeng.guns.core.common.constant.JwtConstants; |
| | | import com.stylefeng.guns.core.util.ToolUtil; |
| | | import com.stylefeng.guns.modular.system.model.Driver; |
| | | import com.stylefeng.guns.modular.system.model.UserInfo; |
| | | import com.stylefeng.guns.modular.system.service.IDriverService; |
| | | 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.RedisUtil; |
| | | import com.stylefeng.guns.modular.system.util.ResultUtil; |
| | | import com.stylefeng.guns.modular.system.util.WeChatUtil; |
| | | 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.VerifiedWarpper; |
| | |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.FileOutputStream; |
| | | import java.io.FileWriter; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * 用户控制器 |
| | |
| | | @Autowired |
| | | private WeChatUtil weChatUtil; |
| | | |
| | | @Autowired |
| | | private IDriverService driverService; |
| | | |
| | | |
| | | |
| | | |
| | |
| | | public ResultUtil queryCaptcha(String phone, Integer type){ |
| | | if(ToolUtil.isNotEmpty(phone)){ |
| | | try { |
| | | phone = AESUtil.decrypt(phone);//对电话号码进行解密 |
| | | |
| | | return userInfoService.queryCaptcha(phone, type); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | |
| | | }else{ |
| | | return ResultUtil.paranErr(); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取图形验证码 |
| | | */ |
| | | @ResponseBody |
| | | @GetMapping("/base/getVerifyCodeUtils") |
| | | @ApiOperation(value = "获取图形验证码", tags = {"用户端-登录"}, notes = "") |
| | | @ApiImplicitParams({ |
| | | }) |
| | | public Object getVerifyCodeUtils(){ |
| | | try { |
| | | String s = VerifyCodeUtils.generateVerifyCode(4); |
| | | File file = new File("/opt/tianma/VerifyCode/" + s + ".jpg"); |
| | | if(!file.exists()){ |
| | | file.createNewFile(); |
| | | FileOutputStream out = new FileOutputStream(file); |
| | | VerifyCodeUtils.outputImage(100, 40, out, s); |
| | | file = new File("/opt/tianma/VerifyCode/" + s + ".jpg"); |
| | | FileInputStream inputStream = new FileInputStream(file); |
| | | byte[] data = new byte[inputStream.available()]; |
| | | inputStream.read(data); |
| | | inputStream.close(); |
| | | String string = Base64.getEncoder().encodeToString(data); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("code", MD5AndKL.MD5(s.toLowerCase())); |
| | | map.put("img", string); |
| | | file.delete(); |
| | | return ResultUtil.success(map); |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | return ResultUtil.success(); |
| | | } |
| | | |
| | | |
| | |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "手机号码", name = "phone", required = true, dataType = "String"), |
| | | @ApiImplicitParam(value = "登录端口-小程序传Applets", name = "loginType", required = false, dataType = "String"), |
| | | @ApiImplicitParam(value = "登录密码", name = "password", required = true, dataType = "String") |
| | | @ApiImplicitParam(value = "登录密码", name = "password", required = true, dataType = "String"), |
| | | @ApiImplicitParam(value = "短信验证码", name = "code", required = true, dataType = "String"), |
| | | }) |
| | | public ResultUtil<LoginWarpper> userLogin(String phone, String password,String loginType){ |
| | | public ResultUtil<LoginWarpper> userLogin(String phone, String password,String loginType, String code){ |
| | | if(ToolUtil.isNotEmpty(phone) && ToolUtil.isNotEmpty(password)){ |
| | | try { |
| | | phone = AESUtil.decrypt(phone);//解密电话号码 |
| | | boolean b = userInfoService.checkCaptcha(phone, code); |
| | | if(!b){ |
| | | return ResultUtil.error("验证码无效"); |
| | | } |
| | | return userInfoService.userLogin(phone, password,loginType); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | |
| | | }) |
| | | public ResultUtil setUrgentUser(String name, String phone, HttpServletRequest request){ |
| | | try { |
| | | System.out.println(phone); |
| | | Integer uid = userInfoService.getUserIdFormRedis(request); |
| | | if(null == uid){ |
| | | return ResultUtil.tokenErr(); |
| | |
| | | return ResultUtil.tokenErr(); |
| | | } |
| | | UserInfo userInfo = userInfoService.selectById(uid); |
| | | smsrecordService.saveData(4, userInfo.getPhone(), code, "短信验证码【" + code + "】已发到您的手机,验证码将在5分钟后失效,请及时登录!"); |
| | | String phone1 = AESUtil.decrypt(userInfo.getPhone());//解密 |
| | | smsrecordService.saveData(4, phone1, code, "短信验证码【" + code + "】已发到您的手机,验证码将在5分钟后失效,请及时登录!"); |
| | | phone = AESUtil.decrypt(phone);//解密 |
| | | boolean b = userInfoService.checkCaptcha(phone, code); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("ok", b ? 1 : 0); |
| | |
| | | return ResultUtil.runErr(); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 对数据库数据进行加密 |
| | | * @param type |
| | | * @return |
| | | */ |
| | | @ResponseBody |
| | | @PostMapping("/base/encryptedData") |
| | | public ResultUtil encryptedData(Integer type, Integer id){ |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | System.err.println("执行加密任务开始"); |
| | | if(type == 1){//用户 |
| | | EntityWrapper<UserInfo> userInfoEntityWrapper = new EntityWrapper<>(); |
| | | if(null != id){ |
| | | userInfoEntityWrapper.eq("id", id); |
| | | } |
| | | List<UserInfo> userInfos = userInfoService.selectList(userInfoEntityWrapper); |
| | | for (UserInfo userInfo : userInfos) { |
| | | if(ToolUtil.isNotEmpty(userInfo.getPhone())){ |
| | | userInfo.setPhone(AESUtil.encrypt(userInfo.getPhone())); |
| | | } |
| | | if(ToolUtil.isNotEmpty(userInfo.getIdCard())){ |
| | | userInfo.setIdCard(AESUtil.encrypt(userInfo.getIdCard())); |
| | | } |
| | | userInfoService.updateById(userInfo); |
| | | } |
| | | }else{ |
| | | EntityWrapper<Driver> userInfoEntityWrapper = new EntityWrapper<>(); |
| | | if(null != id){ |
| | | userInfoEntityWrapper.eq("id", id); |
| | | } |
| | | List<Driver> drivers = driverService.selectList(userInfoEntityWrapper); |
| | | for (Driver driver : drivers) { |
| | | if(ToolUtil.isNotEmpty(driver.getAccount())){ |
| | | driver.setAccount(AESUtil.encrypt(driver.getAccount())); |
| | | } |
| | | if(ToolUtil.isNotEmpty(driver.getPhone())){ |
| | | driver.setPhone(AESUtil.encrypt(driver.getPhone())); |
| | | } |
| | | if(ToolUtil.isNotEmpty(driver.getIdCard())){ |
| | | driver.setIdCard(AESUtil.encrypt(driver.getIdCard())); |
| | | } |
| | | driverService.updateById(driver); |
| | | } |
| | | } |
| | | System.err.println("执行加密任务结束"); |
| | | } |
| | | }).start(); |
| | | return ResultUtil.success(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 解密数据 |
| | | * @param type |
| | | * @return |
| | | */ |
| | | @ResponseBody |
| | | @PostMapping("/base/decryptData") |
| | | public ResultUtil decryptData(Integer type, Integer id){ |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | System.err.println("执行解密任务开始"); |
| | | if(type == 1){//用户 |
| | | EntityWrapper<UserInfo> userInfoEntityWrapper = new EntityWrapper<>(); |
| | | if(null != id){ |
| | | userInfoEntityWrapper.eq("id", id); |
| | | } |
| | | List<UserInfo> userInfos = userInfoService.selectList(userInfoEntityWrapper); |
| | | for (UserInfo userInfo : userInfos) { |
| | | if(ToolUtil.isNotEmpty(userInfo.getPhone())){ |
| | | userInfo.setPhone(AESUtil.decrypt(userInfo.getPhone())); |
| | | } |
| | | if(ToolUtil.isNotEmpty(userInfo.getIdCard())){ |
| | | userInfo.setIdCard(AESUtil.decrypt(userInfo.getIdCard())); |
| | | } |
| | | userInfoService.updateById(userInfo); |
| | | } |
| | | }else{ |
| | | EntityWrapper<Driver> userInfoEntityWrapper = new EntityWrapper<>(); |
| | | if(null != id){ |
| | | userInfoEntityWrapper.eq("id", id); |
| | | } |
| | | List<Driver> drivers = driverService.selectList(userInfoEntityWrapper); |
| | | for (Driver driver : drivers) { |
| | | if(ToolUtil.isNotEmpty(driver.getAccount())){ |
| | | driver.setAccount(AESUtil.decrypt(driver.getAccount())); |
| | | } |
| | | if(ToolUtil.isNotEmpty(driver.getPhone())){ |
| | | driver.setPhone(AESUtil.decrypt(driver.getPhone())); |
| | | } |
| | | if(ToolUtil.isNotEmpty(driver.getIdCard())){ |
| | | driver.setIdCard(AESUtil.decrypt(driver.getIdCard())); |
| | | } |
| | | driverService.updateById(driver); |
| | | } |
| | | } |
| | | System.err.println("执行解密任务结束"); |
| | | } |
| | | }).start(); |
| | | return ResultUtil.success(); |
| | | } |
| | | } |