autojs 云控_autojs实现云端脚本(六)

在autojs实现云端脚本(五)中, 我们把云端脚本填充到了listView中,

今天我们来实现点击运行脚本

点击list中的某个脚本

根据选中的脚本名字,下载指定脚本

运行脚本

var config = {

appId: '填写你自己的',

appKey: '填写你自己的',

}

var scriptName = "云脚本1号.js"

var scriptPath=downloadScript(scriptName)

log('开始执行下载的文件')

engines.execScriptFile(scriptPath);

log('结束执行下载的文件')

function downloadScript(scriptName) {

// 查找指定名字脚本的下载链接

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)

var scriptPath = downloadScript(r.results[0].url)

console.log('下载完毕, scriptPath=', scriptPath)

return scriptPath

} else {

log('没找到指定名字的脚本')

}

// 这是知道了下载链接,下载脚本

function downloadScript(scriptUrl) {

var r = http.get(scriptUrl).body.bytes()

var scriptPath = './' + scriptName

files.writeBytes(scriptPath, r)

return scriptPath

}

}


版权声明:本文为weixin_34435322原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。