网站应用开发微信登录登出

 sell

提示:

官方文档:微信开放平台open.weixin.qq.com

必须具有公司资质的账号才能用微信登陆App或者网站

开放平台的appId和秘钥和公众平台的不一样,用的接口一样WxMpService

redis集群实现分布式session共享:

登录流程:

1.配置文件中配置openAppId和openAppSecret

2.配置类中设置配置:WxMpService

@Component
public class WechatMpConfig {

    @Autowired
    private WechatAccountConfig accountConfig;

    @Bean
    public WxMpService wxMpService() {
        WxMpService wxMpService = new WxMpServiceImpl();
        wxMpService.setWxMpConfigStorage(wxMpConfigStorage());
        return wxMpService;
    }

    @Bean
    public WxMpConfigStorage wxMpConfigStorage() {
        WxMpInMemoryConfigStorage wxMpConfigStorage = new WxMpInMemoryConfigStorage();
        wxMpConfigStorage.setAppId(accountConfig.getMpAppId());
        wxMpConfigStorage.setSecret(accountConfig.getMpAppSecret());
        return wxMpConfigStorage;
    }
}

 3.获取code,通过code获取openid,(见代码)

 4.openid去和数据库的数据匹配

5.设置token至redis(需引入依赖,配置redis的host和port)

6.设置token至cookie

7.登陆成功,跳转(redirect),跳转的时候一般用完整地址

登出流程:

1.清除cookie

2.清除redis(过期时间设为0)

AOP实现身份验证:

用户访问url之前验证一下用户是否登录,如果未登录则抛出异常,然后拦截该异常

 

@Controller
@RequestMapping("/wechat")
@Slf4j
public class WechatController {

    @Autowired

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值