# Privacy Policy Development Guide
# I. Introduction to Functions
Mini Program developers involved in the processing of users' personal information need to prompt users to read the collection and use rules such as privacy policies through obvious means such as pop-ups.
In order to regulate the user's personal information processing and protect the legitimate rights and interests of the user, WeChat requires developers to actively synchronize the current user of WeChat has read and agreed to the privacy policies of the mini program before calling the privacy interface provided by WeChat.
Special attention:
2023.08.22 Update:
Covered in the following guidelines getPrivacySetting、onNeedPrivacyAuthorization、requirePrivacyAuthorize The interface is currently available for normal access debugging. Debugging Instructions:
in Prior to September 15, 2023, in app.json In Configuration
__usePrivacyCheck__: true
Privacy-related features are enabled if they are not configured or configured to false Will not be enabled.in After September 15, 2023, regardless of app.json Is there a configuration in
__usePrivacyCheck__
Privacy related functions are enabled.
Interface usage can be referred to below[Complete example demo ](#IV. Full sample demo)
2023.09.14 Update:
Privacy-related functionality is delayed until October 17, 2023. in Prior to October 17, 2023, in the app.json In Configuration
__usePrivacyCheck__: true
Privacy-related features are enabled if they are not configured or configured to false Will not be enabled. in After October 17, 2023, regardless of app.json Is there a configuration in__usePrivacyCheck__
Privacy related functions are enabled.New official privacy authorization pop-up function, related functions refer to the following[Official Privacy Popup Feature Dxplaination](#VI. Official Privacy Popup Function Dxplaination)。
# II. Access Process
# 1. Configure the Guidelines for Privacy Protection of Mini Program Users
Developers are required toMini Program management backgroundConfigure the "Small Program User Privacy Protection Guidelines," detailed guidelines can be found:User Privacy Protection Guidelines。
It is important to note that the corresponding interface or component provided by the platform can only be invoked if the user information being processed is declared in the guideline. If not declared, the corresponding interface or component is directly disabled.The relationship between the privacy interface and the corresponding processed information is visible:Privacy Protection Guidelines for Small Program Users。
After the configuration is completed, for each user using the mini program, the developer needs to synchronize the current user of WeChat to read and agree to the collection and use rules such as the privacy policy of the mini program before calling the declared interface or component. The development of synchronization is described below.
For users who have already synchronized, if the developer updates the configuration later, there is already an interface or component for the old version, there is no need to resynchronizeFor new interfaces or components resulting from the update, resynchronization is required. For example, the July 11 update containsCollect location information of your choice, synced user consent status on July 12, and added new after the July 13 updateCollect Your WeRun Movement Steps, is not synchronized again, you can call the wx.chooseLocation Interface, unable to call the wx.getWeRunData Interface.
# 2. Proactively query privacy authorization synchronization status and display privacy agreements
From the base library 2.32.3 Start support
The developer can pass wx.getPrivacySetting Interface to query whether the user recorded on the WeChat side has to agree to the privacy policy information. This information can be obtained by returning the results res to hit the target needAuthorization Field gets.
At the same time,wx.getPrivacySetting Interface will return the name information of the "Small Program User Privacy Protection Guidelines" configured by the developer in the Mini Program management background, and the developer can call wx.openPrivacyContract Interface to open the page.
If there is a privacy policy information to be agreed by the user, the developer needs to actively prompt the user to read the privacy policy and other collection and use rules, and for the prompt, the Mini Program developer can design its own, and it needs to be used in the relevant interface. < button open-type="agreePrivacyAuthorization"> Component, when the user touches the < button> After the component, it means that the user has read and agreed to the collection and use rules such as the privacy policy of the mini program, and WeChat will receive the synchronization information. bindagreeprivacyauthorization
The declared privacy interface is invoked after the event callback.
Code Examples
<!-- page.wxml -->
<view wx:if="{{showPrivacy}}">
<view>Privacy Popup Content ....</view>
<button bindtap="handleOpenPrivacyContract" >View Privacy Policy</button>
<button id="agree-btn" open-type="agreePrivacyAuthorization" bindagreeprivacyauthorization="handleAgreePrivacyAuthorization">Agree!</button>
</view>
// page.js
Page({
data: {
showPrivacy: false
},
onLoad() {
wx.getPrivacySetting ({
success: res => {
console.log(res) // The result is: res = { needAuthorization: true/false, privacyContractName: 'XXX Privacy Protection Guide' }
if (res.needAuthorization) {
// Need to pop up the privacy agreement
this.setData({
showPrivacy: true
})
} else {
// The user has already agreed to the privacy agreement, so there is no need to pop up the privacy agreement, but also can call the privacy interface that has been declared.
// wx.getUserProfile ()
// wx.chooseMedia()
// wx.getClipboardData()
// wx.startRecord()
}
},
fail: () => {},
complete: () => {}
})
},
handleAgreePrivacyAuthorization() {
// User Agrees to Privacy Policy Event Callback
// The user clicks agree, and all declared privacy interfaces and components can be invoked
// wx.getUserProfile ()
// wx.chooseMedia()
// wx.getClipboardData()
// wx.startRecord()
},
handleOpenPrivacyContract() {
// Open the Privacy Agreement page
wx.openPrivacyContract({
success: () => {}, // Open Success
fail: () => {}, // Open failure
complete: () => {}
})
}
})
From the base library 2.32.3 From version,Privacy Consent ButtonSupport andMobile Phone Number Quick Verification Component、[Mobile phone number real-time verification component](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/getRealtimePhoneNumber .html)Coupled to use, called in the manner of <button open-type=getPhoneNumber |agreePrivacyAuthorization">
or <button open-type=getRealtimePhoneNumber |agreePrivacyAuthorization">
。
Also supportedPrivacy Consent ButtonandGet User Information ComponentsCoupled to use, called in the manner of<button open-type=getUserInfo |agreePrivacyAuthorization">
sample code
<!-- page.wxml -->
<button id="agree-btn1" open-type=getPhoneNumber |agreePrivacyAuthorization" bindgetphonenumber="handleGetPhoneNumber" bindagreeprivacyauthorization="handleAgreePrivacyAuthorization">Agree to the privacy agreement and authorize the mobile phone number</button>
<button id="agree-btn2" open-type=getRealtimePhoneNumber |agreePrivacyAuthorization" bindgetrealtimephonenumber = "handleGetRealtimePhoneNumber" bindagreeprivacyauthorization="handleAgreePrivacyAuthorization">Agree to the privacy agreement and authorize the mobile phone number</button>
<button id="agree-btn3" open-type=getUserInfo |agreePrivacyAuthorization" bindgetuserinfo="handleGetUserInfo" bindagreeprivacyauthorization="handleAgreePrivacyAuthorization">Agree to the Privacy Agreement and Get Avatar Nickname Information</button>
// page.js
Page({
handleAgreePrivacyAuthorization() {
// User Agrees to Privacy Policy Event Callback
// The user clicks agree, and all declared privacy interfaces and components can be invoked
// wx.getUserProfile ()
// wx.chooseMedia()
// wx.getClipboardData()
// wx.startRecord()
},
handleGetPhoneNumber (e) {
// Get Cell Phone Number Success
console.log(e)
},
handleGetRealtimePhoneNumber (e) {
// Get Real Time Cell Phone Number Success
console.log(e)
},
handleGetUserInfo (e) {
// Get Avatar Nickname Success
console.log(e)
}
})
# 3. Passive Listening Privacy Interface Requires User Authorization Events
From the base library 2.32.3 Start support
In addition to judging the timing on their own and prompting users to read the collection and use rules such as the privacy policy, Mini Program developers can also use the wx.onNeedPrivacyAuthorization Interface to listen when a user needs to be prompted to read the privacy policy. This event is triggered when the user triggers a call to a privacy interface that has not been recorded on the WeChat side. The developer can prompt the user to read the privacy policy when this event is triggered.
It is important to note that for < input type="nickname"> Components, due to the < input> If the user does not agree to the privacy agreement,<input type="nickname">
Does not trigger when focused onNeedPrivacyAuthorization Event, but instead relegated to < input type="text"> 。
In addition, WeChat also provides wx.requirePrivacyAuthorize Interface that can be used to simulate private interface calls.
Code Examples
// page.wxml
<view wx:if="{{showPrivacy}}">
<view>Privacy Popup Content ....</view>
<button id="agree-btn" open-type="agreePrivacyAuthorization" bindagreeprivacyauthorization="handleAgreePrivacyAuthorization">Agree!</button>
</view>
// page.js
Page({
data: {
showPrivacy: false
},
onLoad() {
wx.onNeedPrivacyAuthorization((resolve, eventInfo) => {
console.log(The interface that triggers this event is: + eventInfo.referrer)
// When user consent is required for privacy authorization
// Popup developer-defined privacy authorization popup
this.setData({
showPrivacy: true
})
this.resolvePrivacyAuthorization = resolve
})
wx.getUserProfile ({
success: console.log,
fail: console.error
})
},
handleAgreePrivacyAuthorization() {
// After the user clicks the agree button
this.resolvePrivacyAuthorization({ buttonId: 'agree-btn', event: 'agree' })
// After the user clicks consent, the developer calls the resolve({ buttonId: 'agree-btn', event: 'agree' }) Informs the platform that the user has agreed, and the parameter passes the id of the agree button
// After the user clicks Reject, the developer calls the resolve({ event:'disagree' }) Inform the platform users that they have refused
}
})
# 4. Clear History Sync Status
When the user returns from theWeChat drop-down - Recent - Recently Used Mini ProgramDelete the Mini Program in the, will clear the history synchronization state. After the next visit to the mini program, it is necessary to resync the current user of WeChat has read and agreed to the collection and use rules such as the privacy policy of the mini program.
Developers can debug in this way, or in the developer toolsClear emulator cache - clear authorization dataClear the history sync state.
# III. OTHER NOTES
- Lower than 2.32.3 Version 3 of the base library does not integrate privacy-related features and does not intercept privacy interface calls.
# IV. Full sample demo
demo1: Demonstration use wx.getPrivacySetting
and <button open-type="agreePrivacyAuthorization">
Handle Privacy Popup Logic on Home Page
https://developers.weixin.qq.com/s/gi71sGm67hK0
demo2: Demonstration use wx.onNeedPrivacyAuthorization
and <button open-type="agreePrivacyAuthorization">
Handles the privacy pop-up logic on multiple pages, and demonstrates how to handle multiple privacy interface calls at the same time.
https://developers.weixin.qq.com/s/hndZUOmA7gKn
demo3: Demonstration wx.onNeedPrivacyAuthorization
、wx.requirePrivacyAuthorize
、<button open-type="agreePrivacyAuthorization">
and <input type="nickname">
How components are combined
https://developers.weixin.qq.com/s/jX7xWGmA7UKa
demo4: Demonstration use wx.onNeedPrivacyAuthorization
and <button open-type="agreePrivacyAuthorization">
In multiple tabBar Page Processing Privacy Popup Logic
https://developers.weixin.qq.com/s/g6BWZGmt7XK9
# V. Explanation of Common Errors
{ "errMsg": "A:fail api scope is not declared in the privacy agreement", "errno": 112 }
Used to the A Privacy interface, but the developer is not in theMP Background - Settings - Service Content Statement - User privacy protection guidelinesDeclare the collection A The privacy type corresponding to the interface. Additional Privacy Type Statement, Will take effect in five minutes.{ "errMsg": "A:fail appid privacy api banned" }
Used to the A Privacy interface, but the developer is in the mp When the arraignment is checked, the "privacy is not collected," or the privacy agreement is not declared, and the interface call permission is recycled by the platform.
# VI. Official Privacy Popup Function Dxplaination
In order to enable developers to more easily complete the mini program privacy compliance requirements, in addition to the privacy agreement development through the above guidelines, the platform also provides an official privacy authorization pop-up window. This pop-up window will be opened after privacy-related features are enabled (after October 17, 2023, or after the developer app.json In Configuration __usePrivacyCheck__: true
After), without the need for developers to adapt the development, automatically to the C End user display. The specific logic is:
When the developer calls the privacy-related interface, WeChat will determine whether the call needs to be triggered. wx.onNeedPrivacyAuthorization If the developer does not respond after triggering, WeChat will take the initiative to pop up the official pop-up window. If the user agrees, the interface will execute subsequent invocation logic normallyIf the user refuses, an error will be reported.
It should be noted that the user may reject the official privacy authorization popup, In order to avoid excessive pop-ups disturbing the user, when the developer calls the privacy-related interface again, if it is less than 10 seconds from the last user's refusal, it will no longer trigger the pop-ups, and directly give the developer an error message that the user refuses the privacy authorization pop-ups.
The official privacy pop-up will come in two styles:
- Coupled with the authorization pop-up style: the user in this pop-up window need to check the privacy agreement can be allowed to operate, if the user in the pop-up window refused, error message for the user refused (error code is 103)。
- Direct pop-up style: the user side is directly authorized by the privacy agreement, if the user refuses in the pop-up window, the error message is that the user does not agree to the privacy agreement (the error code is 104)。
The style of coupling with license popups will be supported in subsequent versions of the base library (supported versions will be updated later), and all popups in the lower versions of the base library will be in the direct popup style.