收藏
回答

请问这段代码实现了什么功能?有些看不懂。

在下面这段代码中:

function t(t) {
    if (Array.isArray(t)) {
        for (var s = 0, e = Array(t.length); s < t.length; s++) e[s] = t[s];
        return e;
    }
    return Array.from(t);
}


require("jsencrypt.js");


var s = getApp(), e = (require("aes-js.js"), require("udpbroadcast.js")), a = require("cloudquery.js"), i = require("mdnsscan.js");


Page({
    data: {
        status: 0,
        searching: !1,
        searchDirty: !1,
        allReady: !1,
        deviceResultList: [],
        searchProgress: 0,
    },
	
	startCheck: function() {
	    var t = this;
	    console.info(), t.data.allReady && (t.setData({
	        status: 4
	    }), t.setData({
	        deviceResultList: [],
	        searching: !0,
	        searchDirty: !0
	    }), a.scanPolicies().then(function(s) {
	        if (t.data.searching) {
	            var a = [];
	            if (5200 == (s = JSON.parse(s)).status) {
	                for (var n = 0; n < s.objlist.policies.length; n++) {
	                    var o = s.objlist.policies[n];
	                    if (console.log(o), 64 == o.type && o.arg.length > 0) {
	                        var r = wx.base64ToArrayBuffer(o.arg), c = new Uint8Array(r), l = new e(t.onUdpBroadCastRecv, o.src_port, o.dst_port, o.id);
	                        l.init(), l.send_interval(c), l.timed_close();
	                    } else if (128 == o.type && o.arg.length > 0) {
	                        var f = wx.base64ToArrayBuffer(o.arg), d = new Uint8Array(f), u = String.fromCharCode.apply(null, d);
	                        a.push(u);
	                    }
	                }
	                var h = new i(t.onMDnsRespRecv);
	                h.start_list(a, 10), h.timed_stop_list(30);
	            }
	        }
	    }), t.doProgress(t.stopCheck));
	},


    doProgress: function(t) {
        var s = this;
        if (s.data.searchProgress < 100 && s.data.searching) {
            s.setData({
                searchProgress: s.data.searchProgress + 1
            });
            new Date().getTime();
            setTimeout(function() {
                s.doProgress(t);
            }, 100);
        } else t();
    },
    
    onUdpBroadCastRecv: function(e, i) {
        var n = this, o = new Uint8Array(e.message), r = wx.arrayBufferToBase64(o);
        console.log("onUdpBroadCastRecv");
        var c = [];
        c.push({
            ip: e.remoteInfo.address || "",
            mac: "",
            hostname: "",
            ports: [],
            udp: [ {
                src_port: "" + i.src_port,
                dst_port: "" + i.dst_port,
                send: "" + i.policy_id,
                receive: r
            } ]
        }), a.submitAndQueryApp(c).then(function(e) {
            if (console.log(e), n.data.searching && 5200 == (e = JSON.parse(e)).status && (s.globalData.qdas && s.globalData.qdas.track("microProgram-cameraFinder-resultList", {
                result: e.objlist.toString()
            }), n.data.deviceResultList.length > 0 || e.objlist.length > 0 ? n.setData({
                status: 2
            }) : n.setData({
                status: 4
            }), e.objlist.length > 0)) {
                var a = [].concat(t(n.data.deviceResultList), t(e.objlist)), i = [];
                a.forEach(function(t, s, e) {
                    console.info("item", t);
                    for (var a = 0; a < i.length; a++) if (t.ip) {
                        if (i[a].ip == t.ip) return;
                    } else if (console.info("finalArray[i]", i[a]), console.info("item", t), i[a].hostname == t.hostname) return;
                    i.push(t);
                }), console.info("finalArrayCache", a), console.info("finalArray", i), n.setData({
                    deviceResultList: [].concat(i)
                });
            }
        });
    },
    onMDnsRespRecv: function(e, i) {
        var n = this;
        console.log("onMDnsRespRecv"), console.log(e);
        var o = [];
        o.push({
            ip: e.ip || "",
            mac: "",
            hostname: e.serviceName || "",
            ports: [],
            udp: []
        }), a.submitAndQueryApp(o).then(function(e) {
            if (console.log(e), n.data.searching && 5200 == (e = JSON.parse(e)).status && (s.globalData.qdas && s.globalData.qdas.track("microProgram-cameraFinder-resultList", {
                result: e.objlist.toString()
            }), n.data.deviceResultList.length > 0 || e.objlist.length > 0 ? n.setData({
                status: 2
            }) : n.setData({
                status: 4
            }), e.objlist.length > 0)) {
                var a = [].concat(t(n.data.deviceResultList), t(e.objlist)), i = [];
                a.forEach(function(t, s, e) {
                    console.info("item", t);
                    for (var a = 0; a < i.length; a++) if (t.ip) {
                        if (i[a].ip == t.ip) return;
                    } else if (console.info("finalArray[i]", i[a]), console.info("item", t), i[a].hostname == t.hostname) return;
                    i.push(t);
                }), console.info("finalArrayCache", a), console.info("finalArray", i), n.setData({
                    deviceResultList: [].concat(i)
                });
            }
        });
    },
    
    
  
});


其中如下这段代码实现了什么功能?有些看不懂。

