开发者文档
// https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_webpage_authorization.html
appid:用自己的
第一步:用户同意授权,获取code
官网说的很详细
第二步:通过 code 换取网页授权access_token
let url = `https://api.weixin.qq.com/sns/oauth2/access_token?appid=appid&secret=SECRET&code=code&grant_type=authorization_code`;
axios.get(url, {
params: {
appid:"",
code: "code",
secret: "appsecret",
grant_type:'authorization_code'
},
})
.then((response) => {
console.log("response", response.data);
});
/*返回值*/ 前端请求会暴露一些信息 最好后端请求
{
"access_token":"ACCESS_TOKEN",
"expires_in":7200,
"refresh_token":"REFRESH_TOKEN",
"openid":"OPENID",
"scope":"SCOPE"
}
vue h5 授权微信
最新推荐文章于 2024-07-25 11:00:49 发布