企业官网建站 小程序开发 云逸学习园地
技术文章 许愿墙
技术文章 PHP学习 Javascript学习 DIV+CSS学习 uniapp学习 HTML学习 微信小程序、公众号知识点 VUE知识学习
您所在的位置>云逸小栈>uniapp学习>正文

uniapp网页端授权登录的方法

2024-08-30 16:30:24 浏览 1757

html代码

<template>  
    <view>    
        <button @click="wxWebLogin">微信授权登录</button>  
    </view>
</template>

js端代码

//在methods中
wxWebLogin() {
 // 1. 获取微信公众号的AppID
 const appid = 'YOUR_APPID';

 // 2. 设置回调URL(需在微信公众号平台配置)
 const redirect_uri = encodeURIComponent('https://yourdomain.com/wx-callback');

 // 3. 构造微信授权URL
 const url =
 `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${redirect_uri}&response_type=code&scope
 =snsapi_userinfo&state=STATE#wechat_redirect`;

 // 4. 跳转到微信授权页面
 window.location.href = url;
}


网站开发者电话

18066742510

个人微信号
个人公众号
个人小程序
个人抖音