找回密码
 立即注册
首页 业界区 业界 安卓机: 批量导入-短信

安卓机: 批量导入-短信

羔迪 2025-9-20 16:14:53
方式一(我用的荣耀测试机,失败了。 三星手机和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 )
 
  1. #!usr/bin/env python
  2. # -*- coding:utf-8 _*-
  3. """
  4. @author:Zx
  5. @file: random_sms_content.py
  6. @time: 2025/9/9  17:47
  7. # @describe: 随机短信内容-json 数据
  8. """
  9. import json
  10. import random
  11. from datetime import datetime, timedelta
  12. def generate_sms_data(num_messages=1000):
  13.     # 基础消息模板
  14.     message_templates = [
  15.         {
  16.             "addr": "TELCEL",
  17.             "body": "Recarga HOY $50 y recibe 500Mb p/navegar, 1GB para Redes Sociales, ademas Whatsapp ilimitado con videollamadas incluidas por 7 dias. +Info *264",
  18.             "type": 1
  19.         },
  20.         {
  21.             "addr": "TELCEL",
  22.             "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",
  23.             "type": 1
  24.         },
  25.         {
  26.             "addr": "TELCEL",
  27.             "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",
  28.             "type": 1
  29.         },
  30.         {
  31.             "addr": "TELCEL",
  32.             "body": "Promocion ESPECIAL: $30 por 300MB + WhatsApp ilimitado por 24 horas. Aprovecha ahora! *264#",
  33.             "type": 1
  34.         },
  35.         {
  36.             "addr": "TELCEL",
  37.             "body": "Por tu cumpleanos te regalamos 500MB gratis! Usalos en las proximas 24 horas. Felicidades!",
  38.             "type": 1
  39.         },
  40.         {
  41.             "addr": "MOVISTAR",
  42.             "body": "Bienvenido a MOVISTAR! Disfruta de nuestras promociones especiales. *111# para mas info",
  43.             "type": 1
  44.         },
  45.         {
  46.             "addr": "AT&T",
  47.             "body": "AT&T te ofrece doble datos este fin de semana. Recarga $100 y obtén el doble de megas!",
  48.             "type": 1
  49.         }
  50.     ]
  51.     # 其他可能的发送方
  52.     senders = ["TELCEL", "MOVISTAR", "AT&T", "UNEFON", "SERVICIO_CLIENTE"]
  53.     sms_data = []
  54.     base_timestamp = int(datetime(2024, 1, 1).timestamp() * 1000)  # 2024年1月1日作为基准时间
  55.     for i in range(num_messages):
  56.         # 随机选择消息模板或创建变体
  57.         if random.random() < 0.7:  # 70%的概率使用模板消息
  58.             template = random.choice(message_templates)
  59.             message = template.copy()
  60.         else:
  61.             # 生成随机消息
  62.             message = {
  63.                 "addr": random.choice(senders),
  64.                 "body": generate_random_message(),
  65.                 "type": 1
  66.             }
  67.         # 生成随机时间戳(过去365天内)
  68.         random_days = random.randint(0, 365)
  69.         random_hours = random.randint(0, 23)
  70.         random_minutes = random.randint(0, 59)
  71.         random_seconds = random.randint(0, 59)
  72.         timestamp = base_timestamp + (
  73.                 random_days * 24 * 60 * 60 * 1000 +
  74.                 random_hours * 60 * 60 * 1000 +
  75.                 random_minutes * 60 * 1000 +
  76.                 random_seconds * 1000
  77.         )
  78.         # 随机阅读状态(已读或未读)
  79.         read_status = random.choice([0, 1])
  80.         # 构建完整消息
  81.         sms = {
  82.             "addr": message["addr"],
  83.             "body": message["body"],
  84.             "person": 0,
  85.             "read": read_status,
  86.             "timestamp": timestamp,
  87.             "type": message["type"]
  88.         }
  89.         sms_data.append(sms)
  90.     return sms_data
  91. def generate_random_message():
  92.     # 生成随机短信内容
  93.     promotions = [
  94.         "Oferta ESPECIAL: ",
  95.         "Promocion limitada: ",
  96.         "Solo por hoy: ",
  97.         "Aprovecha esta promocion: ",
  98.         "No te lo pierdas: "
  99.     ]
  100.     services = [
  101.         "recibe minutos ilimitados",
  102.         "obten megas gratis",
  103.         "disfruta de WhatsApp ilimitado",
  104.         "llamadas sin costo",
  105.         "internet a alta velocidad"
  106.     ]
  107.     amounts = ["$20", "$30", "$50", "$100", "$150"]
  108.     durations = ["por 1 dia", "por 3 dias", "por 7 dias", "por 15 dias", "por 30 dias"]
  109.     data_amounts = ["100MB", "500MB", "1GB", "2GB", "5GB"]
  110.     message = (
  111.         f"{random.choice(promotions)}"
  112.         f"Recarga {random.choice(amounts)} y "
  113.         f"{random.choice(services)} "
  114.         f"con {random.choice(data_amounts)} "
  115.         f"{random.choice(durations)}. "
  116.         f"Para mas info marca *{random.randint(100, 999)}#"
  117.     )
  118.     return message
  119. # 生成1000条数据
  120. sms_messages = generate_sms_data(1000)
  121. # 保存到JSON文件
  122. with open('sms_data_1000.json', 'w', encoding='utf-8') as f:
  123.     json.dump(sms_messages, f, ensure_ascii=False, indent=2)
  124. print(f"已生成 {len(sms_messages)} 条短信数据并保存到 sms_data_1000.json")
  125. print("前5条数据示例:")
  126. for i, msg in enumerate(sms_messages[:5]):
  127.     print(f"{i + 1}. {msg['body'][:50]}...")
  128.     print(f"   时间: {datetime.fromtimestamp(msg['timestamp'] / 1000).strftime('%Y-%m-%d %H:%M:%S')}")
  129.     print(f"   状态: {'已读' if msg['read'] else '未读'}")
  130.     print()
