美乐验证码登录取token+自动生成ua

美乐验证码登录取token+自动生成ua

import requests
import random
import json

def generate_random_android_ua():
    """
    随机生成符合指定格式的Android WebView UA
    模板:Mozilla/5.0 (Linux; Android {系统版本}; {设备型号} Build/{Build号}; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/{Chrome版本} Mobile Safari/537.36
    """
    # 随机参数池(基于真实Redmi设备特征)
    android_versions = ["11", "12", "13", "14"]  # Android系统版本
    devices = [
        "Redmi Note 8 Pro", "Redmi Note 9 Pro", "Redmi Note 10 Pro",
        "Redmi K40", "Redmi K50", "Redmi K60", "Redmi 10X", "Redmi 12C"
    ]  # Redmi设备型号
    build_numbers = [
        "RP1A.200720.011", "RKQ1.200826.002", "SKQ1.211006.001",
        "TKQ1.221114.001", "UP1A.230905.001", "VP1A.240205.002"
    ]  # 真实Build编号
    chrome_versions = [
        "87.0.4280.141", "88.0.4324.181", "90.0.4430.212",
        "92.0.4515.131", "96.0.4664.45", "100.0.4896.79"
    ]  # 真实Chrome版本
    
    # 随机选择参数
    android_ver = random.choice(android_versions)
    device = random.choice(devices)
    build = random.choice(build_numbers)
    chrome_ver = random.choice(chrome_versions)
    
    # 拼接UA
    ua = f"Mozilla/5.0 (Linux; Android {android_ver}; {device} Build/{build}; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/{chrome_ver} Mobile Safari/537.36"
    return ua

def get_verification_code(phone, user_agent):
    """获取验证码"""
    url = f'http://app.cslgkj.cn/api/auth/code?phone={phone}'
    headers = {
        'User-Agent': user_agent,
        'Connection': 'Keep-Alive',
        'Accept-Encoding': 'gzip',
        'Cache-Control': 'no-cache',
        'token': 'jL3wOjnadcoKChLimdz+V+MaMV3cXdtED1Bk2d0cdw8=',
        'deviceId': '3cd23421d73d23a5',
        'client': 'app',
        'deviceType': 'Android'
    }
    
    try:
        response = requests.get(url, headers=headers, timeout=10)
        if response.status_code == 200:
            result = response.json()
            if result.get('code') == 200:
                print(f"✅ 验证码已发送至手机号 {phone},请查收")
                return True
            else:
                print(f"❌ 获取验证码失败:{result.get('msg', '未知错误')}")
                return False
        else:
            print(f"❌ 获取验证码失败,状态码:{response.status_code},响应:{response.text}")
            return False
    except Exception as e:
        print(f"❌ 获取验证码出错:{str(e)}")
        return False

def phone_login(phone, code, user_agent):
    """手机号登录获取token"""
    url = 'http://app.cslgkj.cn/api/auth/phoneLogin'
    headers = {
        'User-Agent': user_agent,
        'Connection': 'Keep-Alive',
        'Accept-Encoding': 'gzip',
        'recommend': '',
        'Cache-Control': 'no-cache',
        'token': 'jL3wOjnadcoKChLimdz+V+MaMV3cXdtED1Bk2d0cdw8=',
        'deviceId': '3cd23421d73d23a5',
        'client': 'app',
        'deviceType': 'Android',
        'Content-Type': 'application/json;charset=UTF-8'
    }
    data = {
        "code": code,
        "phone": phone
    }
    
    try:
        response = requests.post(url, headers=headers, json=data, timeout=10)
        if response.status_code == 200:
            result = response.json()
            if result.get('code') == 200:
                login_token = result.get('data', '')
                if login_token:
                    print(f"✅ 登录成功,获取到token:{login_token}")
                    return login_token
                else:
                    print(f"❌ 登录成功但data字段为空,响应:{result}")
                    return None
            else:
                print(f"❌ 登录失败:{result.get('msg', '未知错误')},响应:{result}")
                return None
        else:
            print(f"❌ 登录失败,状态码:{response.status_code},响应:{response.text}")
            return None
    except Exception as e:
        print(f"❌ 登录出错:{str(e)}")
        return None

