Files
ai-proj-helper/skills-integration/wecom-plugin/skills/references/details.md
T
johnQ 237631147a chore(skill): 清理全部 23 条历史校验警告
- 11 个超 20KB 的 SKILL.md 拆分,大章节移入 references/details.md
- 7 处非标准字段(arguments/user_invocable)移入 metadata
- 修 req-dev 4 条相对链接;validate 跳过行内代码避免 ![](...) 误报
- validate-skills.py: 23 warns -> 0 warns,0 errors
2026-10-31 22:21:07 +08:00

8.5 KiB

skills 详细内容

通用函数封装

简单文本文档

适用于报告、记录、会议纪要等。使用符号标记章节。

def create_simple_doc(doc_name: str, content: str) -> dict:
    """
    创建简单文本文档

    Args:
        doc_name: 文档名称
        content: 文档内容(使用【】标记章节)

    Returns:
        dict: {"docid": "xxx", "url": "https://..."}

    Example:
        content = '''项目周报

━━━━━━━━━━━━━━━━━━━━━━━━━━━━

【本周完成】
1. 完成用户模块开发
2. 修复登录bug

【下周计划】
1. 开始订单模块
2. 编写测试用例
'''
        result = create_simple_doc("2026年第5周周报", content)
    """
    token = get_access_token()

    # 1. 创建文档
    create_url = f"https://qyapi.weixin.qq.com/cgi-bin/wedoc/create_doc?access_token={token}"
    create_resp = requests.post(create_url, json={
        "doc_type": 3,
        "doc_name": doc_name
    }).json()

    if create_resp.get("errcode") != 0:
        return create_resp

    docid = create_resp["docid"]
    doc_url = create_resp["url"]

    # 2. 写入内容
    update_url = f"https://qyapi.weixin.qq.com/cgi-bin/wedoc/document/batch_update?access_token={token}"
    update_resp = requests.post(update_url, json={
        "docid": docid,
        "requests": [{
            "insert_text": {
                "text": content,
                "location": {"index": 0}
            }
        }]
    }).json()

    return {
        "errcode": update_resp.get("errcode", 0),
        "docid": docid,
        "url": doc_url
    }

合同类文档(带标题样式)

适用于合同、协议等需要标题层级的正式文档。

import time

def create_contract_doc(doc_name: str, sections: list) -> dict:
    """
    创建带标题样式的合同文档

    Args:
        doc_name: 文档名称
        sections: 内容列表,格式 [(文本, 标题级别), ...]
                  标题级别: 1=主标题, 2=章节标题, 0=正文

    Returns:
        dict: {"docid": "xxx", "url": "https://..."}

    Example:
        sections = [
            ("物流服务合同", 1),
            ("合同编号: WL-2026-0201", 0),
            ("", 0),
            ("甲方(托运方)", 2),
            ("公司名称: xxx公司", 0),
            ("", 0),
            ("第一条 服务内容", 2),
            ("1.1 服务类型:货物运输", 0),
            ("1.2 货物类型:xxx", 0),
        ]
        result = create_contract_doc("物流服务合同-甲方与乙方", sections)
    """
    token = get_access_token()

    # 1. 创建文档
    create_url = f"https://qyapi.weixin.qq.com/cgi-bin/wedoc/create_doc?access_token={token}"
    create_resp = requests.post(create_url, json={
        "doc_type": 3,
        "doc_name": doc_name
    }).json()

    if create_resp.get("errcode") != 0:
        return create_resp

    docid = create_resp["docid"]
    doc_url = create_resp["url"]

    # 2. 倒序内容(因为每次在位置0插入)
    reversed_sections = list(reversed(sections))

    # 3. 分批插入(每批最多25个,留余量)
    update_url = f"https://qyapi.weixin.qq.com/cgi-bin/wedoc/document/batch_update?access_token={token}"
    batch_size = 25

    for i in range(0, len(reversed_sections), batch_size):
        batch = reversed_sections[i:i+batch_size]
        requests_list = []

        for text, level in batch:
            para = {"elements": [{"text_run": {"content": text}}]}
            if level > 0:
                para["paragraph_style"] = {"heading_level": level}

            requests_list.append({
                "insert_paragraph": {
                    "location": {"index": 0},
                    "paragraph": para
                }
            })

        resp = requests.post(update_url, json={
            "docid": docid,
            "requests": requests_list
        }).json()

        if resp.get("errcode") != 0:
            return {
                "errcode": resp.get("errcode"),
                "errmsg": resp.get("errmsg"),
                "docid": docid,
                "url": doc_url
            }

        time.sleep(0.3)  # 避免频率限制

    return {
        "errcode": 0,
        "docid": docid,
        "url": doc_url
    }


