autojs简单手机app截屏颜值检测

1,533 阅读1分钟
auto.waitFor()

toast("hello");
// console.show()
// console.setPosition(0, 0)
// console.setSize(device.width, device.height / 4)
// console.log("hello")
var res = app.launchPackage("xxx");
// console.log("开启app是否成功:"+res)
waitForActivity("xxx", 2000);
toast("begin to find catagray");
// var ra = new RootAutomator();
var sendButton = text("娱乐").findOne().parent();
res = sendButton.click();
// 截图
images.requestScreenCapture()

sleep(3000)

var capRes = images.captureScreen("/storage/emulated/0/0234" +".jpg");
toast("截图操作:"+capRes);
// 将截图上传
var response = http.postMultipart("https://api-cn.faceplusplus.com/facepp/v3/detect",{
    "image_file": open("/storage/emulated/0/0234" +".jpg"),
    "api_key":"xxx",
    "api_secret":"xxx",
    "return_attributes":"gender,age,beauty"
});

var respStr = response.body.string()
toast(respStr)
sleep(3000)
console.show()
console.log(respStr)
faceJson = JSON.parse(respStr)
var attributes = faceJson.faces[0].attributes
var gender = attributes.gender
var age = attributes.age
var beauty = attributes.beauty.male_score

toast("性别:" + (gender=='Female'?'女':'男') + ", 年龄: " + age +"颜值: "+ beauty)