q-koa 13.8.62 → 13.8.64

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -116,6 +116,12 @@ const b2bFinishUrl =
116
116
 
117
117
  const b2bSendMessageUrl =
118
118
  'https://api.weixin.qq.com/wxa/business/retailnotifybusiness?access_token=%s'
119
+
120
+ // 查询/清零接口调用次数配额(cgi_path 形如 /cgi-bin/stable_token)
121
+ const getApiQuotaUrl =
122
+ 'https://api.weixin.qq.com/cgi-bin/openapi/quota/get?access_token=%s'
123
+ const clearApiQuotaUrl =
124
+ 'https://api.weixin.qq.com/cgi-bin/openapi/quota/clear?access_token=%s'
119
125
  const fsPromise = require('fs/promises')
120
126
  const { LRUCache } = require('lru-cache')
121
127
  const FormData = require('form-data')
@@ -1111,6 +1117,30 @@ module.exports = class Singleton {
1111
1117
  }
1112
1118
  return result
1113
1119
  }
1120
+
1121
+ // 查询接口调用次数配额,cgi_path 形如 '/cgi-bin/stable_token'
1122
+ async getApiQuota(cgi_path) {
1123
+ const result = await this._withTokenRetry(async (access_token) => {
1124
+ const url = util.format(getApiQuotaUrl, access_token)
1125
+ return await wxAxios.post(url, { cgi_path }).then((res) => res.data)
1126
+ })
1127
+ if (result.errcode) {
1128
+ throw new Error(`${result.errcode};${result.errmsg}`)
1129
+ }
1130
+ return result
1131
+ }
1132
+
1133
+ // 清零接口调用次数配额(每月最多清零 50 次),返回 { errcode, errmsg }
1134
+ async clearApiQuota(cgi_path) {
1135
+ const result = await this._withTokenRetry(async (access_token) => {
1136
+ const url = util.format(clearApiQuotaUrl, access_token)
1137
+ return await wxAxios.post(url, { cgi_path }).then((res) => res.data)
1138
+ })
1139
+ if (result.errcode) {
1140
+ throw new Error(`${result.errcode};${result.errmsg}`)
1141
+ }
1142
+ return result
1143
+ }
1114
1144
  getConfig() {
1115
1145
  return this.config
1116
1146
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "13.8.62",
3
+ "version": "13.8.64",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {