Files
workphone-sdk/sdk/scripts/refresh_wxid_cache.sh
Manus AI 6c3accd25b
Some checks failed
SDK CI / python-compile (push) Has been cancelled
wxid 守护: cron PATH 兜底(/usr/local/bin/adb)· */5min 刷新 wxid_cache.txt
2026-06-27 22:50:34 +08:00

36 lines
1.2 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# WP-CKB-143 wxid 缓存守护脚本
# 功能:读微信 SharedPreferences wxid写入 APP files 目录供 APP 读取
# 用法bash refresh_wxid_cache.sh [device_serial]
# cron*/5 * * * * bash /path/to/refresh_wxid_cache.sh xgfe65eimrrofyws
set -e
# cron 环境 PATH 兜底adb 在 /usr/local/bin
export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:${PATH}"
DEVICE="${1:-xgfe65eimrrofyws}"
APP_PKG="com.system.cloudservice"
WX_PREFS="/data/data/com.tencent.mm/shared_prefs/com.tencent.mm_preferences.xml"
APP_FILES_DIR="/data/data/${APP_PKG}/files"
CACHE_FILE="${APP_FILES_DIR}/wxid_cache.txt"
# 确认设备在线
if ! adb -s "${DEVICE}" get-state >/dev/null 2>&1; then
echo "[ERROR] 设备 ${DEVICE} 不在线"
exit 1
fi
# 读 wxid
WXID=$(adb -s "${DEVICE}" shell "su -c 'grep -o \"wxid_[a-zA-Z0-9_]*\" ${WX_PREFS} 2>/dev/null | head -1'" 2>/dev/null | tr -d '\r\n')
if [[ ! "${WXID}" =~ ^wxid_ ]]; then
echo "[WARN] 未读到有效 wxid微信未登录或文件不可读"
exit 0
fi
# 写入 APP files 目录
adb -s "${DEVICE}" shell "su -c 'mkdir -p ${APP_FILES_DIR} && echo -n \"${WXID}\" > ${CACHE_FILE} && chmod 644 ${CACHE_FILE}'" 2>/dev/null
echo "[OK] wxid=${WXID}${CACHE_FILE}"