async checkSessionKey(accessToken: string, openid: string, sessionKey: string): Promise<boolean> {
// 定义请求的URL,这是微信API的固定接口地址。
const url = "https://api.weixin.qq.com/wxa/checksession"
// 构造请求参数,包括访问令牌、用户标识、使用sessionKey生成的签名和签名方法。
const parms = {
"access_token": accessToken,
"openid": openid,
"signature": this.encypeData.hmacSha256(sessionKey, ""),
"sig_method": "hmac_sha256"
}
try {
// 发起GET请求,获取微信API的响应。
const response = await this.requestGet(url, parms);
// 如果API返回的错误码为0,表示验证成功,返回true;否则返回false。
return response.errcode == 0? true : false
} catch (error) {
// 如果请求发生错误,返回false。
return false
}
}
我打算把小程序上所有调用服务器的api都走一遍checkSessionKey接口来验证登录的状态,这样会不会涉及频繁请求微信的api,我看官方文档并没有说明不允许频繁请求.或者有没有其他更好的办法来验证用户的登录态
