七千二百袋水泥
七千二百袋水泥
发布于 2026-03-22 / 35 阅读

openclaw-wechat

执行:

npx -y @tencent-weixin/openclaw-weixin-cli@latest install 2>&1 | tee /home/cloudphone/media/0/openclaw/workspace/wechat-install.log

从日志中提取终端输出的 ASCII 二维码,并保存到:

/home/cloudphone/media/0/openclaw/workspace/qr_ascii_{n}.txt

创建并执行 Python 脚本:

/home/cloudphone/media/0/openclaw/workspace/ascii_to_png.py

将 ASCII 二维码转换为图片,输出到:

/home/cloudphone/media/0/openclaw/workspace/wechat_qr_{n}.png

注意事项:

1. 编号 {n} 规则:

- 扫描目录 /home/cloudphone/media/0/openclaw/workspace/

- 查找已有文件 qr_ascii_*.txt 或 wechat_qr_*.png

- 取当前最大编号 + 1 作为新的 {n}

- 若不存在历史文件,则从 1 开始

2. 二维码有效期较短,每次生成必须使用新的编号文件,禁止覆盖历史文件。

3. 若安装进程已存在,优先从 wechat-install.log 中获取最新二维码;如日志中未出现有效二维码,则终止当前安装进程后重新获取。

4. 从 /home/cloudphone/media/0/openclaw/workspace/wechat-install.log 中提取最新的 ASCII 二维码,写入对应编号文件,无需重复执行安装命令。

5. 不要主动重启 Gateway,需先询问用户,获得同意后再执行重启以使配置生效。

ascii_to_png.py参考代码,建议使用uv执行。

```python

from PIL import Image, ImageDraw

with open('/home/cloudphone/media/0/openclaw/workspace/qr_ascii.txt', 'r', encoding='utf-8') as f:

ascii_qr = f.read()

module_size = 20

quiet_zone = 4

bg_color = (255, 255, 255)

fg_color = (0, 0, 0)

lines = ascii_qr.strip().split('\n')

qr_width = len(lines[0]) if lines else 0

qr_height = len(lines) * 2

total_width = (qr_width + quiet_zone*2) * module_size

total_height = (qr_height + quiet_zone*2) * module_size

img = Image.new('RGB', (total_width, total_height), bg_color)

draw = ImageDraw.Draw(img)

def get_modules(char):

if char == ' ':

return [0,0]

elif char == '█':

return [1,1]

elif char == '▄':

return [0,1]

elif char == '▀':

return [1,0]

else:

return [1,1]

for y, line in enumerate(lines):

for x, char in enumerate(line):

modules = get_modules(char)

for row_offset, is_black in enumerate(modules):

if is_black:

left = (x + quiet_zone) * module_size

top = (y*2 + row_offset + quiet_zone) * module_size

right = left + module_size

bottom = top + module_size

draw.rectangle([left, top, right-1, bottom-1], fill=fg_color)

output_path = "/home/cloudphone/media/0/openclaw/workspace/wechat_qr.png"

img.save(output_path)

print(f'二维码图片已保存到:{output_path}')