if (usage == “getProxy”){
//get wx token
if (nowTime < expiryTime + wxTimeStamp) {
console.log(‘wx token is OK’)
}
else {
console.log(‘updating wx token’)
var value = {
method: ‘GET’,
uri: ’ https://api.weixin.qq.com/cgi-bin/token?grant\_type=client\_credential&appid=‘ + wxAppId + ’&secret=' + wxSecret,
json: true
}
if (proxyOn) value.proxy = ‘http://’ + proxyIP;
const newTokenData2 = await rp(value)
if (newTokenData2.access_token == null)
{
return {
validToken:false,
proxyIP: proxyIP,
proxyOn: proxyOn,
}
}
console.log('newToken2 is: ' + newTokenData2.access_token)
await db.collection(‘token’)
.where({ secret: tokenData.data[0].secret })
.update({
data:
{
wxTimeStamp: parseInt(new Date().getTime() / 1000),
wxAccessToken: newTokenData2.access_token,
},
})
console.log(‘get wx new token finished’)
}
return {
validToken: true,
proxyIP: proxyIP,
proxyOn: proxyOn,
}
}