048f25f580
Show privacy popup on launch, gate login on legal consent, and link user agreement and privacy policy pages in the mini program. Co-authored-by: Cursor <cursoragent@cursor.com>
52 lines
1.2 KiB
JavaScript
52 lines
1.2 KiB
JavaScript
function canUsePrivacyApis() {
|
|
return typeof wx.getPrivacySetting === 'function';
|
|
}
|
|
|
|
function getPrivacySetting() {
|
|
return new Promise((resolve) => {
|
|
if (!canUsePrivacyApis()) {
|
|
resolve({ needAuthorization: false, privacyContractName: '' });
|
|
return;
|
|
}
|
|
wx.getPrivacySetting({
|
|
success(res) {
|
|
resolve({
|
|
needAuthorization: Boolean(res?.needAuthorization),
|
|
privacyContractName: String(res?.privacyContractName || ''),
|
|
});
|
|
},
|
|
fail() {
|
|
resolve({ needAuthorization: false, privacyContractName: '' });
|
|
},
|
|
});
|
|
});
|
|
}
|
|
|
|
function openPrivacyContract() {
|
|
if (typeof wx.openPrivacyContract !== 'function') {
|
|
wx.showToast({ title: '请升级微信版本后查看', icon: 'none' });
|
|
return;
|
|
}
|
|
wx.openPrivacyContract({
|
|
fail() {
|
|
wx.showToast({ title: '暂时无法打开隐私指引', icon: 'none' });
|
|
},
|
|
});
|
|
}
|
|
|
|
function registerPrivacyAuthorizationListener(handler) {
|
|
if (typeof wx.onNeedPrivacyAuthorization !== 'function') {
|
|
return;
|
|
}
|
|
wx.onNeedPrivacyAuthorization((resolve) => {
|
|
handler(resolve);
|
|
});
|
|
}
|
|
|
|
module.exports = {
|
|
canUsePrivacyApis,
|
|
getPrivacySetting,
|
|
openPrivacyContract,
|
|
registerPrivacyAuthorizationListener,
|
|
};
|