介绍
本文将展示如何使用 UniApp 请求接口 https://api.52an.fun/xcx/checkxcx.php?appid={appid}
来批量检查微信小程序是否被封禁。每次请求返回的数据格式为 {"code":0,"appid":"wx81894c6dbb81c2e2","status":"已被封禁,封禁原因:存在绕开、规避或对抗平台审核监管的行为"}
,其中 code
为 1
表示小程序正常,code
为 0
表示小程序被封禁,并且返回封禁原因。
UniApp 示例代码
<template>
<view class="container">
<button @click="checkMiniProgramsStatus">检查小程序状态</button>
<view v-for="(item, index) in results" :key="index">
<text>{{ item.appid }} - 状态: {{ item.status }}</text>
</view>
</view>
</template>
<script>
export default {
data() {
return {
appIds: [
'wx81894c6dbb81c2e2', // 示例 AppID 1
'wx123456789abcdef', // 示例 AppID 2
'wx9876543210abcdef', // 示例 AppID 3
],
results: []
};
},
methods: {
// 批量请求检查小程序状态
async checkMiniProgramsStatus() {
this.results = []; // 清空之前的结果
const appIds = this.appIds;
for (let i = 0; i < appIds.length; i++) {
const appId = appIds[i];
try {
const response = await this.checkAppStatus(appId);
if (response.code === 1) {
this.results.push({
appid: appId,
status: '正常'
});
} else {
this.results.push({
appid: appId,
status: '已被封禁,封禁原因:' + response.status
});
}
} catch (error) {
this.results.push({
appid: appId,
status: '请求失败: ' + error
});
}
}
},
// 请求接口获取小程序状态
checkAppStatus(appId) {
return new Promise((resolve, reject) => {
uni.request({
url: `https://api.52an.fun/xcx/checkxcx.php?appid=${appId}`,
method: 'GET',
success: (res) => {
if (res.data) {
resolve(res.data);
} else {
reject('返回数据为空');
}
},
fail: (err) => {
reject('请求失败:' + err.errMsg);
}
});
});
}
}
}
</script>
<style scoped>
.container {
padding: 20px;
}
button {
margin-bottom: 20px;
padding: 10px;
background-color: #007aff;
color: white;
border-radius: 5px;
}
text {
display: block;
margin-top: 10px;
font-size: 16px;
}
</style>
代码解释
data()
:appIds
: 存储多个微信小程序的 AppID,用于批量检查。results
: 存储每个小程序的状态结果,展示给用户。
checkMiniProgramsStatus
方法:- 遍历
appIds
列表,并对每个 AppID 发送请求。 - 对于每个请求,调用
checkAppStatus
方法获取接口返回的数据。 - 根据返回的
code
字段判断小程序的状态:code
为 1 表示正常,为 0 则表示封禁,并附带封禁原因。 - 将每个结果保存到
results
中。
- 遍历
checkAppStatus
方法:- 发送 GET 请求到指定的接口,获取小程序的状态。
- 请求成功时返回响应数据,否则抛出错误。
UI 部分:
- 使用
v-for
循环显示每个小程序的 AppID 和状态。 - 按钮触发
checkMiniProgramsStatus
方法进行批量检查。
- 使用
示例输出
如果点击检查按钮后,可能的输出结果如下:
wx81894c6dbb81c2e2 - 状态: 正常
wx123456789abcdef - 状态: 已被封禁,封禁原因:存在绕开、规避或对抗平台审核监管的行为
wx9876543210abcdef - 状态: 正常
总结
此 UniApp 示例代码实现了批量检查微信小程序封禁状态的功能。用户可以通过点击按钮,查看每个小程序的状态,并显示相关信息。该示例适用于需要同时检查多个小程序是否正常运行的场景。通过 uni.request
发送 HTTP 请求,获取接口返回的 JSON 数据,并根据返回结果动态更新页面显示。
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。