uniapp调用微信授权的方法:1、使用button组件,代码为【61b77cf4fa07163359a97f1773b9041965281c5ac262bf6d81768915a4a77ac0】;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如何调用微信授权的详细内容。