本说明文档定义了模板表达式语法,用于配置文件中的动态字符串生成。
快速查看 - 内置函数列表
表达式使用 ${…} 包裹:
${<函数名|变量名>[(:<定义名>)][:<参数1>[,<参数2>,…]]}
<函数名|变量名>:必填,支持函数调用或变量引用(:<定义名>):可选,声明命名变量(如${username(:user)}):<参数列表>:可选,多参数用逗号,分隔- 如果函数不需要参数,可写成
${fn}或${fn:} - 变量使用示例
params = { "password" = "${password(:pass)}", "nextpassword" = "${pass}" }
-
字符串字面量(双引号)
-
内部
"和\用\"、\\转义 -
例:
${base64:"Hello, world!"} ${replace:"C:\\path\\file.txt","\\","/"}
-
-
数字字面量
- 例:
${substr:"abcdef",2,3}
- 例:
-
嵌套函数调用
- 例:
${upper:${username}}
- 例:
-
反引号模板字符串
-
支持在参数中使用
`${…}`嵌套表达式 -
例:
${base64:`ID:${qqid}, user:${username}`}- 先渲染
`User=${username};ID=${qqid}`结果 - 再对整体做 Base64 编码
- 先渲染
-
| 函数 | 参数 | 说明 | 示例 |
|---|---|---|---|
username |
— | 随机用户名 | ${username} |
password |
— | 随机密码 | ${password} |
qqid |
— | 随机 QQ 号 | ${qqid} |
email |
— | 随机电子邮箱 | ${email} |
cn_mobile |
— | 随机中国电话号码 | ${cn_mobile} |
base64 |
string |
Base64 编码 | ${base64:"test"} → dGVzdA== |
upper |
string |
转大写 | ${upper:"hello"} → HELLO |
lower |
string |
转小写 | ${lower:"HELLO"} → hello |
replace |
str, old, new |
全部替换 | ${replace:"a.b.c",".","-"} → a-b-c |
substr |
str, start[, len] |
取子串 | ${substr:"abcdef",1,3} → bcd |
random |
type, … |
生成随机值 | ${random:chars,8} ${random:number,1,100} |
choose_random |
arg1[, arg2, ...] |
从参数中随机选一个 | ${choose_random:"a","b","c"} |
-
random:chars,length[,charset]生成随机字符串(默认字符集 A–Z/a–z/0–9)。 例:${random:chars,5}、${random:chars,4,"abc"} -
random:number,max生成0到max的整数(含)。 例:${random:number,10} -
random:number,min,max生成min到max的整数(含)。 例:${random:number,100,200}
${base64:${replace:${username},"@","_"}}
解析顺序:
${username}→Steve123${replace:"alice@example.com","@","_"}→alice_example.com${base64:"alice_example.com"}→YWxpY2VfZXhhbXBsZS5jb20=