https://developers.weixin.qq.com/miniprogram/dev/api/wx.authorize.html
一 button获取用户授权
获取用户的授权 授权的button
在wxml中写一个button
<button bindgetuserinfo="onGetUserInfo"
open-type="getUserInfo">获取用户信息</button>
在wxjs中
onGetUserInfo:function(e){
console.log(e.detail) //e包括用户操作的回调
}
点击效果
点击确定后 即可获取用户信息
************************************************************************************************************************
二api获取用户授权 必须得做过上面那一步能进行下面的操作!!
1 在wxml中写一个普通的button
<button bind:tap="onTry" style="margin-top:10pt;">获取信息试试</button>
2在wxjs中
onTry:function(){
wx.getUserInfo({
success: function(e) {
console.log(e)
},
fail: function(e) {
console.log(E)
}
})
}
wx.getSetting({
success(res) {
if (!res.authSetting['scope.record']) {
wx.authorize({
scope: 'scope.record',
success() {
// 用户已经同意小程序使用录音功能,后续调用 wx.startRecord 接口不会弹窗询问
wx.startRecord()
}
})
}
}
})