/*
极简云网络验证//https://yz.52tyun.com/
Autojs SDK
加密类型需要选择RC4加密-2
打开数据签名
打开签名放DATA里
代码贡献：吾爱云
2024/11/09
*/
"ui";
ui.statusBarColor(colors.parseColor("#000000"));
importClass(java.lang.Runnable);
importClass(android.animation.ObjectAnimator)
importClass(android.animation.PropertyValuesHolder)
importClass(android.animation.ValueAnimator)
importClass(android.animation.AnimatorSet)
importClass(android.view.animation.AccelerateInterpolator)
importClass(android.view.animation.TranslateAnimation)
importClass(android.animation.ObjectAnimator)
importClass(android.animation.TimeInterpolator)
importClass(android.os.Bundle)
importClass(android.view.View)
importClass(android.view.Window)
importClass(android.view.WindowManager)
importClass(android.view.animation.AccelerateDecelerateInterpolator)
importClass(android.view.animation.AccelerateInterpolator)
importClass(android.view.animation.AnticipateInterpolator)
importClass(android.view.animation.AnticipateOvershootInterpolator)
importClass(android.view.animation.BounceInterpolator)
importClass(android.view.animation.CycleInterpolator)
importClass(android.view.animation.DecelerateInterpolator)
importClass(android.view.animation.LinearInterpolator)
importClass(android.view.animation.OvershootInterpolator)
importClass(android.view.animation.PathInterpolator)
importClass(android.widget.Button)
importClass(android.widget.ImageView)
importClass(android.widget.TextView)
files.copy("./mp4/1.mp4", "/storage/emulated/0/1.mp4")
var myColor = function () {
    return '#' + getRndColor()
}

//-------------------------填写下面配置---------------------------//

var url = "yz.52tyun.com"//api请求域名
var http_Request = "https"//请求协议 http或者https
var id = "21593" //应用id
var keymy = "REni9IRALln9nPCa" //应用密钥
var rc4key = "4QwO45Y4Fzq21593" //RC4-2密钥

//--------------------------------------------------------------//


var sbm = device.getAndroidId(); //获取应用设备码
var JJY = require("./RC4.js")

ui.layoutFile('./public/ui/ui.xml') //ui
ui.ok.on('click', () => {
    ok(ui.ok)

})
ui.jb.on('click', () => {
    threads.start(function () {
        login(ui.carmi.text())
    })
    playAnimationDaShangjb(ui.jb)
})
ui.ok1.on('click', () => {
    threads.start(function () {
        Untie(ui.carmi.text())
    })
    playAnimationDaShangjb(ui.ok1)
})
function ok(view) {
    ObjectAnimator.ofFloat(view, "translationX", 0, 0, 0).setDuration(1000).start();
    ObjectAnimator.ofFloat(view, "rotation", 0, 1000, 0).setDuration(1000).start();
    ObjectAnimator.ofFloat(view, "translationY", 0, 0, 0).setDuration(1000).start();
}

function playAnimationDaShangjb(view) {
    animatorSetPeople = new AnimatorSet();
    animatorSetPeople.setDuration(1000);
    translationX = ObjectAnimator.ofFloat(view, "translationX", 0, 0, 0, 0);
    scaleX = ObjectAnimator.ofFloat(view, "scaleX", 1, 2, 1, 2, 1, 2, 1, 1.5, 1, 1.2, 1, 1.1, 1, 1.1, 1, 1.03, 1, 1.01, 1);
    scaleY = ObjectAnimator.ofFloat(view, "scaleY", 1, 2, 1, 2, 1, 2, 1, 1.5, 1, 1.2, 1, 1.1, 1, 1.1, 1, 1.03, 1, 1.01, 1);
    translationX.setStartDelay(100);
    animatorSetPeople.play(translationX).with(scaleX).with(scaleY)
    animatorSetPeople.start();
}

ui.gg.on('click', () => {
    threads.start(function () {
        announcement()
    })
    playAnimationDaShangjb(ui.gg)
})
ui.pz.on('click', () => {
    threads.start(function () {
        disposition()
    })
    playAnimationDaShangjb(ui.pz)
})



//公告获取
function announcement() {
    levitation1("公告", rc4_2("notice").msg.app_gg);
}

//配置获取
function disposition() {
    var xx = rc4_2("ini")
    levitation1("应用信息", "应用版本号:" + xx.msg.version + "\n应用版本信息:" + xx.msg.version_info + "\n应用更新说明:" + xx.msg.app_update_show + "\n更新链接:" + xx.msg.app_update_url)
}


//卡密登录
function login(kami) {
    temp = rc4_2(kami, "kmlogon")
    if (temp.code == 200) {
        //————————登录成功后需要运行的程序写这——————————



        levitation1("登录成功", "到期时间:" + timestampToTime(temp.msg.vip));


        //——————————————————————————————————————————————
    } else {
        levitation1(temp.msg, '')
    }
}



//卡密解绑
function Untie(kami) {
    temp = rc4_2(kami, "kmunmachine")
    levitation1(temp.msg, "")

}


//自定义对话框
function levitation1(_data, _content) {
    var textContent = _data;
    var _textContent = _content;
    let view = ui.inflate(
        <frame gravity="center">
            <card w="*" h="auto" layout_gravity='center'>
                <img src="file://./res/a9l.png" layout_gravity="center" scaleType="fitXY" />
                <vertical margin='40'>
                    <text textStyle='bold' textSize='20' text={textContent} gravity='center' />
                    <text textStyle='bold|italic' text={_textContent} gravity='center' />
                </vertical>

            </card>
        </frame>
        , null, false);

    d = dialogs.build({
        customView: view,
        wrapInScrollView: false,
    }).show();


}






