进阶
Lua 脚本功能使用
内置的Lua脚本插件开发了7个主要的用于Lua环境的库:
- string , 点击看详细函数 (opens new window)
- math,点击看详细函数 (opens new window)
- base, 点击看详细函数 (opens new window)
- VsysService (TO BE UPDATED)
- VsysHttp
getpost(string url, string pubKey, lua.LTable body):发送post请求- body会转换成json并使用公钥加密
- 请求的header会包含加密后body的内容的签名
postwosign:发送post
- VsysRefund
- SystemUtils
Lua 脚本中禁用语法
whilecoroutine_Gcollectgarbagedofilegetfenvgetmetatableloadfileloadloadstringrawequalrawgetrawsetsetfenvsetmetatableioosdebugnewproxypackagepcallprintregsxpcallmodule
编写start, stop, refund Lua脚本函数
启动服务脚本
使用VsysHttp 和 SystemUtils 组件库。lua 插件会执行lua代码中名为start 的函数。函数的输入为lua table,包含"id", "createdAt", "duration".
Http 的请求结果应该为 map[string]string
local http = require("VsysHttp")
local util = require("SystemUtils")
func start(inputTable)
util.preventDefault()
resp = http.postwosign("http://xxxxxx/api/v1/start", inputTable)
return resp
end
结束服务脚本
和启动服务脚本一样,lua 插件会执行lua代码中名为stop的函数。函数的输入为lua table,包含"id", "createdAt"。
Http 的请求结果应该为map[string]string
退款脚本
使用VsysRefund组件库。lua插件会执行lua代码中名为refund 的函数。函数的输入依次为refund(amount, recipient, orderId). 其中amount为number,recipient和orderId为string.
local vsysRefund = require("VsysRefund")
func refund(inputTable)
orderId = inputTable["id"]
-- 用户通过orderId获取order信息,使用order信息经过计算决定amount和recipient
vsysRefund.refundInToken(amount, recipeint, orderId)
vsysRefund.refundInVsys(amount, recipient, orderId)
end
← 费用核算