ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

淘宝/天猫/京东/拼多多618抢购软件,抢购助手支持淘金币任务,附上源码

2021-06-14 10:03:06  阅读:258  来源: 互联网

标签:toast function 618 checked 抢购 源码 ui NTP var


下载地址:https://www.lanzoui.com/b01cfbrbi

 

抢购助手是一款自动化任务助手,模拟人工,快捷、方便、安全、高效率!

 

源码

"ui";

var ColoredButton = (function() {
    //继承ui.Widget
    util.extend(ColoredButton, ui.Widget);

    function ColoredButton() {
        //调用父类构造函数
        ui.Widget.call(this);
        //自定义属性color,定义按钮颜色
        this.defineAttr("color", (view, name, defaultGetter) => {
            return this._color;
        }, (view, name, value, defaultSetter) => {
            this._color = value;
            view.attr("backgroundTint", value);
        });

    }
    ColoredButton.prototype.render = function() {
        return (
            <button textSize="16sp" style="Widget.AppCompat.Button.Colored" w="*" h="auto"/>
        );
    }

    ui.registerWidget("colored-button", ColoredButton);
    return ColoredButton;
})();

var color = "#009688";
ui.statusBarColor("#ff5050")
ui.layout(
    <drawer id="drawer" >
        <vertical>
            <appbar>
                <toolbar  id="toolbar" paddingTop="5dp" title="旧版本抢购功能" bg="#ff5050" />
                <tabs id="tabs" bg="#ff5050" />
            </appbar>
       
            <viewpager id="viewpager">

                //淘宝界面
                <frame> //start
                <ScrollView>
                <vertical>
				<Switch id="autoService" text="无障碍服务" checked="{{auto.service != null}}" padding="8 8 8 8" textSize="15sp"/>
                <Switch id="overlayService" text="悬浮窗权限" checked="{{auto.service != null}}" padding="8 8 8 8"textSize="15sp" /> 
				 <text textSize="14sp" textColor="#111111" margin="0 5" text="如果无障碍和悬浮窗提示未开启,可以关闭后重新尝试开启!抢购软件长期更新。"/>
                <text textSize="14sp" id="networkTesttwo" textColor="#ff0000" margin="0 5" text="点击校准淘宝时间!"/>
                <horizontal w="*" h="1sp" margin="0 10 0 20" bg='#ff4040'></horizontal>
                <horizontal>
                <text id="taobao"  text="使用前必须点我查看说明!软件不会记录你的支付密码,更没有能力破解你的账户,请放心使用!如不放心,可以取消自动支付!" textColor="#ff0000" w="auto" />
                </horizontal>

                <radiogroup orientation="horizontal">
                <checkbox id ="pay1" text="自动付款"/>
				<checkbox id ="bt1" text="隐藏密码" checked="false"/>
                <checkbox id ="jiance" text="检测结算价格"/>      
                </radiogroup>

                <horizontal>
				<checkbox id ="shuaxin" text="提前刷新勾选"/>
                <checkbox id ="lianxutijiao" text="连续提交"/>
                <checkbox id ="ceshi" text="测试"/>
                </horizontal>

                <horizontal>
                <text textSize="14sp" textColor="black" text="提前抢购时间"/>
                <input id="delaytime_two" textColor="gray" inputType="number" text="200" w="80"/>
                <text textSize="14sp" textColor="black" text="毫秒"  />
                </horizontal>

                <horizontal>
                <text textSize="14sp" textColor="black" text="提交订单频率"  />
                <input id="interval" textColor="gray" inputType="number" text="100" w="80"/>
                <text textSize="14sp" textColor="black" text="毫秒"  />
                </horizontal>

                <horizontal>
                <text textSize="14sp" textColor="black" text="抢购重复次数"  />
                <input id="count" textColor="gray" inputType="number" text="3" w="80"/>
                <text textSize="14sp" textColor="black" text="次"  />
                </horizontal>

                <horizontal>
                <text textSize="14sp" textColor="black" text="抢购持续时间" />
                <input id="lastTime_two" textColor="gray" inputType="number" text="10" w="80"/>
                <text textSize="14sp" textColor="black" text="秒"  />
                </horizontal>

                
                <horizontal>
                <text textSize="14sp" textColor="black" text="商品价格不等于"  />
                <input id="password_7" textColor="gray" inputType="number|numberDecimal" text="10" w="80"/>
                <text textSize="14sp" textColor="black" text="元不结算"  />
                </horizontal>
                
                <linear id="h" layout_gravity="center">                         
                <horizontal>
                <text textSize="14sp" textColor="black" text="支付密码" />
                <input id="password_1" textColor="gray"  text="*" w="45"/>
                <input id="password_2" textColor="gray"  text="*" w="45"/>
                <input id="password_3" textColor="gray"  text="*" w="45"/>
                <input id="password_4" textColor="gray"  text="*" w="45"/>
                <input id="password_5" textColor="gray"  text="*" w="45"/>
                <input id="password_6" textColor="gray"  text="*" w="45"/>
                </horizontal>
                </linear>
				
				<horizontal>
                <text textSize="14sp" textColor="black" text="提交订单坐标"  />
                <input id="X1" textColor="gray" inputType="number" text="" hint="X轴" w="80"/>
                <input id="X2" textColor="gray" inputType="number" text="" hint="Y轴" w="80"/>
				<colored-button  id="zuobiao" w="170" h="auto"    color="#ff5500" text="点击获取坐标"/>
                </horizontal>
                
				<horizontal>
                <text  text="获取并填写完坐标后,记得取消获取坐标再去淘宝开始运行!否则会崩溃!" textColor="#111111" w="auto" />
                </horizontal>
				
                <text  textSize="14sp" textColor="black" text="请输入抢购时间,格式为:2020/04/14 12:00:00"/> 
                <input hint="请输入抢购时间,格式必须正确" textColor="gray" id="startTime_two" text="2020/04/14 12:00:00"/> 
                //定义按钮的大小颜色和文本
                <colored-button id="ok_two"      layout_gravity="center"  color="#ff5500" text="开始运行"/>   
				
                </vertical>
                </ScrollView>
                </frame> //end

                //京东界面
                <frame> //start
                <ScrollView>
                <vertical>
                <text textSize="14sp" id="networkTest_tree" textColor="#ff0000" margin="0 5" text="点击校准京东时间!"/>
                <horizontal w="*" h="1sp" margin="0 10 0 20" bg='#ff4040'></horizontal>
                <horizontal>
                <text id="jingdong" text="BP链接模式不支持预约抢购商品,使用前必须点我查看说明!" textColor="#ff0000" w="auto" />
                </horizontal>

                <radiogroup orientation="horizontal">
                <radio id="model_tree" text="页面模式" checked="true"/>
                <radio id="model_four" text="购物车模式" />
                <radio id="model_five" text="BP链接模式" />
                </radiogroup>

                <horizontal>
                <text textSize="14sp" textColor="black" text="提前抢购时间"/>
                <input id="delaytime_tree" textColor="gray" inputType="number" text="800" w="80"/>
                <text textSize="14sp" textColor="black" text="毫秒"  />
                </horizontal>

                <horizontal>
                <text textSize="14sp" textColor="black" text="提交订单频率"  />
                <input id="interval" textColor="gray" inputType="number" text="100" w="80"/>
                <text textSize="14sp" textColor="black" text="毫秒"  />
                </horizontal>


                <horizontal>
                <text textSize="14sp" textColor="black" text="抢购持续时间" />
                <input id="lastTime_tree" textColor="gray" inputType="number" text="10" w="80"/>
                <text textSize="14sp" textColor="black" text="秒"  />
                </horizontal>

                <text  textSize="14sp" textColor="black" text="请输入抢购时间,格式为:2020/04/14 12:00:00"/> 
                <input id="startTime_tree" hint="请输入抢购时间,格式必须正确" textColor="gray"  text="2020/04/14 12:00:00"/> 
                //定义按钮的大小颜色和文本
                <colored-button id="ok_tree"      layout_gravity="center"    color="#ff5500"  text="开始运行"/>
				
                </vertical>
                </ScrollView>
                </frame> //end
				
				
				//苏宁界面
                <frame>  //start
                <ScrollView>
                <vertical> 
                <text textSize="14sp" id="networkTest" textColor="#ff0000" margin="0 5" text="点击校准苏宁时间!"/>
                <horizontal w="*" h="1sp" margin="0 10 0 20" bg='#ff4040'></horizontal>
                               
                <horizontal>
                <text text="请先选择正确模式再开始运行!" textColor="#ff0000" w="auto" />
                </horizontal>

                <radiogroup orientation="horizontal">
                <radio id="model_one" text="页面模式" checked="true"/>
                <radio id="model_two" text="购物车模式" />
                </radiogroup>

                <horizontal>
                <text textSize= "14sp" textColor="black" text="提前抢购时间"/>
                <input id="delaytime" textColor="gray" inputType="number" text="800" w="80"/>
                <text textSize="14sp" textColor="black" text="毫秒"  />
                </horizontal>

                <horizontal>
                <text textSize="14sp" textColor="black" text="提交订单频率"  />
                <input id="interval" textColor="gray" inputType="number" text="100" w="80"/>
                <text textSize="14sp" textColor="black" text="毫秒"  />
                </horizontal>

                <horizontal>
                <text textSize="14sp" textColor="black" text="抢购持续时间" />
                <input id="lastTime" textColor="gray" inputType="number" text="10" w="80"/>
                <text textSize="14sp" textColor="black" text="秒"  />
                </horizontal>

                <text  textSize="14sp" textColor="black" text="请输入抢购时间,格式为:2020/04/14 12:00:00"/> 
                <input hint="请输入抢购时间,格式必须正确" textColor="gray" id="startTime" text="2020/04/14 12:00:00"/> 
                //定义按钮的大小颜色和文本
                <colored-button id="ok"      layout_gravity="center"      color="#ff5500"   text="开始运行"/>
                </vertical> 
                </ScrollView>                       
                </frame>  
				//end

                
                <frame> 
                <vertical>
                <text textSize="14sp"  textColor="#ff0000" text="聚划算百亿补贴BP链接获取方法,请咨询客服。" />
                <horizontal w="*" h="1sp" margin="0 10 0 20" bg='#ff4040'></horizontal>
                <text textSize="14sp"  textColor="#111111" text="聚划算:百亿补贴" />
                <colored-button  id="ok_bp"       layout_gravity="center"   w="auto" h="auto"    color="#ff5500" text="百亿补贴BP链接"/>
               
               
                <horizontal w="*" h="1sp" margin="0 10 0 20" bg='#ff4040'></horizontal>
                <text textSize="14sp"  textColor="#111111" text="拼多多:目前只支持抢券哦!" />
                <colored-button  id="pinduoduo"       layout_gravity="center"   w="170" h="auto"    color="#ff5500" text="拼多多"/>
                <horizontal w="*" h="1sp" margin="0 10 0 20" bg='#ff4040'></horizontal>
                </vertical>
                </frame>
            </viewpager>        
        </vertical>
        <vertical layout_gravity="left" bg="#FFFFFF"  w="280">
            <img w="380" h="200" scaleType="fitXY" src="http://pic1.win4000.com/wallpaper/2020-03-12/5e69c8381c24b.jpg"/>
            <list id="menu">
                <horizontal bg="?selectableItemBackground" w="*">
                    <img w="50" h="50" padding="16" src="{{this.icon}}" tint="{{color}}"/>
                    <text textColor="black" textSize="15sp" text="{{this.title}}" layout_gravity="center"/>
                </horizontal>
            </list>
        </vertical>
    </drawer>
);


