Skip to content

微信公众号跳转h5

参考文档:

公众号 -> 微信网页开发 -> 网页授权 https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_webpage_authorization.html

  • redirect_uri:使用 urlEncode 对链接进行处理;

  • 每次用户授权带上的code不一样,code只能使用一次,5分钟未被使用自动过期。


举个栗子:

https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx666&redirect_uri=https%3A%2F%2Fwww.test.com&response_type=code&scope=snsapi_base&state=2#wechat_redirect

h5页面接受参数:

const url = new URL(document.location.href)
let code = url.searchParams.get('code')
let state = url.searchParams.get('state') // 2