def build_contract_sections(
    title: str,
    party_a: dict,
    party_b: dict,
    clauses: list,
    signature: bool = True
) -> list:
    """
    构建合同内容结构

    Args:
        title: 合同标题
        party_a: 甲方信息 {"name": "", "code": "", "address": "", "phone": "", "legal_rep": ""}
        party_b: 乙方信息,格式同上
        clauses: 条款列表 [{"title": "第一条 xxx", "items": ["1.1 xxx", "1.2 xxx"]}, ...]
        signature: 是否包含签章栏

    Returns:
        list: 可直接传给 create_contract_doc 的 sections
    """
    sections = []

    # 标题
    sections.append((title, 1))
    sections.append(("", 0))

    # 甲方
    sections.append(("甲方", 2))
    if party_a.get("name"):
        sections.append((f"公司名称: {party_a['name']}", 0))
    if party_a.get("code"):
        sections.append((f"统一社会信用代码: {party_a['code']}", 0))
    if party_a.get("address"):
        sections.append((f"地址: {party_a['address']}", 0))
    if party_a.get("phone"):
        sections.append((f"联系电话: {party_a['phone']}", 0))
    if party_a.get("legal_rep"):
        sections.append((f"法定代表人: {party_a['legal_rep']}", 0))
    sections.append(("", 0))

    # 乙方
    sections.append(("乙方", 2))
    if party_b.get("name"):
        sections.append((f"公司名称: {party_b['name']}", 0))
    if party_b.get("code"):
        sections.append((f"统一社会信用代码: {party_b['code']}", 0))
    if party_b.get("address"):
        sections.append((f"地址: {party_b['address']}", 0))
    if party_b.get("phone"):
        sections.append((f"联系电话: {party_b['phone']}", 0))
    if party_b.get("legal_rep"):
        sections.append((f"法定代表人: {party_b['legal_rep']}", 0))
    sections.append(("", 0))

    # 条款
    for clause in clauses:
        sections.append((clause["title"], 2))
        for item in clause.get("items", []):
            sections.append((item, 0))
        sections.append(("", 0))

    # 签章
    if signature:
        sections.append(("签章", 2))
        sections.append(("", 0))
        sections.append((f"甲方(盖章): {party_a.get('name', '')}", 0))
        sections.append(("法定代表人/授权代表:________________", 0))
        sections.append(("日期:________________", 0))
        sections.append(("", 0))
        sections.append((f"乙方(盖章): {party_b.get('name', '')}", 0))
        sections.append(("法定代表人/授权代表:________________", 0))
        sections.append(("日期:________________", 0))

    return sections

使用示例

简化示例

# 简化示例:使用占位符
party_a = {"name": "甲方公司名称", "code": "甲方税号"}
party_b = {"name": "乙方公司名称", "code": "乙方税号"}
clauses = [
    {"title": "第一条 服务内容", "items": ["1.1 xxx", "1.2 xxx"]},
    {"title": "第二条 服务期限", "items": ["2.1 xxx"]},
]

sections = build_contract_sections("合同标题", party_a, party_b, clauses)
result = create_contract_doc("合同文档名称", sections)

完整示例

# 完整示例:创建物流合同
party_a = {
    "name": "重庆妗晨工贸有限公司",
    "code": "91500104MA7EJTPA6D",
    "address": "重庆市大渡口区跳磴镇海康路106号1-1",
    "phone": "15213397998"
}

party_b = {
    "name": "北京名风新能源科技有限公司",
    "code": "91110106092440790K",
    "legal_rep": "魏小健"
}

clauses = [
    {
        "title": "第一条 服务内容",
        "items": [
            "1.1 服务类型:货物运输配送服务",
            "1.2 货物类型:今麦郎系列产品",
        ]
    },
    {
        "title": "第二条 服务期限",
        "items": [
            "2.1 合同有效期:自 2026年2月1日 至 2027年1月31日",
        ]
    },
    {
        "title": "第三条 运费标准",
        "items": [
            "3.1 运费标准:今麦郎产品 2.50 元/件",
            "3.2 结算周期:月结",
        ]
    }
]

# 构建并创建文档
sections = build_contract_sections("物流服务合同", party_a, party_b, clauses)
result = create_contract_doc("物流服务合同-妗晨与名风", sections)
print(f"文档链接: {result['url']}")