请高手帮忙还原restful接口

发布于 2022-09-01 19:42:48 字数 24880 浏览 13 评论 0

这种写法看不懂,请高手帮忙还原restful接口,实在 是找不出原来的headers

! function(a, b) {
    b.login = function(b, c) {
        c = c || a.noop, b = b || {}, b.account = b.account || "", b.password = b.password || "";
        var d = new httpRequest;
        return d.addData("username", b.account), d.addData("password", b.password), d.post("authorization", function(a) {
            200 == a.code && (plus.storage.setItem("username", b.account), plus.storage.setItem("password", b.password), plus.storage.setItem("uid", a.data_1.uid), plus.storage.setItem("user_info", JSON.stringify(a.data_1)), app.createState(a.data.open_id, a.data.auth, function() {
                var a = app.getSettings();
                a.autoLogin = !0, app.setSettings(a)
            })), c(a)
        }), !1
    }, b.getUserInfo = function(b, c) {
        c = c || a.noop, b = b || "";
        var d = new httpRequest;
        return d.get("user/" + b, function(a) {
            b == JSON.parse(plus.storage.getItem("user_info")).uid && (plus.storage.setItem("user_info", JSON.stringify(a.data)), plus.storage.setItem("uid", a.data.uid)), c(a)
        }), !1
    }, b.logout = function(b) {
        b = b || a.noop, plus.storage.removeItem("password"), plus.storage.removeItem("user_info"), plus.storage.removeItem("uid"), plus.storage.removeItem("$state");
        var c = app.getSettings();
        return c.autoLogin = !1, app.setSettings(c), b(), !1
    }, b.createState = function(a, c, d) {
        var e = b.getState();
        return e.uid = c.uid, e.open_id = a, b.setState(e), d()
    }, b.reg = function(b, c) {
        c = c || a.noop, b = b || {}, b.username = b.username || "", b.password = b.password || "", b.nickname = b.nickname || "", b.email = b.email || "", b.mobile = b.mobile || "", b.reg_verify = b.reg_verify || "", b.reg_type = b.reg_type || "", b.role = b.role || "";
        var d = app.getConfig("reg"),
            e = d.NICKNAME_MIN_LENGTH,
            f = d.NICKNAME_MAX_LENGTH,
            g = d.USERNAME_MIN_LENGTH,
            h = d.USERNAME_MAX_LENGTH,
            i = d.EMAIL_VERIFY_TYPE,
            j = d.MOBILE_VERIFY_TYPE;
        if ("username" == b.reg_type && (b.username.length < g || b.username.length > h)) return c("用户名长度在" + g + "-" + h + "之间");
        if (b.nickname.length < e || b.nickname.length > f) return c("昵称长度在" + e + "-" + f + "之间");
        if (!("email" != b.reg_type && "mobile" != b.reg_type || "" != b.reg_verify || 2 != i && 1 != j)) return c("验证码不能为空");
        var k = new Object;
        if (k.Email = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/, k.Phone = /^(1[3|4|5|8])[0-9]{9}$/, "email" == b.reg_type && !k.Email.test(b.email)) return c("请输入正确的邮箱");
        if ("mobile" == b.reg_type && !k.Phone.test(b.mobile)) return c("请输入正确的手机");
        if (b.password.length < 6) return c("密码不少于6个字节");
        var l = new httpRequest;
        return l.addData("username", b.username), l.addData("email", b.email), l.addData("mobile", b.mobile), l.addData("nickname", b.nickname), l.addData("password", b.password), l.addData("reg_verify", b.reg_verify), l.addData("reg_type", b.reg_type), l.addData("role", b.role), l.post("account", function(a) {
            c(a)
        }), !1
    }, b.uploadPic = function(b, c) {
        c = c || a.noop, b = b || {}, b.data = b.data || "";
        var d = new httpRequest;
        return d.addData("data", b.data), d.post("picture", function(a) {
            c(a)
        }), !1
    }, b.sendVerify = function(b, c) {
        if (c = c || a.noop, b = b || {}, b.account = b.account || "", b.type = b.type || "", b.open_id = b.open_id || "", "" == b.account) return c("帐号不能为空");
        if ("" == b.type) return c("参数错误");
        var d = new httpRequest;
        return d.addData("account", b.account), d.addData("type", b.type), d.addData("open_id", b.open_id), d.post("reg_verify", function(a) {
            c(a)
        }), !1
    }, b.getState = function() {
        var a = plus.storage.getItem("$state") || "{}";
        return JSON.parse(a)
    }, b.setState = function(a) {
        a = a || {}, plus.storage.setItem("$state", JSON.stringify(a))
    };
    var c = function(a) {
        return a = a || "", a.length > 3 && a.indexOf("@") > -1
    };
    b.forgetPassword = function(b, d) {
        return d = d || a.noop, c(b) ? d(null, "新的随机密码已经发送到您的邮箱,请查收邮件。") : d("邮箱地址不合法")
    }, b.setSettings = function(a) {
        a = a || {}, plus.storage.setItem("$settings", JSON.stringify(a))
    }, b.getSettings = function() {
        var a = plus.storage.getItem("$settings") || "{}";
        return JSON.parse(a)
    }, b.getConfig = function(b, c) {
        c = c || a.noop;
        var d = cache.getCache(b + "_config");
        if (null == d) {
            var e = new httpRequest;
            e.addData("name", b), e.get("config", function(a) {
                d = a.data, cache.setCache(b + "config", a.data), c(a.data)
            }, !1)
        } else c(d);
        return d
    }, b.support = function(b, c) {
        var d = app.getState();
        b = b || {}, c = c || a.noop, b.appname = b.appname || "", b.table = b.table || "", b.jump = b.jump || "", b.row = b.row || "";
        var e = new httpRequest;
        return e.addData("appname", b.appname), e.addData("table", b.table), e.addData("row", b.row), e.addData("jump", b.jump), e.addData("open_id", d.open_id || ""), e.post("support", function(a) {
            c(a)
        }), !1
    }, b.mySupport = function(b, c) {
        var d = app.getState();
        b = b || {}, c = c || a.noop, b.appname = b.appname || "", b.table = b.table || "";
        var e = new httpRequest;
        e.addData("appname", b.appname), e.addData("table", b.table), e.addData("open_id", d.open_id || ""), e.get("my_support", function(a) {
            c(a)
        }, !1)
    }, b.oauth = function(b, c) {
        b = b || {}, c = c || a.noop, b.auth_result = b.auth_result || "", b.user_info = b.user_info || "", b.bind_info = b.bind_info || "", b.type = b.type || "";
        var d = new httpRequest;
        d.addData("auth_result", b.auth_result), d.addData("user_info", b.user_info), d.addData("bind_info", b.bind_info), d.addData("type", b.type), d.post("oauth", function(a) {
            c(a)
        }, !1)
    }, b.versions = function(a) {
        a = a || mui.noop;
        var b = new httpRequest;
        b.get("versions", function(b) {
            a(b)
        })
    }
}(mui, window.app = {});
var apptools = {
        finish: function(a) {
            a.close()
        },
        delayWindow: function(a) {
            setTimeout(function() {
                a.isVisible() || (plus.nativeUI.closeWaiting(), mui.currentWebview.show("slide-in-right", 200))
            }, 3e3), a.addEventListener("loadedEvent", function(b) {
                event.detail.is_ok && !a.isVisible() && (plus.nativeUI.closeWaiting(), mui.currentWebview.show("slide-in-right", 200))
            })
        }
    },
    httpRequest = function() {
        var a = this;
        a.data = {}, a.host = "http://os.baidu.cn/api/", a.addData = function(b, c) {
            a.data[b] = c
        }, a.request = function(b, c, d, e) {
            e = null == e ? !0 : e;
            var f = new FormData;
            f.append("method", c), f.append("access_token", "f9c96961902f533121180b081fadf89c");
            for (key in a.data) f.append(key, a.data[key]);
            var g = new XMLHttpRequest;
            g.onreadystatechange = function() {
                4 == g.readyState && d(JSON.parse(g.responseText))
            }, g.open("POST", a.host + b, e), g.send(f)
        }, a.get = function(b, c, d) {
            a.request(b, "GET", c, d)
        }, a.post = function(b, c, d) {
            a.request(b, "POST", c, d)
        }, a.put = function(b, c, d) {
            a.request(b, "PUT", c, d)
        }, a["delete"] = function(b, c, d) {
            a.request(b, "DELETE", c, d)
        }
    },
    toast = {
        info: function(a) {
            mui.toast(a)
        },
        showLoading: function(a) {
            plus.nativeUI.showWaiting(a)
        },
        hideLoading: function() {
            plus.nativeUI.closeWaiting()
        }
    },
    is_login = function() {
        var a = app.getSettings(),
            b = app.getState();
        return a.autoLogin && b.open_id ? b.uid : 0
    },
    get_from = function() {
        return plus.device.model
    },
    get_parent_node = function(a, b) {
        var c = b.substring(0, 1);
        if ("." == c) var d = b.substr(1),
            e = a.parentNode.classList.contains(d);
        if ("#" == c) var f = b.substr(1),
            e = a.parentNode.getAttribute("id") == f;
        if ("." != c && "#" != c) var e = a.parentNode.nodeName == b;
        return e ? a.parentNode : get_parent_node(a.parentNode, b)
    };
