這里給大家分享我在網(wǎng)上總結(jié)出來的一些知識,希望對大家有所幫助
?
一,問題起因
最新在開發(fā)小程序的時候,調(diào)用微信小程序來獲取用戶信息的時候經(jīng)常報錯一個問題
fail api scope is not declared in the privacy agreement,api
更具公告,是微信更新對應(yīng)的隱私協(xié)議
https://mp.weixin.qq.com/cgi-bin/announce?action=getannouncement&announce_id=11691660367cfUvX&version=&lang=zh_CN&token=
二,解決方案
下面是我總結(jié)的解決步驟
1.前往微信小程序公眾平臺配置設(shè)置,完善并提交信息(注意:更新好隱私協(xié)議,要通過審核的,接口才能正常訪問)
文章來源:http://www.zghlxwxcb.cn/news/detail-734082.html
2.在components新增組件PrivacyPop
vue2版本
<template> <view class="privacy" v-if="showPrivacy"> <view class="content"> <view class="title">隱私保護指引</view> <view class="des"> 在使用當前小程序服務(wù)之前,請仔細閱讀<text class="link" @tap="openPrivacyContract">{{ privacyContractName }}</text>。如你同意{{ privacyContractName }},請點擊“同意”開始使用。 </view> <view class="btns"> <button class="item reject" @tap="exitMiniProgram">拒絕</button> <button id="agree-btn" class="item agree" open-type="agreePrivacyAuthorization" @agreeprivacyauthorization="handleAgreePrivacyAuthorization">同意</button> </view> </view> </view> </template> <script> export default { data() { return { privacyContractName: '《XXX隱私保護引導(dǎo)》', showPrivacy: false } }, methods: { checkPrivacySetting(){ uni.getPrivacySetting({ success: res => { console.log("getPrivacySetting",res) this.showPrivacy = true // 返回結(jié)果為: res = { needAuthorization: true/false, privacyContractName: '《xxx隱私保護指引》' } // if (res.needAuthorization) { // 需要彈出隱私協(xié)議 // this.showPrivacy = false // } else { // this.showPrivacy = true // 用戶已經(jīng)同意過隱私協(xié)議,所以不需要再彈出隱私協(xié)議,也能調(diào)用已聲明過的隱私接口 // wx.getUserProfile() // wx.chooseMedia() // wx.getClipboardData() // wx.startRecord() // } }, fail: () => {}, complete: () => {} }) }, // 打開隱私協(xié)議 openPrivacyContract() { uni.openPrivacyContract({ fail: () => { uni.showToast({ title: '遇到錯誤', icon: 'error' }) } }) }, // 拒絕隱私協(xié)議 exitMiniProgram() { console.log("拒絕隱私協(xié)議") const that = this; // 直接退出小程序 // wx.exitMiniProgram() uni.showModal({ // 如果拒絕,我們將無法獲取您的信息, 包括手機號、位置信息、相冊等該小程序十分重要的功能,您確定要拒絕嗎? content: '您確定要拒絕嗎?', success: res => { if (res.confirm) { that.showPrivacy = false; uni.exitMiniProgram({ success: () => { console.log('退出小程序成功'); } }); } } }); }, // 同意隱私協(xié)議 handleAgreePrivacyAuthorization() { wx.requirePrivacyAuthorize({ success: () => { // 用戶同意授權(quán) // 繼續(xù)小程序邏輯 this.showPrivacy = false }, fail: () => {}, // 用戶拒絕授權(quán) complete: () => {} }) } } } </script> <style scoped> .privacy { position: fixed; top: 0; right: 0; bottom: 0; left: 0; background: rgba(0, 0, 0, .5); z-index: 9999999; display: flex; align-items: center; justify-content: center; } .content { width: 632rpx; padding: 48rpx; box-sizing: border-box; background: #fff; border-radius: 16rpx; } .content .title { text-align: center; color: #333; font-weight: bold; font-size: 32rpx; } .content .des { font-size: 26rpx; color: #666; margin-top: 40rpx; text-align: justify; line-height: 1.6; } .content .des .link { color: #07c160; text-decoration: underline; } .btns { margin-top: 48rpx; display: flex; } .btns .item { justify-content: space-between; width: 244rpx; height: 80rpx; display: flex; align-items: center; justify-content: center; border-radius: 16rpx; box-sizing: border-box; border: none; } .btns .reject { background: #f4f4f5; color: #909399; } .btns .agree { background: #07c160; color: #fff; } </style>
vue3版本
<template> <view class="privacy" v-if="showPrivacy"> <view class="content"> <view class="title">隱私保護指引</view> <view class="des"> 在使用當前小程序服務(wù)之前,請仔細閱讀<text class="link" @tap="openPrivacyContract">{{ privacyContractName }}</text>。如你同意{{ privacyContractName }},請點擊“同意”開始使用。 </view> <view class="btns"> <button class="item reject" @tap="exitMiniProgram">拒絕</button> <button id="agree-btn" class="item agree" open-type="agreePrivacyAuthorization" @agreeprivacyauthorization="handleAgreePrivacyAuthorization">同意</button> </view> </view> </view> </template> <script lang="ts" setup> import { ref } from "vue"; const privacyContractName = ref('《用戶隱私保護引導(dǎo)》'); const showPrivacy = ref(false); const checkPrivacySetting = () => { uni.getPrivacySetting({ success: (res) => { showPrivacy.value = true } }) } // 打開隱私協(xié)議 const openPrivacyContract = () => { uni.openPrivacyContract({ fail: () => { uni.showToast({ title: '遇到錯誤', icon: 'error' }) } }) } // 拒絕隱私協(xié)議 const exitMiniProgram = () => { console.log("拒絕隱私協(xié)議") uni.showModal({ // 如果拒絕,我們將無法獲取您的信息, 包括手機號、位置信息、相冊等該小程序十分重要的功能,您確定要拒絕嗎? content: '您確定要拒絕嗎?', success: res => { if (res.confirm) { showPrivacy.value = false; uni.exitMiniProgram({ success: () => { console.log('退出小程序成功'); } }); } } }); } // 同意隱私協(xié)議 const handleAgreePrivacyAuthorization = () => { wx.requirePrivacyAuthorize({ success: () => { // 用戶同意授權(quán) // 繼續(xù)小程序邏輯 showPrivacy.value = false }, fail: () => { }, // 用戶拒絕授權(quán) complete: () => { } }) } </script> <style scoped> .privacy { position: fixed; top: 0; right: 0; bottom: 0; left: 0; background: rgba(0, 0, 0, .5); z-index: 9999999; display: flex; align-items: center; justify-content: center; } .content { width: 632rpx; padding: 48rpx; box-sizing: border-box; background: #fff; border-radius: 16rpx; } .content .title { text-align: center; color: #333; font-weight: bold; font-size: 32rpx; } .content .des { font-size: 26rpx; color: #666; margin-top: 40rpx; text-align: justify; line-height: 1.6; } .content .des .link { color: #07c160; text-decoration: underline; } .btns { margin-top: 48rpx; display: flex; } .btns .item { justify-content: space-between; width: 244rpx; height: 80rpx; display: flex; align-items: center; justify-content: center; border-radius: 16rpx; box-sizing: border-box; border: none; } .btns .reject { background: #f4f4f5; color: #909399; } .btns .agree { background: #07c160; color: #fff; } </style>
3.在要使用的頁面中引入
vue2版本
import PrivacyPop from '../../components/PrivacyPop/PrivacyPop.vue'; components:{ PrivacyPop }, async onLoad() { this.$refs.PrivacyPopck.checkPrivacySetting(); },
vue3版本(建議點擊事件觸發(fā))
import PrivacyPop from '@/components/PrivacyPop.vue'; import { ref } from "vue"; const PrivacyObj = ref({ }) const ClickFun = ()=>{ if(PrivacyObj.value){ PrivacyObj.value.checkPrivacySetting(); } }
如果對您有所幫助,歡迎您點個關(guān)注,我會定時更新技術(shù)文檔,大家一起討論學(xué)習(xí),一起進步。
?文章來源地址http://www.zghlxwxcb.cn/news/detail-734082.html
到了這里,關(guān)于uni-app 應(yīng)對微信小程序最新隱私協(xié)議接口要求的處理方法的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!