記2023.11.08
一昌犹、配置微信后臺
登錄微信公眾號小程序管理后臺----設(shè)置----服務(wù)內(nèi)容與聲明---用戶隱私保護(hù)指引(更新)----增加信息類型(以下圖示)----選擇需要獲取用戶的隱私信息類型(比如:用戶信息(微信昵稱……)司志,手機(jī)號等)
二扩灯、配置項目文件
項目文件:manifest.json
--源碼視圖
"mp-weixin": {
"__usePrivacyCheck__": true
},
三、自定義隱私彈框
template
<u-modal :show="privacyAuthPopup" v-model="privacyAuthPopup" :mask-close-able="true" title="隱私保護(hù)指引" :show-confirm-button="false">
<view class="content">
<view class="des">
感謝使用{{ projectName }}盹沈!請您仔細(xì)閱讀并充分理解
<text class="link" @click="openPrivacyContract">{{ privacyContractName }}</text>
硼控,如您同意前述協(xié)議的全部內(nèi)容,請點(diǎn)擊“同意并繼續(xù)”開始使用动壤。
<text class="cancel">如您不同意,將被限制使用部分功能淮逻,或?qū)⒃谀褂镁唧w功能前再次詢問以取得您的授權(quán)同意琼懊。</text>
</view>
<view class="buttons">
<button class="reject" @click="handleDisagree">不同意</button>
<button class="agree" id="agree-btn" open-type="agreePrivacyAuthorization" @agreeprivacyauthorization="handleAgreePrivacyAuthorization">同意并繼續(xù)</button>
</view>
</view>
</u-modal>
script
export default {
data() {
return {
privacyAuthPopup: false,
privacyContractName: 'xxx小程序隱私協(xié)議'
};
},
onLoad() {
let that = this;
if (wx.getPrivacySetting) {
wx.getPrivacySetting({
success: (res) => {
console.log(res);
if (res.needAuthorization) {
this.privacyContractName = res.privacyContractName;
this.popUp();
} else {
// 用戶已經(jīng)同意過隱私協(xié)議,所以不需要再彈出隱私協(xié)議爬早,也能調(diào)用隱私接口
}
},
fail: () => {},
complete: () => {}
});
} else {
this.triggerEvent('agree');
}
if (wx.onNeedPrivacyAuthorization) {
wx.onNeedPrivacyAuthorization((resolve, eventInfo) => {
console.log('觸發(fā)本次事件的接口是:', resolve, eventInfo.referrer);
});
}
},
methods: {
// 用戶點(diǎn)擊同意按鈕后
handleAgreePrivacyAuthorization() {
this.triggerEvent('agree');
this.disPopUp();
},
// 不同意
handleDisagree() {
this.triggerEvent('disagree');
this.disPopUp();
// 退出小程序
uni.exitMiniProgram();
},
// 打開
popUp() {
this.privacyAuthPopup = true;
},
// 關(guān)閉
disPopUp() {
this.privacyAuthPopup = false;
},
triggerEvent(e) {
if (wx.onNeedPrivacyAuthorization) {
wx.onNeedPrivacyAuthorization((resolve, eventInfo) => {
resolve({ buttonId: 'agree-btn', event: e });
});
}
},
// 跳轉(zhuǎn)小程序協(xié)議
openPrivacyContract() {
wx.openPrivacyContract({
success: (res) => {
console.log('openPrivacyContract success');
},
fail: (res) => {
console.error('openPrivacyContract fail', res);
}
});
},
}
}
style
.buttons {
margin-top: 20px;
display: flex;
}
.buttons button {
height: 40px;
line-height: 40px;
background: #1183ff;
border-radius: 20px;
color: #fff;
padding: 0 20px;
}
.link {
color: #1183ff;
cursor: pointer;
}