安卓機: 批量導入-短信
方式一(我用的榮耀測試機,失敗了。 三星手機和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("轉換完成!")
本文來自博客園,作者:浪里小白龍qaq,轉載請注明原文鏈接:http://www.rzrgm.cn/xiao-bai-long/p/19083323

浙公網安備 33010602011771號