Browse Source

🐞 fix(GetToken): 修复无法获取企业微信token的问题

Pchen. 8 months ago
parent
commit
0f2a6194cc
1 changed files with 4 additions and 7 deletions
  1. 4 7
      plugin/WXWork/GetToken.js

+ 4 - 7
plugin/WXWork/GetToken.js

@@ -12,17 +12,14 @@ const GetToken = async () => {
 
     // 如果 token 未过期,直接返回 token
     if (token && tokenExpiresAt > currentTime) {
+        logger.info('返回已有企业微信token');
         return Promise.resolve(token);
     }
 
     // 否则重新获取 token
     try {
-        const response = await axios.get('https://qyapi.weixin.qq.com/cgi-bin/gettoken', {
-            params: {
-                corpid: config.wxwork.corpid,
-                corpsecret: config.wxwork.corpsecret
-            }
-        });
+        logger.info('企业微信token不存在或已过期,正在重新获取token');
+        const response = await axios.get(`https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=${config.wxwork.corpid}&corpsecret=${config.wxwork.corpsecret}`);
 
         const body = response.data;
 
@@ -37,7 +34,7 @@ const GetToken = async () => {
             throw new Error(body.errmsg);
         }
     } catch (error) {
-        logger.error(`获取企业微信 token 失败!原因:${error.message}`);
+        logger.error(`获取企业微信 token 失败!原因:${error.stack}`);
         throw error;
     }
 };