chore: auto release commit (2026-09-15 10:19:55)
All checks were successful
技能自动化发布 / release (push) Successful in 18s

This commit is contained in:
chenfuqiang
2026-09-15 10:19:55 +08:00
parent 3a80db8a7e
commit 39eacc4c4a
9 changed files with 62 additions and 77 deletions

View File

@@ -141,8 +141,8 @@ def _handle_list_holidays(args: argparse.Namespace) -> int:
def _handle_extract_invoices(args: argparse.Namespace) -> int:
return cmd_extract_invoices(
username=str(args.username or "").strip(),
password=str(args.password or "").strip(),
username="",
password="",
profile_dir=str(args.profile_dir or "").strip(),
headless=bool(args.headless),
detail_mode=bool(args.detail_mode),
@@ -151,8 +151,8 @@ def _handle_extract_invoices(args: argparse.Namespace) -> int:
def _handle_test_rpa_connection(args: argparse.Namespace) -> int:
return cmd_test_rpa_connection(
username=str(args.username or "").strip(),
password=str(args.password or "").strip(),
username="",
password="",
profile_dir=str(args.profile_dir or "").strip(),
)
@@ -192,9 +192,9 @@ def _print_full_usage() -> None:
print(" python main.py list-holidays [--year YYYY]")
print(" python main.py stats")
print(" python main.py run [target [input_id]] [-t target] [-i input_id]")
print(" python main.py extract-invoices --username U --password P --profile-dir DIR")
print(" python main.py extract-invoices --profile-dir DIR")
print(" [--headless] [--detail-mode]")
print(" python main.py test-rpa-connection --username U --password P --profile-dir DIR")
print(" python main.py test-rpa-connection --profile-dir DIR")
print(" python main.py health")
print(" python main.py config-path")
print(" python main.py version")
@@ -288,17 +288,13 @@ def build_parser() -> ZhArgumentParser:
sp.set_defaults(handler=lambda _a: cmd_stats())
# RPA commands
sp = sub.add_parser("extract-invoices", help="从网站提取发票信息")
sp.add_argument("--username", required=True, metavar="用户名")
sp.add_argument("--password", required=True, metavar="密码")
sp = sub.add_parser("extract-invoices", help="从网站提取发票信息(sandbox 需手动登录)")
sp.add_argument("--profile-dir", required=True, metavar="浏览器配置目录", dest="profile_dir")
sp.add_argument("--headless", action="store_true", help="无头模式(生产不建议)")
sp.add_argument("--detail-mode", action="store_true", help="提取详细信息", dest="detail_mode")
sp.set_defaults(handler=_handle_extract_invoices)
sp = sub.add_parser("test-rpa-connection", help="测试RPA连接和登录")
sp.add_argument("--username", required=True, metavar="用户名")
sp.add_argument("--password", required=True, metavar="密码")
sp = sub.add_parser("test-rpa-connection", help="测试RPA连接(sandbox 需手动登录)")
sp.add_argument("--profile-dir", required=True, metavar="浏览器配置目录", dest="profile_dir")
sp.set_defaults(handler=_handle_test_rpa_connection)

View File

@@ -70,9 +70,9 @@ async def _start_browser(profile_dir: str, headless: bool = False) -> tuple[Any,
@rpa_step("登录 sandbox 门户")
async def _login_sandbox_portal(page: Any, phone: str, password: str) -> bool:
"""登录 sandbox.jc2009.com 门户。"""
return await login_sandbox(page, phone, password)
async def _login_sandbox_portal(page: Any) -> bool:
"""登录 sandbox.jc2009.com 门户(人工输入)。"""
return await login_sandbox(page)
@rpa_step("进入智慧校园")
@@ -152,7 +152,7 @@ async def run_invoice_rpa(
pw, context, page = await _start_browser(profile_dir, headless)
# 步骤 2:登录 sandbox 门户
sandbox_ok = await _login_sandbox_portal(page, username, password)
sandbox_ok = await _login_sandbox_portal(page)
if not sandbox_ok:
return InvoiceRpaResult(
success=False,

View File

@@ -18,8 +18,7 @@ from jiangchang_skill_core.activity import interruptible_sleep
logger = logging.getLogger(__name__)
# ── Sandbox 门户登录配置 ──
SANDBOX_LOGIN_PHONE = "15527406659"
SANDBOX_LOGIN_PASSWORD = "qwer1234"
SANDBOX_WAIT_TIMEOUT_SEC = 180 # 等待人工完成 sandbox 登录的最长时间
# ── 智慧校园默认凭据 ──
SMART_CAMPUS_DEFAULT_USER = "demo"
@@ -35,13 +34,10 @@ async def login_if_needed(
page: Any,
username: str,
password: str,
wait_sec: int = 120,
wait_sec: int = 180,
) -> bool:
"""检查登录状态,如需要则执行登录。"""
phone = username or SANDBOX_LOGIN_PHONE
pwd = password or SANDBOX_LOGIN_PASSWORD
sandbox_ok = await login_sandbox(page, phone, pwd)
sandbox_ok = await login_sandbox(page, wait_sec=wait_sec)
if not sandbox_ok:
return False
@@ -80,60 +76,46 @@ async def _poll_until(check_fn, timeout_sec: float = 30.0) -> bool:
# ── 阶段一:登录 sandbox.jc2009.com ──
async def login_sandbox(page: Any, phone: str, password: str) -> bool:
"""登录 sandbox.jc2009.com 门户。已登录则直接返回 True。"""
logger.info("sandbox_login_start phone=%s***", phone[:3])
async def login_sandbox(page: Any, wait_sec: int = SANDBOX_WAIT_TIMEOUT_SEC) -> bool:
"""登录 sandbox.jc2009.com 门户。
- 已登录(有智慧校园/Sign out/首页 URL)→ 直接返回 True
- 未登录 → 打开登录页,提示用户在浏览器中手动完成登录,轮询等待
"""
logger.info("sandbox_login_start")
try:
if _is_sandbox_home(page.url) or await page.get_by_role("button", name=re.compile(r"Sign out|退出")).count() > 0 or await page.get_by_text("智慧校园", exact=False).count() > 0:
# 1. 检查是否已登录
if await _is_sandbox_logged_in(page):
logger.info("sandbox_already_logged_in url=%s", page.url)
return True
# 找登录表单
phone_input = page.get_by_role("textbox", name=re.compile(r"Phone|phone|手机"))
if await phone_input.count() == 0:
# 2. 打开 sandbox 首页
if await page.get_by_role("textbox", name=re.compile(r"Phone|phone|手机")).count() == 0:
await page.goto("https://sandbox.jc2009.com/", wait_until="domcontentloaded", timeout=NAVIGATION_TIMEOUT_MS)
# 用轮询替代固定等待
async def _home_check():
return _is_sandbox_home(page.url) or await page.get_by_text("智慧校园", exact=False).count() > 0
await _poll_until(_home_check, timeout_sec=10.0)
if _is_sandbox_home(page.url) or await page.get_by_text("智慧校园", exact=False).count() > 0:
await asyncio.sleep(2.0)
if await _is_sandbox_logged_in(page):
logger.info("sandbox_already_logged_in_after_redirect")
return True
phone_input = page.get_by_role("textbox", name=re.compile(r"Phone|phone|手机"))
if await phone_input.count() == 0:
logger.warning("sandbox_login_page_not_found url=%s", page.url)
return False
# 3. 提示用户手动登录
print("\n" + "=" * 50)
print("请在浏览器中手动完成 sandbox 登录")
print(f"登录地址:{page.url}")
print(f"最多等待 {wait_sec} 秒...")
print("=" * 50 + "\n")
logger.info("sandbox_waiting_for_human_login url=%s timeout=%ss", page.url, wait_sec)
logger.info("sandbox_login_page_detected")
# 输入手机号(fill 直接设值,比 type 快)
await _type_field(phone_input, phone)
# 输入密码
pwd_input = page.get_by_role("textbox", name=re.compile(r"Password|password|密码"))
if await pwd_input.count() == 0:
pwd_input = page.get_by_label("Password")
await _type_field(pwd_input, password)
# 点击 Sign in
sign_in_btn = page.get_by_role("button", name=re.compile(r"Sign in|登录"))
await sign_in_btn.click()
logger.info("sandbox_login_click_sign_in")
# 快速轮询等待登录成功
# 4. 轮询等待登录完成
async def _login_done():
return (
_is_sandbox_home(page.url)
or await page.get_by_role("button", name=re.compile(r"Sign out|退出")).count() > 0
or await page.get_by_text("智慧校园", exact=False).count() > 0
)
return await _is_sandbox_logged_in(page)
if await _poll_until(_login_done, timeout_sec=30.0):
if await _poll_until(_login_done, timeout_sec=float(wait_sec)):
logger.info("sandbox_login_success url=%s", page.url)
return True
logger.warning("sandbox_login_timeout")
print("❌ sandbox 登录超时,请重新运行。")
return False
except Exception as e:
@@ -141,6 +123,17 @@ async def login_sandbox(page: Any, phone: str, password: str) -> bool:
return False
async def _is_sandbox_logged_in(page: Any) -> bool:
"""快速检查是否已在 sandbox 首页(已登录)。"""
if _is_sandbox_home(page.url):
return True
if await page.get_by_role("button", name=re.compile(r"Sign out|退出")).count() > 0:
return True
if await page.get_by_text("智慧校园", exact=False).count() > 0:
return True
return False
# ── 阶段二:进入智慧校园 ──

View File

@@ -8,7 +8,7 @@ from jiangchang_skill_core import config
# ── 技能标识 ──
SKILL_SLUG = "verify-invoice-default"
SKILL_VERSION = "1.0.4"
SKILL_VERSION = "1.0.5"
LOG_LOGGER_NAME = "openclaw.skill.verify_invoice_default"
PLATFORM_KIT_MIN_VERSION = "1.2.11"
@@ -17,11 +17,7 @@ TARGET_PLATFORM = "jc2009"
LEASE_HOLDER = "verify-invoice-default"
LEASE_TTL_SEC = "1800"
# ── Sandbox 登录凭据 ──
SANDBOX_LOGIN_PHONE = "15527406659"
SANDBOX_LOGIN_PASSWORD = "qwer1234"
# ── 智慧校园默认凭据 ──
# ── 智慧校园默认凭据(sandbox 平台内置 demo 账号) ──
SMART_CAMPUS_DEFAULT_USER = "demo"
SMART_CAMPUS_DEFAULT_PASSWORD = "demo123"