后端接口

后端接口是指在【后端服务】里执行的接口,在前端不能调用,也不受【接口安全】控制。
后端接口用法跟前端接口基本一致,不一致的地方粗体显示,未列出来的接口不可用。

$product

$product.get(_id)

$product.search(path, query, option, cache)

$product.count(path, query, cache)

$product.modify(_id, updater)

$product.create(type, x, y)

$product.delete(_id)

$product.deletes(query)

$product.changeType(oldType, newType)

$user

$user.get(_id)

$user.search(path, query, option, cache)

$user.count(path, query, cache)

$user.modify(_id, updater)

$user.delete(_id)

$user.deletes(query)

$user.create(phone, passwd, x, y)

由管理员手动创建手机号为phone,密码为passwd,具体内容为x对象的账号。
尽量少用而采用用户自主注册$me.register()或微信自动注册/扫码注册

$xdb

$xdb.get(_id)

$xdb.search(path, query, option, cache)

$xdb.count(path, query, cache)

$xdb.modify(_id, updater)

$xdb.create(type, key, x, y)

$xdb.delete(_id)

$xdb.deletes(query)

$xdb.changeType(oldType, newType)

$xtk

$xtk.get(type, key)

$xtk.modify(type, key, updater, upsert)

$xtk.delete(type, key)

$order

$order.get(_id)

$order.search(path, query, option, cache)

$order.count(path, query, cache)

$order.modify(_id, updater)

$order.create(type, desc, total, x, y)

$order.delete(_id)

$order.deletes(query)

$order.changeType(oldType, newType)

$wx

$wx.sendText(openid, txt)

$wx.sendNews(openid, article)

$wx.sendTemplate(openid, url, template_id, data)

$wx.syncOrder(_id)

$wx.refund(_id, sum, reason)

申请退款,传入原订单_id,退款金额,退款缘由。

$wx.findRefund(_id, out_refund_no)

查询退款状态,传入原订单_id和退款单号。

$socket

$socket.send(from, to, type, x, opt)

由于后端接口不一定是人触发的,不能用登录用户_id作为消息发送方,因此必须传from参数,
另外还多了opt选项:{ sendBack: false, cc: [] }。
sendBack:是否要给接口调用者也回发一次消息,前端是一定会回发的,后端默认不回发。
cc:抄送列表,同时也发送给其他人。

$api

$api.request(url, option, body)

$api.valiCode(to, code)

验证发给指定手机号/邮箱的验证码是否有效。

$rdb

即Redis缓存DB,用于临时存储数据。

$rdb.set(key, value, ttl)

插入一条字符数据value,缓存时间ttl(Time To Live)最大值为600秒,默认为60秒。
Reids是内存数据库,应节制使用,平台会阻止10分钟内超过1000次value长度超过1000字符的操作,或10分钟内超过10000次的操作。

$rdb.get(key)

取得key的数据

$rdb.del(key)

删除key的数据

search()的前后端差异

search()在前后端的用法相同,但表现有所差异。
前端取得数据后会把arr数组里的每项数据都存放在对应表路径下,比如$product.search()取得的数据会放到$c.product里;同时也会把arr数组原样到到all列表里已方便翻页的时候继续把下一页取得的数据合并到all列表里。
后端是不做这两项工作的。比如把页面request中search到的列表展示到可翻页的表格中,可以用$c.x.path.arr || $c.x.path.all,这样就可以兼顾前后两端了。

由众触低代码平台生成和驱动