| | |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.core.domain.entity.TAppUserResp; |
| | | import com.ruoyi.common.core.domain.model.LoginAppBody; |
| | | import com.ruoyi.common.core.domain.model.LoginBody; |
| | | import com.ruoyi.common.core.domain.model.LoginUserApplet; |
| | | import com.ruoyi.common.core.redis.RedisCache; |
| | | import com.ruoyi.common.redis.service.RedisService; |
| | |
| | | import com.ruoyi.system.utils.wx.body.resp.Code2SessionRespBody; |
| | | import com.ruoyi.system.utils.wx.body.resq.Code2SessionResqBody; |
| | | import com.ruoyi.system.utils.wx.model.WeixinProperties; |
| | | import com.ruoyi.system.utils.wx.pojo.AppletUserDecodeData; |
| | | import com.ruoyi.system.utils.wx.pojo.AppletUserEncrypteData; |
| | | import com.ruoyi.system.utils.wx.tools.WxAppletTools; |
| | | import com.ruoyi.system.utils.wx.tools.WxUtils; |
| | | import com.ruoyi.web.controller.tool.MsgUtils; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.util.StringUtils; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | /** |
| | | * 登录验证 |
| | |
| | | private RedisService redisService; |
| | | @Autowired |
| | | private TAppUserService appUserService; |
| | | |
| | | /** |
| | | * 获取验证码 |
| | | * |
| | | * @param phone 手机号 |
| | | * @return 结果 |
| | | */ |
| | | @ApiOperation(value = "获取验证码",notes = "获取验证码") |
| | | @GetMapping("/getCode") |
| | | public AjaxResult getCode(@RequestParam String phone) |
| | | { |
| | | // 发送验证码并存储到redis |
| | | if (StringUtils.hasLength(phone)) { |
| | | |
| | | String code = String.valueOf((int) (Math.random() * 1000000)); |
| | | redisCache.setCacheObject(phone, code,5*60, TimeUnit.SECONDS); |
| | | try { |
| | | //TODO 待对接 |
| | | // smsUtil.sendSms(phone, "2369926", new String[]{code}); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | return AjaxResult.success("发送短信验证码成功!5分钟内有效"); |
| | | } |
| | | return AjaxResult.error(500, "发送短信验证码失败,请确认手机号码!"); |
| | | } |
| | | |
| | | /** |
| | | * 账号密码登录 |
| | | * |
| | | * @param loginBody 登录信息 |
| | | * @return 结果 |
| | | */ |
| | | @ApiOperation(value = "短信登录",notes = "短信登录") |
| | | @PostMapping("/loginCode") |
| | | public AjaxResult loginCode(@RequestBody LoginBody loginBody) |
| | | { |
| | | AjaxResult ajax = AjaxResult.success(); |
| | | // 生成令牌 |
| | | LoginUserApplet loginUser = loginService.loginCodeApplet(loginBody.getUsername(), loginBody.getCode()); |
| | | ajax.put(Constants.TOKEN, tokenService.createTokenApplet(loginUser)); |
| | | ajax.put("userInfo",loginUser); |
| | | return ajax; |
| | | } |
| | | |
| | | /** |
| | | * 账号密码登录 |
| | | * |
| | |
| | | LoginAppBody loginAppBody = JSON.parseObject(param, LoginAppBody.class); |
| | | AjaxResult ajax = AjaxResult.success(); |
| | | // 生成令牌 |
| | | LoginUserApplet loginUser = loginService.loginCodeApplet(loginAppBody.getAccount(), loginAppBody.getPassword()); |
| | | LoginUserApplet loginUser = loginService.loginPwdApplet(loginAppBody.getAccount(), loginAppBody.getPassword()); |
| | | ajax.put(Constants.TOKEN, tokenService.createTokenApplet(loginUser)); |
| | | ajax.put("data",loginUser); |
| | | return ajax; |
| | |
| | | // appletUserDecodeData.setOpenId(openid); |
| | | // 先使用openId和当前手机号进行查询 |
| | | TAppUser sysAppUser = appUserService.getOne(Wrappers.lambdaQuery(TAppUser.class) |
| | | .and(e->e.eq(TAppUser::getOpenId, openid))); |
| | | .and(e->e.eq(TAppUser::getOpenid, openid))); |
| | | if (sysAppUser==null){ |
| | | sysAppUser = new TAppUser(); |
| | | // sysAppUser.setPhoneNumber(appletUserDecodeData.getPhoneNumber()); |
| | | sysAppUser.setOpenId(openid); |
| | | sysAppUser.setOpenid(openid); |
| | | // 手机号中间四位替换为* |
| | | // sysAppUser.setNickName(appletUserDecodeData.getPhoneNumber().replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2")); |
| | | appUserService.save(sysAppUser); |
| | |
| | | return R.fail("账号已冻结,请联系管理员"); |
| | | } |
| | | // 手机号相同但openId为空的情况 |
| | | sysAppUser.setOpenId(openid); |
| | | sysAppUser.setOpenid(openid); |
| | | appUserService.updateById(sysAppUser); |
| | | } |
| | | LoginUserApplet loginUserApplet = new LoginUserApplet(); |