广告:宝塔Linux面板高效运维的服务器管理软件 点击【 https://www.bt.cn/p/uNLv1L 】立即购买
uniapp调用微信授权的方法:1、使用button组件,代码为【<button open-type="getUserInfo"@click="loginMP"></button>】;2、使用openSetting引导用户打开相应的权限。
本教程操作环境:windows7系统、uni-app2.5.1版本,Dell G3电脑。
推荐(免费):uni-app开发教程
uniapp调用微信授权的方法:
方法一
**使用button组件(open-type属性)**<button open-type="getUserInfo"@click="loginMP"></button>uni.getUserInfo({provider:"weixin",success(userInfo) {loginMP().then(res=>{uni.setStorageSync('token', res.result.token)uni.getUserInfo({provider:"weixin",success(res) {console.log(res);},fail(err) {console.log(err);}})uni.showToast({title: '登录成功'});}).catch(err=>{uni.showModal({title: "提示",content: '稍后重试'+err.message,showCancel: false,});})}登录后复制
方法二
**使用openSetting引导用户打开相应的权限,相关的API还有getSetting **uni.authorize({scope:"scope.scope.userInfo",success(res) {console.log(res);},fail() {uni.openSetting({success(authSetting) {console.log(authSetting);}})}})登录后复制
相关免费推荐:编程视频课程
以上就是uniapp如何调用微信授权的详细内容,更多请关注9543建站博客其它相关文章!
发表评论