//=================================================================================
var 连续提交 = "无"
ui.lianxutijiao.on("check", (checked)=>{
    if(checked){
        连续提交= "有"
        toast("已开启连续提交功能,此功能必须填写坐标!");
    }
    else
    {
        连续提交 = "无"
    }
});
ui.zuobiao.click(function () {
    if(ui.zuobiao.getText()=="点击获取坐标") {
        ui.zuobiao.setText("取消获取坐标");    
        threads.start(获取坐标);
        device.keepScreenOn()//保持屏幕常亮
    }else{
        ui.zuobiao.setText("点击获取坐标");
        console.clear();
        console.hide();
        threads.shutDownAll();
        device.cancelKeepingAwake();   
        }
})

ui.taobao.on("click",function(){
    app.openUrl("https://docs.qq.com/doc/DU0pSZ3BTWXl4U1pk")
})
ui.jingdong.on("click",function(){
    app.openUrl("https://docs.qq.com/doc/DU0pSZ3BTWXl4U1pk")
})
var 开启刷新 = "无"
var 提前刷新 = "无"
ui.shuaxin.on("check", (checked)=>{
    if(checked){
        开启刷新= "有"
        提前刷新 = "有"
        toast("已开启购物车自动刷新功能!");
    }
    else
    {
        开启刷新 = "无"
        提前刷新 = "无"
    }
});
var 自动付款 = "无"
ui.pay1.on("check", (checked)=>{
    if(checked){
        自动付款= "有"
        toast("已开启自动付款");
    }
    else
    {
        自动付款 = "无"
    }
});