def get_auth_token(login_token, user_agent, phone):
    """调用/auth接口获取authCode,再调用sync接口获取Bearer token"""
    # 第一步:调用/api/v1/app/apk/xjsdk/auth获取authCode
    auth_url = 'http://app.cslgkj.cn/api/v1/app/apk/xjsdk/auth'
    auth_headers = {
        'User-Agent': user_agent,
        'Connection': 'Keep-Alive',
        'Accept-Encoding': 'gzip',
        'Cache-Control': 'no-cache',
        'token': login_token,
        'deviceId': '3cd23421d73d23a5',
        'client': 'app',
        'deviceType': 'Android',
        'Content-Type': 'application/json;charset=UTF-8'
    }
    auth_data = {
        "appId": "app003",
        "codeChallenge": "7FXKujT_bXZT0C52zdZoo3T07tmJ25twXlwYWODLHSU"
    }
    
    try:
        auth_response = requests.post(auth_url, headers=auth_headers, json=auth_data, timeout=10)
        if auth_response.status_code == 200:
            auth_result = auth_response.json()
            if auth_result.get('code') == 200:
                auth_code = auth_result.get('data', {}).get('authCode', '')
                if auth_code:
                    print(f"✅ 获取到authCode:{auth_code}")
                else:
                    print(f"❌ auth接口data中无authCode字段,响应:{auth_result}")
                    return None
            else:
                print(f"❌ auth接口调用失败:{auth_result.get('msg', '未知错误')}")
                return None
        else:
            print(f"❌ auth接口调用失败,状态码:{auth_response.status_code},响应:{auth_response.text}")
            return None
    except Exception as e:
        print(f"❌ 调用auth接口出错:{str(e)}")
        return None
    
    # 第二步:调用sync接口获取Bearer token
    sync_url = 'https://sdk.xjdy2024.com/api/user/sync'
    sync_headers = {
        'User-Agent': user_agent,
        'Accept-Encoding': 'gzip',
        'Content-Type': 'application/json',
        'x-app-id': 'app003',
        'xj-sdk-version': '1.0.7',
        'xj-sdk-code-version': '113'
    }
    sync_data = {
        "app_id":"app003",
        "auth_code": auth_code,
        "third_user_id":"72512",
        "third_username":f"用户{phone[-4:]}",
        "nickname":f"用户{phone[-4:]}",
        "avatar_url":"",
        "phone": phone,
        "inviter_third_user_id":"",
        "code_verifier":"D0_upf5VqTeHaA1F9kxRKd8Y1RKeyHIsHsfqnMcZJg4"
    }
    
    try:
        sync_response = requests.post(sync_url, headers=sync_headers, json=sync_data, timeout=10)
        if sync_response.status_code == 200:
            sync_result = sync_response.json()
            print(f"📝 sync接口完整响应:{sync_result}")
            
            # 从result.token提取最终token
            bearer_token = sync_result.get('result', {}).get('token', '')
            if bearer_token:
                print(f"✅ 获取到Bearer token:{bearer_token}")
                return bearer_token
            else:
                print(f"❌ sync接口result中无token字段,响应:{sync_result}")
                return None
        else:
            print(f"❌ sync接口调用失败,状态码:{sync_response.status_code},响应:{sync_response.text}")
            return None
    except Exception as e:
        print(f"❌ 调用sync接口出错:{str(e)}")
        return None

def save_to_file(phone, bearer_token, user_agent, filename='token_result.txt'):
    """保存结果到文本文件,格式:手机号----Bearer token----user-agent"""
    full_bearer_token = f"Bearer {bearer_token}"
    content = f"{phone}----{full_bearer_token}----{user_agent}\n"
    try:
        with open(filename, 'a', encoding='utf-8') as f:
            f.write(content)
        print(f"✅ 结果已保存到 {filename}")
    except Exception as e:
        print(f"❌ 保存文件出错:{str(e)}")

def main():
    print("===== 手机号登录获取Token脚本 =====")
    phone = input("请输入手机号:").strip()
    if not phone.isdigit() or len(phone) != 11:
        print("❌ 请输入有效的11位手机号!")
        return
    
    # 动态生成指定格式的随机UA
    user_agent = generate_random_android_ua()
    print(f"✅ 生成的随机User-Agent:{user_agent}")
    
    print("🔄 正在发送验证码...")
    if not get_verification_code(phone, user_agent):
        return
    
    code = input("请输入收到的验证码:").strip()
    if not code.isdigit():
        print("❌ 验证码必须为数字!")
        return
    
    print("🔄 正在登录获取token...")
    login_token = phone_login(phone, code, user_agent)
    if not login_token:
        return
    
    print("🔄 正在调用auth和sync接口获取Bearer token...")
    bearer_token = get_auth_token(login_token, user_agent, phone)
    if not bearer_token:
        return
    
    save_to_file(phone, bearer_token, user_agent)
    
    print("\n===== 操作完成 =====")
    print(f"📱 手机号:{phone}")
    print(f"🔑 Bearer token:Bearer {bearer_token}")
    print(f"🌐 User-Agent:{user_agent}")

if __name__ == "__main__":
    # 安装依赖:pip install requests
    main()

直接复制代码python 运行或者自己找ai修改自己试用的版本

图片[1]-美乐验证码登录取token+自动生成ua-暴富社区
© 版权声明
THE END
喜欢就支持一下吧
点赞14 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容