概述:

此Python脚本用于批量请求微信小程序的封禁状态。脚本通过访问API接口https://api.52an.fun/xcx/checkxcx.php?appid=wx81894c6dbb81c2e2来获取每个小程序的封禁状态。接口返回的JSON格式数据包含了封禁状态信息,其中"code": 0表示小程序已被封禁,"code": 1表示小程序正常。

脚本源码:

import requests
import json

# API接口模板
API_URL = "https://api.52an.fun/xcx/checkxcx.php?appid={appid}"

# 读取待检查的小程序appids(可以根据需求从文件中读取或直接在这里定义)
appids = [
    "wx81894c6dbb81c2e2",  # 示例appid
    "wx1234567890abcdef",  # 添加更多appid
    # 可以继续添加更多小程序的appid
]

# 批量检查函数
def check_appids_status(appids):
    results = {}
    
    for appid in appids:
        try:
            # 发送请求获取数据
            response = requests.get(API_URL.format(appid=appid))
            # 解析JSON数据
            data = response.json()
            
            # 判断小程序是否被封禁
            if data.get("code") == 1:
                results[appid] = "正常"
            elif data.get("code") == 0:
                results[appid] = f"已被封禁,封禁原因:{data.get('status')}"
            else:
                results[appid] = "未知状态"
        except Exception as e:
            results[appid] = f"请求失败: {str(e)}"
    
    return results

# 打印所有小程序的检查结果
def print_results(results):
    for appid, status in results.items():
        print(f"小程序 AppID: {appid}, 状态: {status}")

if __name__ == "__main__":
    # 调用批量检查函数
    results = check_appids_status(appids)
    # 打印检查结果
    print_results(results)

代码介绍:

  1. API 请求:该脚本使用了 requests.get() 方法向指定的API接口发送请求,查询每个小程序的封禁状态。接口需要传入小程序的 appid 作为查询参数。
  2. 数据解析:接口返回的是一个JSON格式的响应。脚本通过 response.json() 方法将返回的JSON字符串转换为字典格式,并提取其中的 code 字段来判断小程序的封禁状态。
  3. 批量检查:在代码中,我们定义了一个列表 appids,包含了多个小程序的 appid。批量请求是通过遍历这个列表实现的,检查每个小程序的封禁状态。
  4. 结果输出:通过遍历结果字典,脚本会输出每个小程序的封禁状态。如果小程序被封禁,输出封禁原因;如果小程序正常,输出 "正常";如果发生请求失败或其他未知错误,输出错误信息。

使用方法:

  1. 安装依赖库 requests,可以使用以下命令进行安装:

    pip install requests
  2. 将需要检查的小程序的 appid 填写到 appids 列表中,或者通过读取文件等方式动态加载 appid
  3. 运行脚本,检查小程序的封禁状态。

示例输出:

小程序 AppID: wx81894c6dbb81c2e2, 状态: 已被封禁,封禁原因:存在绕开、规避或对抗平台审核监管的行为
小程序 AppID: wx1234567890abcdef, 状态: 正常

扩展功能:

  • 可以将待检查的 appid 从外部文件(例如 CSV、JSON)中读取。
  • 可以将结果保存到文件(如 JSON 或 CSV 格式)中,以便后续分析。

1 声望2 粉丝