前言
集成微信扫码登录的话,需要把项目的账号和微信账号进行绑定,然后才可以进行扫码登录
本篇内容是扫码登录微信,如果没有绑定
本篇是基于上篇继续写的
后端
Constants增加一个常量
/**
* 微信openid redis key
*/
public static final String WX_OPENID_KEY = "wx_openid:";
在WXController新增方法
/**
* 扫码登录用uuid生成
*/
@GetMapping("/uuid/get")
public AjaxResult getUUID() throws IOException
{
AjaxResult ajax = AjaxResult.success();
String uuid = IdUtils.simpleUUID();
String verifyKey = Constants.WX_OPENID_KEY + uuid;
redisTemplate.opsForValue().set(verifyKey, "", 1, TimeUnit.MINUTES);
ajax.put("uuid", uuid);
return ajax;
}
/**
* uuid绑定openid
*/
@GetMapping("/uuid/bind/openid")
public AjaxResult bindOpenid(@RequestParam("code") String code, @RequestParam("uuid") String uuid) throws IOException
{
AjaxResult ajax = AjaxResult.success();
SysUser user = sysUserService.getOpenid(code);
String openid = user.getOpenid();
String wxNickName = user.getWxNickName();
String verifyKey = CacheConstants.WX_OPENID_KEY + uuid;
long expire = redisTemplate.getExpire(verifyKey);
redisTemplate.opsForValue().set(verifyKey, openid);
if (expire > 0) {
redisTemplate.expire(verifyKey, expire, TimeUnit.S

最低0.47元/天 解锁文章
1718

被折叠的 条评论
为什么被折叠?



