测试基础 安卓机: 批量导入 - 短信

浪里小白龙 · 2025年09月10日 · 最后由 西米 回复于 2025年09月10日 · 332 次阅读

方式一 (我用的荣耀测试机,失败了。 三星手机和 OPPO 手机可以):下载软件: SMS Backup

使用该软件,备份文件到 本机目录å

将生成的 .xml 文件,传到 本机备份的目录

点击 SMS Backup 左上角的选项 - “恢复” - 选择 “本地备份位置” -- 选择 “选择另一个备份” , 使用 脚本生成的.xml 文件, 点击 “恢复”

方式二:下载 Super Backup(我用的这个)

下载链接:https://filehippo.com/zh/android/download_super-backup-sms-contacts/

备份文件,查看短信备份文件的格式、内容,

根据备份的文件,生成对应的格式和内容文件

将生成的 xml 传到 手机中

使用 Super Backup,选择 “还原短信”,使用 脚本生成的 .xml 文件 (注意点:默认应用设置为 Super Backup )

#!usr/bin/env python
# -*- coding:utf-8 _*-
"""
@author:Zx
@file: random_sms_content.py
@time: 2025/9/9  17:47
# @describe: 随机短信内容-json 数据
"""

import json
import random
from datetime import datetime, timedelta


def generate_sms_data(num_messages=1000):
    # 基础消息模板
    message_templates = [
        {
            "addr": "TELCEL",
            "body": "Recarga HOY $50 y recibe 500Mb p/navegar, 1GB para Redes Sociales, ademas Whatsapp ilimitado con videollamadas incluidas por 7 dias. +Info *264",
            "type": 1
        },
        {
            "addr": "TELCEL",
            "body": "TU LINEA ESTA INACTIVA, REACTIVALA CON $20 Y RECIBE MIN/SMS Y WHATSAPP ILIMITADOS+200 MEGAS P/FB Y TW+100 MEGAS P/INTERNET POR 1 DIA. +INFO *264",
            "type": 1
        },
        {
            "addr": "TELCEL",
            "body": "Recarga HOY $50 y recibe 500 MB p/navegar, 1 GB para Redes Sociales, ademas Whatsapp ilimitado con videollamadas incluidas por 7 dias. Info *264",
            "type": 1
        },
        {
            "addr": "TELCEL",
            "body": "Promocion ESPECIAL: $30 por 300MB + WhatsApp ilimitado por 24 horas. Aprovecha ahora! *264#",
            "type": 1
        },
        {
            "addr": "TELCEL",
            "body": "Por tu cumpleanos te regalamos 500MB gratis! Usalos en las proximas 24 horas. Felicidades!",
            "type": 1
        },
        {
            "addr": "MOVISTAR",
            "body": "Bienvenido a MOVISTAR! Disfruta de nuestras promociones especiales. *111# para mas info",
            "type": 1
        },
        {
            "addr": "AT&T",
            "body": "AT&T te ofrece doble datos este fin de semana. Recarga $100 y obtén el doble de megas!",
            "type": 1
        }
    ]

    # 其他可能的发送方
    senders = ["TELCEL", "MOVISTAR", "AT&T", "UNEFON", "SERVICIO_CLIENTE"]

    sms_data = []
    base_timestamp = int(datetime(2024, 1, 1).timestamp() * 1000)  # 2024年1月1日作为基准时间

    for i in range(num_messages):
        # 随机选择消息模板或创建变体
        if random.random() < 0.7:  # 70%的概率使用模板消息
            template = random.choice(message_templates)
            message = template.copy()
        else:
            # 生成随机消息
            message = {
                "addr": random.choice(senders),
                "body": generate_random_message(),
                "type": 1
            }

        # 生成随机时间戳(过去365天内)
        random_days = random.randint(0, 365)
        random_hours = random.randint(0, 23)
        random_minutes = random.randint(0, 59)
        random_seconds = random.randint(0, 59)

        timestamp = base_timestamp + (
                random_days * 24 * 60 * 60 * 1000 +
                random_hours * 60 * 60 * 1000 +
                random_minutes * 60 * 1000 +
                random_seconds * 1000
        )

        # 随机阅读状态(已读或未读)
        read_status = random.choice([0, 1])

        # 构建完整消息
        sms = {
            "addr": message["addr"],
            "body": message["body"],
            "person": 0,
            "read": read_status,
            "timestamp": timestamp,
            "type": message["type"]
        }

        sms_data.append(sms)

    return sms_data


