确保用户隐私指引已经明确使用相机功能

“mp-weixin”:

"permission": {

"scope.camera": {

"desc": "需要使用相机功能,请授权"

}

}

wx.authorize({

scope: 'scope.camera',

success(res) {

console.log(res, '用户成功授权')

// 用户授权相机权限

that.scanFlag = true

},

fail(rew1) {

console.log(rew1, '用户未成功授权')

that.scanFlag = true

// 用户拒绝相机权限或未完全授权

wx.getSetting({

success: async (res) => {

if (!res.authSetting['scope.camera']) {

// 权限封装

wx.showModal({

title: '相机权限申请',

content: '需要获取您的相机权限,请在设置中打开相机权限',

showCancel: false,

confirmText: '去设置',

success(res) {

if (res.confirm) {

// 用户点击去设置,跳转到微信权限设置页面

wx.openSetting({

success(res) {

// 进行相机授权后的回调处理

if (res.authSetting['scope.camera']) {

// 用户已授权相机权限,可以执行相机相关操作

this.scanFlag = true

}

}

});

}

}

});

// 也可自己写,通过 wx.authorize 打开有关授权=>官方链接https://developers.weixin.qq.com/miniprogram/dev/api/open-api/authorize/wx.authorize.html

} else {

this.scanFlag = true

}

}

})

}

});

参考文章

评论可见,请评论后查看内容,谢谢!!!
 您阅读本篇文章共花了: