# 获取模板列表

获取系统模板和用户自定义模板列表。

# 📋 API概览

# 基础信息

  • 接口地址: GET https://waterfallapi.zhaoyizhe.com/waterfall/wapi/getTemplateList
  • 请求方式: GET
  • 认证方式: 通过 accessSecret 参数认证
  • 响应格式: JSON

# 📝 请求参数

# 参数说明

参数 类型 必需 说明 示例
accessSecret string 应用密钥 5dae3031043e4.....60754
type string 模板类型
1:系统模板
2:用户自定义模板
1

# 请求示例

GET https://waterfallapi.zhaoyizhe.com/waterfall/wapi/getTemplateList?accessSecret=5dae3031043e4.....60754&type=1

# 📊 响应格式

# 成功响应

{
  "code": 1,
  "message": "操作成功!",
  "data": [
    {
      "id": "4d5e6f7g8h9i0j1k2l3m4n5o6p7q8r9s",
      "name": "物流通知模板",
      "affiliatedJson": "[{\"label\":\"物流状态\",\"type\":\"text\",\"key\":\"${title}\"},{\"label\":\"快递单号\",\"type\":\"text\",\"key\":\"${field_2}\"},{\"label\":\"预计送达\",\"type\":\"text\",\"key\":\"${field_3}\"}]"
    },
    {
      "id": "9a8b7c6d5e4f3g2h1i0j9k8l7m6n5o4p",
      "name": "系统通知模板",
      "affiliatedJson": "[{\"label\":\"通知标题\",\"type\":\"text\",\"key\":\"${title}\"},{\"label\":\"通知内容\",\"type\":\"text\",\"key\":\"${content}\"}]"
    }
  ]
}

# 错误响应

当请求失败时,会返回相应的错误码和错误信息:

{
  "code": 10011,
  "message": "应用不存在"
}

# 📋 返回字段说明

# data 数组字段

字段 类型 说明
id string 模板ID,用于发送消息时指定模板
name string 模板名称
affiliatedJson string 模板变量定义,JSON字符串格式,定义了模板需要的动态参数

# affiliatedJson 格式说明

affiliatedJson 是一个JSON字符串,定义了模板的动态变量:

[
  {
    "label": "物流状态",
    "type": "text", 
    "key": "${title}"
  },
  {
    "label": "快递单号",
    "type": "text",
    "key": "${field_2}"
  }
]
  • label: 变量显示名称
  • type: 变量类型(目前支持text)
  • key: 变量键名,用于在发送消息时替换

# ❗ 注意事项

重要提醒

  1. 认证必需: 必须提供有效的 accessSecret
  2. 模板类型:
    • type=1 获取系统模板(所有应用共享)
    • type=2 获取当前应用的自定义模板
  3. 模板状态: 只返回已审核通过的模板(status=2)
  4. 排序规则: 按创建时间倒序返回

# 🔧 使用示例

# JavaScript 示例

async function getTemplateList(accessSecret, type) {
  try {
    const response = await fetch(
      `https://waterfallapi.zhaoyizhe.com/waterfall/wapi/getTemplateList?accessSecret=${accessSecret}&type=${type}`
    );
    const result = await response.json();
    
    if (result.code === 1) {
      console.log('模板列表:', result.data);
      return result.data;
    } else {
      console.error('获取模板列表失败:', result.message);
      return null;
    }
  } catch (error) {
    console.error('请求出错:', error);
    return null;
  }
}

// 使用示例
const templates = await getTemplateList('your_access_secret', '1');

# Python 示例

import requests

def get_template_list(access_secret, template_type):
    """获取模板列表"""
    url = "https://waterfallapi.zhaoyizhe.com/waterfall/wapi/getTemplateList"
    params = {
        'accessSecret': access_secret,
        'type': template_type
    }
    
    try:
        response = requests.get(url, params=params)
        result = response.json()
        
        if result['code'] == 1:
            print('模板列表:', result['data'])
            return result['data']
        else:
            print('获取模板列表失败:', result['message'])
            return None
    except Exception as e:
        print('请求出错:', str(e))
        return None

# 使用示例
templates = get_template_list('your_access_secret', '1')

# 📞 技术支持

如果在使用过程中遇到问题:

  • 📧 邮箱: zhangxiao@zhaoyizhe.com
  • 💬 公众号: 瀑布消息

下一步: 获取用户列表 | 发送消息