🎉 now you can push message to wechat
This commit is contained in:
+5
-6
@@ -7,16 +7,15 @@ async function initializeTokenStore() {
|
||||
users.forEach((user) => {
|
||||
if (user.wechatAppId) {
|
||||
tokenStore.set(user.prefix, {
|
||||
appId: user.wechatAppId,
|
||||
appSecret: user.wechatAppSecret,
|
||||
templateId: user.wechatTemplateId,
|
||||
openId: user.wechatOpenId,
|
||||
serverVerifyToken: user.wechatVerifyToken,
|
||||
wechatAppId: user.wechatAppId,
|
||||
wechatAppSecret: user.wechatAppSecret,
|
||||
wechatTemplateId: user.wechatTemplateId,
|
||||
wechatOpenId: user.wechatOpenId,
|
||||
wechatVerifyToken: user.wechatVerifyToken,
|
||||
token: '',
|
||||
});
|
||||
}
|
||||
});
|
||||
console.debug(tokenStore);
|
||||
console.log('Token store initialized.');
|
||||
}
|
||||
|
||||
|
||||
+10
-5
@@ -3,8 +3,9 @@ const { tokenStore } = require('./token');
|
||||
const config = require('../config');
|
||||
|
||||
async function refreshToken() {
|
||||
for (const item of tokenStore) {
|
||||
item.token = await this.requestToken();
|
||||
for (let [key, value] of tokenStore) {
|
||||
value.token = await requestToken(value.wechatAppId, value.wechatAppSecret);
|
||||
tokenStore.set(key, value);
|
||||
}
|
||||
console.log('Token refreshed.');
|
||||
}
|
||||
@@ -15,9 +16,13 @@ async function requestToken(appId, appSecret) {
|
||||
let res = await axios.get(
|
||||
`https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=${appId}&secret=${appSecret}`
|
||||
);
|
||||
console.log(res);
|
||||
if (res && res.data && res.data.access_token) {
|
||||
token = res.data.access_token;
|
||||
// console.debug(res);
|
||||
if (res && res.data) {
|
||||
if (res.data.access_token) {
|
||||
token = res.data.access_token;
|
||||
} else {
|
||||
console.error(res.data);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
|
||||
Reference in New Issue
Block a user