var 自动勾选 = "无"
var 手动勾选 = "有"
ui.jiance.on("check", (checked)=>{
    if(checked){
        自动勾选= "有"
        toast("已开启自动勾选商品,并检测价格进行结算!"); 
        手动勾选 = "无" 
    }
    else
    {
        自动勾选 = "无"
    }
});
//淘宝密码隐藏
ui.bt1.on("check", (checked)=>{
    if (ui.bt1.getText() == "隐藏密码") {
        ui.bt1.setText("显示密码");
        ui.h.visibility = 8;
        toast("密码已隐藏!");
    } else {
        ui.bt1.setText("隐藏密码");
        ui.h.visibility = 0;
        toast("密码已显示!");
    }
});


var 平台类别2="苏宁页面"
ui.model_one.on("check", (checked)=>{
    if(checked){
        平台类别2="苏宁页面" 
        toast("已切换到苏宁页面抢购模式")
    }
});
ui.model_two.on("check", (checked)=>{
    if(checked){
        平台类别2="苏宁购物车" 
        toast("已切换到苏宁购物车抢购模式")    
    }
});

var 平台类别="京东页面"
ui.model_tree.on("check", (checked)=>{
    if(checked){
        平台类别="京东页面" 
        toast("已切换到京东页面抢购模式")
    }
});
ui.model_four.on("check", (checked)=>{
    if(checked){
        平台类别="京东购物车" 
        toast("已切换到京东购物车抢购模式")    
    }
});
ui.model_five.on("check", (checked)=>{
    if(checked){
        平台类别="京东BP链接" 
        toast("已切换到京东BP链接抢购模式")    
    }
});