String.prototype.parseContent = function() {
    return this.parseExpression()
}, String.prototype.parseExpression = function() {
    var a = this,
        b = a.replace(/\[(.+?)\]/g, '<img class="expression_img" data-src="../../images/expression/miniblog/$1.gif" src="../../images/expression/miniblog/$1.gif"/>');
    return b
}, Element.prototype.createExpression = function(a) {
    function b(a) {
        var b = 0;
        if (document.selection) {
            a.focus();
            var c = document.selection.createRange();
            c.moveStart("character", -a.value.length), b = c.text.length
        } else(a.selectionStart || "0" == a.selectionStart) && (b = a.selectionStart);
        return b
    }

    function c(a, b) {
        if (a.setSelectionRange) a.setSelectionRange(b, b);
        else if (a.createTextRange) {
            var c = a.createTextRange();
            c.collapse(!0), c.moveEnd("character", b), c.moveStart("character", b), c.select()
        }
        a.blur()
    }
    var d = this;
    d.option = a, d.expressionList = [], d.addEventListener("tap", function() {
        if ("none" == d.option.showDiv.style.display) {
            d.option.showDiv.style.display = "block";
            var a = document.createElement("div");
            a.setAttribute("class", "mui-slider"), d.option.showDiv.appendChild(a);
            var e = document.createElement("div");
            e.setAttribute("class", "mui-slider-group mui-slider-loop"), a.appendChild(e);
            var f = document.createElement("div");
            f.setAttribute("class", "mui-slider-indicator"), a.appendChild(f), plus.io.resolveLocalFileSystemURL("_www/images/expression/miniblog", function(a) {
                var b = a.createReader();
                b.readEntries(function(a) {
                    var b, c, g, h = "",
                        i = "",
                        j = a.length,
                        k = [];
                    mui.os.android && (a = a.reverse());
                    for (var l = 0; j > l; l += 20) k.push(a.slice(l, l + 20));
                    for (var m = 0; m < k.length; m++) {
                        c = '<div class="mui-slider-item" style="height: 170px;">', i += 0 == m ? '<div class="mui-indicator mui-grid-view mui-active"></div>' : '<div class="mui-indicator mui-grid-view"></div>';
                        for (var n = 0; n < k[m].length; n++) {
                            var o = k[m][n].name.replace(".gif", "");
                            d.expressionList.push("[" + o + "]"), c += '<div  style="float:left; padding:8px; width:14%" class="expression_tap" data-title="' + o + '"><img data-src="' + k[m][n].toRemoteURL() + '"  src="' + k[m][n].toRemoteURL() + '"></div>'
                        }
                        c += '<div style="float:right;padding:11px 22px 10px 10px;width:14%" class="del_expression"><img data-src="../../images/resize.png" src="../../images/resize.png" style="margin-top:4px;"></div>', c += "</div>", h += c, 0 == m && (b = c), m + 1 == k.length && (g = c)
                    }
                    e.innerHTML = g + h + b, f.innerHTML = i;
                    var p = mui(".mui-slider");
                    p.slider({
                        interval: 0
                    }), mui.os.ios && document.querySelector(".mui-slider").addEventListener("scrollend", function(a) {
                        for (var b = a.detail.slideNumber, c = d.option.showDiv.getElementsByClassName("mui-slider-item")[b + 1].getElementsByTagName("img"), e = 0; e < c.length; e++) c[e].setAttribute("src", c[e].getAttribute("data-src") + "?t=" + Math.random())
                    })
                }, function(a) {
                    console.log("Read entries failed: " + a.message)
                })
            }, function(a) {
                console.log("Resolve file URL failed: " + a.message)
            }), mui(".mui-slider").on("tap", ".expression_tap", function(a) {
                var e = this.getAttribute("data-title"),
                    f = d.option.target,
                    g = b(f),
                    h = f.value;
                f.value = h.substring(0, g) + "[" + e + "]" + h.substring(g), c(f, g + 2 + e.length)
            }), mui(".mui-slider").on("tap", ".del_expression", function(a) {
                var c = d.option.target,
                    e = b(c),
                    f = c.value,
                    g = f.substring(0, e),
                    h = f.substring(e),
                    i = g.substr(g.length - 1, 1);
                if ("]" != i) g = g.substring(0, g.length - 1);
                else {
                    var j = g.lastIndexOf("["),
                        k = g.substring(j);
                    g = d.expressionList.indexOf(k) > -1 ? g.substring(0, j) : g.substring(0, g.length - 1)
                }
                c.value = g + h
            })
        }
    }), d.option.target.addEventListener("tap", function() {
        d.option.showDiv.style.display = "none", d.option.showDiv.innerHTML = ""
    })
};
var get_expression_list = function() {
        var a = plus.storage.getItem("expression_list");
        return null == a && plus.io.resolveLocalFileSystemURL("_www/images/expression/miniblog", function(b) {
            var c = b.createReader();
            c.readEntries(function(b) {
                a = {}, mui.os.android && (b = b.reverse());
                for (var c = 0; c < b.length; c++) {
                    var d = b[c].name.replace(".gif", "");
                    a[d] = b[c].toRemoteURL()
                }
                a = JSON.stringify(a), plus.storage.setItem("expression_list", a)
            }, function(a) {
                console.log("Read entries failed: " + a.message)
            })
        }, function(a) {
            console.log("Resolve file URL failed: " + a.message)
        }), JSON.parse(a)
    },
    get_expression = function(a) {
        var b = get_expression_list();
        return b[a] + "?t=" + Math.random()
    },
    get_role = function() {
        var a = cache.getCache("role");
        if (null == a) {
            var b = new httpRequest;
            b.get("role", function(a) {
                404 == a.code && (cache.setCache("role", a.data), show_role(a.data))
            })
        } else show_role(a)
    },
    show_role = function(a) {
        var b = new mui.PopPicker,
            c = document.getElementById("showUserType"),
            d = document.getElementById("role_id");
        c.innerHTML = a[0].title, d.value = a[0].id;
        var e = [];
        for (var f in a) e[f] = {
            value: a[f].id,
            text: a[f].title
        };
        b.setData(e), c.addEventListener("tap", function(a) {
            b.show(function(a) {
                d.value = a[0].value, console.log(a[0].value), c.innerHTML = a[0].text
            })
        }, !1)
    },
    after_reg = function(a) {
        "object" == typeof a ? (toast.info(a.info), 200 == parseInt(a.code) && mui.openWindow({
            url: "login.html",
            id: "login",
            show: {
                aniShow: "pop-in"
            },
            styles: {
                popGesture: "hide"
            },
            waiting: {
                autoShow: !1
            }
        })) : toast.info(a), toast.hideLoading()
    },
    DecTime = {
        obj: 0,
        time: 0,
        dec_time: function() {
            this.time > 0 ? (this.obj.innerHTML = this.time--+"S", setTimeout("DecTime.dec_time()", 1e3)) : (this.obj.innerHTML = "验证手机", this.obj.disabled = !1)
        }
    };
