New file |
| | |
| | | package com.supersavedriving.driver.core.common.annotion; |
| | | |
| | | import com.supersavedriving.driver.modular.system.warpper.ResponseWarpper; |
| | | |
| | | import java.lang.annotation.*; |
| | | |
| | | /** |
| | | * 接口日志注解 |
| | | */ |
| | | @Inherited |
| | | @Retention(RetentionPolicy.RUNTIME) |
| | | @Target({ElementType.METHOD}) |
| | | public @interface ServiceLog { |
| | | /** |
| | | * 接口名称 |
| | | * @return |
| | | */ |
| | | String name() default ""; |
| | | |
| | | /** |
| | | * 接口地址 |
| | | * @return |
| | | */ |
| | | String url() default ""; |
| | | } |
New file |
| | |
| | | package com.supersavedriving.driver.core.common.aspect; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.supersavedriving.driver.core.common.annotion.ServiceLog; |
| | | import org.aspectj.lang.ProceedingJoinPoint; |
| | | import org.aspectj.lang.annotation.Around; |
| | | import org.aspectj.lang.annotation.Aspect; |
| | | import org.aspectj.lang.annotation.Pointcut; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.lang.reflect.Method; |
| | | import java.lang.reflect.Parameter; |
| | | |
| | | @Aspect |
| | | @Component |
| | | public class ServiceLogAspect { |
| | | |
| | | Logger logger = LoggerFactory.getLogger("ServiceLog"); |
| | | |
| | | /** |
| | | * //切面点为标记了@ServiceLog注解的方法 |
| | | */ |
| | | @Pointcut("@annotation(com.supersavedriving.driver.core.common.annotion.ServiceLog)") |
| | | public void serviceLog(){ |
| | | } |
| | | |
| | | |
| | | //环绕通知 |
| | | @Around("serviceLog()") |
| | | @SuppressWarnings("unchecked") |
| | | public Object around(ProceedingJoinPoint joinPoint) throws Throwable { |
| | | long starTime = System.currentTimeMillis(); |
| | | //通过反射获取被调用方法的Class |
| | | Class type = joinPoint.getSignature().getDeclaringType(); |
| | | //获取类名 |
| | | String typeName = type.getSimpleName(); |
| | | //方法名 |
| | | String methodName = joinPoint.getSignature().getName(); |
| | | //获取参数列表 |
| | | Object[] args = joinPoint.getArgs(); |
| | | //参数Class的数组 |
| | | Class[] clazz = new Class[args.length]; |
| | | for (int i = 0; i < args.length; i++) { |
| | | clazz[i] = args[i].getClass(); |
| | | } |
| | | //通过反射获取调用的方法method |
| | | Method method = type.getMethod(methodName, clazz); |
| | | ServiceLog serviceLog = method.getAnnotation(ServiceLog.class); |
| | | //获取方法的参数 |
| | | Parameter[] parameters = method.getParameters(); |
| | | JSONObject jsonObject = new JSONObject(); |
| | | for (int i = 0; i < parameters.length; i++) { |
| | | Parameter parameter = parameters[i]; |
| | | String name = parameter.getName(); |
| | | jsonObject.put(name, args[i]); |
| | | } |
| | | //执行结果 |
| | | //执行目标方法,获取执行结果 |
| | | Object res = joinPoint.proceed(); |
| | | logger.debug("调用{}.{}方法成功\n" + |
| | | "接口名称:{}\n" + |
| | | "接口地址:{}\n" + |
| | | "耗时:{}ms\n" + |
| | | "参数为:{}\n" + |
| | | "返回结果:{}", typeName, methodName, serviceLog.name(), serviceLog.url(), |
| | | (System.currentTimeMillis() - starTime), jsonObject.toJSONString(), JSONObject.toJSONString(res)); |
| | | //返回执行结果 |
| | | return res; |
| | | } |
| | | } |
| | |
| | | package com.supersavedriving.driver.modular.system.api; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.supersavedriving.driver.core.common.annotion.ServiceLog; |
| | | import com.supersavedriving.driver.core.util.ToolUtil; |
| | | import com.supersavedriving.driver.modular.system.service.IBranchOfficeService; |
| | | import com.supersavedriving.driver.modular.system.service.IDriverService; |
| | | import com.supersavedriving.driver.modular.system.util.RedisUtil; |
| | | import com.supersavedriving.driver.modular.system.util.ResultUtil; |
| | | import com.supersavedriving.driver.modular.system.util.SMSUtil; |
| | | import com.supersavedriving.driver.modular.system.util.UUIDUtil; |
| | | import com.supersavedriving.driver.modular.system.warpper.DriverRegisterWarpper; |
| | | import com.supersavedriving.driver.modular.system.warpper.OpenCityWarpper; |
| | | import com.supersavedriving.driver.modular.system.warpper.ResponseWarpper; |
| | | import com.supersavedriving.driver.modular.system.warpper.TokenWarpper; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | @RequestMapping("") |
| | | public class DriverController { |
| | | |
| | | Logger logger = LoggerFactory.getLogger("ServiceLog"); |
| | | |
| | | @Autowired |
| | | private IBranchOfficeService branchOfficeService; |
| | | |
| | | @Autowired |
| | | private IDriverService driverService; |
| | | |
| | | @Autowired |
| | | private RedisUtil redisUtil; |
| | | |
| | | |
| | | |
| | |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/base/driver/queryCityList") |
| | | @ServiceLog(name = "获取开通的省市数据", url = "/base/driver/queryCityList") |
| | | @ApiOperation(value = "获取开通的省市数据", tags = {"司机端-登录注册"}, notes = "") |
| | | @ApiImplicitParams({ |
| | | }) |
| | | public ResponseWarpper<List<OpenCityWarpper>> queryCityList(){ |
| | | ResponseWarpper responseWarpper = null; |
| | | try { |
| | | List<OpenCityWarpper> list = branchOfficeService.queryOpenCity(); |
| | | responseWarpper = ResponseWarpper.success(list); |
| | | return ResponseWarpper.success(list); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | responseWarpper = new ResponseWarpper(500, e.getMessage()); |
| | | return new ResponseWarpper(500, e.getMessage()); |
| | | } |
| | | logger.debug("" + |
| | | "\n接口地址:/base/driver/queryCityList" + |
| | | "\n接口名称:获取开通的省市数据" + |
| | | "\n请求参数:" + |
| | | "\n响应结果:{}" |
| | | , JSON.toJSONString(responseWarpper)); |
| | | return responseWarpper; |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/base/driver/queryOpenDistrict") |
| | | @ServiceLog(name = "根据城市code获取开通区域", url = "/base/driver/queryOpenDistrict") |
| | | @ApiOperation(value = "根据城市code获取开通区域", tags = {"司机端-登录注册"}, notes = "") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "城市code", name = "cityCode", required = true, dataType = "string"), |
| | | }) |
| | | public ResponseWarpper<List<OpenCityWarpper>> queryOpenDistrict(String cityCode){ |
| | | ResponseWarpper responseWarpper = null; |
| | | if(ToolUtil.isEmpty(cityCode)){ |
| | | responseWarpper = ResponseWarpper.success(ResultUtil.paranErr()); |
| | | return ResponseWarpper.success(ResultUtil.paranErr("cityCode")); |
| | | } |
| | | |
| | | if(ToolUtil.isNotEmpty(cityCode)){ |
| | | try { |
| | | List<OpenCityWarpper> list = branchOfficeService.queryOpenDistrict(cityCode); |
| | | responseWarpper = ResponseWarpper.success(list); |
| | | return ResponseWarpper.success(list); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | responseWarpper = new ResponseWarpper(500, e.getMessage()); |
| | | return new ResponseWarpper(500, e.getMessage()); |
| | | } |
| | | } |
| | | logger.debug("" + |
| | | "\n接口地址:/base/driver/queryOpenDistrict" + |
| | | "\n接口名称:根据城市code获取开通区域" + |
| | | "\n请求参数:cityCode={}" + |
| | | "\n响应结果:{}" |
| | | , cityCode, JSON.toJSONString(responseWarpper)); |
| | | return responseWarpper; |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/base/driver/driverRegister") |
| | | @ServiceLog(name = "司机注册申请", url = "/base/driver/driverRegister") |
| | | @ApiOperation(value = "司机注册申请", tags = {"司机端-登录注册"}, notes = "") |
| | | @ApiImplicitParams({ |
| | | }) |
| | | public ResponseWarpper driverRegister(DriverRegisterWarpper driverRegisterWarpper){ |
| | | ResponseWarpper responseWarpper = null; |
| | | try { |
| | | ResultUtil resultUtil = driverService.driverRegister(driverRegisterWarpper); |
| | | responseWarpper = ResponseWarpper.success(resultUtil); |
| | | return ResponseWarpper.success(resultUtil); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | responseWarpper = new ResponseWarpper(500, e.getMessage()); |
| | | return new ResponseWarpper(500, e.getMessage()); |
| | | } |
| | | logger.debug("" + |
| | | "\n接口地址:/base/driver/driverRegister" + |
| | | "\n接口名称:司机注册申请" + |
| | | "\n请求参数:" + JSON.toJSONString(driverRegisterWarpper) + |
| | | "\n响应结果:{}" |
| | | , JSON.toJSONString(responseWarpper)); |
| | | return responseWarpper; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/base/driver/getVerificationCode") |
| | | @ServiceLog(name = "获取短信验证码", url = "/base/driver/getVerificationCode") |
| | | @ApiOperation(value = "获取短信验证码", tags = {"司机端-登录注册"}, notes = "") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "国家代码+86", name = "receiver", required = true, dataType = "string"), |
| | | @ApiImplicitParam(value = "电话号码", name = "phone", required = true, dataType = "string"), |
| | | }) |
| | | public ResponseWarpper getVerificationCode(String receiver, String phone){ |
| | | if(ToolUtil.isEmpty(receiver)){ |
| | | return ResponseWarpper.success(ResultUtil.paranErr("receiver")); |
| | | } |
| | | if(ToolUtil.isEmpty(phone)){ |
| | | return ResponseWarpper.success(ResultUtil.paranErr("phone")); |
| | | } |
| | | try { |
| | | String numberRandom = UUIDUtil.getNumberRandom(6); |
| | | SMSUtil.send_huawei_sms("", receiver + phone, "[\"" + numberRandom + "\"]"); |
| | | redisUtil.setStrValue(receiver + phone, numberRandom, 300);//5分钟有效期 |
| | | return ResponseWarpper.success(ResultUtil.success()); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | return new ResponseWarpper(500, e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/base/driver/driverCodeLogin") |
| | | @ServiceLog(name = "司机短信验证码登录", url = "/base/driver/driverCodeLogin") |
| | | @ApiOperation(value = "司机短信验证码登录", tags = {"司机端-登录注册"}, notes = "") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "国家代码+86", name = "receiver", required = true, dataType = "string"), |
| | | @ApiImplicitParam(value = "电话号码", name = "phone", required = true, dataType = "string"), |
| | | @ApiImplicitParam(value = "短信验证码", name = "code", required = true, dataType = "string"), |
| | | }) |
| | | public ResponseWarpper<TokenWarpper> driverCodeLogin(String receiver, String phone, String code){ |
| | | if(ToolUtil.isEmpty(receiver)){ |
| | | return ResponseWarpper.success(ResultUtil.paranErr("receiver")); |
| | | } |
| | | if(ToolUtil.isEmpty(phone)){ |
| | | return ResponseWarpper.success(ResultUtil.paranErr("phone")); |
| | | } |
| | | try { |
| | | ResultUtil<TokenWarpper> tokenWarpper = driverService.driverLogin(receiver, phone, code); |
| | | return ResponseWarpper.success(tokenWarpper); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | return new ResponseWarpper(500, e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/api/driver/flushedToken") |
| | | @ServiceLog(name = "刷新token", url = "/api/driver/flushedToken") |
| | | @ApiOperation(value = "刷新token", tags = {"司机端-登录注册"}, notes = "") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") |
| | | }) |
| | | public ResponseWarpper<TokenWarpper> flushedToken(HttpServletRequest request){ |
| | | try { |
| | | Integer uid = driverService.getUserByRequset(request); |
| | | if(null == uid){ |
| | | return ResponseWarpper.success(ResultUtil.tokenErr()); |
| | | } |
| | | ResultUtil<TokenWarpper> tokenWarpper = driverService.flushedToken(uid); |
| | | return ResponseWarpper.success(tokenWarpper); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | return new ResponseWarpper(500, e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/api/driver/setPassword") |
| | | @ServiceLog(name = "司机设置密码", url = "/api/driver/setPassword") |
| | | @ApiOperation(value = "司机设置密码", tags = {"司机端-首页"}, notes = "") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "密码", name = "password", required = true, dataType = "string"), |
| | | @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") |
| | | }) |
| | | public ResponseWarpper setPassword(String password, HttpServletRequest request){ |
| | | if(ToolUtil.isEmpty(password)){ |
| | | return ResponseWarpper.success(ResultUtil.paranErr("password")); |
| | | } |
| | | try { |
| | | Integer uid = driverService.getUserByRequset(request); |
| | | if(null == uid){ |
| | | return ResponseWarpper.success(ResultUtil.tokenErr()); |
| | | } |
| | | driverService.setPassword(uid, password); |
| | | return ResponseWarpper.success(); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | return new ResponseWarpper(500, e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | } |
| | |
| | | <result column="name" property="name"/> |
| | | <result column="avatar" property="avatar"/> |
| | | <result column="phone" property="phone"/> |
| | | <result column="password" property="password"/> |
| | | <result column="sex" property="sex"/> |
| | | <result column="source" property="source"/> |
| | | <result column="emergencyContact" property="emergencyContact"/> |
| | |
| | | @TableField("phone") |
| | | private String phone; |
| | | /** |
| | | * 密码 |
| | | */ |
| | | @TableField("password") |
| | | private String password; |
| | | /** |
| | | * 性别(1=男,2=女) |
| | | */ |
| | | @TableField("sex") |
| | |
| | | import com.supersavedriving.driver.modular.system.model.Driver; |
| | | import com.supersavedriving.driver.modular.system.util.ResultUtil; |
| | | import com.supersavedriving.driver.modular.system.warpper.DriverRegisterWarpper; |
| | | import com.supersavedriving.driver.modular.system.warpper.TokenWarpper; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | |
| | | /** |
| | | * 司机 |
| | |
| | | * @throws Exception |
| | | */ |
| | | ResultUtil driverRegister(DriverRegisterWarpper driverRegisterWarpper) throws Exception; |
| | | |
| | | |
| | | /** |
| | | * 司机登录 |
| | | * @param receiver 国家代码+86 |
| | | * @param phone 登录手机号 |
| | | * @param code 短信验证码 |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | ResultUtil<TokenWarpper> driverLogin(String receiver, String phone, String code) throws Exception; |
| | | |
| | | |
| | | /** |
| | | * 刷新token |
| | | * @param uid |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | ResultUtil<TokenWarpper> flushedToken(Integer uid) throws Exception; |
| | | |
| | | |
| | | /** |
| | | * 校验token获取用户信息 |
| | | * @param request |
| | | * @return |
| | | */ |
| | | Integer getUserByRequset(HttpServletRequest request) throws Exception; |
| | | |
| | | |
| | | /** |
| | | * 设置司机密码 |
| | | * @param uid |
| | | * @param password |
| | | * @throws Exception |
| | | */ |
| | | void setPassword(Integer uid, String password) throws Exception; |
| | | } |
| | |
| | | |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.service.impl.ServiceImpl; |
| | | import com.supersavedriving.driver.core.common.constant.JwtConstants; |
| | | import com.supersavedriving.driver.core.shiro.ShiroKit; |
| | | import com.supersavedriving.driver.core.shiro.ShiroUser; |
| | | import com.supersavedriving.driver.core.util.JwtTokenUtil; |
| | | import com.supersavedriving.driver.core.util.ToolUtil; |
| | | import com.supersavedriving.driver.modular.system.dao.DriverMapper; |
| | | import com.supersavedriving.driver.modular.system.model.BranchOffice; |
| | | import com.supersavedriving.driver.modular.system.model.Driver; |
| | | import com.supersavedriving.driver.modular.system.service.IBranchOfficeService; |
| | | import com.supersavedriving.driver.modular.system.service.IDriverService; |
| | | import com.supersavedriving.driver.modular.system.util.RedisUtil; |
| | | import com.supersavedriving.driver.modular.system.util.ResultUtil; |
| | | import com.supersavedriving.driver.modular.system.util.UUIDUtil; |
| | | import com.supersavedriving.driver.modular.system.warpper.DriverRegisterWarpper; |
| | | import com.supersavedriving.driver.modular.system.warpper.TokenWarpper; |
| | | import org.apache.shiro.authc.SimpleAuthenticationInfo; |
| | | import org.apache.shiro.authc.UsernamePasswordToken; |
| | | import org.apache.shiro.authc.credential.HashedCredentialsMatcher; |
| | | import org.apache.shiro.crypto.hash.Md5Hash; |
| | | import org.apache.shiro.util.ByteSource; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.util.Date; |
| | | |
| | | import static org.bouncycastle.asn1.x500.style.RFC4519Style.c; |
| | | |
| | | /** |
| | | * 司机 |
| | |
| | | */ |
| | | @Service |
| | | public class DriverServiceImpl extends ServiceImpl<DriverMapper, Driver> implements IDriverService { |
| | | |
| | | private final String salt = "i#sm4"; |
| | | |
| | | @Autowired |
| | | private IBranchOfficeService branchOfficeService; |
| | | |
| | | @Autowired |
| | | private RedisUtil redisUtil; |
| | | |
| | | |
| | | /** |
| | |
| | | |
| | | //账号审核拒绝后的处理 |
| | | if(null != driver && driver.getApprovalStatus() == 3){ |
| | | try { |
| | | driver = setDriverParamete(driver, driverRegisterWarpper); |
| | | this.updateById(driver); |
| | | }catch (Exception e){ |
| | | return ResultUtil.error(e.getMessage()); |
| | | } |
| | | this.updateAllColumnById(driver); |
| | | } |
| | | //新账号 |
| | | if(null == driver){ |
| | | driver = new Driver(); |
| | | driver.setCode(UUIDUtil.getNumberRandom(16)); |
| | | try { |
| | | driver = setDriverParamete(driver, driverRegisterWarpper); |
| | | }catch (Exception e){ |
| | | return ResultUtil.error(e.getMessage()); |
| | | } |
| | | driver.setCreateTime(new Date()); |
| | | this.insert(driver); |
| | | } |
| | | //发送消息 |
| | | |
| | | return ResultUtil.success(); |
| | | } |
| | | |
| | |
| | | * @param driverRegisterWarpper |
| | | * @return |
| | | */ |
| | | public Driver setDriverParamete(Driver driver, DriverRegisterWarpper driverRegisterWarpper){ |
| | | public Driver setDriverParamete(Driver driver, DriverRegisterWarpper driverRegisterWarpper) throws Exception{ |
| | | driver.setAvatar(driverRegisterWarpper.getAvatar()); |
| | | driver.setPhone(driverRegisterWarpper.getPhone()); |
| | | driver.setEmergencyContact(driverRegisterWarpper.getEmergencyContact()); |
| | | driver.setEmergencyPhone(driverRegisterWarpper.getEmergencyPhone()); |
| | | driver.setIdcardBack(driverRegisterWarpper.getIdcardBack()); |
| | | driver.setIdcardFront(driverRegisterWarpper.getIdcardFront()); |
| | | driver.setDriverLicense(driverRegisterWarpper.getDriverLicense()); |
| | | //注册地 |
| | | String code = driverRegisterWarpper.getCode(); |
| | | BranchOffice branchOffice = branchOfficeService.selectOne(new EntityWrapper<BranchOffice>().eq("districtCode", code).eq("status", 1)); |
| | | if(null == branchOffice){ |
| | | throw new Exception("该区域无服务商"); |
| | | } |
| | | driver.setBranchOfficeId(branchOffice.getId()); |
| | | driver.setAgentId(branchOffice.getAgentId()); |
| | | driver.setInviterType(driverRegisterWarpper.getInviterType()); |
| | | driver.setInviterId(driverRegisterWarpper.getInviterId()); |
| | | driver.setApprovalStatus(1); |
| | | driver.setApprovalNotes(""); |
| | | driver.setApprovalTime(null); |
| | | driver.setApprovalUserId(null); |
| | | driver.setStatus(1); |
| | | return driver; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 司机登录逻辑 |
| | | * @param receiver 国家代码+86 |
| | | * @param phone 登录手机号 |
| | | * @param code 短信验证码 |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public ResultUtil<TokenWarpper> driverLogin(String receiver, String phone, String code) throws Exception { |
| | | String value = redisUtil.getValue(receiver + phone); |
| | | if(ToolUtil.isEmpty(value)){ |
| | | return ResultUtil.error("短信验证码无效"); |
| | | } |
| | | if(!value.equals(code)){ |
| | | return ResultUtil.error("短信验证码无效"); |
| | | } |
| | | String token = getToken(phone, code); |
| | | if(ToolUtil.isEmpty(token)){ |
| | | return ResultUtil.error("登录异常,请联系管理员。"); |
| | | } |
| | | Driver driver = this.selectOne(new EntityWrapper<Driver>().eq("phone", phone).ne("status", 3)); |
| | | if(null == driver){ |
| | | return ResultUtil.error("请先进行注册"); |
| | | } |
| | | if(driver.getStatus() == 2){ |
| | | return ResultUtil.error("账号已被冻结,请联系管理员。"); |
| | | } |
| | | if(driver.getApprovalStatus() == 1){ |
| | | return ResultUtil.error("账号正在审核中。"); |
| | | } |
| | | if(driver.getApprovalStatus() == 3){ |
| | | return ResultUtil.error("账号审核不通过,请重新申请。"); |
| | | } |
| | | |
| | | TokenWarpper tokenWarpper = new TokenWarpper(); |
| | | tokenWarpper.setToken(token); |
| | | tokenWarpper.setValidTime(7200L); |
| | | tokenWarpper.setIsSetPassword(ToolUtil.isEmpty(driver.getPassword()) ? 0 : 1); |
| | | return ResultUtil.success(tokenWarpper); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取身份凭证 |
| | | * @param phone |
| | | * @param password |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | private String getToken(String phone, String password) throws Exception{ |
| | | //封装请求账号密码为shiro可验证的token |
| | | UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(phone, password.toCharArray()); |
| | | |
| | | //获取数据库中的账号密码,准备比对 |
| | | String credentials = ShiroKit.md5(password, salt); |
| | | Driver driver = this.selectOne(new EntityWrapper<Driver>().eq("phone", phone).eq("status", 1)); |
| | | ByteSource credentialsSalt = new Md5Hash(salt); |
| | | SimpleAuthenticationInfo simpleAuthenticationInfo = new SimpleAuthenticationInfo( |
| | | new ShiroUser(), credentials, credentialsSalt, ""); |
| | | |
| | | //校验用户账号密码 |
| | | HashedCredentialsMatcher md5CredentialsMatcher = new HashedCredentialsMatcher(); |
| | | md5CredentialsMatcher.setHashAlgorithmName(ShiroKit.hashAlgorithmName); |
| | | md5CredentialsMatcher.setHashIterations(ShiroKit.hashIterations); |
| | | boolean passwordTrueFlag = md5CredentialsMatcher.doCredentialsMatch( |
| | | usernamePasswordToken, simpleAuthenticationInfo); |
| | | |
| | | if (passwordTrueFlag) { |
| | | String token = JwtTokenUtil.generateToken(phone); |
| | | String key = token; |
| | | if(token.length() > 16){ |
| | | key = token.substring(token.length() - 16); |
| | | } |
| | | redisUtil.setStrValue(key, driver.getId().toString(), 7200);//2小时 |
| | | return token; |
| | | } |
| | | return ""; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 刷新token |
| | | * @param uid |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public ResultUtil<TokenWarpper> flushedToken(Integer uid) throws Exception { |
| | | Driver driver = this.selectById(uid); |
| | | String token = getToken(driver.getPhone(), driver.getPhone()); |
| | | if(ToolUtil.isEmpty(token)){ |
| | | return ResultUtil.error("刷新token异常,请联系管理员。"); |
| | | } |
| | | TokenWarpper tokenWarpper = new TokenWarpper(); |
| | | tokenWarpper.setToken(token); |
| | | tokenWarpper.setValidTime(7200L); |
| | | tokenWarpper.setIsSetPassword(ToolUtil.isEmpty(driver.getPassword()) ? 0 : 1); |
| | | return ResultUtil.success(tokenWarpper); |
| | | } |
| | | |
| | | /** |
| | | * 校验token获取用户信息 |
| | | * @param request |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public Integer getUserByRequset(HttpServletRequest request) throws Exception { |
| | | String requestHeader = request.getHeader(JwtConstants.AUTH_HEADER); |
| | | if (ToolUtil.isNotEmpty(requestHeader) && requestHeader.startsWith("Bearer ")) { |
| | | requestHeader = requestHeader.substring(requestHeader.indexOf(" ") + 1); |
| | | String key = null; |
| | | int length = requestHeader.length(); |
| | | if(length > 16){ |
| | | key = requestHeader.substring(length - 16); |
| | | }else{ |
| | | key = requestHeader; |
| | | } |
| | | String value = redisUtil.getValue(key); |
| | | return null != value ? Integer.valueOf(value) : null; |
| | | }else{ |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 设置司机密码 |
| | | * @param uid |
| | | * @param password |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public void setPassword(Integer uid, String password) throws Exception { |
| | | Driver driver = this.selectById(uid); |
| | | driver.setPassword(ShiroKit.md5(password, salt)); |
| | | this.updateById(driver); |
| | | } |
| | | } |
| | |
| | | |
| | | public static final Integer RUNTIME_ERROR = 10050; |
| | | |
| | | public static final String Token = "TOKEN_INVALID"; |
| | | public static final String Token = "token无效"; |
| | | |
| | | public static final String SIGN = "SIGN_INVALID"; |
| | | public static final String SIGN = "签名无效"; |
| | | |
| | | @ApiModelProperty(name = "code", value = "业务状态码 10000:成功,10010:参数错误,10020:系统提示, 10030:身份校验异常,10040:签名不通过,10050:系统运行异常") |
| | | private Integer code;//备用状态码 |
| | |
| | | * 参数异常 |
| | | * @return |
| | | */ |
| | | public static ResultUtil paranErr(){ |
| | | return ResultUtil.getResult(ResultUtil.PARAM_ERROR, "param_error", new Object()); |
| | | public static ResultUtil paranErr(String...ages){ |
| | | return ResultUtil.getResult(ResultUtil.PARAM_ERROR, "【" + ages + "】参数异常", new Object()); |
| | | } |
| | | |
| | | /** |
| | | * 参数异常 |
| | | * @return |
| | | */ |
| | | public static <T> ResultUtil<T> paranErr(T data){ |
| | | return ResultUtil.getResult(ResultUtil.PARAM_ERROR, "system_run_error", data); |
| | | public static ResultUtil paranErr(){ |
| | | return ResultUtil.getResult(ResultUtil.PARAM_ERROR, "参数异常", new Object()); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return |
| | | */ |
| | | public static ResultUtil runErr(){ |
| | | return ResultUtil.getResult(ResultUtil.RUNTIME_ERROR, "system_run_error", new Object()); |
| | | return ResultUtil.getResult(ResultUtil.RUNTIME_ERROR, "系统运行异常", new Object()); |
| | | } |
| | | |
| | | |
| | |
| | | * @return |
| | | */ |
| | | public static <T>ResultUtil<T> runErr(T data){ |
| | | return ResultUtil.getResult(ResultUtil.RUNTIME_ERROR, "system_run_error", data); |
| | | return ResultUtil.getResult(ResultUtil.RUNTIME_ERROR, "系统运行异常", data); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return |
| | | */ |
| | | public static ResultUtil success(){ |
| | | return ResultUtil.getResult(ResultUtil.SUCCESS, "ok", new Object()); |
| | | return ResultUtil.getResult(ResultUtil.SUCCESS, "成功", new Object()); |
| | | } |
| | | |
| | | |
| | |
| | | * @return |
| | | */ |
| | | public static <T> ResultUtil<T> success(T data){ |
| | | return ResultUtil.getResult(ResultUtil.SUCCESS, "ok", data); |
| | | return ResultUtil.getResult(ResultUtil.SUCCESS, "成功", data); |
| | | } |
| | | |
| | | /** |
New file |
| | |
| | | package com.supersavedriving.driver.modular.system.util; |
| | | |
| | | |
| | | import javax.net.ssl.*; |
| | | import java.io.*; |
| | | import java.net.URL; |
| | | import java.net.URLEncoder; |
| | | import java.security.MessageDigest; |
| | | import java.security.NoSuchAlgorithmException; |
| | | import java.security.cert.CertificateException; |
| | | import java.security.cert.X509Certificate; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | |
| | | public class SMSUtil { |
| | | |
| | | //无需修改,用于格式化鉴权头域,给"X-WSSE"参数赋值 |
| | | private static final String WSSE_HEADER_FORMAT = "UsernameToken Username=\"%s\",PasswordDigest=\"%s\",Nonce=\"%s\",Created=\"%s\""; |
| | | //无需修改,用于格式化鉴权头域,给"Authorization"参数赋值 |
| | | private static final String AUTH_HEADER_VALUE = "WSSE realm=\"SDP\",profile=\"UsernameToken\",type=\"Appkey\""; |
| | | |
| | | /** |
| | | * 发送短信(华为云) |
| | | * @param templateId 模板id |
| | | * @param receiver 必填,全局号码格式(包含国家码),示例:+8615123456789,多个号码之间用英文逗号分隔 |
| | | * @param templateParas 选填,使用无变量模板时请赋空值 String templateParas = "",双变量模板示例:模板内容为"您有${1}件快递请到${2}领取"时,templateParas可填写为"[\"3\",\"人民公园正门\"]" |
| | | * 模板变量,此处以单变量验证码短信为例,请客户自行生成6位验证码,并定义为字符串类型,以杜绝首位0丢失的问题(例如:002569变成了2569) |
| | | * @throws Exception |
| | | */ |
| | | public static void send_huawei_sms(String templateId, String receiver, String templateParas) throws Exception { |
| | | |
| | | //必填,请参考"开发准备"获取如下数据,替换为实际值 |
| | | String url = "https://smsapi.cn-south-1.myhuaweicloud.com:443"; //APP接入地址(在控制台"应用管理"页面获取)+接口访问URI |
| | | String appKey = "g3DW0G5Fbp3110UiGl5fkWcn799s"; //APP_Key |
| | | String appSecret = "LaT1NYvQKNkHO5KikniEueN8iTaz"; //APP_Secret |
| | | String sender = "ismsapp0000000103"; //国内短信签名通道号或国际/港澳台短信通道号 |
| | | |
| | | //条件必填,国内短信关注,当templateId指定的模板类型为通用模板时生效且必填,必须是已审核通过的,与模板类型一致的签名名称 |
| | | //国际/港澳台短信不用关注该参数 |
| | | String signature = "IGO"; //签名名称 |
| | | |
| | | //选填,短信状态报告接收地址,推荐使用域名,为空或者不填表示不接收状态报告 |
| | | String statusCallBack = ""; |
| | | |
| | | //请求Body,不携带签名名称时,signature请填null |
| | | String body = buildRequestBody(sender, receiver, templateId, templateParas, statusCallBack, signature); |
| | | if (null == body || body.isEmpty()) { |
| | | System.out.println("body is null."); |
| | | return; |
| | | } |
| | | |
| | | //请求Headers中的X-WSSE参数值 |
| | | String wsseHeader = buildWsseHeader(appKey, appSecret); |
| | | if (null == wsseHeader || wsseHeader.isEmpty()) { |
| | | System.out.println("wsse header is null."); |
| | | return; |
| | | } |
| | | |
| | | Writer out = null; |
| | | BufferedReader in = null; |
| | | StringBuffer result = new StringBuffer(); |
| | | HttpsURLConnection connection = null; |
| | | InputStream is = null; |
| | | |
| | | |
| | | HostnameVerifier hv = new HostnameVerifier() { |
| | | |
| | | @Override |
| | | public boolean verify(String hostname, SSLSession session) { |
| | | return true; |
| | | } |
| | | }; |
| | | trustAllHttpsCertificates(); |
| | | |
| | | try { |
| | | URL realUrl = new URL(url); |
| | | connection = (HttpsURLConnection) realUrl.openConnection(); |
| | | |
| | | connection.setHostnameVerifier(hv); |
| | | connection.setDoOutput(true); |
| | | connection.setDoInput(true); |
| | | connection.setUseCaches(true); |
| | | //请求方法 |
| | | connection.setRequestMethod("POST"); |
| | | //请求Headers参数 |
| | | connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); |
| | | connection.setRequestProperty("Authorization", AUTH_HEADER_VALUE); |
| | | connection.setRequestProperty("X-WSSE", wsseHeader); |
| | | |
| | | connection.connect(); |
| | | out = new OutputStreamWriter(connection.getOutputStream()); |
| | | out.write(body); //发送请求Body参数 |
| | | out.flush(); |
| | | out.close(); |
| | | |
| | | int status = connection.getResponseCode(); |
| | | if (200 == status) { //200 |
| | | is = connection.getInputStream(); |
| | | } else { //400/401 |
| | | is = connection.getErrorStream(); |
| | | } |
| | | in = new BufferedReader(new InputStreamReader(is, "UTF-8")); |
| | | String line = ""; |
| | | while ((line = in.readLine()) != null) { |
| | | result.append(line); |
| | | } |
| | | System.out.println(result.toString()); //打印响应消息实体 |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | try { |
| | | if (null != out) { |
| | | out.close(); |
| | | } |
| | | if (null != is) { |
| | | is.close(); |
| | | } |
| | | if (null != in) { |
| | | in.close(); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 构造请求Body体 |
| | | * @param sender |
| | | * @param receiver |
| | | * @param templateId |
| | | * @param templateParas |
| | | * @param statusCallBack |
| | | * @param signature | 签名名称,使用国内短信通用模板时填写 |
| | | * @return |
| | | */ |
| | | static String buildRequestBody(String sender, String receiver, String templateId, String templateParas, |
| | | String statusCallBack, String signature) { |
| | | if (null == sender || null == receiver || null == templateId || sender.isEmpty() || receiver.isEmpty() |
| | | || templateId.isEmpty()) { |
| | | System.out.println("buildRequestBody(): sender, receiver or templateId is null."); |
| | | return null; |
| | | } |
| | | Map<String, String> map = new HashMap<String, String>(); |
| | | |
| | | map.put("from", sender); |
| | | map.put("to", receiver); |
| | | map.put("templateId", templateId); |
| | | if (null != templateParas && !templateParas.isEmpty()) { |
| | | map.put("templateParas", templateParas); |
| | | } |
| | | if (null != statusCallBack && !statusCallBack.isEmpty()) { |
| | | map.put("statusCallback", statusCallBack); |
| | | } |
| | | if (null != signature && !signature.isEmpty()) { |
| | | map.put("signature", signature); |
| | | } |
| | | |
| | | StringBuilder sb = new StringBuilder(); |
| | | String temp = ""; |
| | | |
| | | for (String s : map.keySet()) { |
| | | try { |
| | | temp = URLEncoder.encode(map.get(s), "UTF-8"); |
| | | } catch (UnsupportedEncodingException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | sb.append(s).append("=").append(temp).append("&"); |
| | | } |
| | | |
| | | return sb.deleteCharAt(sb.length()-1).toString(); |
| | | } |
| | | |
| | | /** |
| | | * 构造X-WSSE参数值 |
| | | * @param appKey |
| | | * @param appSecret |
| | | * @return |
| | | */ |
| | | static String buildWsseHeader(String appKey, String appSecret) { |
| | | if (null == appKey || null == appSecret || appKey.isEmpty() || appSecret.isEmpty()) { |
| | | System.out.println("buildWsseHeader(): appKey or appSecret is null."); |
| | | return null; |
| | | } |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); |
| | | String time = sdf.format(new Date()); //Created |
| | | String nonce = UUID.randomUUID().toString().replace("-", ""); //Nonce |
| | | |
| | | MessageDigest md; |
| | | byte[] passwordDigest = null; |
| | | |
| | | try { |
| | | md = MessageDigest.getInstance("SHA-256"); |
| | | md.update((nonce + time + appSecret).getBytes()); |
| | | passwordDigest = md.digest(); |
| | | } catch (NoSuchAlgorithmException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | //如果JDK版本是1.8,请加载原生Base64类,并使用如下代码 |
| | | String passwordDigestBase64Str = Base64.getEncoder().encodeToString(passwordDigest); //PasswordDigest |
| | | //如果JDK版本低于1.8,请加载三方库提供Base64类,并使用如下代码 |
| | | //String passwordDigestBase64Str = Base64.encodeBase64String(passwordDigest); //PasswordDigest |
| | | //若passwordDigestBase64Str中包含换行符,请执行如下代码进行修正 |
| | | //passwordDigestBase64Str = passwordDigestBase64Str.replaceAll("[\\s*\t\n\r]", ""); |
| | | return String.format(WSSE_HEADER_FORMAT, appKey, passwordDigestBase64Str, nonce, time); |
| | | } |
| | | |
| | | /*** @throws Exception |
| | | */ |
| | | static void trustAllHttpsCertificates() throws Exception { |
| | | TrustManager[] trustAllCerts = new TrustManager[] { |
| | | new X509TrustManager() { |
| | | public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { |
| | | return; |
| | | } |
| | | public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { |
| | | return; |
| | | } |
| | | public X509Certificate[] getAcceptedIssuers() { |
| | | return null; |
| | | } |
| | | } |
| | | }; |
| | | SSLContext sc = SSLContext.getInstance("SSL"); |
| | | sc.init(null, trustAllCerts, null); |
| | | HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); |
| | | } |
| | | } |
| | |
| | | * @return |
| | | */ |
| | | public synchronized static String getTimeStr(){ |
| | | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddhhmmssS"); |
| | | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmssSSS"); |
| | | return simpleDateFormat.format(new Date()); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * @Description: 获取数字随机码 |
| | | * @Author pzb |
| | | * @Date 2021/8/11 16:52 |
| | | * @Param |
| | | * @Return |
| | | * @Exception |
| | | */ |
| | | public static String getNumberRandom(Integer num){ |
| | | if(null == num){ |
| | | num = 32; |
| | | } |
| | | StringBuffer sb = new StringBuffer(); |
| | | for(int i = 0; i < num; i++){ |
| | | sb.append(Double.valueOf(Math.random() * 10).intValue()); |
| | | } |
| | | return sb.toString(); |
| | | } |
| | | } |
| | |
| | | private String idcardBack; |
| | | @ApiModelProperty(value = "驾驶证照片", required = true, dataType = "string") |
| | | private String driverLicense; |
| | | @ApiModelProperty(value = "邀约人类型(1=用户,2=司机)", required = false, dataType = "int") |
| | | private Integer inviterType; |
| | | @ApiModelProperty(value = "邀约人Id", required = false, dataType = "int") |
| | | private Integer inviterId; |
| | | } |
| | |
| | | this.resultUtil = resultUtil; |
| | | } |
| | | |
| | | public static ResponseWarpper success() { |
| | | return new ResponseWarpper(200, "success", ResultUtil.success()); |
| | | } |
| | | |
| | | public static <T> ResponseWarpper<T> success(T data) { |
| | | return new ResponseWarpper(200, "success", ResultUtil.success(data)); |
| | | } |
New file |
| | |
| | | package com.supersavedriving.driver.modular.system.warpper; |
| | | |
| | | import io.swagger.annotations.ApiModel; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.Data; |
| | | |
| | | /** |
| | | * 登录token实体类 |
| | | */ |
| | | @Data |
| | | @ApiModel |
| | | public class TokenWarpper { |
| | | @ApiModelProperty(value = "token", required = true, dataType = "string") |
| | | private String token; |
| | | @ApiModelProperty(value = "token有效期(秒)", required = true, dataType = "long") |
| | | private Long validTime; |
| | | @ApiModelProperty(value = "是否设置密码(0=否,1=是)", required = true, dataType = "int") |
| | | private Integer isSetPassword; |
| | | } |
| | |
| | | |
| | | |
| | | --- |
| | | |
| | | #交通部推送数据功能开关 |
| | | pushMinistryOfTransport: false |
| | |
| | | <appender-ref ref="ALL_FILE" /> |
| | | </root> |
| | | <logger name="ServiceLog" level="debug"/> |
| | | <logger name="com.supersavedriving.driver.modular.system.dao" level="debug"/> |
| | | </springProfile> |
| | | |
| | | <springProfile name="fat"> |
| | |
| | | <appender-ref ref="ALL_FILE" /> |
| | | </root> |
| | | <logger name="ServiceLog" level="debug"/> |
| | | <logger name="com.supersavedriving.driver.modular.system.dao" level="debug"/> |
| | | </springProfile> |
| | | |
| | | <springProfile name="produce"> |
| | |
| | | <appender-ref ref="ALL_FILE" /> |
| | | </root> |
| | | <logger name="ServiceLog" level="debug"/> |
| | | <logger name="com.supersavedriving.driver.modular.system.dao" level="debug"/> |
| | | </springProfile> |
| | | |
| | | </configuration> |