微信开封平台——根据JWT生成token回写客户端(5)

简介:

用户授权登录之后,需要生成登录凭证,重定向到页面上

之前的access_page表示当前的页面

当我们点击微信登录的时候

url地址栏的state会指向当前的地址

首页点击微信登录

https://open.weixin.qq.com/connect/qrconnect?appid=wx25bc3c42ddcc664f&redirect_uri=https%3A%2F%2Fapi.xdclass.net%2Fpub%2Fapi%2Fv1%2Fwechat%2Fuser%2Fcallback1&response_type=code&scope=snsapi_login&state=https%3A%2F%2Fxdclass.net%2F%23%2Findex%3Flogin_type%3Dpc#wechat_redirect

点开某个页面点击微信登录

二级页面的地址

https://open.weixin.qq.com/connect/qrconnect?appid=wx25bc3c42ddcc664f&redirect_uri=https%3A%2F%2Fapi.xdclass.net%2Fpub%2Fapi%2Fv1%2Fwechat%2Fuser%2Fcallback1&response_type=code&scope=snsapi_login&state=https%3A%2F%2Fxdclass.net%2F%23%2Fcourselist%3Fcp_id%3D2%26%2338%3Bc_id%3D17%26login_type%3Dpc#wechat_redirect

 

public void wechatUserCallback(@RequestParam(value = "code",required = true) String code,
                               String state, HttpServletResponse response) throws Exception {


    User user = userService.saveWeChatUser(code);
    if(user != null){
        //生成jwt
        String token= JwtUtils.geneJsonWebToken(user);
        System.out.println("token========================"+token);
        /**
         *
         * 获取状态  表示当前的地址
         * 并拼装头像地址+昵称(前端减少数据库的查询)
         * @date: 2019/2/26 21:03
         */
        response.sendRedirect(state+"?token="+token+"&head_img="+user.getHeadImg()+"&name="+user.getName());

    }

Http:

 

 

 

 

 

 

整体思路:

  1. 获取当前页面访问地址
  2. 根据User的基本信息生成token
  3. 重定向到指定页面
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

智达教育‍

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值