Element.prototype.createUploader = function(a) {
    var b = this;
    b.option = a, b.option.limit = b.option.limit || 9, b.option.title = b.option.title || "上传图片";
    var c = document.createElement("input");
    c.setAttribute("type", "hidden"), c.setAttribute("name", b.option.input_name), b.appendChild(c), b.inputNode = c, b.addEventListener("tap", function() {
        var a = [{
            title: "拍照"
        }, {
            title: "从手机相册选择"
        }];
        plus.nativeUI.actionSheet({
            title: b.option.title,
            cancel: "取消",
            buttons: a
        }, function(a) {
            switch (a.index) {
                case 0:
                    break;
                case 1:
                    var c = plus.camera.getCamera();
                    c.captureImage(function(a) {
                        plus.io.resolveLocalFileSystemURL(a, function(a) {
                            a.file(function(a) {
                                b.showImg(a)
                            })
                        }, function(a) {
                            console.log("读取拍照文件错误:" + a.message)
                        })
                    }, function(a) {
                        console.log("error" + a)
                    }, {});
                    break;
                case 2:
                    plus.gallery.pick(function(a) {
                        if ("string" == typeof a) plus.io.resolveLocalFileSystemURL(a, function(a) {
                            a.file(function(a) {
                                b.showImg(a)
                            })
                        });
                        else
                            for (var c = 0; c < a.files.length; c++) plus.io.resolveLocalFileSystemURL(a.files[c], function(a) {
                                a.file(function(a) {
                                    b.showImg(a)
                                })
                            })
                    }, function() {}, {
                        filter: "image",
                        multiple: b.option.multiple
                    })
            }
        })
    }), b.showImg = function(a) {
        var c = b.inputNode.value.split(","),
            d = 0;
        if ("" != b.inputNode.value && (d = c.length), d < b.option.limit || 1 == b.option.limit) {
            var e = new plus.io.FileReader;
            e.readAsDataURL(a), e.onloadend = function(a) {
                var d = a.target.result,
                    e = {
                        data: d
                    };
                toast.showLoading("上传图片中..."), app.uploadPic(e, function(a) {
                    if (toast.hideLoading(), "object" == typeof a)
                        if (200 == a.code)
                            if (-1 == c.indexOf(a.data.id)) {
                                b.updateAttachValue("add", a.data.id, b.inputNode);
                                var e = document.getElementById(b.option.showDiv),
                                    f = document.createElement("div");
                                f.setAttribute("style", "display: inline-block"), 1 == b.option.limit && (e.innerHTML = ""), e.appendChild(f);
                                var g = document.createElement("img");
                                g.setAttribute("src", d), g.setAttribute("style", "width: 100px; height: 100px;margin-right:2px;"), g.setAttribute("data-preview-src", d), g.setAttribute("data-preview-group", 1), f.appendChild(g);
                                var h = document.createElement("span");
                                h.setAttribute("class", "mui-icon mui-icon-close img-close-btn"), h.setAttribute("picture_id", a.data.id), h.setAttribute("id", "picture_" + a.data.id), f.appendChild(h), b.bindCloseBtn(a.data.id), mui.previewImage()
                            } else toast.info("图片已在队列中");
                    else toast.info(a.info);
                    else toast.info(a.info)
                })
            }
        } else toast.info("超出图片限制")
    }, b.updateAttachValue = function(a, c, d) {
        if (1 == b.option.limit) return "add" === a ? d.value = c : d.value = "", d.value;
        var e = d.value,
            f = e.split(","),
            g = [];
        for (var h in f) "" !== f[h] && f[h] !== c.toString() && g.push(f[h]);
        return "add" === a && g.push(c), d.value = g.join(","), g
    }, b.bindCloseBtn = function(a) {
        document.getElementById("picture_" + a).addEventListener("tap", function() {
            this.parentNode.remove(), b.updateAttachValue("del", a, b.inputNode)
        })
    }
};