var 测试 = "无"
ui.ceshi.on("check", (checked)=>{
    if(checked){
      测试 = "有"    
    }
    else
    {
       测试 = "无"
    }
});
    //创建选项菜单(右上角)
    ui.emitter.on("create_options_menu", menu=>{ 
        menu.add("日志");  
    });
    //监听选项菜单点击
    ui.emitter.on("options_item_selected", (e, item)=>{
        switch(item.getTitle()){
            case "日志":
                app.startActivity("console");
                break;
    }
            e.consumed = true;
    });
    activity.setSupportActionBar(ui.toolbar);

    //设置滑动页面的标题
    ui.viewpager.setTitles(["淘宝","京东","苏宁","其他"]);
    //让滑动页面和标签栏联动
    ui.tabs.setupWithViewPager(ui.viewpager);
    //让工具栏左上角可以打开侧拉菜单
    ui.toolbar.setupWithDrawer(ui.drawer);

    ui.menu.setDataSource([
	
    {
         title: "使用教程",
            icon: "@drawable/ic_description_black_48dp"
    },
]);

	
    ui.menu.on("item_click", item =>{
        switch(item.title){
            case"使用教程":
            app.openUrl("https://docs.qq.com/doc/DU0pSZ3BTWXl4U1pk");
    }
    });


 
    //这里是无障碍触发方式
    ui.autoService.on("check", function(checked) {
    // 用户勾选无障碍服务的选项时,跳转到页面让用户去开启 
    if(checked && auto.service == null) { 
     app.startActivity({
     action: "android.settings.ACCESSIBILITY_SETTINGS"  }); } 
      if(!checked && auto.service != null){ 
     auto.service.disableSelf();    }    }); 
   // 当用户回到本界面时,resume事件会被触发
     ui.emitter.on("resume", function() {
    // 此时根据无障碍服务的开启情况,同步开关的状态 
    ui.autoService.checked = auto.service != null;    }); 
   //开启悬浮窗权限
    ui.overlayService.on("check", function (checked) {
    // 用户勾选无障碍服务的选项时,跳转到页面让用户去开启
    if (checked) {
        int = app.startActivity({
            packageName: "com.android.settings",
            className: "com.android.settings.Settings$AppDrawOverlaySettingsActivity",
            data: "package:" + auto.service.getPackageName().toString()
        });
        toast("请打开悬浮窗开关");
    }

     if (!checked && auto.service != null) {
         auto.service.disableSelf();
         toast("已关闭悬浮窗权限");
         }
    });


    ui.ok_bp.on("click", () => {
        // engines.execScriptFile("tb_bp.js");
        "ui";

var color = "#009688";
ui.statusBarColor("#ff4040")
ui.layout(
    <drawer id="drawer" >
        <vertical>
            <appbar>
                <toolbar  id="toolbar"paddingTop="5dp" title="聚划算百亿补贴模式"  bg="#ff4040" />
            </appbar>
       
            <viewpager id="viewpager">
                //这是聚划算百亿补贴界面
                <frame> //start
                <ScrollView>
                <vertical>
                <Switch id="autoService" text="无障碍服务" checked="{{auto.service != null}}" padding="8 8 8 8" textSize="13sp"/>
                {/* <Switch id="overlayService" text="悬浮窗权限" checked="{{auto.service != null}}" padding="8 8 8 8"textSize="13sp" />  */}
                <text textSize="13sp" id="networkTesttwo" textColor="#ff0000" margin="0 5" text="点击校准淘宝时间!"/>

                <radiogroup orientation="horizontal">
                <checkbox id ="pay1" text="自动付款"/>
				<checkbox id ="bt1" text="隐藏密码" checked="false"/>
                <checkbox id ="tijiao" text="检测提交价格"/>
                </radiogroup>
               
                <horizontal>
                <text id="lianjie" text="请输入聚划算商品BP链接!支持聚划算百亿补贴!如何获取BP链接请点击我!" textColor="#ff0000" w="auto" />
                </horizontal>


                <text textSize="14sp" textColor="black" text="商品BP链接:" />
                <input id="id1" textColor="gray"  text="h5.m.taobao.com/cart/order.html?buyParam=610051376150_1_0" w="*"/>

           
                <horizontal>
                <text textSize="13sp" textColor="black" text="提前抢购时间"/>
                <input id="delaytime_two" textColor="gray" inputType="number" text="700" w="80"/>
                <text textSize="13sp" textColor="black" text="毫秒"  />
                </horizontal>

                <horizontal>
                <text textSize="13sp" textColor="black" text="提交订单频率"  />
                <input id="interval" textColor="gray" inputType="number" text="100" w="80"/>
                <text textSize="13sp" textColor="black" text="毫秒"  />
                </horizontal>

                <horizontal>
                <text textSize="13sp" textColor="black" text="抢购持续时间" />
                <input id="lastTime_two" textColor="gray" inputType="number" text="10" w="80"/>
                <text textSize="13sp" textColor="black" text="秒"  />
                </horizontal>

                <horizontal>
                <text textSize="14sp" textColor="black" text="商品价格不等于"  />
                <input id="password_7" textColor="gray" inputType="number|numberDecimal" text="10" w="80"/>
                <text textSize="14sp" textColor="black" text="元不提交"  />
                </horizontal>

                <linear id="h" layout_gravity="center">                         
                <horizontal>
                <text textSize="13sp" textColor="black" text="支付密码:" />
                <input id="password_1" textColor="gray"  text="*" w="45"/>
                <input id="password_2" textColor="gray"  text="*" w="45"/>
                <input id="password_3" textColor="gray"  text="*" w="45"/>
                <input id="password_4" textColor="gray"  text="*" w="45"/>
                <input id="password_5" textColor="gray"  text="*" w="45"/>
                <input id="password_6" textColor="gray"  text="*" w="45"/>
                </horizontal>
                </linear>

                <text  textSize="13sp" textColor="black" text="请输入抢购时间,格式为:2020/04/14 12:00:00"/> 
                <input hint="请输入抢购时间,格式必须正确" textColor="gray" id="startTime_two" /> 
                //定义按钮的大小颜色和文本
                <colored-button  id="ok_two"      layout_gravity="center"      color="#ff5500"  text="开始运行"/>
                <colored-button  id="fastTbUrlOpen"       layout_gravity="center"     color="#ff5500"  text="点击跳转"/>
                </vertical>
                </ScrollView>
                </frame> //end

            </viewpager>        
        </vertical>
    </drawer>
);

ui.lianjie.on("click",function(){
    app.openUrl("https://docs.qq.com/doc/DU0pSZ3BTWXl4U1pk")
})
//BP跳转
ui.fastTbUrlOpen.on("click", () => {
    if(ui.id1.text() ==""){
        toast("请输入聚划算商品的BP链接!")
    }
    else {
    var url = ui.id1.text();
    app.startActivity({
        action: "android.intent.action.VIEW",
        data: "taobao://" + url,
        packageName: "com.taobao.taobao",
    });
    }
});
var 不提交订单 = "无"
var 提交订单 = "有"
ui.tijiao.on("check", (checked)=>{
    if(checked){
        不提交订单 = "有"
        提交订单 = "无"
        toast("检测商品提交价格,大于预定价格不提交!"); 
    }
    else
    {
        不提交订单 = "无"
        提交订单 = "有"
    }
});
//密码隐藏
ui.bt1.on("check", (checked)=>{
    if (ui.bt1.getText() == "隐藏密码") {
        ui.bt1.setText("显示密码");
        ui.h.visibility = 8;
        toast("密码已隐藏!");
    } else {
        ui.bt1.setText("隐藏密码");
        ui.h.visibility = 0;
        toast("密码已显示!");
    }
});
//自动付款
var 自动付款 = "无"
ui.pay1.on("check", (checked)=>{
    if(checked){
        自动付款= "有"
        toast("已开启自动付款"); 
    }
    else
    {
        自动付款 = "无"
    }
});


 //这里是无障碍触发方式
 ui.autoService.on("check", function(checked) {
    // 用户勾选无障碍服务的选项时,跳转到页面让用户去开启 
    if(checked && auto.service == null) { 
     app.startActivity({
     action: "android.settings.ACCESSIBILITY_SETTINGS"  }); } 
      if(!checked && auto.service != null){ 
     auto.service.disableSelf();    }    }); 
   // 当用户回到本界面时,resume事件会被触发
     ui.emitter.on("resume", function() {
    // 此时根据无障碍服务的开启情况,同步开关的状态 
    ui.autoService.checked = auto.service != null;    }); 
//    //开启悬浮窗权限
//     ui.overlayService.on("check", function (checked) {
//     // 用户勾选无障碍服务的选项时,跳转到页面让用户去开启
//     if (checked) {
//         int = app.startActivity({
//             packageName: "com.android.settings",
//             className: "com.android.settings.Settings$AppDrawOverlaySettingsActivity",
//             data: "package:" + auto.service.getPackageName().toString()
//         });
//         toast("请打开悬浮窗开关");
//     }

//      if (!checked && auto.service != null) {
//          auto.service.disableSelf();
//          toast("已关闭悬浮窗权限");
//          }
//     });


    // 获取时分秒用于记录日志
    function logWithTime(msg) {
        console.info(formatDate(getNow()) + " " + msg);
       }
   
       // 检测淘宝网络延迟和时间偏差
       var NTP = {
       requiredResponses: 3,
       serverTimes: [],//服务器时间
       serverDelay: [],//服务器延迟
       serverUrl: "http://api.m.taobao.com/rest/api3.do?api=mtop.common.getTimestamp",
       resyncTime: 0, // minutes
       sync: function () {
           var offset = storage.get("NTPClockOffset");//获取时钟偏移
           if (offset) {
               try {
                   var t = offset.split("|")[1];
                   var d = NTP.fixTime() - parseInt(t, 10);
                   if (d < (1000 * 60 * NTP.resyncTime)) {
                       return false;
                   }
               } catch (e) {
               }
           }
           NTP.getServerTime();
       },
       getNow: function () {
           var date = new Date();
           return date.getTime();
       },
       //分析服务器响应
       parseServerResponse: function (data) {
           var NtpStartTime = storage.get("NtpStartTime");
           var NtpStopTime = NTP.getNow();
           var origtime = parseInt(data.data.t);//起始时间
           var delay = ((NtpStopTime - NtpStartTime) / 2);//延迟
           var offset = NtpStopTime - origtime - delay;//抵消
           NTP.serverTimes.push(offset);
           NTP.serverDelay.push(delay);
   
           // 因为网络问题,需要多次获取偏移值,获取平均值
           if (NTP.serverTimes.length >= NTP.requiredResponses) {
               var sumOffset = 0;
               var sumDelay = 0;
               var i = 0;
               for (i = 0; i < NTP.serverTimes.length; i++) {
                   sumOffset += NTP.serverTimes[i];
                   sumDelay += NTP.serverDelay[i];
               }
               var averageOffset = Math.round(sumOffset / i);
               var averageDelay = Math.round(sumDelay / i);
               storage.put("NTPClockOffset", averageOffset + '|' + NTP.fixTime()); // 保存获得offset时的时间戳
               storage.put("NTPClockDelay", averageDelay); // 保存获得offset时的时间戳
           } else {
               NTP.getServerTime();
           }
       },
       //获取服务器时间并判断是否获取成功
       getServerTime: function () {
           var NtpStartTime = NTP.getNow();
           storage.put("NtpStartTime", NtpStartTime);
           var res = http.get(NTP.serverUrl);
           if (res.statusCode !== 200) {
               toast("获取网络时间失败: " + res.statusCode + " " + res.statusMessage);
               return false;
           } else {
               NTP.parseServerResponse(res.body.json());
           }
       },
       //固定时间
       fixTime: function (timeStamp) {
           if (!timeStamp) {
               timeStamp = NTP.getNow();
           }
           var offset = storage.get("NTPClockOffset");
           try {
               if (!offset) {
                   offset = 0;
               } else {
                   offset = offset.split("|")[0];
               }
               if (isNaN(parseInt(offset, 10))) {
                   return timeStamp;
               }
               return timeStamp + parseInt(offset, 10);
           } catch (e) {
               return timeStamp;
           }
       }
   }; 
   
   
       // 获取默认开始时间
       function getTime() {
           var fmt = "YYYY-MM-dd hh:mm:ss";
           var d = new Date();
           var hh = d.getHours();
           var mm = d.getMinutes();
           var ss = d.getSeconds();
           if (mm < 30) {
            mm = 30
            ss = 00
           }
           else{
            hh+=1
            mm = 00
            ss = 00       
           }
           
           var o = {
               "Y+": d.getYear() + 1900,
               "M+": d.getMonth() + 1,
               "d+": d.getDate(),
               "h+": hh,
               // "m+": d.getMinutes(),
               // "s+": d.getSeconds()
               "m+": mm,
               "s+": ss
           };
           for (var k in o) {
               if (new RegExp("(" + k + ")").test(fmt)) {
                   fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 4) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
               }
           }
           fmt = fmt.replace(/-/g, '/');
           return fmt;
         };
   
         //定义初始化界面数据
         var storage = storages.create("tmalltaobaohelper.byfly");
         threads.start(NTP.sync);
   
         //初始化淘宝界面
       setTimeout(initConfig_two, 500);
       function initConfig_two() {
           NTPClockOffset = storage.get("NTPClockOffset", "0");
           NTPClockDelay = storage.get("NTPClockDelay", "0");
       if (!NTPClockOffset) {
           NTPClockOffset = 0;
       } else {
           NTPClockOffset = parseInt(NTPClockOffset.split("|")[0]);
       }
       if (NTPClockOffset < 0) {
           var offset_str = "慢了" + -NTPClockOffset + 'ms,'
       } else {
           offset_str = "快了" + NTPClockOffset + 'ms,'
       }
       if (NTPClockDelay < 50) {
           var good_str = "网速评估:"+"您的网络延迟低于50ms,非常优秀!" 
       } 
       else if (NTPClockDelay < 100) {
           var good_str = "网速评估:"+"您的网络延迟低于100ms,优秀!" 
       } 
       else if (NTPClockDelay>100 && NTPClockDelay<200) {
           var good_str = "网速评估:"+"您的网络延迟高于100ms,抢购可能会有影响!" 
       } 
       else {
           good_str = "网速评估:"+"您的网络质量不佳,建议切换网络!" 
       }
   
       ui.networkTesttwo.on("click",function(){
           ui.networkTesttwo.setText("时间校准:"+"本地时间比淘宝" + offset_str +"已经为您校准了淘宝时间!"+'\n'+ "网络延迟:" + NTPClockDelay+'\n'+good_str );
           });       
   
           ui.startTime_two.setText(getTime());
           ui.interval.setText(storage.get("interval", "100").toString());
           ui.lastTime_two.setText(storage.get("lastTime_two", "10").toString());   
           ui.delaytime_two.setText(storage.get("delaytime_two", "700").toString());  
         }

              // 时间戳转时间字符串
    function add0(m) {
        return m < 10 ? '0' + m : m
    }
    function getNow() {
        var now = new Date().getTime();
        return now - NTPClockOffset; 
    }

    function formatDate(needTime) {
        //needTime是整数,否则要parseInt转换
        var time = new Date(parseInt(needTime));
        var h = time.getHours();
        var mm = time.getMinutes();
        var s = time.getSeconds();
        var S = time.getMilliseconds();
        return add0(h) + ':' + add0(mm) + ':' + add0(s)+":"+add0(S);
    }

 

标签:toast,function,618,checked,抢购,源码,ui,NTP,var
来源: https://blog.csdn.net/weixin_45504660/article/details/117898230

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有