monitor.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. ! function(t, e) {
  2. "object" == typeof exports && "undefined" != typeof module ? module.exports = e() : "function" == typeof define &&
  3. define.amd ? define(e) : (t = "undefined" != typeof globalThis ? globalThis : t || self).MonitorMinSDK = e()
  4. }(this, (function() {
  5. "use strict";
  6. function t(e) {
  7. return t = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(t) {
  8. return typeof t
  9. } : function(t) {
  10. return t && "function" == typeof Symbol && t.constructor === Symbol && t !== Symbol.prototype ?
  11. "symbol" : typeof t
  12. }, t(e)
  13. }
  14. function e(t, e) {
  15. for (var n = 0; n < e.length; n++) {
  16. var i = e[n];
  17. i.enumerable = i.enumerable || !1, i.configurable = !0, "value" in i && (i.writable = !0), Object
  18. .defineProperty(t, i.key, i)
  19. }
  20. }
  21. var n, i, r = r || function(t, e) {
  22. var n = {},
  23. i = n.lib = {},
  24. r = function() {},
  25. o = i.Base = {
  26. extend: function(t) {
  27. r.prototype = this;
  28. var e = new r;
  29. return t && e.mixIn(t), e.hasOwnProperty("init") || (e.init = function() {
  30. e.$super.init.apply(this, arguments)
  31. }), e.init.prototype = e, e.$super = this, e
  32. },
  33. create: function() {
  34. var t = this.extend();
  35. return t.init.apply(t, arguments), t
  36. },
  37. init: function() {},
  38. mixIn: function(t) {
  39. for (var e in t) t.hasOwnProperty(e) && (this[e] = t[e]);
  40. t.hasOwnProperty("toString") && (this.toString = t.toString)
  41. },
  42. clone: function() {
  43. return this.init.prototype.extend(this)
  44. }
  45. },
  46. s = i.WordArray = o.extend({
  47. init: function(t, e) {
  48. t = this.words = t || [], this.sigBytes = null != e ? e : 4 * t.length
  49. },
  50. toString: function(t) {
  51. return (t || c).stringify(this)
  52. },
  53. concat: function(t) {
  54. var e = this.words,
  55. n = t.words,
  56. i = this.sigBytes;
  57. if (t = t.sigBytes, this.clamp(), i % 4)
  58. for (var r = 0; r < t; r++) e[i + r >>> 2] |= (n[r >>> 2] >>> 24 - r % 4 *
  59. 8 & 255) << 24 - (i + r) % 4 * 8;
  60. else if (65535 < n.length)
  61. for (r = 0; r < t; r += 4) e[i + r >>> 2] = n[r >>> 2];
  62. else e.push.apply(e, n);
  63. return this.sigBytes += t, this
  64. },
  65. clamp: function() {
  66. var e = this.words,
  67. n = this.sigBytes;
  68. e[n >>> 2] &= 4294967295 << 32 - n % 4 * 8, e.length = t.ceil(n / 4)
  69. },
  70. clone: function() {
  71. var t = o.clone.call(this);
  72. return t.words = this.words.slice(0), t
  73. },
  74. random: function(e) {
  75. for (var n = [], i = 0; i < e; i += 4) n.push(4294967296 * t.random() | 0);
  76. return new s.init(n, e)
  77. }
  78. }),
  79. a = n.enc = {},
  80. c = a.Hex = {
  81. stringify: function(t) {
  82. var e = t.words;
  83. t = t.sigBytes;
  84. for (var n = [], i = 0; i < t; i++) {
  85. var r = e[i >>> 2] >>> 24 - i % 4 * 8 & 255;
  86. n.push((r >>> 4).toString(16)), n.push((15 & r).toString(16))
  87. }
  88. return n.join("")
  89. },
  90. parse: function(t) {
  91. for (var e = t.length, n = [], i = 0; i < e; i += 2) n[i >>> 3] |= parseInt(t
  92. .substr(i, 2), 16) << 24 - i % 8 * 4;
  93. return new s.init(n, e / 2)
  94. }
  95. },
  96. u = a.Latin1 = {
  97. stringify: function(t) {
  98. var e = t.words;
  99. t = t.sigBytes;
  100. for (var n = [], i = 0; i < t; i++) n.push(String.fromCharCode(e[i >>> 2] >>> 24 -
  101. i % 4 * 8 & 255));
  102. return n.join("")
  103. },
  104. parse: function(t) {
  105. for (var e = t.length, n = [], i = 0; i < e; i++) n[i >>> 2] |= (255 & t.charCodeAt(
  106. i)) << 24 - i % 4 * 8;
  107. return new s.init(n, e)
  108. }
  109. },
  110. f = a.Utf8 = {
  111. stringify: function(t) {
  112. try {
  113. return decodeURIComponent(escape(u.stringify(t)))
  114. } catch (t) {
  115. throw Error("Malformed UTF-8 data")
  116. }
  117. },
  118. parse: function(t) {
  119. return u.parse(unescape(encodeURIComponent(t)))
  120. }
  121. },
  122. l = i.BufferedBlockAlgorithm = o.extend({
  123. reset: function() {
  124. this._data = new s.init, this._nDataBytes = 0
  125. },
  126. _append: function(t) {
  127. "string" == typeof t && (t = f.parse(t)), this._data.concat(t), this
  128. ._nDataBytes += t.sigBytes
  129. },
  130. _process: function(e) {
  131. var n = this._data,
  132. i = n.words,
  133. r = n.sigBytes,
  134. o = this.blockSize,
  135. a = r / (4 * o);
  136. if (e = (a = e ? t.ceil(a) : t.max((0 | a) - this._minBufferSize, 0)) * o, r = t
  137. .min(4 * e, r), e) {
  138. for (var c = 0; c < e; c += o) this._doProcessBlock(i, c);
  139. c = i.splice(0, e), n.sigBytes -= r
  140. }
  141. return new s.init(c, r)
  142. },
  143. clone: function() {
  144. var t = o.clone.call(this);
  145. return t._data = this._data.clone(), t
  146. },
  147. _minBufferSize: 0
  148. });
  149. i.Hasher = l.extend({
  150. cfg: o.extend(),
  151. init: function(t) {
  152. this.cfg = this.cfg.extend(t), this.reset()
  153. },
  154. reset: function() {
  155. l.reset.call(this), this._doReset()
  156. },
  157. update: function(t) {
  158. return this._append(t), this._process(), this
  159. },
  160. finalize: function(t) {
  161. return t && this._append(t), this._doFinalize()
  162. },
  163. blockSize: 16,
  164. _createHelper: function(t) {
  165. return function(e, n) {
  166. return new t.init(n).finalize(e)
  167. }
  168. },
  169. _createHmacHelper: function(t) {
  170. return function(e, n) {
  171. return new p.HMAC.init(t, n).finalize(e)
  172. }
  173. }
  174. });
  175. var p = n.algo = {};
  176. return n
  177. }(Math);
  178. ! function(t) {
  179. for (var e = r, n = (o = e.lib).WordArray, i = o.Hasher, o = e.algo, s = [], a = [], c = function(t) {
  180. return 4294967296 * (t - (0 | t)) | 0
  181. }, u = 2, f = 0; 64 > f;) {
  182. var l;
  183. t: {
  184. l = u;
  185. for (var p = t.sqrt(l), h = 2; h <= p; h++)
  186. if (!(l % h)) {
  187. l = !1;
  188. break t
  189. } l = !0
  190. }
  191. l && (8 > f && (s[f] = c(t.pow(u, .5))), a[f] = c(t.pow(u, 1 / 3)), f++), u++
  192. }
  193. var d = [];
  194. o = o.SHA256 = i.extend({
  195. _doReset: function() {
  196. this._hash = new n.init(s.slice(0))
  197. },
  198. _doProcessBlock: function(t, e) {
  199. for (var n = this._hash.words, i = n[0], r = n[1], o = n[2], s = n[3], c = n[4], u =
  200. n[5], f = n[6], l = n[7], p = 0; 64 > p; p++) {
  201. if (16 > p) d[p] = 0 | t[e + p];
  202. else {
  203. var h = d[p - 15],
  204. y = d[p - 2];
  205. d[p] = ((h << 25 | h >>> 7) ^ (h << 14 | h >>> 18) ^ h >>> 3) + d[p - 7] + (
  206. (y << 15 | y >>> 17) ^ (y << 13 | y >>> 19) ^ y >>> 10) + d[p - 16]
  207. }
  208. h = l + ((c << 26 | c >>> 6) ^ (c << 21 | c >>> 11) ^ (c << 7 | c >>> 25)) + (
  209. c & u ^ ~c & f) + a[p] + d[p], y = ((i << 30 | i >>> 2) ^ (i << 19 |
  210. i >>> 13) ^ (i << 10 | i >>> 22)) + (i & r ^ i & o ^ r & o), l = f, f =
  211. u, u = c, c = s + h | 0, s = o, o = r, r = i, i = h + y | 0
  212. }
  213. n[0] = n[0] + i | 0, n[1] = n[1] + r | 0, n[2] = n[2] + o | 0, n[3] = n[3] + s | 0,
  214. n[4] = n[4] + c | 0, n[5] = n[5] + u | 0, n[6] = n[6] + f | 0, n[7] = n[7] + l |
  215. 0
  216. },
  217. _doFinalize: function() {
  218. var e = this._data,
  219. n = e.words,
  220. i = 8 * this._nDataBytes,
  221. r = 8 * e.sigBytes;
  222. return n[r >>> 5] |= 128 << 24 - r % 32, n[14 + (r + 64 >>> 9 << 4)] = t.floor(i /
  223. 4294967296), n[15 + (r + 64 >>> 9 << 4)] = i, e.sigBytes = 4 * n.length,
  224. this._process(), this._hash
  225. },
  226. clone: function() {
  227. var t = i.clone.call(this);
  228. return t._hash = this._hash.clone(), t
  229. }
  230. });
  231. e.SHA256 = i._createHelper(o), e.HmacSHA256 = i._createHmacHelper(o)
  232. }(Math), i = (n = r).enc.Utf8, n.algo.HMAC = n.lib.Base.extend({
  233. init: function(t, e) {
  234. t = this._hasher = new t.init, "string" == typeof e && (e = i.parse(e));
  235. var n = t.blockSize,
  236. r = 4 * n;
  237. e.sigBytes > r && (e = t.finalize(e)), e.clamp();
  238. for (var o = this._oKey = e.clone(), s = this._iKey = e.clone(), a = o.words, c = s
  239. .words, u = 0; u < n; u++) a[u] ^= 1549556828, c[u] ^= 909522486;
  240. o.sigBytes = s.sigBytes = r, this.reset()
  241. },
  242. reset: function() {
  243. var t = this._hasher;
  244. t.reset(), t.update(this._iKey)
  245. },
  246. update: function(t) {
  247. return this._hasher.update(t), this
  248. },
  249. finalize: function(t) {
  250. var e = this._hasher;
  251. return t = e.finalize(t), e.reset(), e.finalize(this._oKey.clone().concat(t))
  252. }
  253. });
  254. var o = r.HmacSHA256;
  255. function s(t, e, n, i) {
  256. return new Promise((function(r, o) {
  257. try {
  258. var s = new XMLHttpRequest;
  259. s && (s.withCredentials = !1, s.onreadystatechange = function() {
  260. if (4 === s.readyState)
  261. if (s.status >= 200 && s.status < 300 || 304 == s.status) {
  262. var t = JSON.parse(s.responseText);
  263. n(t, r, o)
  264. } else i(s.status, r, o)
  265. }, s.open("POST", t, !0), s.setRequestHeader("Content-type",
  266. "application/json; charset=UTF-8"), s.send(JSON.stringify(e) || null))
  267. } catch (t) {
  268. i("请求异常", r, o)
  269. }
  270. }))
  271. }
  272. var a = {
  273. INIT_CONFIG: "monitorsdk_config",
  274. BASE_INFO: "monitorsdk_base_info",
  275. PENDING_DATA: "monitorsdk_pending_data",
  276. MAIN_APP_MONITORED: "monitorsdk_main_app"
  277. },
  278. c = function(t) {
  279. var e;
  280. try {
  281. e = JSON.parse(window.localStorage.getItem(t)) || null
  282. } catch (n) {
  283. e = window.localStorage.getItem(t)
  284. }
  285. return e
  286. },
  287. u = function(e, n) {
  288. "object" === t(n) && (n = JSON.stringify(n)), window.localStorage.setItem(e, n)
  289. },
  290. f = window.localStorage.clear;
  291. window.localStorage.clear = function() {
  292. var t = {},
  293. e = Object.values(a);
  294. e.forEach((function(e) {
  295. t[e] = c(e)
  296. })), f.apply(this, arguments), e.forEach((function(e) {
  297. u(e, t[e])
  298. }))
  299. };
  300. var l = ["token", "deviceId", "appId", "platform", "reportTime"],
  301. p = function() {
  302. var t = c("monitorsdk_base_info");
  303. if (null != t && t.deviceId) return t.deviceId;
  304. var e = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (function(t) {
  305. var e = 16 * Math.random() | 0;
  306. return ("x" == t ? e : 3 & e | 8).toString(16)
  307. }));
  308. return u("monitorsdk_base_info", {
  309. deviceId: e
  310. }), e
  311. };
  312. function h(t, e) {
  313. var n = l.sort().filter((function(e) {
  314. return t[e]
  315. })).map((function(e) {
  316. return e + "=" + t[e]
  317. })).join("&");
  318. return o("POST" + n, e).toString()
  319. }
  320. var d = function() {
  321. function n() {
  322. ! function(t, e) {
  323. if (!(t instanceof e)) throw new TypeError("Cannot call a class as a function")
  324. }(this, n), this.version = "min-1.0.3", this.initPrams = null, this.postbeUrl = {
  325. dev: "http://jpostbe.huifutest.com",
  326. pro: "https://jua.cloudpnr.com"
  327. }
  328. }
  329. var i, r, o;
  330. return i = n, r = [{
  331. key: "init",
  332. value: function(e) {
  333. if ("object" === t(e)) {
  334. var n = e.pid,
  335. i = e.appKey,
  336. r = e.appToken,
  337. o = e.isDev,
  338. s = void 0 !== o && o;
  339. if (n && i && r) return this.initPrams = {
  340. pid: n,
  341. appKey: i,
  342. appToken: r,
  343. isDev: s,
  344. deviceId: p()
  345. }, this;
  346. console.error("配置信息缺少必填字段!")
  347. } else console.error("初始化配置信息错误")
  348. }
  349. }, {
  350. key: "track",
  351. value: function(t, e) {
  352. var n = arguments.length > 2 && void 0 !== arguments[2] && arguments[2],
  353. i = this.initPrams,
  354. r = i.pid,
  355. o = i.appKey,
  356. a = i.appToken,
  357. c = i.isDev,
  358. u = i.deviceId,
  359. f = {
  360. actionCode: t,
  361. sensorAttr: e,
  362. actionType: 2,
  363. occurTime: Date.now()
  364. };
  365. n && (f.sensorNo = t, f.actionCode = "");
  366. var l = {
  367. appId: r,
  368. token: a,
  369. deviceId: u,
  370. platform: 3,
  371. reportTime: Date.now(),
  372. sensorData: [f]
  373. };
  374. l.sign = h(l, o);
  375. var p = this.postbeUrl.pro;
  376. return c && (p = this.postbeUrl.dev), s(p + "/api/jpostbeApi/autoTrack/save", l,
  377. (function(t, e) {
  378. "90000" === (null == t ? void 0 : t.respCode) ? e(!0): e(!1)
  379. }), (function(t, e) {
  380. e(!1)
  381. }))
  382. }
  383. }], r && e(i.prototype, r), o && e(i, o), n
  384. }();
  385. return new d
  386. }));