6d424c7f-7979-42f0-97b7-5947321ffbb8.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. "use strict";
  2. cc._RF.push(module, '6d424x/eXlC8Je3WUcyH/u4', 'YZ_Tool_Xiaomi');
  3. // common-plugin/Scripts/YZ_Tool_Xiaomi.ts
  4. "use strict";
  5. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  6. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  7. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  8. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  9. return c > 3 && r && Object.defineProperty(target, key, r), r;
  10. };
  11. var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
  12. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  13. return new (P || (P = Promise))(function (resolve, reject) {
  14. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  15. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  16. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  17. step((generator = generator.apply(thisArg, _arguments || [])).next());
  18. });
  19. };
  20. var __generator = (this && this.__generator) || function (thisArg, body) {
  21. var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
  22. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
  23. function verb(n) { return function (v) { return step([n, v]); }; }
  24. function step(op) {
  25. if (f) throw new TypeError("Generator is already executing.");
  26. while (_) try {
  27. if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
  28. if (y = 0, t) op = [op[0] & 2, t.value];
  29. switch (op[0]) {
  30. case 0: case 1: t = op; break;
  31. case 4: _.label++; return { value: op[1], done: false };
  32. case 5: _.label++; y = op[1]; op = [0]; continue;
  33. case 7: op = _.ops.pop(); _.trys.pop(); continue;
  34. default:
  35. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
  36. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
  37. if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
  38. if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
  39. if (t[2]) _.ops.pop();
  40. _.trys.pop(); continue;
  41. }
  42. op = body.call(thisArg, _);
  43. } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
  44. if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
  45. }
  46. };
  47. Object.defineProperty(exports, "__esModule", { value: true });
  48. var PlatUtils_1 = require("./PlatUtils");
  49. var Utils_1 = require("./Utils");
  50. var YZ_Constant_1 = require("./YZ_Constant");
  51. var YZ_LocalStorage_1 = require("./YZ_LocalStorage");
  52. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  53. var ST_ServerUrl = "http://apps.youlesp.com/gss?";
  54. var POST_ServerUrl = "http://report.youlesp.com/gss?";
  55. var ST_DefaultServerConfig = "";
  56. var ST_NativeInsertAdClickTimes = "NativeInsertAdClickTimes";
  57. var ST_LastDateTime = "LastDateTime";
  58. var ST_InsertAdShowCounts = "NativeInsertAdShowCount"; //插屏显示次数
  59. var ST_BannerAdCloseCounts = "ST_BannerAdCloseCounts"; //banner广告关闭次数
  60. var ST_YZBannerShowCounts = "YZBannerShowCounts"; //banner广告关闭次数
  61. var YZ_Tool_Xiaomi = /** @class */ (function () {
  62. function YZ_Tool_Xiaomi() {
  63. this._sysInfo = null;
  64. this._serverConfig = null;
  65. this._nativeInsertAdClickTimes = 0;
  66. this._insertAdShowCounts = 0;
  67. this._bannerAdCloseCounts = 0;
  68. this._yzBannerShowCounts = 0;
  69. //设备UID
  70. this._uid = "0";
  71. //服务器返回UID
  72. this._service_uid = "0";
  73. this._loginTime = 0;
  74. this._loginInterval = 30;
  75. this._reportLoginTime = 0;
  76. this._reportLoginInterval = 30;
  77. this.isReport = false;
  78. }
  79. Object.defineProperty(YZ_Tool_Xiaomi.prototype, "SysInfo", {
  80. get: function () {
  81. return this._sysInfo || {};
  82. },
  83. enumerable: false,
  84. configurable: true
  85. });
  86. Object.defineProperty(YZ_Tool_Xiaomi.prototype, "ServerConfig", {
  87. get: function () {
  88. return this._serverConfig;
  89. },
  90. enumerable: false,
  91. configurable: true
  92. });
  93. Object.defineProperty(YZ_Tool_Xiaomi.prototype, "NativeInsertAdClickTimes", {
  94. get: function () {
  95. return this._nativeInsertAdClickTimes;
  96. },
  97. enumerable: false,
  98. configurable: true
  99. });
  100. Object.defineProperty(YZ_Tool_Xiaomi.prototype, "insertAdShowCounts", {
  101. /**
  102. * 插屏广告展示次数
  103. */
  104. get: function () {
  105. return this._insertAdShowCounts;
  106. },
  107. enumerable: false,
  108. configurable: true
  109. });
  110. Object.defineProperty(YZ_Tool_Xiaomi.prototype, "bannerAdCloseCounts", {
  111. /**
  112. * banner关闭次数
  113. */
  114. get: function () {
  115. return this._bannerAdCloseCounts;
  116. },
  117. enumerable: false,
  118. configurable: true
  119. });
  120. Object.defineProperty(YZ_Tool_Xiaomi.prototype, "yzBannerShowCounts", {
  121. /**
  122. * 自定义banner展示次数
  123. */
  124. get: function () {
  125. return this._yzBannerShowCounts;
  126. },
  127. enumerable: false,
  128. configurable: true
  129. });
  130. Object.defineProperty(YZ_Tool_Xiaomi.prototype, "uid", {
  131. get: function () {
  132. // if (this._service_uid != "0") return this._uid;
  133. // this._login();
  134. return "0";
  135. },
  136. enumerable: false,
  137. configurable: true
  138. });
  139. Object.defineProperty(YZ_Tool_Xiaomi.prototype, "serviceId", {
  140. /**
  141. * 服务器返回UID
  142. */
  143. get: function () {
  144. if (this._service_uid != "0")
  145. return this._service_uid;
  146. this.reportLogin();
  147. return "0";
  148. },
  149. enumerable: false,
  150. configurable: true
  151. });
  152. YZ_Tool_Xiaomi.prototype._login = function () {
  153. return __awaiter(this, void 0, void 0, function () {
  154. var curTime, interval, self;
  155. return __generator(this, function (_a) {
  156. curTime = new Date().getTime();
  157. interval = (curTime - this._loginTime) / 1000;
  158. if (interval > 0 && interval < this._loginInterval) {
  159. Utils_1.utils.showLog("\u767B\u5F55\u8BF7\u6C42\u95F4\u9694\u5C0F\u4E8E\uFF1A" + this._loginInterval + "\u79D2");
  160. return [2 /*return*/];
  161. }
  162. this._loginTime = curTime;
  163. self = this;
  164. Utils_1.utils.showLog("vivo暂时不获取uid,uid全部为0");
  165. this._uid = "0";
  166. this.reportLogin();
  167. return [2 /*return*/];
  168. });
  169. });
  170. };
  171. YZ_Tool_Xiaomi.prototype.countNativeInserClick = function () {
  172. this._nativeInsertAdClickTimes++;
  173. YZ_LocalStorage_1.default.setItem(Utils_1.utils.config.xiaomiConfig.appID + "_" + ST_NativeInsertAdClickTimes, this._nativeInsertAdClickTimes);
  174. };
  175. /**
  176. * 增加插屏显示的次数
  177. */
  178. YZ_Tool_Xiaomi.prototype.countInserShowCount = function () {
  179. this._insertAdShowCounts++;
  180. YZ_LocalStorage_1.default.setItem(Utils_1.utils.config.xiaomiConfig.appID + "_" + ST_InsertAdShowCounts, this._insertAdShowCounts);
  181. };
  182. /**
  183. * 增加banner的关闭次数
  184. */
  185. YZ_Tool_Xiaomi.prototype.countBannerCloseCount = function () {
  186. this._bannerAdCloseCounts++;
  187. YZ_LocalStorage_1.default.setItem(Utils_1.utils.config.xiaomiConfig.appID + "_" + ST_BannerAdCloseCounts, this._bannerAdCloseCounts);
  188. };
  189. /**
  190. * 增加自定义banner的显示次数
  191. */
  192. YZ_Tool_Xiaomi.prototype.countYzBannerShowCount = function () {
  193. this._yzBannerShowCounts++;
  194. YZ_LocalStorage_1.default.setItem(Utils_1.utils.config.xiaomiConfig.appID + "_" + ST_YZBannerShowCounts, this._yzBannerShowCounts);
  195. };
  196. /**
  197. * 上报登录接口获取UID
  198. */
  199. YZ_Tool_Xiaomi.prototype.reportLogin = function () {
  200. var _this = this;
  201. if (this.isReport)
  202. return;
  203. this.isReport = true;
  204. var self = this;
  205. var curTime = new Date().getTime();
  206. var interval = (curTime - this._reportLoginTime) / 1000;
  207. if (interval > 0 && interval < this._reportLoginInterval) {
  208. Utils_1.utils.showLog("\u4E0A\u62A5\u767B\u5F55\u83B7\u53D6UID\u5C0F\u4E8E\uFF1A" + this._reportLoginInterval + "\u79D2");
  209. return;
  210. }
  211. this._reportLoginTime = curTime;
  212. var method = "m=login";
  213. var url = ST_ServerUrl + method + ("&device_data=" + encodeURI(JSON.stringify(this._sysInfo)));
  214. Utils_1.utils.commomHttpRequest(url, function (ret, data) {
  215. if (ret) {
  216. if (data) {
  217. var result = JSON.parse(data);
  218. Utils_1.utils.showLog("data=" + data);
  219. Utils_1.utils.showLog("result=" + result);
  220. Utils_1.utils.showLog("result.uid=" + result.uid);
  221. if (result.uid) {
  222. self._service_uid = "" + result.uid;
  223. Utils_1.utils.showLog("服务器请求登录成功! _service_uid=" + self._service_uid);
  224. YZ_LocalStorage_1.default.setItem(YZ_Constant_1.default.ST_SERVICE_UID, self._service_uid);
  225. }
  226. }
  227. }
  228. else {
  229. Utils_1.utils.showLog("获取数据失败1");
  230. }
  231. _this.isReport = false;
  232. });
  233. };
  234. /**
  235. *
  236. * @param data 配置数据
  237. */
  238. YZ_Tool_Xiaomi.prototype.init = function (data) {
  239. if (PlatUtils_1.default.IsXiaoMi) {
  240. if (data) {
  241. var configObj = JSON.parse(data);
  242. if (configObj && configObj.xiaomi) {
  243. ST_DefaultServerConfig = JSON.stringify(configObj.xiaomi);
  244. }
  245. }
  246. this._service_uid = YZ_LocalStorage_1.default.getItem(YZ_Constant_1.default.ST_SERVICE_UID);
  247. this._service_uid = this._service_uid ? this._service_uid : "0";
  248. //@ts-ignore
  249. if (qg.getUpdateManager) {
  250. //@ts-ignore
  251. var updateManager_1 = qg.getUpdateManager();
  252. updateManager_1.onCheckForUpdate(function (res) {
  253. // 请求完新版本信息的回调
  254. Utils_1.utils.showLog('onCheckForUpdate', res.hasUpdate);
  255. });
  256. updateManager_1.onUpdateReady(function () {
  257. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  258. updateManager_1.applyUpdate();
  259. });
  260. updateManager_1.onUpdateFailed(function () {
  261. // 新版本下载失败
  262. Utils_1.utils.showMsg("自动更新失败,请手动重启游戏!");
  263. });
  264. }
  265. this.getSystemInfo();
  266. this._loadConfig();
  267. }
  268. };
  269. YZ_Tool_Xiaomi.prototype._loadConfig = function () {
  270. var _this = this;
  271. if (PlatUtils_1.default.IsXiaoMi) {
  272. var method = "m=g";
  273. var url = ST_ServerUrl + method;
  274. Utils_1.utils.commomHttpRequest(url, function (ret, data) {
  275. if (ret) {
  276. Utils_1.utils.showLog("小米服务器配置数据获取成功: data = " + data);
  277. if (data) {
  278. var result = JSON.parse(data);
  279. if (result) {
  280. if (!Utils_1.utils.DebugLoacalConfig) {
  281. _this._serverConfig = result;
  282. if (_this._serverConfig.is_show_log_view && _this._serverConfig.is_show_log_view == "true") {
  283. Utils_1.utils.showLogView = true;
  284. }
  285. }
  286. else {
  287. Utils_1.utils.showLog("开启了本地数据测试,使用本地配置!");
  288. }
  289. }
  290. else {
  291. Utils_1.utils.showLog("小米服务器配置数据不是合法的JSON数据, 使用本地配置!");
  292. }
  293. }
  294. }
  295. else {
  296. Utils_1.utils.showLog("小米服务器配置数据获取失败, 使用本地配置!");
  297. }
  298. if (!_this._serverConfig) {
  299. _this._serverConfig = JSON.parse(ST_DefaultServerConfig);
  300. }
  301. else {
  302. if (_this._serverConfig.is_local_pos_id
  303. && _this._serverConfig.is_local_pos_id == "false") {
  304. // 使用服务器下发的广告id
  305. Utils_1.utils.showLog("使用服务器下发的广告id");
  306. Utils_1.utils.config.xiaomiConfig.insertId = _this._serverConfig.intersititia_pos_id;
  307. Utils_1.utils.config.xiaomiConfig.videoId = _this._serverConfig.video_pos_id;
  308. Utils_1.utils.config.xiaomiConfig.nativeInsertIds = _this.ServerConfig.native_intersititial_pos_id;
  309. Utils_1.utils.config.xiaomiConfig.nativeBannerIds = _this.ServerConfig.native_banner_pos_id;
  310. Utils_1.utils.config.xiaomiConfig.nativeTryGameIds = _this.ServerConfig.native_trygame_pos_id;
  311. Utils_1.utils.config.xiaomiConfig.bannerId = _this._serverConfig.banner_pos_id;
  312. }
  313. else {
  314. Utils_1.utils.showLog("使用本地配置的广告ID");
  315. }
  316. if (_this.ServerConfig.native_banner_configs) {
  317. for (var i = 0; i < _this.ServerConfig.native_banner_configs.length; i++) {
  318. Utils_1.utils.showLog("获取到原生广告配置:" + _this.ServerConfig.native_banner_configs[i].location, ">>>>", JSON.stringify(_this.ServerConfig.native_banner_configs[i]));
  319. Utils_1.utils.config.xiaomiConfig.setNativeBannerInfo(_this.ServerConfig.native_banner_configs[i].location, _this.ServerConfig.native_banner_configs[i]);
  320. }
  321. }
  322. }
  323. Utils_1.utils.emitServerInitEvent();
  324. });
  325. }
  326. };
  327. /**
  328. * 比较当前平台版本是否高于指定的版本号
  329. * @param miniVersion 最低平台版本号
  330. */
  331. YZ_Tool_Xiaomi.prototype.isOverMiniVersion = function (miniVersion) {
  332. if (PlatUtils_1.default.IsXiaoMi) {
  333. if (this._sysInfo && this._sysInfo.platformVersionCode) {
  334. return this._sysInfo.platformVersionCode >= miniVersion;
  335. }
  336. }
  337. return false;
  338. };
  339. /**
  340. * 上报关卡数据
  341. * @param level 当前关卡ID
  342. * @param levelName 关卡名称
  343. * @param status 状态
  344. */
  345. YZ_Tool_Xiaomi.prototype.postLevel = function (level, status, levelName) {
  346. if (PlatUtils_1.default.IsXiaoMi) {
  347. var method = "m=rlevel";
  348. var url = POST_ServerUrl + method + ("&level_id=" + level + "&level_name=" + encodeURI(levelName) + "&status=" + status);
  349. Utils_1.utils.commomHttpRequest(url, function (ret, data) {
  350. if (ret) {
  351. Utils_1.utils.showLog("关卡数据上报成功!");
  352. }
  353. else {
  354. Utils_1.utils.showLog("关卡数据上报失败!");
  355. }
  356. }.bind(this));
  357. }
  358. };
  359. /**
  360. * 上报自定义事件
  361. * @param level 当前关卡ID
  362. * @param levelName 关卡名称
  363. * @param status 状态
  364. */
  365. YZ_Tool_Xiaomi.prototype.sendEvent = function (eventName) {
  366. if (PlatUtils_1.default.IsXiaoMi) {
  367. var method = "m=revent";
  368. var url = POST_ServerUrl + method + ("&event=" + encodeURI(eventName));
  369. Utils_1.utils.commomHttpRequest(url, function (ret, data) {
  370. if (ret) {
  371. Utils_1.utils.showLog("上报自定义事件成功!");
  372. }
  373. else {
  374. Utils_1.utils.showLog("上报自定义事件失败!");
  375. }
  376. }.bind(this));
  377. }
  378. };
  379. /**
  380. * 获取系统信息
  381. */
  382. YZ_Tool_Xiaomi.prototype.getSystemInfo = function () {
  383. if (PlatUtils_1.default.IsXiaoMi) {
  384. //@ts-ignore
  385. this._sysInfo = qg.getSystemInfoSync();
  386. Utils_1.utils.showLog("获取系统信息成功:" + JSON.stringify(this._sysInfo));
  387. }
  388. };
  389. YZ_Tool_Xiaomi.prototype.GameExit = function () {
  390. if (PlatUtils_1.default.IsXiaoMi) {
  391. //@ts-ignore
  392. //可以退出游戏
  393. qg.exitApplication({
  394. success: function () {
  395. Utils_1.utils.showLog("exit Game success");
  396. },
  397. fail: function () {
  398. Utils_1.utils.showLog("exit Game fail");
  399. }
  400. });
  401. }
  402. };
  403. YZ_Tool_Xiaomi = __decorate([
  404. ccclass
  405. ], YZ_Tool_Xiaomi);
  406. return YZ_Tool_Xiaomi;
  407. }());
  408. exports.default = YZ_Tool_Xiaomi;
  409. cc._RF.pop();