JS轮询查找接口
// 轮询查找用户的订单支付状态
const statueInfo = await getPayStatus(`${orderInfo.data.orderNumberStr}`).catch(res => res);
const getPayStatus = async (orderNumber) => { // 轮询查找订单状态
let counter = 0;
const MAXCOUNTER = 3;
return new Promise((resolve) => {
const loopFun = async () => {
if (counter > MAXCOUNTER) {
resolve(false);
} else {
counter++;
const payInfo = await paySatus({ orderNumber, noLoading: true }).catch(res => res);
console.log(' === payinfo ==', payInfo);
if (payInfo?.data?.status && parseInt(payInfo.data.status) === 2) {
resolve(true);
} else {
setTimeout(() => {
loopFun();
}, 1000)
}
}
}
loopFun();
})
};
本文标题:JS轮询查找接口
本文链接:https://www.haomeiwen.com/subject/ngwjgltx.html
网友评论