first commit
This commit is contained in:
54
SKILL.md
Normal file
54
SKILL.md
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
---
|
||||||
|
name: account-manager
|
||||||
|
description: 多平台多账号管理。管理各平台账号与Chrome Profile的对应关系,供publisher类Skill调用获取账号信息。
|
||||||
|
version: 1.0.0
|
||||||
|
author: 深圳匠厂科技有限公司
|
||||||
|
metadata:
|
||||||
|
openclaw:
|
||||||
|
emoji: "👤"
|
||||||
|
allowed-tools:
|
||||||
|
- bash
|
||||||
|
---
|
||||||
|
|
||||||
|
# 账号管理器
|
||||||
|
|
||||||
|
## 使用时机
|
||||||
|
|
||||||
|
当用户发送以下内容时触发本Skill:
|
||||||
|
- 说"初始化账号登录"、"登录搜狐账号"、"帮我登录账号"
|
||||||
|
- 说"列出账号"、"查看所有账号"、"有哪些账号"
|
||||||
|
- 说"添加账号"、"删除账号"、"获取账号信息"
|
||||||
|
|
||||||
|
## 执行步骤
|
||||||
|
|
||||||
|
### 列出某平台所有账号
|
||||||
|
```bash
|
||||||
|
python3 {baseDir}/scripts/account.py list <platform>
|
||||||
|
```
|
||||||
|
|
||||||
|
### 获取某个账号详情
|
||||||
|
```bash
|
||||||
|
python3 {baseDir}/scripts/account.py get <account_id>
|
||||||
|
```
|
||||||
|
|
||||||
|
### 初始化账号登录(首次使用,打开浏览器手动登录)
|
||||||
|
```bash
|
||||||
|
python3 {baseDir}/scripts/account.py login <account_id>
|
||||||
|
```
|
||||||
|
|
||||||
|
## 输出格式
|
||||||
|
|
||||||
|
- list:逐行返回账号ID和名称
|
||||||
|
- get:返回账号完整信息
|
||||||
|
- login:打开浏览器后提示用户手动完成登录
|
||||||
|
|
||||||
|
## 错误处理
|
||||||
|
|
||||||
|
- 账号不存在:提示"未找到该账号,请检查账号ID是否正确"
|
||||||
|
- 平台无账号:提示"该平台暂无账号,请先在accounts.json中添加"
|
||||||
|
|
||||||
|
## 注意事项
|
||||||
|
|
||||||
|
- 账号档案存储在 `accounts.json`,新增账号需手动编辑该文件
|
||||||
|
- Chrome Profile目录首次登录后自动创建,登录态永久保存
|
||||||
|
- 每个账号只需初始化登录一次
|
||||||
81
accounts.json
Normal file
81
accounts.json
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
{
|
||||||
|
"sohu": [
|
||||||
|
{
|
||||||
|
"id": "sohu_account1",
|
||||||
|
"name": "搜狐账号1",
|
||||||
|
"phone": "13800000000",
|
||||||
|
"platform": "sohu",
|
||||||
|
"profile_dir": "D:/OpenClaw/chrome-profiles/sohu_account1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "sohu_account2",
|
||||||
|
"name": "搜狐账号2",
|
||||||
|
"phone": "13900000000",
|
||||||
|
"platform": "sohu",
|
||||||
|
"profile_dir": "D:/OpenClaw/chrome-profiles/sohu_account2"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"zhihu": [
|
||||||
|
{
|
||||||
|
"id": "zhihu_account1",
|
||||||
|
"name": "知乎账号1",
|
||||||
|
"phone": "",
|
||||||
|
"platform": "zhihu",
|
||||||
|
"profile_dir": "D:/OpenClaw/chrome-profiles/zhihu_account1"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"kimi": [
|
||||||
|
{
|
||||||
|
"id": "kimi_account1",
|
||||||
|
"name": "Kimi账号1",
|
||||||
|
"phone": "13800000000",
|
||||||
|
"platform": "kimi",
|
||||||
|
"profile_dir": "D:/OpenClaw/chrome-profiles/kimi_account1"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"deepseek": [
|
||||||
|
{
|
||||||
|
"id": "deepseek_account1",
|
||||||
|
"name": "DeepSeek账号1",
|
||||||
|
"phone": "",
|
||||||
|
"platform": "deepseek",
|
||||||
|
"profile_dir": "D:/OpenClaw/chrome-profiles/deepseek_account1"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"doubao": [
|
||||||
|
{
|
||||||
|
"id": "doubao_account1",
|
||||||
|
"name": "豆包账号1",
|
||||||
|
"phone": "",
|
||||||
|
"platform": "doubao",
|
||||||
|
"profile_dir": "D:/OpenClaw/chrome-profiles/doubao_account1"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"qianwen": [
|
||||||
|
{
|
||||||
|
"id": "qianwen_account1",
|
||||||
|
"name": "千问账号1",
|
||||||
|
"phone": "",
|
||||||
|
"platform": "qianwen",
|
||||||
|
"profile_dir": "D:/OpenClaw/chrome-profiles/qianwen_account1"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"yiyan": [
|
||||||
|
{
|
||||||
|
"id": "yiyan_account1",
|
||||||
|
"name": "一言账号1",
|
||||||
|
"phone": "",
|
||||||
|
"platform": "yiyan",
|
||||||
|
"profile_dir": "D:/OpenClaw/chrome-profiles/yiyan_account1"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"yuanbao": [
|
||||||
|
{
|
||||||
|
"id": "yuanbao_account1",
|
||||||
|
"name": "元宝账号1",
|
||||||
|
"phone": "",
|
||||||
|
"platform": "yuanbao",
|
||||||
|
"profile_dir": "D:/OpenClaw/chrome-profiles/yuanbao_account1"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
134
scripts/account.py
Normal file
134
scripts/account.py
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
import sys
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
# Windows GBK 编码兼容修复
|
||||||
|
if sys.platform == "win32":
|
||||||
|
import io
|
||||||
|
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace')
|
||||||
|
sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8', errors='replace')
|
||||||
|
|
||||||
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
ACCOUNTS_FILE = os.path.join(BASE_DIR, "accounts.json")
|
||||||
|
|
||||||
|
PLATFORM_URLS = {
|
||||||
|
# 自媒体/图文平台
|
||||||
|
"sohu": "https://mp.sohu.com",
|
||||||
|
"zhihu": "https://www.zhihu.com",
|
||||||
|
"wechat": "https://mp.weixin.qq.com",
|
||||||
|
|
||||||
|
# 大模型平台
|
||||||
|
"kimi": "https://kimi.moonshot.cn",
|
||||||
|
"deepseek": "https://chat.deepseek.com",
|
||||||
|
"doubao": "https://www.doubao.com",
|
||||||
|
"qianwen": "https://tongyi.aliyun.com",
|
||||||
|
"yiyan": "https://yiyan.baidu.com",
|
||||||
|
"yuanbao": "https://yuanbao.tencent.com"
|
||||||
|
}
|
||||||
|
|
||||||
|
def load_accounts():
|
||||||
|
with open(ACCOUNTS_FILE, "r", encoding="utf-8") as f:
|
||||||
|
return json.load(f)
|
||||||
|
|
||||||
|
def cmd_list(platform="all"):
|
||||||
|
"""
|
||||||
|
修改后的 list 功能,能直观打出带着【手机号】的详细台账供AI查询匹配!
|
||||||
|
支持查全部(all),或指定(sohu)
|
||||||
|
"""
|
||||||
|
accounts = load_accounts()
|
||||||
|
if platform == "all":
|
||||||
|
platforms_to_check = accounts.keys()
|
||||||
|
else:
|
||||||
|
platforms_to_check = [platform]
|
||||||
|
|
||||||
|
found = False
|
||||||
|
for plat in platforms_to_check:
|
||||||
|
platform_accounts = accounts.get(plat, [])
|
||||||
|
for acc in platform_accounts:
|
||||||
|
phone = acc.get('phone', '未绑定手机')
|
||||||
|
print(f"账号ID:{acc['id']} | 名称:{acc['name']} | 手机号:{phone} | 平台:{acc['platform']}")
|
||||||
|
found = True
|
||||||
|
|
||||||
|
if not found:
|
||||||
|
print(f"ERROR:NO_ACCOUNTS_FOUND")
|
||||||
|
|
||||||
|
|
||||||
|
def cmd_get(account_id):
|
||||||
|
accounts = load_accounts()
|
||||||
|
for platform_accounts in accounts.values():
|
||||||
|
for acc in platform_accounts:
|
||||||
|
if acc["id"] == account_id:
|
||||||
|
print(json.dumps(acc, ensure_ascii=False))
|
||||||
|
return
|
||||||
|
print("ERROR:ACCOUNT_NOT_FOUND")
|
||||||
|
|
||||||
|
def cmd_login(account_id):
|
||||||
|
"""首次登录:打开浏览器,用户手动登录,登录态自动保存到Profile目录"""
|
||||||
|
accounts = load_accounts()
|
||||||
|
target = None
|
||||||
|
for platform_accounts in accounts.values():
|
||||||
|
for acc in platform_accounts:
|
||||||
|
if acc["id"] == account_id:
|
||||||
|
target = acc
|
||||||
|
break
|
||||||
|
|
||||||
|
if not target:
|
||||||
|
print("ERROR:ACCOUNT_NOT_FOUND")
|
||||||
|
return
|
||||||
|
|
||||||
|
profile_dir = target["profile_dir"]
|
||||||
|
os.makedirs(profile_dir, exist_ok=True)
|
||||||
|
url = PLATFORM_URLS.get(target["platform"], "https://www.google.com")
|
||||||
|
|
||||||
|
print(f"正在为账号 [{target['name']}] 打开浏览器...")
|
||||||
|
print(f"请在浏览器中完成登录,登录后直接关闭浏览器窗口即可。")
|
||||||
|
print(f"登录态将自动保存到:{profile_dir}")
|
||||||
|
|
||||||
|
# 用Playwright打开持久化浏览器,等待用户手动登录
|
||||||
|
login_script = f"""
|
||||||
|
import asyncio
|
||||||
|
from playwright.async_api import async_playwright
|
||||||
|
async def main():
|
||||||
|
async with async_playwright() as p:
|
||||||
|
browser = await p.chromium.launch_persistent_context(
|
||||||
|
user_data_dir=r"{profile_dir}",
|
||||||
|
headless=False,
|
||||||
|
channel="chrome", # 【修改处】也加上这行
|
||||||
|
no_viewport=True, # 确保浏览器内容视口也最大化
|
||||||
|
args=["--start-maximized"]
|
||||||
|
)
|
||||||
|
page = browser.pages[0] if browser.pages else await browser.new_page()
|
||||||
|
await page.goto("{url}")
|
||||||
|
print("浏览器已打开,请完成登录后关闭窗口...")
|
||||||
|
# 移除自动超时,无限等待直到用户扫码完手动关闭
|
||||||
|
await browser.wait_for_event("close", timeout=0)
|
||||||
|
print("登录态已保存!")
|
||||||
|
asyncio.run(main())
|
||||||
|
"""
|
||||||
|
|
||||||
|
import tempfile
|
||||||
|
with tempfile.NamedTemporaryFile(mode='w', suffix='.py',
|
||||||
|
delete=False, encoding='utf-8') as f:
|
||||||
|
f.write(login_script)
|
||||||
|
tmp_path = f.name
|
||||||
|
|
||||||
|
os.system(f'python "{tmp_path}"')
|
||||||
|
os.unlink(tmp_path)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
if len(sys.argv) < 2:
|
||||||
|
print("用法:python account.py list [platform] | get <id> | login <id>")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
cmd = sys.argv[1]
|
||||||
|
if cmd == "list":
|
||||||
|
# 默认不传 platform 时打出 all
|
||||||
|
cmd_list(sys.argv[2] if len(sys.argv) >= 3 else "all")
|
||||||
|
elif cmd == "get" and len(sys.argv) >= 3:
|
||||||
|
cmd_get(sys.argv[2])
|
||||||
|
elif cmd == "login" and len(sys.argv) >= 3:
|
||||||
|
cmd_login(sys.argv[2])
|
||||||
|
else:
|
||||||
|
print("参数错误")
|
||||||
|
sys.exit(1)
|
||||||
Reference in New Issue
Block a user