|  |  |  | 
|---|
|  |  |  | import javax.annotation.Resource; | 
|---|
|  |  |  | import javax.servlet.http.HttpServletRequest; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.toolkit.Wrappers; | 
|---|
|  |  |  | import com.ruoyi.account.api.feignClient.AppUserClient; | 
|---|
|  |  |  | import com.ruoyi.account.api.model.TAppUser; | 
|---|
|  |  |  | import com.ruoyi.common.core.constant.Constants; | 
|---|
|  |  |  | import com.ruoyi.common.core.constant.MsgConstants; | 
|---|
|  |  |  | import com.ruoyi.common.core.utils.HttpUtils; | 
|---|
|  |  |  | import com.ruoyi.common.core.utils.MsgUtil; | 
|---|
|  |  |  | import com.ruoyi.common.core.web.domain.AjaxResult; | 
|---|
|  |  |  | import com.ruoyi.common.redis.service.RedisService; | 
|---|
|  |  |  | import com.ruoyi.system.api.domain.SysRole; | 
|---|
|  |  |  | import com.ruoyi.system.api.domain.SysUser; | 
|---|
|  |  |  | import com.ruoyi.system.api.feignClient.SysUserClient; | 
|---|
|  |  |  | import io.swagger.annotations.ApiOperation; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.util.CollectionUtils; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  | import com.ruoyi.auth.form.LoginBody; | 
|---|
|  |  |  | import com.ruoyi.auth.form.RegisterBody; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.ruoyi.system.api.model.LoginUser; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  | import java.util.concurrent.TimeUnit; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * token 控制 | 
|---|
|  |  |  | 
|---|
|  |  |  | private SysLoginService sysLoginService; | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private SysUserClient userClient; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private RedisService redisService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private AppUserClient appUserClient; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @DeleteMapping("logoutApplet") | 
|---|
|  |  |  | public R<?> logoutApplet(HttpServletRequest request) { | 
|---|
|  |  |  | String token = SecurityUtils.getToken(request); | 
|---|
|  |  |  | if (StringUtils.isNotEmpty(token)) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | // 删除用户缓存记录 | 
|---|
|  |  |  | AuthUtil.logoutByToken(token); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PostMapping("refresh") | 
|---|
|  |  |  | public R<?> refresh(HttpServletRequest request) | 
|---|
|  |  |  | 
|---|
|  |  |  | // 用户注册 | 
|---|
|  |  |  | sysLoginService.register(registerBody.getUsername(), registerBody.getPassword(), request); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取验证码 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param phone 手机号 | 
|---|
|  |  |  | * @return 结果 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @ApiOperation(value = "获取验证码",notes = "获取验证码",tags = {"更换手机号获取验证码"}) | 
|---|
|  |  |  | @GetMapping("getCode") | 
|---|
|  |  |  | public AjaxResult getCode(@RequestParam("phone") String phone) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | TAppUser appUser = appUserClient.selectByPhone(phone).getData(); | 
|---|
|  |  |  | if (Objects.nonNull(appUser)){ | 
|---|
|  |  |  | return AjaxResult.error("该手机号已绑定账号"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String code = MsgUtil.createCode(); | 
|---|
|  |  |  | redisService.setCacheObject(phone+Constants.APPLET,code,5L, TimeUnit.MINUTES); | 
|---|
|  |  |  | String reqStr = MsgUtil.codeMsg(phone, code); | 
|---|
|  |  |  | String result = HttpUtils.post(MsgConstants.SEND_URL, reqStr); | 
|---|
|  |  |  | return AjaxResult.success(result); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|