網站首頁 編程語言 正文
說明:微信授權頁面一經用戶拒絕過一次后后續就不會再彈出 只能手動點擊右上角打開設置去授權,此方法解決了不需要用戶手動打開設置授權 只要用戶拒絕過授權 下次進來就會以彈窗的形式詢問是否需要授權 是的話自動跳轉到設置頁面
1. 新建公共的js文件 commonAuth.js
let setting = null;
const dealAuth = (authSetting, key, content, callback) => {
if (authSetting?.[key] === true) callback?.(true)
if (authSetting?.[key] === false) {
wx.showModal({
title: '提示',
content,
success(res) {
if (res.confirm) {
wx.openSetting({
withSubscriptions: true,
success(res) {
res.authSetting[key] && callback?.(true)
!res.authSetting[key] && callback?.(false)
},
// fail() { callback?.(false) }
})
} else if (res.cancel) callback?.(false)
}
})
}
if (authSetting?.[key] === undefined) {
wx.authorize({
scope: key,
success() { callback?.(true) },
fail() { callback?.(false) }
})
}
}
module.exports.commonAuth = (key, content, callback) => {
!setting && wx.getSetting({
success(res) {
setting = res
dealAuth(res.authSetting, key, content, callback)
}
})
setting && dealAuth(setting.authSetting, key, content, callback)
}
2. 使用方式
const { commonAuth } = require('@/common/utils/commonAuth')
commonAuth('scope.record', '打開錄音授權頁面嗎?', (result) => {
// result true授權成功 可以使用對應api false拒絕授權
// 授權打開后開始調用相關api
wx.startRecord()
})
原文鏈接:https://blog.csdn.net/weixin_44147791/article/details/123201707
- 上一篇:沒有了
- 下一篇:沒有了
相關推薦
- 2022-06-25 關于Ubuntu?Server?18.04?LTS?安裝Tomcat并配置systemctl管理To
- 2022-12-08 重溫Python基礎之列表操作_python
- 2022-05-13 FAILED: Execution Error, return code 1 from org.ap
- 2022-10-27 教你快速搭建?React?Native?開發環境_React
- 2022-09-06 Python中閉包與lambda的作用域解析_python
- 2023-04-22 python的open函數使用案例代碼_python
- 2022-05-03 如何利用Python實現簡易的音頻播放器_python
- 2022-05-23 Oracle配置dblink訪問PostgreSQL的操作方法_oracle
- 欄目分類
-
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支