# Interface call frequency specification
# Concept introduction
Mini Program WX interface can be divided into "ordinary interface" and "limited frequency interface."
"frequency limited interface" refers to a wx interface that a user is not allowed to call frequently for a period of time, Such interfaces are generally called to the WeChat background system resources, in order to protect the system, while preventing the abuse of user resources, developers need to do a moderate frequency limit on such interfaces, can not be called without restraint.
The platform will monitor the call of the "limited frequency interface" in the Mini Program. If the Mini Program calls such an interface more frequently than the platform specification, it will receive a reminder. The system will give priority to protecting the services of reasonably used Mini Programs under resource constraints.
Developers can login Mini Program management background - development management - interface settings to view the "limited frequency interface" call.
Currently, the "frequency limiting interface" includes the following interfaces:
- wx.login
- wx.checkSession
- wx.getSetting
- [wx.getUserInfo ]((wx.getUserInfo ))
- [wx.getUserProfile ]((wx.getUserProfile ))
# Frequency specification
API | specification | Other Notes |
---|---|---|
wx.login | The total number of calls a day is not more than twice the Mini Program pv, a single user a second can not be more than 4 times | - |
wx.checkSession | The total number of calls a day is not more than twice the Mini Program pv, a single user a second can not be more than 4 times | - |
wx.getSetting | The total number of calls a day is not more than twice the Mini Program pv, a single user a second can not be more than 4 times | - |
wx.getUserInfo | The total number of calls a day is not more than twice the Mini Program pv, a single user a second can not be more than 4 times | - |
wx.getUserProfile | The total number of calls a day is not more than twice the Mini Program pv, a single user a second can not be more than 4 times | - |
Tips: WeChat background will delay one day statistics on the day of the total number of Mini Program pv and api calls, more than the total number of norms will remind adjustment as soon as possible.
# Optimization method
Developers can refer to the following methods to optimize the call frequency of the "limited frequency interface":
- Cache the results of the last call to the interface for subsequent logical reuse, rather than reinvoking the interface
- Avoid repeated calls to the "frequency limiting interface" within the logic of the timing loop
- Avoid initializing events on the page
onLoad
、onShow
、onReady
Call the frequency limiting interface in the Mini Program initialization eventonLaunch
Call in
Here are examples of incorrect and correct usage:
- wx.getSetting Incorrect usage:
setInterval (() => {
wx.getSetting()
}, 5000)
- wx.getSetting Correct usage:
let setting
wx.getSetting({
success(res) {
setting = res
}
})
// When you need to get a geographic location
if (setting.authSetting['scope.userLocation']) {
wx.getLocation({
success(res) {},
fail(res) {
if (res.errMsg.indexOf ('auth deny') >= 0) {
// If permissions are not enabled, direct the user to the settings page to open geolocation authorization
}
}
})
}
- wx.getUserInfo Incorrect usage:
Page({
onShow() {
wx.getUserInfo ()
}
})
- wx.getUserInfo Correct usage:
App({
onLaunch() {
wx.getUserInfo ()
}
})