const request = require("request");
const BASE_URL = 'https://api.weixin.qq.com/cgi-bin'
const getToken = async () => {
const url = `${BASE_URL}/token?grant_type=client_credential`;
const APP_ID = 'wxxxxxxxxxxxxx';
const APP_SECRET = 'xxxxxxxxxxxxx';
return new Promise((resolve, reject) => {
request(`${url}&appid=${APP_ID}&secret=${APP_SECRET}`, (err, resp, body) => {
// 这里的body里面,每次errcode=40164,都提示ip不在白名单,而且每次的ip还都不一样
if (err) {
return reject(err);
}
const { access_token } = JSON.parse(body);
return resolve(access_token);
});
});
};
const getArticleList = async (offset, pageSize) => {
const token = await getToken();
const url = `${BASE_URL}/material/batchget_material?access_token=${token}`;
return new Promise((resolve, reject) => {
request.post({
url,
headers: { 'content-type': 'application/json' },
json: true,
body: { type: 'news', offset, count: pageSize }
}, (err, resp, body) => {
if (err) {
return reject(err);
}
return resolve(body);
});
});
};
exports.main = async (event) => {
const { offset = 0, pageSize = 20 } = event;
const res = await getArticleList(offset, pageSize);
return {
total: res.total_count,
items: res.item
};
}
每次调用 getToken 方法,都报 ip 不在白名单,我去公众号里加了这个ip后,再刷新调用,又说另外一个ip不在白名单,就这样反反复复,我都加了好多个ip到白名单了,有时候可以,有时候提示ip不在白名单。
而且,我小程序发体验版了后,发现依然会有这个问题。请问怎么根治?
云函数默认不固定ip 云函数跟小程序发版不发版没关系