同问,遇到这个问题
wx.navigateTo() 出现警告[Deprecation] ?[Deprecation] SharedArrayBuffer will require cross-origin isolation as of M92, around July 2021. See https://developer.chrome.com/blog/enabling-shared-array-buffer/ for more details. e.onmessage @ worker.js?libName=WAAccelerateWorker.js:1 [worker] reportRealtimeAction:fail not support e.workerInvokeJsApi @ worker.js?libName=WAAccelerateWorker.js:1 (anonymous) @ WAWorker.js:2 k @ WAWorker.js:2 invoke @ WAWorker.js:2 f @ WAWorker.js:2 (anonymous) @ WAWorker.js:2 re @ WAWorker.js:2 y @ WAWorker.js:2 l @ WAWorker.js:2 (anonymous) @ WAWorker.js:2 (anonymous) @ WAWorker.js:2 setTimeout (async) globalThis.setTimeout @ WAWorker.js:2 (anonymous) @ WAWorker.js:2 Q @ WAWorker.js:2 (anonymous) @ WAWorker.js:2 (anonymous) @ WAWorker.js:2 S @ WAWorker.js:2 eval @ VM10:1 e.onmessage @ worker.js?libName=WAAccelerateWorker.js:1
2022-07-03const cloud = require('wx-server-sdk') const request = require('request') class AccessToken { constructor({ appid, secret }) { this.appid = appid this.secret = secret } // 获取公众号access_token async getWechatAccessToken() { let token_url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' + this.appid + '&' + 'secret=' + this.secret; const rp = options => new Promise((resolve, reject) => { request(options, (error, response, body) => { if (error) { reject(error); } resolve(response); }); }); const result = await rp({ url: token_url, method: 'GET' }); return (typeof result.body === 'object') ? result.body : JSON.parse(result.body); } // 获取保存在数据库的公众号access_token async getCachedWechatAccessToken() { cloud.init(); let db = cloud.database(); let _this=this; let collection = 'wx-access-token'; //数据库集合名称 let gapTime = 300000; // 5 分钟 let result = await db.collection(collection).get(); if (result.code) { return null; } // 数据库没有,获取token添加到数据库 if (!result.data.length) { let accessTokenBody = await _this.getWechatAccessToken(); let act = accessTokenBody.access_token; let ein = accessTokenBody.expires_in * 1000; await db.collection(collection).add({ data: { accessToken: act, expiresIn: ein, createTime: Date.now() } }); return act; } else { // 数据库中存在token let data = result.data[0]; let { _id, accessToken, expiresIn, createTime } = data; // 判断access_token是否有效 if (Date.now() < createTime + expiresIn - gapTime) { return accessToken; } // 失效,重新获取,更新token数据 else { let accessTokenBody = await _this.getWechatAccessToken(); let act = accessTokenBody.access_token; let ein = accessTokenBody.expires_in * 1000; await db.collection(collection).doc(_id).update({ data:{ accessToken: act, expiresIn: ein, createTime: Date.now() } }); return accessTokenBody.access_token; } } } } module.exports = AccessToken
小程序调用云函数获取公众号的token失败,获取小程序的token成功?用公众号开发者对应的appid和secret换取token的时候失败,返回的错误信息如下: Error: cloud.callFunction:fail Error: errCode: -504002 functions execute fail | errMsg: Error: document.update:fail -501007 invalid parameters. [InvalidParameterValue.InvalidDoc] Document entered in the request is illegal. Please check your request, but if the problem persists, contact us. 后尝试换成小程序的appid和secret,是可以成功获取到小程序的token值的。 同样一段代码可以成功获取小程序的token但无法获取公众号的token。请帮忙看看是什么原因?
2022-02-21