var path = "/storage/emulated/0/1.mp4"
ui.video.setOnCompletionListener(function () {
    //视频重复播放
    ui.run(() => {
        ui.video.setVideoPath(path);
        ui.video.start();
    });
});
threads.start(function () {
    ui.run(() => {
        ui.video.setVideoPath(path);
        ui.video.start();

    });

});
ui.tv_text.setSelected(true);
v = ui.tv_text
r = "0"
g = "0"
b = "0"
threads.start(function () {
    setInterval(function () {
        ui.run(function () {
            if (r < "255".toString(16) && g == 0 && b == 0) {
                r++
                var rgb = 整理(r, g, b)
                v.textColor = colors.parseColor(rgb)
            }
            //初始+r
            if (r == "255".toString(16) && g < "255".toString(16) && b == 0) {
                g++
                var rgb = 整理(r, g, b)
                v.textColor = colors.parseColor(rgb)
            }
            //渐变到黄
            if (r <= "255".toString(16) && g == "255".toString(16) && b == 0 && r != 0) {
                r--
                var rgb = 整理(r, g, b)
                v.textColor = colors.parseColor(rgb)
            }
            //渐变到绿
            if (r == 0 && g == "255".toString(16) && b < "255".toString(16)) {
                b++
                var rgb = 整理(r, g, b)
                v.textColor = colors.parseColor(rgb)
            }
            //渐变到青
            if (r == 0 && g <= "255".toString(16) && b == "255".toString(16) && g != 0) {
                g--
                var rgb = 整理(r, g, b)
                v.textColor = colors.parseColor(rgb)
            }
            //渐变到蓝
            if (r < "255".toString(16) && g == 0 && b == "255".toString(16)) {
                r++
                var rgb = 整理(r, g, b)
                v.textColor = colors.parseColor(rgb)
                //渐变到紫
            }
            if (r == "255".toString(16) && g == 0 && b <= "255".toString(16) && b != 0) {
                b--
                var rgb = 整理(r, g, b)
                v.textColor = colors.parseColor(rgb)
            }
            //渐变到红
        })
    }, 10)
})


function 整理(r, g, b) {
    if (r > 255 || g > 255 || b > 255) {
        return "#ffffff"
    }

    if (r <= "15".toString(16)) {
        r = "0" + r.toString(16)

    }
    r = r.toString(16)

    if (g <= "15".toString(16)) {
        g = "0" + g.toString(16)

    }
    g = g.toString(16)

    if (b <= "15".toString(16)) {
        b = "0" + b.toString(16)

    }
    b = b.toString(16)

    return "#" + r + g + b
}




ui.emitter.on("resume", () => {
    ui.run(() => {
        //当返回界面，视频重新刷新
        ui.video.setVideoPath(path);
        ui.video.start();
    });
})



ui.carmi.addTextChangedListener({
    afterTextChanged: function (_s) {
        ok(ui.ok)
    }
});




function rc4_2(name, api) { //卡密登录RC4-2解密
    if (api === undefined) {
        api = name;
    }
    arr = {
        "app": id,
        "kami": name,
        "markcode": sbm,
        "t": getTimestamp(),
        "key": keymy
    }
    var Random = $crypto.digest(arr.t + arr.key + arr.markcode, "MD5")
    var md5 = $crypto.digest("kami=" + arr.kami + "&markcode=" + arr.markcode + "&t=" + arr.t + "&" + arr.key, "MD5")
    var bac = JJY.RC4(rc4key, 'kami=' + arr.kami + '&markcode=' + arr.markcode + '&t=' + arr.t + '&sign=' + md5 + "&value=" + Random, 0)

    var temp = http.post(http_Request + "://" + url + '/api.php?api=' + api + '&app=' + arr.app + '&data=' + bac, {
        "": "undefined"
    }, {
        "headers": {
            "Host": url,
            "Connection": "Keep-Alive",
            "User-Agent": "http/3.11.0"
        }
    }).body.string()
    try {
        //log(temp)
        var temp = JSON.parse(JJY.RC4(rc4key, temp.replace("\n", ""), 1))

    } catch (e) {
        alert("加密类型错误")
        return false;
    }

    var db = $crypto.digest(temp.time + arr.key + Random, "MD5")
    if (api == "kmlogon") {
        if (db !== temp.check) {
            alert("数据被修改，终止运行")
            return false;
        } else {
            return temp;
        }
    } else {
        return temp;
    }
}

function getTimestamp() {
    try {
        let res = http.get("http://api.m.taobao.com/rest/api3.do?api=mtop.common.getTimestamp");
        let data = res.body.json();
        return Math.floor(data["data"]["t"] / 1000);
    } catch (error) {
        return Math.floor(new Date().getTime() / 1000);
    }
}

function timestampToTime(timestamp) {
    var date = new Date(timestamp * 1000),
        Y = date.getFullYear() + '-',
        M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-', //月份
        D = date.getDate() + ' ',
        h = date.getHours() + ':',
        m = date.getMinutes() + ':',
        s = date.getSeconds()
    return Y + M + D + h + m + s
}

