var H = Object.defineProperty;
var J = (a, o, n) => o in a ? H(a, o, { enumerable: !0, configurable: !0, writable: !0, value: n }) : a[o] = n;
var p = (a, o, n) => J(a, typeof o != "symbol" ? o + "" : o, n);
const Y = (a, o) => a("openApi/adv/getAdvertisement", o);
var q = /* @__PURE__ */ ((a) => (a.H5 = "1", a.MINI = "2", a.GDT = "4", a.PLUGIN = "5", a.HALF_MINI = "6", a.KL = "9", a))(q || {});
const z = {
  dev: {
    appId: "30dc981f6368458e8d1814581fbfebee",
    serverUrl: "https://talogshushu.postar.cn"
  },
  test: {
    appId: "30dc981f6368458e8d1814581fbfebee",
    serverUrl: "https://talogshushu.postar.cn"
  },
  uat: {
    appId: "30dc981f6368458e8d1814581fbfebee",
    serverUrl: "https://talogshushu.postar.cn"
  },
  prod: {
    appId: "28d05c6cecaf45cbb9eb6867633e478b",
    serverUrl: "https://talogshushu.postar.cn"
  }
}, D = {
  dev: "http://jghwucyshtgjcbrnxgwe.gtxygroup.com/testterpay/",
  test: "https://jghwucyshtgjcbrnxgwe.gtxygroup.com/syncpromotecs/",
  uat: "https://mktcldxylmyxrhgwzsc.postar.cn/",
  prod: "https://mktcldxylmyxrhgw.postar.cn/"
}, M = {
  public: "-----BEGIN PUBLIC KEY-----MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC2D5Z2SOgofxIp1r4Mhgf5AvN1orm9bPWySpGqnyJgvxLFvp/DbokhYZP9NqYnLvPeilVamIaxJUzw/u2hvQUQ1bPL6TKGAEce9cDfowb+ud90OKYeKnVOm3xMOKu5KaONNMHCa4VCwxS7+ykaGqQ8sm2Kj5WBk2eGzAV30BJ0YQIDAQAB-----END PUBLIC KEY-----",
  private: "-----BEGIN RSA PRIVATE KEY-----MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAKBGm6KY2IuHRb+AqJvQtrsaXbFRAfzI6idcaj+0xiHU7T/FHoTjBP/bhIJ2iZiwIJuSHclaLeIGUT12Bzn/TUPMZy+vuATE00BaMYDVXxr/e0dkgZXPwYBL48an9fLx2YtTqaerYCy7KQvtbnyG+7eo9Z9nV/+Hm+KECq3VKdf7AgMBAAECgYBXQ/qLflMxLTcBvOiQ5gQIPaPT3rqJS0+KnNvQ0fmrBAclWIt0aTMYqAovCqGCfCtU6SrErhAbZ7smDrSClIoZSoYkLYdc9aStiyVxmoUQziDHCqd14q62itHyxF2fpmoc3BtOqqCLGDf78w+yP9vuCBhnyCYC47O383tFuVCfcQJBAMsrzYeub9fgUN095Q5UvkyGo0E/XGH9VQM4jtYoLn4yE2JLlqCzi/tAuu8pc1QY/CgMnEsRjmkC2UPg8ca83ekCQQDJ83TIgDKm9ZEu8hi19CXvtArtgzSDa9DvLFuueYxgli0xQNU+l9a+uSFBVmGRT/RcDYI0wzH7Dyfyrdym7yRDAkEAjbyJLdarf9alkzLS0SSdfZWP3rztHg81d4HFY/G0PaWBkFlbQ9D+HtIRlzc7lbe4cdgaUOR2jRvHpmsPQK4RwQJAMQX1cnqUUS1JehDw6LKExwR4pqF0DPcOOBEXjGobJpMuE0e+vDwVuCSuqvKyKpkzI2lwEyjTKDPMqb+E0c05iwJAHryFkEaQ+OZIGizE7nCx9ertNsrPtIHxoi7gzusxk0kfcbDfO+Ck4/zDCaBPUTJwDq8c8lg3PtNV3ezly1+tkQ==-----END RSA PRIVATE KEY-----"
};
var u = /* @__PURE__ */ ((a) => (a.ERR_Params = "000011", a.ERR_Request = "000012", a.ERR_SupAd = "000013", a.ERR_OpenMiniProgram = "000014", a.ERR_OpenH5 = "000015", a.ERR_requestTraceId = "000016", a))(u || {});
const _ = {
  "000011": "流量主ID或订单号不能为空",
  "000012": "请求广告失败",
  "000013": "暂不支持该广告类型",
  "000014": "打开小程序失败",
  "000015": "打开H5失败",
  "000016": "请求流水号不能为空"
}, V = new Int32Array(4), d = class d {
  constructor() {
    p(this, "_dataLength", 0);
    p(this, "_bufferLength", 0);
    p(this, "_state", new Int32Array(4));
    p(this, "_buffer", new ArrayBuffer(68));
    p(this, "_buffer8");
    p(this, "_buffer32");
    this._buffer8 = new Uint8Array(this._buffer, 0, 68), this._buffer32 = new Uint32Array(this._buffer, 0, 17), this.start();
  }
  static hashStr(o, n = !1) {
    return this.onePassHasher.start().appendStr(o).end(n);
  }
  static hashAsciiStr(o, n = !1) {
    return this.onePassHasher.start().appendAsciiStr(o).end(n);
  }
  static _hex(o) {
    const n = d.hexChars, e = d.hexOut;
    let t, r, s, f;
    for (f = 0; f < 4; f += 1)
      for (r = f * 8, t = o[f], s = 0; s < 8; s += 2)
        e[r + 1 + s] = n.charAt(t & 15), t >>>= 4, e[r + 0 + s] = n.charAt(t & 15), t >>>= 4;
    return e.join("");
  }
  static _md5cycle(o, n) {
    let e = o[0], t = o[1], r = o[2], s = o[3];
    e += (t & r | ~t & s) + n[0] - 680876936 | 0, e = (e << 7 | e >>> 25) + t | 0, s += (e & t | ~e & r) + n[1] - 389564586 | 0, s = (s << 12 | s >>> 20) + e | 0, r += (s & e | ~s & t) + n[2] + 606105819 | 0, r = (r << 17 | r >>> 15) + s | 0, t += (r & s | ~r & e) + n[3] - 1044525330 | 0, t = (t << 22 | t >>> 10) + r | 0, e += (t & r | ~t & s) + n[4] - 176418897 | 0, e = (e << 7 | e >>> 25) + t | 0, s += (e & t | ~e & r) + n[5] + 1200080426 | 0, s = (s << 12 | s >>> 20) + e | 0, r += (s & e | ~s & t) + n[6] - 1473231341 | 0, r = (r << 17 | r >>> 15) + s | 0, t += (r & s | ~r & e) + n[7] - 45705983 | 0, t = (t << 22 | t >>> 10) + r | 0, e += (t & r | ~t & s) + n[8] + 1770035416 | 0, e = (e << 7 | e >>> 25) + t | 0, s += (e & t | ~e & r) + n[9] - 1958414417 | 0, s = (s << 12 | s >>> 20) + e | 0, r += (s & e | ~s & t) + n[10] - 42063 | 0, r = (r << 17 | r >>> 15) + s | 0, t += (r & s | ~r & e) + n[11] - 1990404162 | 0, t = (t << 22 | t >>> 10) + r | 0, e += (t & r | ~t & s) + n[12] + 1804603682 | 0, e = (e << 7 | e >>> 25) + t | 0, s += (e & t | ~e & r) + n[13] - 40341101 | 0, s = (s << 12 | s >>> 20) + e | 0, r += (s & e | ~s & t) + n[14] - 1502002290 | 0, r = (r << 17 | r >>> 15) + s | 0, t += (r & s | ~r & e) + n[15] + 1236535329 | 0, t = (t << 22 | t >>> 10) + r | 0, e += (t & s | r & ~s) + n[1] - 165796510 | 0, e = (e << 5 | e >>> 27) + t | 0, s += (e & r | t & ~r) + n[6] - 1069501632 | 0, s = (s << 9 | s >>> 23) + e | 0, r += (s & t | e & ~t) + n[11] + 643717713 | 0, r = (r << 14 | r >>> 18) + s | 0, t += (r & e | s & ~e) + n[0] - 373897302 | 0, t = (t << 20 | t >>> 12) + r | 0, e += (t & s | r & ~s) + n[5] - 701558691 | 0, e = (e << 5 | e >>> 27) + t | 0, s += (e & r | t & ~r) + n[10] + 38016083 | 0, s = (s << 9 | s >>> 23) + e | 0, r += (s & t | e & ~t) + n[15] - 660478335 | 0, r = (r << 14 | r >>> 18) + s | 0, t += (r & e | s & ~e) + n[4] - 405537848 | 0, t = (t << 20 | t >>> 12) + r | 0, e += (t & s | r & ~s) + n[9] + 568446438 | 0, e = (e << 5 | e >>> 27) + t | 0, s += (e & r | t & ~r) + n[14] - 1019803690 | 0, s = (s << 9 | s >>> 23) + e | 0, r += (s & t | e & ~t) + n[3] - 187363961 | 0, r = (r << 14 | r >>> 18) + s | 0, t += (r & e | s & ~e) + n[8] + 1163531501 | 0, t = (t << 20 | t >>> 12) + r | 0, e += (t & s | r & ~s) + n[13] - 1444681467 | 0, e = (e << 5 | e >>> 27) + t | 0, s += (e & r | t & ~r) + n[2] - 51403784 | 0, s = (s << 9 | s >>> 23) + e | 0, r += (s & t | e & ~t) + n[7] + 1735328473 | 0, r = (r << 14 | r >>> 18) + s | 0, t += (r & e | s & ~e) + n[12] - 1926607734 | 0, t = (t << 20 | t >>> 12) + r | 0, e += (t ^ r ^ s) + n[5] - 378558 | 0, e = (e << 4 | e >>> 28) + t | 0, s += (e ^ t ^ r) + n[8] - 2022574463 | 0, s = (s << 11 | s >>> 21) + e | 0, r += (s ^ e ^ t) + n[11] + 1839030562 | 0, r = (r << 16 | r >>> 16) + s | 0, t += (r ^ s ^ e) + n[14] - 35309556 | 0, t = (t << 23 | t >>> 9) + r | 0, e += (t ^ r ^ s) + n[1] - 1530992060 | 0, e = (e << 4 | e >>> 28) + t | 0, s += (e ^ t ^ r) + n[4] + 1272893353 | 0, s = (s << 11 | s >>> 21) + e | 0, r += (s ^ e ^ t) + n[7] - 155497632 | 0, r = (r << 16 | r >>> 16) + s | 0, t += (r ^ s ^ e) + n[10] - 1094730640 | 0, t = (t << 23 | t >>> 9) + r | 0, e += (t ^ r ^ s) + n[13] + 681279174 | 0, e = (e << 4 | e >>> 28) + t | 0, s += (e ^ t ^ r) + n[0] - 358537222 | 0, s = (s << 11 | s >>> 21) + e | 0, r += (s ^ e ^ t) + n[3] - 722521979 | 0, r = (r << 16 | r >>> 16) + s | 0, t += (r ^ s ^ e) + n[6] + 76029189 | 0, t = (t << 23 | t >>> 9) + r | 0, e += (t ^ r ^ s) + n[9] - 640364487 | 0, e = (e << 4 | e >>> 28) + t | 0, s += (e ^ t ^ r) + n[12] - 421815835 | 0, s = (s << 11 | s >>> 21) + e | 0, r += (s ^ e ^ t) + n[15] + 530742520 | 0, r = (r << 16 | r >>> 16) + s | 0, t += (r ^ s ^ e) + n[2] - 995338651 | 0, t = (t << 23 | t >>> 9) + r | 0, e += (r ^ (t | ~s)) + n[0] - 198630844 | 0, e = (e << 6 | e >>> 26) + t | 0, s += (t ^ (e | ~r)) + n[7] + 1126891415 | 0, s = (s << 10 | s >>> 22) + e | 0, r += (e ^ (s | ~t)) + n[14] - 1416354905 | 0, r = (r << 15 | r >>> 17) + s | 0, t += (s ^ (r | ~e)) + n[5] - 57434055 | 0, t = (t << 21 | t >>> 11) + r | 0, e += (r ^ (t | ~s)) + n[12] + 1700485571 | 0, e = (e << 6 | e >>> 26) + t | 0, s += (t ^ (e | ~r)) + n[3] - 1894986606 | 0, s = (s << 10 | s >>> 22) + e | 0, r += (e ^ (s | ~t)) + n[10] - 1051523 | 0, r = (r << 15 | r >>> 17) + s | 0, t += (s ^ (r | ~e)) + n[1] - 2054922799 | 0, t = (t << 21 | t >>> 11) + r | 0, e += (r ^ (t | ~s)) + n[8] + 1873313359 | 0, e = (e << 6 | e >>> 26) + t | 0, s += (t ^ (e | ~r)) + n[15] - 30611744 | 0, s = (s << 10 | s >>> 22) + e | 0, r += (e ^ (s | ~t)) + n[6] - 1560198380 | 0, r = (r << 15 | r >>> 17) + s | 0, t += (s ^ (r | ~e)) + n[13] + 1309151649 | 0, t = (t << 21 | t >>> 11) + r | 0, e += (r ^ (t | ~s)) + n[4] - 145523070 | 0, e = (e << 6 | e >>> 26) + t | 0, s += (t ^ (e | ~r)) + n[11] - 1120210379 | 0, s = (s << 10 | s >>> 22) + e | 0, r += (e ^ (s | ~t)) + n[2] + 718787259 | 0, r = (r << 15 | r >>> 17) + s | 0, t += (s ^ (r | ~e)) + n[9] - 343485551 | 0, t = (t << 21 | t >>> 11) + r | 0, o[0] = e + o[0] | 0, o[1] = t + o[1] | 0, o[2] = r + o[2] | 0, o[3] = s + o[3] | 0;
  }
  /**
   * Initialise buffer to be hashed
   */
  start() {
    return this._dataLength = 0, this._bufferLength = 0, this._state.set(d.stateIdentity), this;
  }
  // Char to code point to to array conversion:
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charCodeAt
  // #Example.3A_Fixing_charCodeAt_to_handle_non-Basic-Multilingual-Plane_characters_if_their_presence_earlier_in_the_string_is_unknown
  /**
   * Append a UTF-8 string to the hash buffer
   * @param str String to append
   */
  appendStr(o) {
    const n = this._buffer8, e = this._buffer32;
    let t = this._bufferLength, r, s;
    for (s = 0; s < o.length; s += 1) {
      if (r = o.charCodeAt(s), r < 128)
        n[t++] = r;
      else if (r < 2048)
        n[t++] = (r >>> 6) + 192, n[t++] = r & 63 | 128;
      else if (r < 55296 || r > 56319)
        n[t++] = (r >>> 12) + 224, n[t++] = r >>> 6 & 63 | 128, n[t++] = r & 63 | 128;
      else {
        if (r = (r - 55296) * 1024 + (o.charCodeAt(++s) - 56320) + 65536, r > 1114111)
          throw new Error(
            "Unicode standard supports code points up to U+10FFFF"
          );
        n[t++] = (r >>> 18) + 240, n[t++] = r >>> 12 & 63 | 128, n[t++] = r >>> 6 & 63 | 128, n[t++] = r & 63 | 128;
      }
      t >= 64 && (this._dataLength += 64, d._md5cycle(this._state, e), t -= 64, e[0] = e[16]);
    }
    return this._bufferLength = t, this;
  }
  /**
   * Append an ASCII string to the hash buffer
   * @param str String to append
   */
  appendAsciiStr(o) {
    const n = this._buffer8, e = this._buffer32;
    let t = this._bufferLength, r, s = 0;
    for (; ; ) {
      for (r = Math.min(o.length - s, 64 - t); r--; )
        n[t++] = o.charCodeAt(s++);
      if (t < 64)
        break;
      this._dataLength += 64, d._md5cycle(this._state, e), t = 0;
    }
    return this._bufferLength = t, this;
  }
  /**
   * Append a byte array to the hash buffer
   * @param input array to append
   */
  appendByteArray(o) {
    const n = this._buffer8, e = this._buffer32;
    let t = this._bufferLength, r, s = 0;
    for (; ; ) {
      for (r = Math.min(o.length - s, 64 - t); r--; )
        n[t++] = o[s++];
      if (t < 64)
        break;
      this._dataLength += 64, d._md5cycle(this._state, e), t = 0;
    }
    return this._bufferLength = t, this;
  }
  /**
   * Get the state of the hash buffer
   */
  getState() {
    const o = this._state;
    return {
      buffer: String.fromCharCode.apply(null, Array.from(this._buffer8)),
      buflen: this._bufferLength,
      length: this._dataLength,
      state: [o[0], o[1], o[2], o[3]]
    };
  }
  /**
   * Override the current state of the hash buffer
   * @param state New hash buffer state
   */
  setState(o) {
    const n = o.buffer, e = o.state, t = this._state;
    let r;
    for (this._dataLength = o.length, this._bufferLength = o.buflen, t[0] = e[0], t[1] = e[1], t[2] = e[2], t[3] = e[3], r = 0; r < n.length; r += 1)
      this._buffer8[r] = n.charCodeAt(r);
  }
  /**
   * Hash the current state of the hash buffer and return the result
   * @param raw Whether to return the value as an `Int32Array`
   */
  end(o = !1) {
    const n = this._bufferLength, e = this._buffer8, t = this._buffer32, r = (n >> 2) + 1;
    this._dataLength += n;
    const s = this._dataLength * 8;
    if (e[n] = 128, e[n + 1] = e[n + 2] = e[n + 3] = 0, t.set(d.buffer32Identity.subarray(r), r), n > 55 && (d._md5cycle(this._state, t), t.set(d.buffer32Identity)), s <= 4294967295)
      t[14] = s;
    else {
      const f = s.toString(16).match(/(.*?)(.{0,8})$/);
      if (f === null) return o ? V : "";
      const c = parseInt(f[2], 16), m = parseInt(f[1], 16) || 0;
      t[14] = c, t[15] = m;
    }
    return d._md5cycle(this._state, t), o ? this._state : d._hex(this._state);
  }
};
// Private Static Variables
p(d, "stateIdentity", new Int32Array([
  1732584193,
  -271733879,
  -1732584194,
  271733878
])), p(d, "buffer32Identity", new Int32Array([
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0
])), p(d, "hexChars", "0123456789abcdef"), p(d, "hexOut", []), // Permanent instance is to use for one-call hashing
p(d, "onePassHasher", new d());
let S = d;
if (S.hashStr("hello") !== "5d41402abc4b2a76b9719d911017c592")
  throw new Error("Md5 self test failed.");
