| | |
| | | |
| | | import java.io.IOException; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Random; |
| | | import java.util.Set; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | import com.ruoyi.common.core.redis.RedisCache; |
| | | import com.ruoyi.system.mapper.SysUserMapper; |
| | | import com.smartor.domain.BaseSmsRequest; |
| | | import com.smartor.service.IBaseSmsaccountService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | |
| | | @Autowired |
| | | private SysUserMapper sysUserMapper; |
| | | |
| | | @Autowired |
| | | private RedisCache redisCache; |
| | | |
| | | @Autowired |
| | | private IBaseSmsaccountService baseSmsaccountService; |
| | | |
| | | |
| | | @Value("${spring.profiles.active}") |
| | | private String active; |
| | | |
| | | |
| | | /** |
| | | * 登录方法 |
| | | * |
| | |
| | | @PostMapping("/login") |
| | | public AjaxResult login(@RequestBody LoginBody loginBody) { |
| | | AjaxResult ajax = AjaxResult.success(); |
| | | // 生成令牌 |
| | | String token = loginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(), loginBody.getUuid()); |
| | | String token = null; |
| | | if (loginBody.getPhoneCode() != null) { |
| | | String phone = redisCache.getCacheObject(loginBody.getPhoneCode()); |
| | | token = loginService.loginByPhone(phone); |
| | | } else { |
| | | // 生成令牌 |
| | | token = loginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(), loginBody.getUuid()); |
| | | } |
| | | ajax.put(Constants.TOKEN, token); |
| | | return ajax; |
| | | } |
| | |
| | | List<SysMenu> menus = menuService.selectMenuTreeByUserId(userId); |
| | | return AjaxResult.success(menuService.buildMenus(menus)); |
| | | } |
| | | |
| | | /** |
| | | * 验证码发送 |
| | | * |
| | | * @param payload |
| | | * @return |
| | | */ |
| | | @PostMapping("/phoneLogin") |
| | | public AjaxResult sendCode(@RequestBody Map<String, String> payload) { |
| | | String phone = payload.get("phone"); |
| | | String code = String.format("%06d", new Random().nextInt(999999)); |
| | | |
| | | // 存入 Redis,有效期2分钟 |
| | | redisCache.setCacheObject(code, phone, 2, TimeUnit.MINUTES); |
| | | |
| | | //无锡线上环境才发短信 |
| | | if (active.equals("wx")) { |
| | | BaseSmsRequest baseSmsRequest = new BaseSmsRequest(); |
| | | baseSmsRequest.setPhoneNumber(phone); |
| | | baseSmsRequest.setContent("登陆验证码:" + code + " ,2分钟内效,切勿将验证码提供给他人,谨防被骗。"); |
| | | baseSmsaccountService.sendMsg(baseSmsRequest); |
| | | } |
| | | // 调用短信服务发送验证码 |
| | | System.out.println("登陆验证码:" + code); |
| | | |
| | | return AjaxResult.success(true); |
| | | } |
| | | } |