在autojs实现云端脚本(二)中,
我们实现了点击脚本列表, 弹出脚本名字的功能,
我们继续实现, 根据脚本名字下载脚本的功能.
要下载脚本,就得有脚本下载, 所以我们先去后台上传几个脚本
云脚本123.jpg
从图片中可以看到这个_File表中有字段 name, url,
我们查找脚本名字是name的url
var config = {
appId: '填写你自己的',
appKey: '填写你自己的',
}
var scriptName = "云脚本1号.js"
var scriptUrl = util.format('https://n2y09qsw.api.lncld.net/1.1/classes/_File?where={"name":"%s"}', scriptName)
var url = encodeURI(scriptUrl)
var r = http.get(url, {
headers: {
"X-LC-Id": config.appId,
"X-LC-Key": config.appKey,
"Content-Type": "application/json"
}
}).body.json()
console.log(r)
if (r.results && r.results.length > 0 && r.results[0].name === scriptName) {
log('找到了指定名字的脚本')
console.log(r.results[0].url)
} else {
log('没找到指定名字的脚本')
}
找到链接之后, 我们就可以下载脚本了.
var url='http://lc-n2Y09QsW.cn-n1.lcfile.com/3c4f3b2055b7001e439b/%E4%BA%91%E8%84%9A%E6%9C%AC1%E5%8F%B7.js'
var r=http.get(url).body.bytes()
var scriptPath='./云脚本1号.js'
files.writeBytes(scriptPath,r)