"""批量替换 api-config.json 中的 qrCodeUrl,UTF-8 安全""" import os, glob old = "authid=T0iOotHcDX" new = "user={{user}}&apigid={{apigid}}&fun_id=HOkkX72PMF" root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) pattern = os.path.join(root, "**", "api-config.json") count = 0 for f in glob.glob(pattern, recursive=True): with open(f, "r", encoding="utf-8") as fh: content = fh.read() if old in content: content = content.replace(old, new) with open(f, "w", encoding="utf-8", newline="\n") as fh: fh.write(content) count += 1 print(f"Updated: {os.path.relpath(f, root)}") print(f"\nTotal: {count} files updated")