# Interface call frequency specification

# Concept introduction

Weixin Mini Program wx interfaces can be divided into "normal 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 typically call back-end system resources in WeChat. In order to protect the system and prevent user resources from being misused, developers need to limit the frequency of such interfaces to a modest degree and not call them uncontrollably.

The platform will monitor the invocation of "frequency limited interface" in Weixin Mini Program, and if the Mini Program's invocation frequency of such interface exceeds the platform's specification, it will receive a reminder from the station. The system prioritizes the services of reasonably used Mini Programs in cases of resource constraints.

Developers can log in Weixin Mini Program management background - development management - interface settings to view the "frequency limited interface" call.

At present, the "bandwidth limitation interface" includes the following interfaces:

  1. wx.login
  2. wx.checkSession
  3. wx.getSetting
  4. wx.getUserInfo
  5. wx.getUserProfile

# Frequency specification

API specification Other Notes
wx.login The total number of calls per day should not be more than twice as many as the Weixin Mini Program pv, and a single user should not be more than 4 calls per second -
wx.checkSession The total number of calls per day should not be more than twice as many as the Weixin Mini Program pv, and a single user should not be more than 4 calls per second -
wx.getSetting The total number of calls per day should not be more than twice as many as the Weixin Mini Program pv, and a single user should not be more than 4 calls per second -
wx.getUserInfo The total number of calls per day should not be more than twice as many as the Weixin Mini Program pv, and a single user should not be more than 4 calls per second -
wx.getUserProfile The total number of calls per day should not be more than twice as many as the Weixin Mini Program pv, and a single user should not be more than 4 calls per second -

Tips: WeChat background will delay one day statistics on the last day of the total number of pv and api calls, more than the total number of specifications will be reminded to adjust as soon as possible.

# Optimization method

Developers can optimize the call frequency of the Frequency Limit Interface by following the following methods:

  • Cache the return results of the last call to the interface for subsequent logical reuse, rather than recalling the interface
  • Avoid repeating calls to the "Limited Frequency Interface" within the logic of a timed loop
  • Avoid initializing events on a pageonLoadonShowonReadyShould be called in Weixin Mini Program Initialization eventonLaunch

Here are examples of misuse and correct use:

  • Wx.getSetting Error Usage:
setInterval(() => {
  wx.getSetting()
}, 5000)
  • Correct usage of wx.getSetting:
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) {
        // 如果权限没有开,引导用户打开设置页开启地理位置授权
      }
    }
  })
}
  • Wx.getUserInfo Error Usage:
Page({
  onShow() {
    wx.getUserInfo()
  }
})
  • Correct usage of wx.getUserInfo:
App({
  onLaunch() {
    wx.getUserInfo()
  }
})