今天突然小程序登錄不了,后臺報錯“The given payload is invalid.”但是小程序這邊流程是正確的,絕對沒錯的,找了半天想起來看看wx.login的報錯,結(jié)果顯示:“fail api scope is not declared in the privacy agreement”,于是就去更新了用戶協(xié)議,但是更新了還不對,才發(fā)現(xiàn)微信
于是就去查看這到底是什么東西
在components新增組件PrivacyPop
<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隱私保護引導》',
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>
在login頁引入:文章來源:http://www.zghlxwxcb.cn/news/detail-735623.html
import PrivacyPop from '../../components/PrivacyPop/PrivacyPop.vue';
components:{
PrivacyPop
},
async onLoad() {
this.wxLoginCode = await this.wxLogin();
this.$refs.PrivacyPopck.checkPrivacySetting();
},
這樣就可以了
后面發(fā)現(xiàn):checkPrivacySetting返回false的時候點擊登錄還是報錯未授權(quán),所以每次登錄都得授權(quán)才能繼續(xù)請求接口文章來源地址http://www.zghlxwxcb.cn/news/detail-735623.html
到了這里,關(guān)于微信小程序用戶隱私保護指引fail api scope is not declared in the privacy agreement的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!