复制代码
 
  1. #!usr/bin/env python
  2. # -*- coding:utf-8 _*-
  3. """
  4. @author:Zx
  5. @file: json_to_xml.py
  6. @time: 2025/9/9  17:52
  7. # @describe: 短信 JSON数据,转为 .xml文件(安卓手机短信格式)
  8. """
  9. import json
  10. import xml.etree.ElementTree as ET
  11. from xml.dom import minidom
  12. from datetime import datetime
  13. def json_to_xml(json_file, xml_file):
  14.     # 读取JSON数据
  15.     with open(json_file, 'r', encoding='utf-8') as f:
  16.         sms_data = json.load(f)
  17.     # 创建XML根元素
  18.     root = ET.Element("allsms")
  19.     root.set("count", str(len(sms_data)))
  20.     # 添加每条短信
  21.     for sms in sms_data:
  22.         sms_element = ET.SubElement(root, "sms")
  23.         # 设置属性
  24.         sms_element.set("address", sms.get("addr", ""))
  25.         # 转换时间戳为XML格式的时间
  26.         timestamp = sms.get("timestamp", 0)
  27.         dt = datetime.fromtimestamp(timestamp / 1000)
  28.         sms_element.set("time", dt.strftime("%Y年%m月%d日 %H:%M:%S"))
  29.         sms_element.set("date", str(timestamp))
  30.         sms_element.set("type", str(sms.get("type", 1)))
  31.         sms_element.set("body", sms.get("body", ""))
  32.         sms_element.set("read", str(sms.get("read", 1)))
  33.         sms_element.set("service_center", "")
  34.         sms_element.set("name", "")
  35.     # 美化XML输出
  36.     rough_string = ET.tostring(root, encoding='utf-8')
  37.     reparsed = minidom.parseString(rough_string)
  38.     pretty_xml = reparsed.toprettyxml(indent="\t", encoding='utf-8')
  39.     # 写入文件
  40.     with open(xml_file, 'wb') as f:
  41.         f.write(pretty_xml)
  42.     print(f"成功转换 {len(sms_data)} 条短信数据到 {xml_file}")
  43. # 使用示例
  44. if __name__ == "__main__":
  45.     # 转换JSON到XML
  46.     json_to_xml('sms_data_1000.json', 'sms_data_1000.xml')
  47.     print("转换完成!")
复制代码
  

来源:程序园用户自行投稿发布,如果侵权,请联系站长删除
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

相关推荐

前天 13:28

举报

用心讨论,共获提升!
您需要登录后才可以回帖 登录 | 立即注册