var e, r = arequire("@babel/runtime/helpers/interopRequireDefault"), t = arequire("@babel/runtime/helpers/typeof"), a = r(arequire("./mlh5/mlh5")), o = r(arequire("./partner_config.js")), n = (e = {}, 
{
    order_data: {},
    init: function(e, r) {
        var t = e && e.game_ver ? e.game_ver : 0;
        console.log("[SDK]CP调用init接口");
        var n, l = wx.getStorageSync("plat_uuid");
        l ? n = 0 : (l = this.uuid(16, 32), wx.setStorageSync("plat_uuid", l), n = 1);
        var i = wx.getStorageSync("plat_idfv");
        i || (i = this.uuid(16, 32), wx.setStorageSync("plat_idfv", i));
        var s = wx.getLaunchOptionsSync(), c = s.scene ? s.scene : "";
        n && s.query && s.query.ad_code && wx.setStorageSync("plat_ad_code", s.query.ad_code);
        var u = {
            install: n,
            scene: c
        };
        this.log("start", u), a.default.init({
            appId: o.default.partner_app_id,
            channelId: o.default.partner_channel_id,
            appKey: o.default.partner_app_key,
            version: o.default.game_ver,
            callback: function() {
                console.log("[AKSDK]渠道初始化成功");
            }
        });
        var p = s.query && s.query.invite ? s.query.invite : "", g = s.query && s.query.invite_type ? s.query.invite_type : "";
        p && (d = {
            invite: p,
            invite_type: g,
            is_new: n,
            scene: c
        }), t && this.checkGameVersion(t, function(e) {
            r && r(e);
        });
    },
    login: function(r, t) {
        console.log("[SDK]调起登录");
        var o = this;
        e.login = "function" == typeof t ? t : null, a.default.login({
            callback: function(r) {
                console.log("[AKSDK]联运登录结果 " + JSON.stringify(r)), r.userToken ? o.do_login(r) : e.login && e.login(1, {
                    errMsg: r.errMsg
                });
            }
        });
    },
    do_login: function(r) {
        var a = this, o = a.getPublicData();
        if (o.userToken = r.userToken, o.userId = r.userId, o.is_from_min = 1, d && "object" == t(d)) for (var n in d) o[n] = d[n];
        wx.request({
            url: "https://" + l + "/partner/auth",
            method: "POST",
            dataType: "json",
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            data: o,
            success: function(r) {
                if (console.log("[SDK]登录结果："), console.log(r), 200 == r.statusCode) {
                    var t = r.data;
                    if (t.state) {
                        s = {
                            ad_id: t.data.ext
                        };
                        try {
                            wx.setStorageSync("plat_sdk_token", t.data.sdk_token), wx.setStorageSync("plat_uid", t.data.user_id), 
                            wx.setStorageSync("plat_username", t.data.username), t.data.ext && wx.setStorageSync("plat_session_key", t.data.ext);
                        } catch (e) {}
                        var o = {
                            userid: t.data.user_id,
                            account: t.data.nick_name,
                            token: t.data.token,
                            invite_uid: t.data.invite_uid || "",
                            invite_nickname: t.data.invite_nickname || "",
                            invite_head_img: t.data.invite_head_img || "",
                            head_img: t.data.head_img || "",
                            is_client: t.data.is_client || "0",
                            ios_pay: t.data.ios_pay || "0"
                        };
                        e.login && e.login(0, o);
                    } else e.login && e.login(1, {
                        errMsg: t.msg
                    });
                    a.getShareInfo("menu", function(e) {
                        console.log("[SDK]开始监听右上角菜单分享"), wx.onShareAppMessage(function() {
                            return a.logStartShare("menu"), {
                                title: e.title,
                                imageUrl: e.img,
                                query: e.query
                            };
                        });
                    });
                } else e.login && e.login(1, {
                    errMsg: "请求平台服务器失败！"
                });
            }
        });
    },
    share: function(r) {
        e.share = "function" == typeof callback ? callback : null;
        var t = r.type || "share";
        console.log("[SDK]CP调用分享 type=" + t);
        var a = this;
        this.getShareInfo(t, function(e) {
            a.logStartShare(t), wx.shareAppMessage({
                title: e.title,
                imageUrl: e.img,
                query: e.query
            });
        });
    },
    inspireVideo: function(e) {
        a.default.getRewarderdVideo({
            adUnitId: s.ad_id,
            callback: function(r) {
                r.is_close_finish ? e(0) : e(1);
            }
        });
    },
    logStartShare: function(e) {
        var r = wx.getStorageSync("plat_sdk_token");
        wx.request({
            url: "https://" + l + "/game/min/?ac=logStartShare",
            method: "POST",
            dataType: "json",
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            data: {
                game_pkg: o.default.game_pkg,
                partner_id: o.default.partner_id,
                sdk_token: r,
                server_id: i ? i.server_id : "",
                role_id: i ? i.role_id : "",
                type: e
            },
            success: function(e) {}
        });
    },
    openService: function() {
        wx.openCustomerServiceConversation();
    },
    checkGameVersion: function(e, r) {
        console.log("[SDK]检查游戏版本"), wx.getStorageSync("plat_sdk_token"), wx.request({
            url: "https://" + l + "/game/min/?ac=checkGameVersion",
            method: "POST",
            dataType: "json",
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            data: {
                game_pkg: o.default.game_pkg,
                partner_id: o.default.partner_id,
                game_ver: e
            },
            success: function(e) {
                if (console.log("[SDK]获取游戏版本结果"), console.log(e), 200 == e.statusCode) {
                    var t = e.data;
                    t.state ? r && r(t.data) : r && r({
                        develop: 0
                    });
                } else r && r({
                    develop: 0
                });
            }
        });
    },
    getShareInfo: function(r, t) {
        console.log("[SDK]获取分享参数");
        var a = wx.getStorageSync("plat_sdk_token");
        wx.request({
            url: "https://" + l + "/game/min/?ac=shareConfig",
            method: "POST",
            dataType: "json",
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            data: {
                game_pkg: o.default.game_pkg,
                partner_id: o.default.partner_id,
                sdk_token: a,
                type: r,
                server_id: i ? i.server_id : "",
                role_id: i ? i.role_id : "",
                no_log: 1
            },
            success: function(r) {
                if (console.log("[SDK]获取分享参数结果"), console.log(r), 200 == r.statusCode) {
                    var a = r.data;
                    a.state ? t && t(a.data) : e.share && e.share(1, {
                        errMsg: "分享失败：" + a.msg
                    });
                } else e.share && e.share(1, {
                    errMsg: "获取分享数据失败！"
                });
            }
        });
    },
    updateShare: function(e, r, t, a, n, i) {
        console.log("[SDK]分享过来的玩家上报给服务器");
        var d = wx.getStorageSync("plat_sdk_token");
        wx.request({
            url: "https://" + l + "/game/min/?ac=updateShare",
            method: "POST",
            dataType: "json",
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            data: {
                game_pkg: o.default.game_pkg,
                partner_id: o.default.partner_id,
                sdk_token: d,
                invite: e,
                invite_type: r,
                is_new: t,
                role_id: a,
                sever_id: n,
                scene: i
            },
            success: function(e) {
                console.log("[SDK]上报分享结果返回:"), console.log(e);
            }
        });
    },
    msgCheck: function(e, r) {
        console.log("[SDK]查看文本是否有违规内容"), a.default.msgSecCheck({
            content: e,
            scene: 1,
            callback: function(e) {
                function r(r) {
                    return e.apply(this, arguments);
                }
                return r.toString = function() {
                    return e.toString();
                }, r;
            }(function(e) {
                console.log("msg:", e), e.data = {}, 200 === e.result ? (e.statusCode = 200, e.data.state = 1) : (e.statusCode = 0, 
                e.data.state = 0), r && r(e);
            })
        });
    },
    pay: function(e, r) {
        this.startPay(e, r);
    },
    startPay: function(r, t) {
        console.log("[SDK]调起支付，CP传值："), console.log(r), e.pay = "function" == typeof t ? t : null;
        var o = wx.getStorageSync("plat_sdk_token"), n = wx.getStorageSync("plat_session_key");
        if (o || n) {
            var i = wx.getSystemInfoSync(), d = {
                cpbill: r.cpbill,
                productid: r.productid,
                productname: r.productname,
                productdesc: r.productdesc,
                serverid: r.serverid,
                servername: r.servername,
                roleid: r.roleid,
                rolename: r.rolename,
                rolelevel: r.rolelevel,
                price: r.price,
                extension: r.extension,
                sdk_token: o,
                session_key: n,
                platform: i.platform
            };
            this.order_data = d;
            var s = this.getPublicData();
            s.order_data = JSON.stringify(d), s.is_from_min = 1, wx.request({
                url: "https://" + l + "/partner/order",
                method: "POST",
                dataType: "json",
                header: {
                    "content-type": "application/x-www-form-urlencoded"
                },
                data: s,
                success: function(r) {
                    if (console.log("[SDK]完成创建订单"), console.log(r), 200 == r.statusCode) {
                        var t = r.data;
                        if (t.state) {
                            var o = {
                                amount: t.data.pay_data.post_order_data.price,
                                currency: "CNY",
                                productId: t.data.pay_data.post_order_data.productid,
                                productName: t.data.pay_data.post_order_data.productname,
                                productDesc: t.data.pay_data.post_order_data.productdesc,
                                roleId: t.data.pay_data.post_order_data.roleid,
                                roleName: t.data.pay_data.post_order_data.rolename,
                                roleLevel: t.data.pay_data.post_order_data.rolelevel,
                                serverId: t.data.pay_data.post_order_data.serverid,
                                serverName: t.data.pay_data.post_order_data.servername,
                                orderExt: t.data.orderId,
                                callback: function(r) {
                                    "200" == r.result || e.pay && e.pay(1, {
                                        errMsg: t.msg
                                    });
                                }
                            };
                            console.log("[SDK]联运支付参数" + JSON.stringify(o)), a.default.pay(o);
                        } else e.pay && e.pay(1, {
                            errMsg: t.msg
                        });
                    } else e.login && e.login(1, {
                        errMsg: "请求平台服务器失败！"
                    });
                }
            });
        } else e.pay && e.pay(1, {
            errMsg: "用户未登录，支付失败！"
        });
    },
    logCreateRole: function(e) {
        var r = wx.getStorageSync("plat_uid"), t = wx.getStorageSync("plat_username"), o = {};
        o.user_id = r, o.user_name = t, o.role_id = e.roleid, o.role_lev = e.rolelevel, 
        o.role_name = e.rolename, o.server_id = e.serverid, e.roleid && e.serverid && (i = {
            role_id: e.roleid,
            server_id: e.serverid
        }), this.log("create", o);
        var n = {
            roleId: e.roleid,
            roleName: e.rolename,
            roleLevel: e.rolelevel,
            serverId: e.serverid,
            serverName: e.servername,
            roleVip: 0,
            rolePower: 0,
            eventType: 2
        };
        a.default.gameReport(n);
    },
    logEnterGame: function(e, r) {
        var t = wx.getStorageSync("plat_uid"), o = wx.getStorageSync("plat_username"), n = {};
        n.user_id = t, n.user_name = o, n.role_id = e.roleid, n.role_lev = e.rolelevel, 
        n.role_name = e.rolename, n.server_id = e.serverid, e.roleid && e.serverid && (i = {
            role_id: e.roleid,
            server_id: e.serverid
        }), this.log("enter", n), d && this.updateShare(d.invite, d.invite_type, d.is_new, e.roleid, e.serverid, d.scene);
        var l = {
            roleId: e.roleid,
            roleName: e.rolename,
            roleLevel: e.rolelevel,
            serverId: e.serverid,
            serverName: e.servername,
            roleVip: 0,
            rolePower: e.rolepower,
            eventType: 1
        };
        a.default.gameReport(l), a.default.pswitch({
            roleId: e.roleid,
            roleName: e.rolename,
            roleLevel: e.rolelevel,
            serverId: e.serverid,
            serverName: e.servername,
            roleVip: 0,
            rolePower: e.rolepower,
            callback: function(e) {
                function r(r) {
                    return e.apply(this, arguments);
                }
                return r.toString = function() {
                    return e.toString();
                }, r;
            }(function(e) {
                var t = 0;
                1 == e && (t = 1), r && r({
                    show_pay: t
                });
            })
        });
    },
    logRoleUpLevel: function(e, r) {
        var t = wx.getStorageSync("plat_uid"), o = wx.getStorageSync("plat_username"), n = {};
        n.user_id = t, n.user_name = o, n.role_id = e.roleid, n.role_lev = e.rolelevel, 
        n.role_name = e.rolename, n.server_id = e.serverid, e.roleid && e.serverid && (i = {
            role_id: e.roleid,
            server_id: e.serverid
        }), this.log("levelup", n);
        var l = {
            roleId: e.roleid,
            roleName: e.rolename,
            roleLevel: e.rolelevel,
            serverId: e.serverid,
            serverName: e.servername,
            roleVip: 0,
            rolePower: e.rolepower,
            eventType: 3
        };
        a.default.gameReport(l), a.default.pswitch({
            roleId: e.roleid,
            roleName: e.rolename,
            roleLevel: e.rolelevel,
            serverId: e.serverid,
            serverName: e.servername,
            roleVip: 0,
            rolePower: e.rolepower,
            callback: function(e) {
                function r(r) {
                    return e.apply(this, arguments);
                }
                return r.toString = function() {
                    return e.toString();
                }, r;
            }(function(e) {
                var t = 0;
                1 == e && (t = 1), r && r({
                    show_pay: t
                });
            })
        });
    },
    sendUrl: function() {
        a.default.toMiniD();
    },
    uuid: function(e, r) {
        var t, a, o = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""), n = [];
        if (e = e || o.length, r) for (t = 0; t < r; t++) n[t] = o[0 | Math.random() * e]; else for (n[8] = n[13] = n[18] = n[23] = "-", 
        n[14] = "4", t = 0; t < 36; t++) n[t] || (a = 0 | 16 * Math.random(), n[t] = o[19 == t ? 3 & a | 8 : a]);
        return n.join("");
    },
    getPublicData: function() {
        var e = wx.getSystemInfoSync(), r = wx.getStorageSync("plat_uuid"), t = wx.getStorageSync("plat_idfv"), a = wx.getStorageSync("plat_ad_code");
        return {
            game_id: o.default.game_id,
            game_pkg: o.default.game_pkg,
            partner_id: o.default.partner_id,
            partner_label: o.default.partner_label,
            ad_code: a,
            uuid: r,
            idfv: t,
            dname: e.model,
            mac: "0000",
            net_type: 0 == e.wifiSignal ? "4G" : "WIFI",
            os_ver: e.system,
            sdk_ver: e.version,
            game_ver: o.default.game_ver,
            device: "android" == e.platform ? 1 : 2
        };
    },
    turnminiC: function(e, r) {
        a.default.turnminiC({
            callback: function(e) {
                0 == e.code ? r(e.data) : r({
                    jump_to: 0
                }), console.log("turnminiC", e);
            }
        });
    },
    log: function(e, r) {
        var t = this.getPublicData();
        for (var a in r) t[a] = r[a];
        console.log("[SDK]上报数据：" + e), console.log(t), wx.request({
            url: "https://" + l + "/partner/h5Log/?type=" + e + "&data=" + encodeURIComponent(JSON.stringify(t))
        });
    },
    getDate: function() {
        var e = new Date();
        return e.getFullYear() + "-" + e.getMonth() + "-" + e.getDate();
    },
    downloadClient: function() {
        wx.openCustomerServiceConversation();
    }
}), l = "sdk.sh9130.com", i = null, d = null, s = null;