function Z(a) {
  const o = Date.now().toString(), n = k(), e = {
    ...a,
    timestamp: o,
    nonceStr: n
  }, t = X(e), r = S.hashStr(t).toString().toLowerCase();
  return JSON.stringify({
    timestamp: o,
    data: e,
    nonceStr: n,
    sign: r
  });
}
function k() {
  const a = "abcdefghijklmnopqrstuvwxyz0123456789";
  let o = "";
  for (let n = 0; n < 16; n++)
    o += a.charAt(Math.floor(Math.random() * a.length));
  return o;
}
function X(a) {
  const o = Object.keys(a).sort();
  let n = "";
  return o.forEach((e) => {
    e !== "sign" && (n += `${e}=${a[e]}&`);
  }), n.slice(0, -1);
}
let N = require("./tdanalytics.my.min.js");
const O = ({
  appId: a,
  serverUrl: o
}) => {
  N.init({ appId: a, serverUrl: o, enableLog: !1 });
}, W = (a) => {
  const o = Object.fromEntries(
    Object.entries(a).filter(
      ([n, e]) => e !== void 0 && e !== ""
    )
  );
  N.track({
    eventName: "ad_exposure_platform",
    properties: {
      ...o
    }
  });
}, R = (a, o) => {
  let n = "";
  o.adType == "1" ? n = "H5广告" : n = "广告类型错误" + o.adType;
  const { trafficId: e, orderNumber: t, ...r } = a;
  W({
    ...r,
    traffic_master_id: e,
    traffic_master_s_name: o.abbreviation,
    advertising_number: o.adId,
    advertising_name: o.adName,
    advertisers: o.advertisersName,
    taskId: o.taskId,
    adType: n,
    orderNumber: t,
    cashier: "流量主支付宝小程序收银台"
  });
};
var x = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
function $(a) {
  return a && a.__esModule && Object.prototype.hasOwnProperty.call(a, "default") ? a.default : a;
}
var b = { exports: {} };
/*! https://mths.be/base64 v1.0.0 by @mathias | MIT license */
var j = b.exports, P;
function ee() {
  return P || (P = 1, function(a, o) {
    (function(n) {
      var e = o, t = a && a.exports == e && a, r = typeof x == "object" && x;
      (r.global === r || r.window === r) && (n = r);
      var s = function(i) {
        this.message = i;
      };
      s.prototype = new Error(), s.prototype.name = "InvalidCharacterError";
      var f = function(i) {
        throw new s(i);
      }, c = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", m = /[\t\n\f\r ]/g, g = function(i) {
        i = String(i).replace(m, "");
        var h = i.length;
        h % 4 == 0 && (i = i.replace(/==?$/, ""), h = i.length), (h % 4 == 1 || // http://whatwg.org/C#alphanumeric-ascii-characters
        /[^+a-zA-Z0-9/]/.test(i)) && f(
          "Invalid character: the string to be decoded is not correctly encoded."
        );
        for (var y = 0, E, B, C = "", w = -1; ++w < h; )
          B = c.indexOf(i.charAt(w)), E = y % 4 ? E * 64 + B : B, y++ % 4 && (C += String.fromCharCode(
            255 & E >> (-2 * y & 6)
          ));
        return C;
      }, I = function(i) {
        i = String(i), /[^\0-\xFF]/.test(i) && f(
          "The string to be encoded contains characters outside of the Latin1 range."
        );
        for (var h = i.length % 3, y = "", E = -1, B, C, w, A, G = i.length - h; ++E < G; )
          B = i.charCodeAt(E) << 16, C = i.charCodeAt(++E) << 8, w = i.charCodeAt(++E), A = B + C + w, y += c.charAt(A >> 18 & 63) + c.charAt(A >> 12 & 63) + c.charAt(A >> 6 & 63) + c.charAt(A & 63);
        return h == 2 ? (B = i.charCodeAt(E) << 8, C = i.charCodeAt(++E), A = B + C, y += c.charAt(A >> 10) + c.charAt(A >> 4 & 63) + c.charAt(A << 2 & 63) + "=") : h == 1 && (A = i.charCodeAt(E), y += c.charAt(A >> 2) + c.charAt(A << 4 & 63) + "=="), y;
      }, v = {
        encode: I,
        decode: g,
        version: "1.0.0"
      };
      if (e && !e.nodeType)
        if (t)
          t.exports = v;
        else
          for (var l in v)
            v.hasOwnProperty(l) && (e[l] = v[l]);
      else
        n.base64 = v;
    })(j);
  }(b, b.exports)), b.exports;
}
var te = ee();
const K = /* @__PURE__ */ $(te), L = 117, T = 128;
function re(a) {
  let o = "";
  for (let n = 0; n < a.length; n++)
    o += String.fromCharCode(a[n]);
  return K.encode(o);
}
function se(a) {
  let o = 0;
  for (const t of a)
    o += t.length;
  const n = new Uint8Array(o);
  let e = 0;
  for (const t of a)
    n.set(t, e), e += t.length;
  return n;
}
function U(a) {
  for (var o = [], n = 0; n < a.length; n++) {
    var e = a.charCodeAt(n);
    e < 128 ? o.push(e) : e < 2048 ? o.push(192 | e >> 6, 128 | e & 63) : (e < 55296 || e >= 57344) && o.push(
      224 | e >> 12,
      128 | e >> 6 & 63,
      128 | e & 63
    );
  }
  return new Uint8Array(o);
}
function Q(a) {
  const o = my.base64ToArrayBuffer(a);
  return new Uint8Array(o);
}
function F(a) {
  const o = new Uint8Array(a);
  let n = "";
  for (let e = 0; e < o.byteLength; e++)
    n += String.fromCharCode(o[e]);
  return K.encode(n);
}
function ne(a) {
  let o = "", n = 0;
  for (; n < a.length; ) {
    const e = a[n++];
    if (e < 128)
      o += String.fromCharCode(e);
    else if (e >= 192 && e < 224) {
      const t = a[n++] & 63;
      o += String.fromCharCode((e & 31) << 6 | t);
    } else if (e >= 224 && e < 240) {
      const t = a[n++] & 63, r = a[n++] & 63;
      o += String.fromCharCode((e & 15) << 12 | t << 6 | r);
    } else
      o += "�";
  }
  return o;
}
function oe(a, o) {
  const e = U(a).buffer, t = F(e), r = U(t);
  let s = [], f = 0, c = 0, m = 0;
  for (; f < r.length; ) {
    const g = Math.min(
      L,
      r.length - f
    ), I = r.slice(f, f + g);
    let v = "";
    for (let l = 0; l < I.length; l++)
      v += String.fromCharCode(I[l]);
    my.rsa({
      action: "encrypt",
      text: v,
      // 设置公钥，需替换你自己的公钥
      key: M.public.replace("-----BEGIN PUBLIC KEY-----", "").replace("-----END PUBLIC KEY-----", ""),
      success: (l) => {
        m = m + 1;
        const i = l.text;
        try {
          const h = Q(i);
          h && s.splice(c, 0, h);
        } catch (h) {
          throw console.error("Base64解码错误:", h), h;
        }
        if (m === c) {
          const h = se(s), y = re(h);
          o(y);
        }
      },
      fail(l) {
        console.error("加密失败: ", JSON.stringify(l));
      }
    }), c++, f = c * L;
  }
}
function ae(a, o) {
  if (!a) {
    console.error("Decrypt error: Input string is null or undefined");
    return;
  }
  const n = Q(a);
  try {
    let e = [], t = 0, r = 0, s = 0;
    for (; t < n.byteLength; ) {
      const f = Math.min(
        T,
        n.byteLength - t
      ), c = n.slice(t, t + f), m = F(c);
      my.rsa({
        action: "decrypt",
        text: m,
        // 设置公钥，需替换你自己的公钥
        key: M.private.replace("-----BEGIN RSA PRIVATE KEY-----", "").replace("-----END RSA PRIVATE KEY-----", ""),
        success: (g) => {
          s = s + 1;
          const I = g.text;
          if (I ? e.push(I) : console.error(`块 ${r + 1} 解密失败`), s === r) {
            const v = e.join("");
            if (v) {
              let l = null;
              const i = my.base64ToArrayBuffer(v);
              l = new Uint8Array(i);
              let h = "";
              const y = new Uint8Array(l);
              h = ne(y), o(h);
            }
          }
        },
        fail(g) {
          console.error("加密失败: ", JSON.stringify(g));
        }
      }), r++, t = r * T;
    }
  } catch (e) {
    throw console.error("RSA解密过程失败:", e), e;
  }
}
const ie = (a) => (my.hideLoading(), new Promise((o, n) => {
  ae(a.data, (e) => {
    const t = JSON.parse(e);
    t.code === "000000" ? o(e) : n(t);
  });
})), fe = (a) => new Promise((o, n) => {
  my.request({
    ...a,
    success: (e) => {
      o(ie(e));
    },
    fail: (e) => {
      my.hideLoading(), n(e);
    }
  });
}), ce = (a, o, n) => fe({
  url: a,
  method: "POST",
  data: o,
  headers: {
    "content-type": "application/json"
    //默认值
  },
  dataType: "json",
  ...n
}), he = (a) => ({
  post: (o, n, e) => ce(D[a] + o, n, e)
});
class ue {
  constructor(o) {
    p(this, "env");
    this.env = o || "prod", O(z[this.env]);
  }
  async showAd(o, n) {
    if (!o.trafficId || !o.orderNumber) {
      this.callBackOnError(
        _[u.ERR_Params],
        u.ERR_Params,
        n
      );
      return;
    }
    this.getAd(o, n);
  }
  async getAd(o, n) {
    const e = {
      adMarkEntry: "1",
      trafficId: o.trafficId || "",
      //流量主id
      adType: o.adType || "",
      //广告类型
      openId: o.openId || ""
      //用户id
    }, t = Z(e);
    oe(t, (r) => {
      Y(he(this.env).post, r).then(
        (s) => {
          this.handleAdsData(o, JSON.parse(s), n);
        },
        (s) => {
          console.log("请求失败:", s), this.callBackOnError(
            _[u.ERR_Request],
            u.ERR_Request,
            n
          );
        }
      );
    });
  }
  // 处理广告数据（跳转小程序、H5）
  handleAdsData(o, n, e) {
    const t = n.data;
    if (!t) {
      this.callBackOnError(
        _[u.ERR_Request],
        u.ERR_Request,
        e
      );
      return;
    }
    if (t.adType !== "1") {
      this.callBackOnError(
        _[u.ERR_SupAd],
        u.ERR_SupAd,
        e
      );
      return;
    }
    let r = t.adDefaultUrl;
    if (t.adType === q.H5 && t.adUrl && (r = t.adUrl), r) {
      r.includes("alipays://") ? this.navigateToMiniProgramScheme(
        o,
        t,
        r,
        e
      ) : my.navigateTo({
        url: "/pages/gtWebView/gtWebView?url=" + r
      }).then(() => {
        var s;
        (s = e == null ? void 0 : e.onSuccess) == null || s.call(e, "success"), R(o, t);
      }).catch((s) => {
        console.log("navigateToWebView err", s), this.callBackOnError(
          _[u.ERR_OpenH5],
          u.ERR_OpenH5,
          e
        );
      });
      return;
    }
  }
  // // 将 scheme 转换为 my.navigateToMiniProgram 的参数
  schemeToParams(o) {
    if (!o.startsWith("alipays:"))
      return { message: "! 非 alipays: 开头" };
    var n = {}, e = (m) => m.replace(/^.*?\?/, "").split("&").map((g) => {
      var I = g.includes("=") ? g.indexOf("=") : g.length;
      return [g.slice(0, I), g.slice(I + 1)].map(decodeURIComponent);
    });
    for (var [t, r] of e(o)) {
      if (t == "appId") {
        if (r.length != 16)
          return { message: `! 非 16 位 appId '${r}'` };
      } else if (t == "page")
        t = "path";
      else if (t == "query") {
        var s = {};
        for (var [f, c] of e(r))
          s[f] = c;
        r = s;
      } else
        return { message: `! 不支持参数 '${t}' ` };
      n[t] = r;
    }
    return { params: n };
  }
  // // 使用 scheme 跳转小程序
  navigateToMiniProgramScheme(o, n, e, t) {
    var { params: r } = this.schemeToParams(e);
    r ? my.navigateToMiniProgram({
      ...r,
      success: (s) => {
        var f;
        (f = t == null ? void 0 : t.onSuccess) == null || f.call(t, "success"), R(o, n);
      },
      fail: (s) => {
        console.log("open err", s), this.callBackOnError(
          _[u.ERR_OpenMiniProgram],
          u.ERR_OpenMiniProgram,
          t
        );
      }
    }) : this.callBackOnError(
      _[u.ERR_OpenMiniProgram],
      u.ERR_OpenMiniProgram,
      t
    );
  }
  callBackOnError(o, n, e) {
    var r;
    const t = {
      data: {
        msg: o,
        code: n
      }
    };
    (r = e == null ? void 0 : e.onError) == null || r.call(e, t);
  }
}
export {
  ue as default
};
