确保用户隐私指引已经明确使用相机功能
“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}}})}});