//载入配置文件--由于文件路径不统一。所以暂时先两个一起载入。以后能获取根目录时修改  todo
document.write("<script language='javascript' src='../../config.js'></script>");
document.write("<script language='javascript' src='config.js'></script>");

var httpRequest = function () {
    var $this = this;
    $this.data = {};
    $this.host = api_host;
    $this.addData = function (key, value) {
        $this.data[key] = value;
    };
    $this.request = function (url, method, callback, asynch) {

        asynch = asynch == null ? true : asynch;
        var data = new FormData();
        data.append('method', method);
        data.append('access_token', 'f9c96961902f533121180b081fadf89c'); //todo 将access_token隐藏掉
        for (key in $this.data) {
            data.append(key, $this.data[key]);
        }

        // var XML =new plus.net.XMLHttpRequest();

        var XML = new XMLHttpRequest();
        XML.onreadystatechange = function () {
            if (XML.readyState == 4) {
                callback(JSON.parse(XML.responseText));
            }
        };
        XML.open('POST', $this.host + url, asynch);
        XML.send(data);
    };


    $this.get = function (url, callback, asynch) {
        $this.request(url, 'GET', callback, asynch)
    };

    $this.post = function (url, callback, asynch) {
        $this.request(url, 'POST', callback, asynch)
    };

    $this.put = function (url, callback, asynch) {
        $this.request(url, 'PUT', callback, asynch)
    };

    $this.delete = function (url, callback, asynch) {
        $this.request(url, 'DELETE', callback, asynch)
    }
};