function c(e, r, t) {
    e in n && n[e](r, t);
}

exports.init = function(e, r) {
    c("init", e, r);
}, exports.login = function(e) {
    c("login", "", e);
}, exports.pay = function(e, r) {
    c("pay", e, r);
}, exports.openService = function() {
    c("openService");
}, exports.logCreateRole = function(e, r, t, a, o) {
    c("logCreateRole", {
        serverid: e,
        servername: r,
        roleid: t,
        rolename: a,
        rolelevel: o
    });
}, exports.logEnterGame = function(e, r, t, a, o, n, l) {
    c("logEnterGame", {
        serverid: e,
        servername: r,
        roleid: t,
        rolename: a,
        rolelevel: o,
        rolecreatetime: n,
        rolepower: l && l.rolepower ? l.rolepower : ""
    }, l && l.callback ? l.callback : "");
}, exports.logRoleUpLevel = function(e, r, t, a, o, n, l) {
    c("logRoleUpLevel", {
        serverid: e,
        servername: r,
        roleid: t,
        rolename: a,
        rolelevel: o,
        rolecreatetime: n,
        rolepower: l && l.rolepower ? l.rolepower : ""
    }, l && l.callback ? l.callback : "");
}, exports.share = function(e) {
    c("share", {
        type: e
    });
}, exports.msgCheck = function(e, r) {
    c("msgCheck", e, r);
}, exports.downloadClient = function() {
    c("downloadClient");
}, exports.getConfig = function() {
    return {
        game_id: o.default.game_id,
        game_pkg: o.default.game_pkg,
        partner_id: o.default.partner_id
    };
}, exports.getPublicData = function() {
    c("getPublicData");
}, exports.sendUrl = function() {
    c("sendUrl");
}, exports.inspireVideo = function(e) {
    c("inspireVideo", e);
}, exports.turnminiC = function(e) {
    c("turnminiC", "", e);
};