有没有设计网站在广州的,网站已运行时间代码,海尔商城网站建设维护,app开发公司属于什么行业配置问题 这是小程序登录问题#xff0c;必要的两个配置。
流程思路
1. 微信小程序端#xff0c;会返回一个code。 2. 查看需要返回给微信小程序端的数据。 3. 既然需要返回三个数据#xff0c;先看openid如何拿到 WX-Login https://api.weixin.qq.com/sns/jscode2ses…配置问题 这是小程序登录问题必要的两个配置。
流程思路
1. 微信小程序端会返回一个code。 2. 查看需要返回给微信小程序端的数据。 3. 既然需要返回三个数据先看openid如何拿到 WX-Login https://api.weixin.qq.com/sns/jscode2session 原来如此可以看到它根据AppId 和 密钥 前端发送的唯一标识和固定的type类型分装成map之后发送了一个请求,解析出来json拿到了openid!。
4. token令牌 PostMapping(/login)ApiOperation(微信登录)public ResultUserLoginVO login(RequestBody UserLoginDTO userLoginDTO) {log.info(微信用户登录, userLoginDTO.getCode());System.out.println(登录凭证.....................................userLoginDTO.getCode());// 微信登录User user userService.wxLogin(userLoginDTO);// 为微信用户生成JWT令牌HashMapString, Object clamis new HashMap();clamis.put(JwtClaimsConstant.USER_ID, user.getId());String token JwtUtil.createJWT(jwtProperties.getUserSecretKey(), jwtProperties.getUserTtl(), clamis);UserLoginVO userLoginVO UserLoginVO.builder().id(user.getId()).openid(user.getOpenid()).token(token).build();System.out.println(返回参数.............................userLoginVO.toString());return Result.success(userLoginVO);} public User wxLogin(UserLoginDTO userLoginDTO) {// 调用微信接口服务获得当前微信用户的openidString openid getOpenid(userLoginDTO.getCode());System.out.println(查看返回的微信用户idopenid);//判断openid是否为空如果为空表示登录失败抛出业务异常if (openid null) {throw new LoginFailedException(MessageConstant.LOGIN_FAILED);}// 判断当前用户是否为新用户User user userMapper.getByOpenid(openid);System.out.println(新用户前...........................user.toString());// 如果是新用户自动完成注册if (user null) {user User.builder().openid(openid).createTime(LocalDateTime.now()).build();userMapper.insert(user);}System.out.println(新用户......................user.toString());// 返回这个用户对象return user;}
user类根据前端code拿到用户(如果没有先注册)
openid :那么首先wxLogin方法里面封装的数据里面有openid的值。
token 令牌规则: appid, 密钥 用户id 加密而成
id: user类中获得
最后要返回的数据封装成userLoginVO类发送到小程序完成微信登录