var toast = {
    info: function (msg) {
        mui.toast(msg);
    },
    showLoading: function (msg) {
        plus.nativeUI.showWaiting(msg);
    },
    hideLoading: function () {
        plus.nativeUI.closeWaiting();
    }
};


var is_login = function () {
    var settings = app.getSettings();
    var state = app.getState();
    if (settings.autoLogin && state.open_id) {
        return state.uid;
    } else {
        return 0;
    }

};


var get_from = function () {
    return plus.device.model;
};

var get_parent_node = function ($this, find) {
    var first = find.substring(0, 1);
    if (first == '.') {
        var class_name = find.substr(1);

        var check = $this.parentNode.classList.contains(class_name);
    }
    if (first == '#') {
        var id_name = find.substr(1);
        var check = $this.parentNode.getAttribute('id') == id_name;
    }

    if (first != '.' && first != '#') {
        var check = $this.parentNode.nodeName == find;
    }

    if (check) {
        return $this.parentNode;
    } else {
        return get_parent_node($this.parentNode, find);
    }

};


String.prototype.parseContent = function () {
    return this.parseExpression();
};

String.prototype.parseExpression = function () {
    var string = this;
    //var content = string.replace(/\[(.+?)\]/g, '<img class="expression_img" data-src="../../images/expression/miniblog/$1.gif" src="../../images/expression/miniblog/$1.gif"/>'); // todo 暂时使用相对路径

    var content = string.replace(/\[(.+?)\]/g, function(find){
        find = find.replace('[','').replace(']','');
        if(find.indexOf(':') == -1 ){
           return ' <img class="expression_img" data-src="../../images/expression/miniblog/'+find+'.gif" src="../../images/expression/miniblog/'+find+'.gif"/>';
        }else{
            return  '['+find+']'
        }

    });

    return content;
};

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

泅渡 2022-09-08 19:42:48

= =其实我觉得不是大家不想帮。。是真没看懂问题。。

染火枫林 2022-09-08 19:42:48

代(wan)码(quan)很(kan)漂(bu)亮(dong)

是不是混淆过了

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文