startCheck: function() {
	    var t = this;
	    console.info(), t.data.allReady && (t.setData({
	        status: 4
	    }), t.setData({
	        deviceResultList: [],
	        searching: !0,
	        searchDirty: !0
	    }), a.scanPolicies().then(function(s) {
	        if (t.data.searching) {
	            var a = [];
	            if (5200 == (s = JSON.parse(s)).status) {
	                for (var n = 0; n < s.objlist.policies.length; n++) {
	                    var o = s.objlist.policies[n];
	                    if (console.log(o), 64 == o.type && o.arg.length > 0) {
	                        var r = wx.base64ToArrayBuffer(o.arg), c = new Uint8Array(r), l = new e(t.onUdpBroadCastRecv, o.src_port, o.dst_port, o.id);
	                        l.init(), l.send_interval(c), l.timed_close();
	                    } else if (128 == o.type && o.arg.length > 0) {
	                        var f = wx.base64ToArrayBuffer(o.arg), d = new Uint8Array(f), u = String.fromCharCode.apply(null, d);
	                        a.push(u);
	                    }
	                }
	                var h = new i(t.onMDnsRespRecv);
	                h.start_list(a, 10), h.timed_stop_list(30);
	            }
	        }
	    }), t.doProgress(t.stopCheck));
	},


globalData:

globalData: {
        
        qdas: o
    }


cloudquery.js:

function n() {
    this.publicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA+Iyg9XdDC2ial4TTCsPR\n8/76Y+a+nMKyKRobWirim9uXJHjIvyiieGnVXAtMtHbjcxJ6AMkc7d4jscaGdjuu\nx/jIq9KvAmFvvhgJPQvnkttJuV2tyO+z40aeG42Yr65lO2A5pFZct4b6ssCZwnBC\nyZsNtHoU0HQ1FdFlHVk41IVjd1WvMmpnuy7BBwVD7jPoARigwxnkT03ddnpcUavQ\nA+R2sko9YJBvCDKV6Hb+VfMhIGKXK9jdDOKIhSRnGWyc1473GSdlFoVxJR6gDdMd\ns+ItdxwlSneoSKpNcv/CLfXpYkrCM3tFDSrX+C22p24MmuLEXm8YyOcGhdBQDSQX\npQIDAQAB", 
    this.cnToken = "hHwJWHnEHGgiLlwN", this.input_rsa = "9pt9bv0s8q8wtcu2";
}
var t = require("jsencrypt.js"), e = require("aes-js.js");
n.prototype.scanPolicies = function() {
    var n = this;
    return new Promise(function(e, r) {
        var s = n.publicKey, i = n.randomString(16);
        n.input_rsa = i;
        var c = new t.JSEncrypt();
        c.setPublicKey(s);
        var o = c.encrypt(i), a = {
            cntoken: n.cnToken,
            test: "true",
            ssid: "",
            bssid: "",
            signal: "",
            query: [],
            nearby: [ {
                ssid: "WiFi458FD",
                bssid: "000000000000",
                "signal ": "1"
            } ]
        };
        console.info(a);
        var p = n.AesEncrypt(JSON.stringify(a), i);
        wx.request({
            method: "POST",
            url: "https://newapi.cloudquery.luyou.360.cn/Interfaces/AppInterface/scanPolicies",
            header: {
                TOKEN: o,
                CNTOKEN: n.cnToken,
                contentType: "text/plain"
            },
            data: p,
            success: function(t) {
                e(n.AesDecrypt(t.data, i));
            }
        });
    });
}


n.prototype.submitAndQueryApp = function(n) {
    var e = this;
    return new Promise(function(r, s) {
        var i = e.publicKey, c = e.randomString(16);
        e.input_rsa = c;
        var o = new t.JSEncrypt();
        o.setPublicKey(i);
        for (var a = o.encrypt(c), p = {
            cntoken: e.cnToken,
            ssid: "",
            bssid: "",
            signal: "",
            query: [],
            nearby: [ {
                ssid: "360-WiFi458FD",
                bssid: "000000000000",
                "signal ": "1"
            } ]
        }, u = 0; u < n.length; u++) p.query.push({
            ip: n[u].ip || "",
            mac: n[u].mac || "",
            hostname: n[u].serviceName || n[u].hostname || "",
            port: n[u].port || [],
            udp: n[u].udp || []
        });
        console.info(p);
        var d = e.AesEncrypt(JSON.stringify(p), c);
        wx.request({
            method: "POST",
            url: "https://newapi.cloudquery.luyou.360.cn/Interfaces/AppInterface/submitAndQueryApp",
            header: {
                TOKEN: a,
                CNTOKEN: e.cnToken,
                contentType: "text/plain"
            },
            data: d,
            success: function(n) {
                r(e.AesDecrypt(n.data, c));
            }
        });
    });
}


mdnsscan.js:

function o(o) {
    this.onrecv_callback = o, this.discovery_interval_handle = null;
}
o.prototype.start_list = function(o) {
    var e = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : 5, t = this, c = 0;
    !o || o.length < 0 || (console.log(o), t.start(o[c]), t.timed_stop(e - 1), ++c < o.length && (this.discovery_interval_handle = setInterval(function() {
        c < o.length ? (t.start(o[c]), t.timed_stop(e - 1), c++) : (clearInterval(this), 
        this.discovery_interval_handle = null);
    }, 1e3 * e)));
}


o.prototype.timed_stop_list = function() {
    var o = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : 10, e = this;
    setTimeout(function() {
        e.stop_list();
    }, 1e3 * o);
}

回答关注问题邀请回答
收藏

1 个回答

  • ᥬ[吃瓜]᭄
    ᥬ[吃瓜]᭄
    2020-06-04

    出门左转找JS社区

    2020-06-04
    有用
    回复
登录 后发表内容
问题标签