def generate_random_message():
    # 生成随机短信内容
    promotions = [
        "Oferta ESPECIAL: ",
        "Promocion limitada: ",
        "Solo por hoy: ",
        "Aprovecha esta promocion: ",
        "No te lo pierdas: "
    ]

    services = [
        "recibe minutos ilimitados",
        "obten megas gratis",
        "disfruta de WhatsApp ilimitado",
        "llamadas sin costo",
        "internet a alta velocidad"
    ]

    amounts = ["$20", "$30", "$50", "$100", "$150"]
    durations = ["por 1 dia", "por 3 dias", "por 7 dias", "por 15 dias", "por 30 dias"]
    data_amounts = ["100MB", "500MB", "1GB", "2GB", "5GB"]

    message = (
        f"{random.choice(promotions)}"
        f"Recarga {random.choice(amounts)} y "
        f"{random.choice(services)} "
        f"con {random.choice(data_amounts)} "
        f"{random.choice(durations)}. "
        f"Para mas info marca *{random.randint(100, 999)}#"
    )

    return message


# 生成1000条数据
sms_messages = generate_sms_data(1000)

# 保存到JSON文件
with open('sms_data_1000.json', 'w', encoding='utf-8') as f:
    json.dump(sms_messages, f, ensure_ascii=False, indent=2)

print(f"已生成 {len(sms_messages)} 条短信数据并保存到 sms_data_1000.json")
print("前5条数据示例:")
for i, msg in enumerate(sms_messages[:5]):
    print(f"{i + 1}. {msg['body'][:50]}...")
    print(f"   时间: {datetime.fromtimestamp(msg['timestamp'] / 1000).strftime('%Y-%m-%d %H:%M:%S')}")
    print(f"   状态: {'已读' if msg['read'] else '未读'}")
    print()

#!usr/bin/env python
# -*- coding:utf-8 _*-
"""
@author:Zx
@file: json_to_xml.py
@time: 2025/9/9  17:52
# @describe: 短信 JSON数据,转为 .xml文件(安卓手机短信格式)
"""
import json
import xml.etree.ElementTree as ET
from xml.dom import minidom
from datetime import datetime


def json_to_xml(json_file, xml_file):
    # 读取JSON数据
    with open(json_file, 'r', encoding='utf-8') as f:
        sms_data = json.load(f)

    # 创建XML根元素
    root = ET.Element("allsms")
    root.set("count", str(len(sms_data)))

    # 添加每条短信
    for sms in sms_data:
        sms_element = ET.SubElement(root, "sms")

        # 设置属性
        sms_element.set("address", sms.get("addr", ""))

        # 转换时间戳为XML格式的时间
        timestamp = sms.get("timestamp", 0)
        dt = datetime.fromtimestamp(timestamp / 1000)
        sms_element.set("time", dt.strftime("%Y年%m月%d日 %H:%M:%S"))
        sms_element.set("date", str(timestamp))

        sms_element.set("type", str(sms.get("type", 1)))
        sms_element.set("body", sms.get("body", ""))
        sms_element.set("read", str(sms.get("read", 1)))
        sms_element.set("service_center", "")
        sms_element.set("name", "")

    # 美化XML输出
    rough_string = ET.tostring(root, encoding='utf-8')
    reparsed = minidom.parseString(rough_string)
    pretty_xml = reparsed.toprettyxml(indent="\t", encoding='utf-8')

    # 写入文件
    with open(xml_file, 'wb') as f:
        f.write(pretty_xml)

    print(f"成功转换 {len(sms_data)} 条短信数据到 {xml_file}")


# 使用示例
if __name__ == "__main__":
    # 转换JSON到XML
    json_to_xml('sms_data_1000.json', 'sms_data_1000.xml')

    print("转换完成!")
  
共收到 1 条回复 时间 点赞
回复内容未通过审核,暂不显示
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册