1dff8b41-181f-4cbd-bd92-614af8b54a55.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. "use strict";
  2. cc._RF.push(module, '1dff8tBGB9Mvb2SYUr4tUpV', 'YZ_Tool_Vivo');
  3. // common-plugin/Scripts/YZ_Tool_Vivo.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. //@ts-ignore
  53. var uma = require('./UMengSDK/quickGame/uma.min.js');
  54. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  55. var ST_DefaultServerConfig = "";
  56. var ST_ServerUrl = "http://apps.youlesp.com/gss?";
  57. var POST_ServerUrl = "http://report.youlesp.com/gss?";
  58. var ST_NativeInsertAdClickTimes = "NativeInsertAdClickTimes";
  59. var ST_LastDateTime = "LastDateTime";
  60. var YZ_Tool_Vivo = /** @class */ (function () {
  61. function YZ_Tool_Vivo() {
  62. //@ts-ignore
  63. this.qg = window.qg;
  64. /*
  65. brand String 设备品牌
  66. manufacturer String 设备生产商
  67. model String 设备型号
  68. product String 设备代号
  69. osType String 操作系统名称
  70. osVersionName String 操作系统版本名称
  71. osVersionCode Number 操作系统版本号
  72. platformVersionName String 运行平台版本名称
  73. platformVersionCode Number 运行平台版本号
  74. language String 系统语言
  75. region String 系统地区
  76. screenWidth Number 屏幕宽
  77. screenHeight Number 屏幕高
  78. battery Number 当前电量,0.0 - 1.0 之间
  79. wifiSignal Number wifi信号强度,范围0 - 4
  80. */
  81. this._sysInfo = null;
  82. this._serverConfig = null;
  83. this._nativeInsertAdClickTimes = 0;
  84. // 桌面图标是否创建
  85. this._shortcutCreated = false;
  86. //设备UID
  87. this._uid = "0";
  88. //服务器返回UID
  89. this._service_uid = "0";
  90. this._loginTime = 0;
  91. this._loginInterval = 30;
  92. this._reportLoginTime = 0;
  93. this._reportLoginInterval = 30;
  94. this.isReport = false;
  95. //用户来源
  96. this._source = "";
  97. this._rec_game_banner = null;
  98. this._rec_game_portal = null;
  99. }
  100. Object.defineProperty(YZ_Tool_Vivo.prototype, "SysInfo", {
  101. get: function () {
  102. return this._sysInfo;
  103. },
  104. enumerable: false,
  105. configurable: true
  106. });
  107. Object.defineProperty(YZ_Tool_Vivo.prototype, "ServerConfig", {
  108. get: function () {
  109. return this._serverConfig;
  110. },
  111. enumerable: false,
  112. configurable: true
  113. });
  114. Object.defineProperty(YZ_Tool_Vivo.prototype, "NativeInsertAdClickTimes", {
  115. get: function () {
  116. return this._nativeInsertAdClickTimes;
  117. },
  118. enumerable: false,
  119. configurable: true
  120. });
  121. Object.defineProperty(YZ_Tool_Vivo.prototype, "ShortcutCreated", {
  122. get: function () {
  123. return this._shortcutCreated;
  124. },
  125. enumerable: false,
  126. configurable: true
  127. });
  128. Object.defineProperty(YZ_Tool_Vivo.prototype, "uid", {
  129. get: function () {
  130. // if (this._service_uid != "0") return this._uid;
  131. // this._login();
  132. return "0";
  133. },
  134. enumerable: false,
  135. configurable: true
  136. });
  137. Object.defineProperty(YZ_Tool_Vivo.prototype, "serviceId", {
  138. /**
  139. * 服务器返回UID
  140. */
  141. get: function () {
  142. if (this._service_uid != "0")
  143. return this._service_uid;
  144. this.reportLogin();
  145. return "0";
  146. },
  147. enumerable: false,
  148. configurable: true
  149. });
  150. YZ_Tool_Vivo.prototype._login = function () {
  151. return __awaiter(this, void 0, void 0, function () {
  152. var curTime, interval, self;
  153. return __generator(this, function (_a) {
  154. curTime = new Date().getTime();
  155. interval = (curTime - this._loginTime) / 1000;
  156. if (interval > 0 && interval < this._loginInterval) {
  157. Utils_1.utils.showLog("\u767B\u5F55\u8BF7\u6C42\u95F4\u9694\u5C0F\u4E8E\uFF1A" + this._loginInterval + "\u79D2");
  158. return [2 /*return*/];
  159. }
  160. this._loginTime = curTime;
  161. self = this;
  162. Utils_1.utils.showLog("vivo暂时不获取uid,uid全部为0");
  163. this._uid = "0";
  164. this.reportLogin();
  165. return [2 /*return*/];
  166. });
  167. });
  168. };
  169. /**
  170. * 上报登录接口获取UID
  171. */
  172. YZ_Tool_Vivo.prototype.reportLogin = function () {
  173. var _this = this;
  174. if (this.isReport)
  175. return;
  176. this.isReport = true;
  177. var self = this;
  178. var curTime = new Date().getTime();
  179. var interval = (curTime - this._reportLoginTime) / 1000;
  180. if (interval > 0 && interval < this._reportLoginInterval) {
  181. Utils_1.utils.showLog("\u4E0A\u62A5\u767B\u5F55\u83B7\u53D6UID\u5C0F\u4E8E\uFF1A" + this._reportLoginInterval + "\u79D2");
  182. return;
  183. }
  184. this._reportLoginTime = curTime;
  185. var method = "m=login";
  186. var url = ST_ServerUrl + method + ("&device_data=" + encodeURI(JSON.stringify(this._sysInfo)));
  187. Utils_1.utils.commomHttpRequest(url, function (ret, data) {
  188. if (ret) {
  189. if (data) {
  190. var result = JSON.parse(data);
  191. Utils_1.utils.showLog("data=" + data);
  192. Utils_1.utils.showLog("result=" + result);
  193. Utils_1.utils.showLog("result.uid=" + result.uid);
  194. if (result.uid) {
  195. self._service_uid = "" + result.uid;
  196. Utils_1.utils.showLog("服务器请求登录成功! _service_uid=" + self._service_uid);
  197. YZ_LocalStorage_1.default.setItem(YZ_Constant_1.default.ST_SERVICE_UID, self._service_uid);
  198. }
  199. }
  200. }
  201. else {
  202. Utils_1.utils.showLog("获取数据失败1");
  203. }
  204. _this.isReport = false;
  205. });
  206. };
  207. /**
  208. *
  209. * @param data 配置数据
  210. */
  211. YZ_Tool_Vivo.prototype.init = function (data) {
  212. var _this = this;
  213. if (PlatUtils_1.default.IsVIVO) {
  214. this.umaInit();
  215. //@ts-ignore 检车是否由桌面图标启动
  216. qg.isStartupByShortcut({
  217. success: function (status) {
  218. if (status) {
  219. Utils_1.utils.showLog('通过桌面图标启动应用');
  220. _this._source = "shortCut";
  221. }
  222. else {
  223. Utils_1.utils.showLog('不是通过桌面图标启动应用');
  224. }
  225. }
  226. });
  227. if (data) {
  228. var configObj = JSON.parse(data);
  229. if (configObj && configObj.vivo) {
  230. ST_DefaultServerConfig = JSON.stringify(configObj.vivo);
  231. }
  232. }
  233. this._service_uid = YZ_LocalStorage_1.default.getItem(YZ_Constant_1.default.ST_SERVICE_UID);
  234. this._service_uid = this._service_uid ? this._service_uid : "0";
  235. this._sysInfo = this.qg.getSystemInfoSync();
  236. if (this._sysInfo) {
  237. Utils_1.utils.showLog("VIVO 小游戏平台信息: " + JSON.stringify(this.SysInfo));
  238. }
  239. this._loadConfig();
  240. this._nativeInsertAdClickTimes = YZ_LocalStorage_1.default.getItem(ST_NativeInsertAdClickTimes);
  241. var day = YZ_LocalStorage_1.default.getItem(ST_LastDateTime);
  242. var curDate = new Date();
  243. if (day != curDate.toDateString()) {
  244. this._nativeInsertAdClickTimes = 0;
  245. YZ_LocalStorage_1.default.setItem(ST_NativeInsertAdClickTimes, 0);
  246. }
  247. // 检测桌面图标是否创建
  248. if (this.isOverMiniVersion("1041")) {
  249. Utils_1.utils.registerServerInitEvent(function () {
  250. _this.checkHasShortCut(function (res) {
  251. if (!res && Utils_1.utils.ServerConfig && Utils_1.utils.ServerConfig.start_auto_create_short_cut_time) {
  252. Utils_1.utils.SendEvent("组件初始化成功,弹出自动创建桌面!");
  253. Utils_1.utils.showLog("\u7EC4\u4EF6\u521D\u59CB\u5316\u6210\u529F\uFF0C" + Utils_1.utils.ServerConfig.start_auto_create_short_cut_time + "\u79D2\u540E\u5F39\u51FA\u81EA\u52A8\u521B\u5EFA\u684C\u9762\uFF01");
  254. setTimeout(function () {
  255. _this.createShortcut(function (res) {
  256. if (res) {
  257. Utils_1.utils.showLog("自动创建桌面成功!");
  258. }
  259. else {
  260. Utils_1.utils.showLog("自动创建桌面失败!");
  261. }
  262. });
  263. }, Utils_1.utils.ServerConfig.start_auto_create_short_cut_time * 1000);
  264. }
  265. });
  266. }, this);
  267. }
  268. }
  269. };
  270. YZ_Tool_Vivo.prototype._buildServerUrl = function () {
  271. if (PlatUtils_1.default.IsVIVO) {
  272. var url = "";
  273. if (Utils_1.utils.config.vivoconfig && Utils_1.utils.config.vivoconfig.appID) {
  274. url = ST_ServerUrl + "kyx=true&app_id=" + Utils_1.utils.config.vivoconfig.appID.trim() + "&" + "channel=vivo";
  275. }
  276. else {
  277. Utils_1.utils.showLog("VIVO APPID配置出错!");
  278. }
  279. return url;
  280. }
  281. return null;
  282. };
  283. YZ_Tool_Vivo.prototype._loadConfig = function () {
  284. var _this = this;
  285. if (PlatUtils_1.default.IsVIVO) {
  286. var method = "m=g";
  287. Utils_1.utils.commomHttpRequest(ST_ServerUrl + method, function (ret, data) {
  288. if (ret) {
  289. Utils_1.utils.showLog("VIVO服务器配置数据获取成功: data = " + data);
  290. if (data) {
  291. var result = JSON.parse(data);
  292. if (result) {
  293. if (!Utils_1.utils.DebugLoacalConfig) {
  294. _this._serverConfig = result;
  295. if (_this._serverConfig.is_show_log_view && _this._serverConfig.is_show_log_view == "true") {
  296. Utils_1.utils.showLogView = true;
  297. }
  298. }
  299. else {
  300. Utils_1.utils.showLog("开启了本地数据测试,使用本地配置!");
  301. }
  302. }
  303. else {
  304. Utils_1.utils.showLog("VIVO服务器配置数据不是合法的JSON数据, 使用本地配置!");
  305. }
  306. }
  307. }
  308. else {
  309. Utils_1.utils.showLog("VIVO服务器配置数据获取失败, 使用本地配置!");
  310. }
  311. if (!_this._serverConfig) {
  312. _this._serverConfig = JSON.parse(ST_DefaultServerConfig);
  313. }
  314. else {
  315. if (_this._serverConfig.is_local_pos_id
  316. && _this._serverConfig.is_local_pos_id == "false") {
  317. // 使用服务器下发的广告id
  318. Utils_1.utils.showLog("使用服务器下发的广告id");
  319. Utils_1.utils.config.vivoconfig.bannerId = _this._serverConfig.banner_pos_id;
  320. Utils_1.utils.config.vivoconfig.insertId = _this._serverConfig.intersititia_pos_id;
  321. Utils_1.utils.config.vivoconfig.videoId = _this._serverConfig.video_pos_id;
  322. Utils_1.utils.config.vivoconfig.nativeInsertIds = _this.ServerConfig.native_intersititial_pos_id;
  323. Utils_1.utils.config.vivoconfig.nativeBannerIds = _this.ServerConfig.native_banner_pos_id;
  324. Utils_1.utils.config.vivoconfig.nativeTryGameIds = _this.ServerConfig.native_trygame_pos_id;
  325. Utils_1.utils.config.vivoconfig.recGameBannerId = _this.ServerConfig.rec_game_banner_id;
  326. Utils_1.utils.config.vivoconfig.recPortalId = _this.ServerConfig.rec_portal_id;
  327. Utils_1.utils.config.vivoconfig.nativeSingleAdIds = _this.ServerConfig.native_single_pos_id || Utils_1.utils.config.vivoconfig.nativeSingleAdIds;
  328. }
  329. else {
  330. Utils_1.utils.showLog("使用本地配置的广告ID");
  331. }
  332. if (_this.ServerConfig.native_banner_configs) {
  333. for (var i = 0; i < _this.ServerConfig.native_banner_configs.length; i++) {
  334. Utils_1.utils.showLog("获取到原生广告配置:" + _this.ServerConfig.native_banner_configs[i].location, ">>>>", JSON.stringify(_this.ServerConfig.native_banner_configs[i]));
  335. Utils_1.utils.config.vivoconfig.setNativeBannerInfo(_this.ServerConfig.native_banner_configs[i].location, _this.ServerConfig.native_banner_configs[i]);
  336. }
  337. }
  338. if (_this.ServerConfig.native_customad_configs) {
  339. for (var i = 0; i < _this.ServerConfig.native_customad_configs.length; i++) {
  340. Utils_1.utils.showLog("获取到原生模版广告配置:" + _this.ServerConfig.native_customad_configs[i].location, ">>>>", JSON.stringify(_this.ServerConfig.native_customad_configs[i]));
  341. Utils_1.utils.config.vivoconfig.setCustomAdInfo(_this.ServerConfig.native_customad_configs[i].location, _this.ServerConfig.native_customad_configs[i]);
  342. }
  343. }
  344. }
  345. Utils_1.utils.emitServerInitEvent();
  346. });
  347. }
  348. };
  349. /**
  350. * 比较当前平台版本是否高于指定的版本号
  351. * @param miniVersion 最低平台版本号
  352. */
  353. YZ_Tool_Vivo.prototype.isOverMiniVersion = function (miniVersion) {
  354. if (PlatUtils_1.default.IsVIVO) {
  355. if (this._sysInfo && this._sysInfo.platformVersionCode) {
  356. return this._sysInfo.platformVersionCode >= miniVersion;
  357. }
  358. }
  359. return false;
  360. };
  361. /**
  362. * 创建桌面图标
  363. */
  364. YZ_Tool_Vivo.prototype.createShortcut = function (callback) {
  365. var callbackFunc = callback;
  366. if (PlatUtils_1.default.IsVIVO && this.canCreateShortcut()) {
  367. var self_1 = this;
  368. self_1.qg.installShortcut({
  369. success: function () {
  370. Utils_1.utils.showLog('桌面图标创建成功!');
  371. self_1._shortcutCreated = true;
  372. if (callbackFunc) {
  373. callbackFunc(true);
  374. }
  375. },
  376. fail: function (err) {
  377. self_1._shortcutCreated = true;
  378. cc.log('vivo创建失败err' + err);
  379. if (callbackFunc) {
  380. callbackFunc(false);
  381. }
  382. },
  383. complete: function () {
  384. }
  385. });
  386. }
  387. else {
  388. cc.log("不能创建");
  389. if (callbackFunc) {
  390. callbackFunc(false);
  391. }
  392. }
  393. };
  394. /**
  395. * 是否可以创建桌面图标, 当前平台是否支持创建快捷方式
  396. */
  397. YZ_Tool_Vivo.prototype.canCreateShortcut = function () {
  398. if (PlatUtils_1.default.IsVIVO) {
  399. return this.isOverMiniVersion("1041");
  400. }
  401. return false;
  402. };
  403. YZ_Tool_Vivo.prototype.countNativeInserClick = function () {
  404. this._nativeInsertAdClickTimes++;
  405. YZ_LocalStorage_1.default.setItem(ST_NativeInsertAdClickTimes, this._nativeInsertAdClickTimes);
  406. };
  407. /**
  408. * 分享事件
  409. * @param callback 分享回调
  410. */
  411. YZ_Tool_Vivo.prototype.share = function (callback) {
  412. if (!this.isOverMiniVersion("1052")) {
  413. callback && callback(false, "当前平台不支持");
  414. return;
  415. }
  416. this.qg.share();
  417. callback && callback(true);
  418. return;
  419. };
  420. /**
  421. * 验证桌面快捷方式是否创建过
  422. * @param callBack
  423. */
  424. YZ_Tool_Vivo.prototype.checkHasShortCut = function (callBack) {
  425. var _this = this;
  426. this.qg.hasShortcutInstalled({
  427. success: function (res) {
  428. Utils_1.utils.showLog("检测桌面快捷方式是否已经创建过: result=", res);
  429. if (res == false) {
  430. _this._shortcutCreated = false;
  431. callBack && callBack(false);
  432. }
  433. else {
  434. _this._shortcutCreated = true;
  435. callBack && callBack(true);
  436. }
  437. },
  438. fail: function () {
  439. Utils_1.utils.showLog("检测失败!");
  440. },
  441. complete: function () {
  442. Utils_1.utils.showLog("检测完成!");
  443. }
  444. });
  445. };
  446. /**
  447. * 上报关卡数据
  448. * @param level 当前关卡ID
  449. * @param levelName 关卡名称
  450. * @param status 状态
  451. */
  452. YZ_Tool_Vivo.prototype.postLevel = function (level, status, levelName) {
  453. if (PlatUtils_1.default.IsVIVO) {
  454. var method = "m=rlevel";
  455. var url = POST_ServerUrl + method + ("&level_id=" + level + "&level_name=" + encodeURI(levelName) + "&status=" + status);
  456. Utils_1.utils.commomHttpRequest(url, function (ret, data) {
  457. if (ret) {
  458. Utils_1.utils.showLog("关卡数据上报成功!");
  459. }
  460. else {
  461. Utils_1.utils.showLog("关卡数据上报失败!");
  462. }
  463. }.bind(this));
  464. }
  465. };
  466. /**
  467. * 上报自定义事件
  468. * @param level 当前关卡ID
  469. * @param levelName 关卡名称
  470. * @param status 状态
  471. */
  472. YZ_Tool_Vivo.prototype.sendEvent = function (eventName) {
  473. if (PlatUtils_1.default.IsVIVO) {
  474. var method = "m=revent";
  475. var url = POST_ServerUrl + method + ("&event=" + encodeURI(eventName));
  476. Utils_1.utils.commomHttpRequest(url, function (ret, data) {
  477. if (ret) {
  478. Utils_1.utils.showLog("上报自定义事件成功!");
  479. }
  480. else {
  481. Utils_1.utils.showLog("上报自定义事件失败!");
  482. }
  483. }.bind(this));
  484. }
  485. };
  486. /**
  487. * 弹出提示框
  488. * @param msg 消息
  489. */
  490. YZ_Tool_Vivo.prototype.showToast = function (msg) {
  491. if (PlatUtils_1.default.IsVIVO) {
  492. //@ts-ignore
  493. //@ts-ignore
  494. qg.showToast({
  495. message: msg,
  496. duration: 2000
  497. });
  498. }
  499. };
  500. /**
  501. * 是否支持互推
  502. */
  503. YZ_Tool_Vivo.prototype.canShowRecommend = function () {
  504. if (this.qg.createBoxBannerAd && this.qg.createBoxPortalAd) {
  505. return true;
  506. }
  507. return false;
  508. };
  509. /**
  510. * 展示VIVO互推banner
  511. */
  512. YZ_Tool_Vivo.prototype.showRecBanner = function (location) {
  513. var _this = this;
  514. if (!this.canShowRecommend()) {
  515. Utils_1.utils.showLog("当前版本不支持显示官方互推!");
  516. return false;
  517. }
  518. if (Utils_1.utils.config.vivoconfig.recGameBannerId) {
  519. if (!this._rec_game_banner) {
  520. this._rec_game_banner = this.qg.createBoxBannerAd({
  521. adUnitId: Utils_1.utils.config.vivoconfig.recGameBannerId
  522. });
  523. this._rec_game_banner.onLoad(function () {
  524. Utils_1.utils.showLog('互推banner加载成功!');
  525. });
  526. this._rec_game_banner.show().then(function () {
  527. Utils_1.utils.showLog('互推banner展示成功!');
  528. }).catch(function (error) {
  529. Utils_1.utils.showLog('互推banner展示失败:' + error.errCode + ',' + error.errMsg);
  530. });
  531. this._rec_game_banner.onError(function (err) {
  532. Utils_1.utils.showLog('互推banner加载异常!', err.errCode + ',' + err.errMsg);
  533. _this._rec_game_banner.destroy();
  534. _this._rec_game_banner = null;
  535. });
  536. }
  537. else {
  538. this._rec_game_banner.show().then(function () {
  539. Utils_1.utils.showLog('互推banner展示成功!');
  540. if (location) {
  541. Utils_1.utils.SendEvent("互推Banner展示成功,位置:" + location);
  542. }
  543. }).catch(function (error) {
  544. Utils_1.utils.showLog('互推banner展示失败:' + error.errCode + ',' + error.errMsg);
  545. });
  546. }
  547. }
  548. else {
  549. Utils_1.utils.showLog("VIVO 互推banner ID未配置!");
  550. }
  551. };
  552. /**
  553. * 隐藏互推banner
  554. */
  555. YZ_Tool_Vivo.prototype.hideRecBanner = function () {
  556. var _this = this;
  557. if (this._rec_game_banner) {
  558. this._rec_game_banner.hide().then(function () {
  559. Utils_1.utils.showLog('VIVO 互推banner 隐藏成功!');
  560. }).catch(function (error) {
  561. Utils_1.utils.showLog('VIVO 互推banner 隐藏失败:' + error.errCode + ',' + error.errMsg);
  562. _this._rec_game_banner.destroy();
  563. _this._rec_game_banner = null;
  564. });
  565. }
  566. };
  567. /**
  568. * 展示VIVO九宫格
  569. */
  570. YZ_Tool_Vivo.prototype.showGamePortal = function (top) {
  571. var _this = this;
  572. if (top === void 0) { top = 200; }
  573. if (!this.canShowRecommend()) {
  574. Utils_1.utils.showLog("当前版本不支持显示官方互推!");
  575. return false;
  576. }
  577. if (Utils_1.utils.config.vivoconfig.recPortalId) {
  578. if (this._rec_game_portal) {
  579. this.hideGamePortal();
  580. }
  581. this._rec_game_portal = this.qg.createBoxPortalAd({
  582. posId: Utils_1.utils.config.vivoconfig.recPortalId,
  583. image: '',
  584. marginTop: top / cc.winSize.height * this.SysInfo.screenHeight
  585. });
  586. this._rec_game_portal.onError(function (err) {
  587. Utils_1.utils.showLog("盒子九宫格广告加载失败", JSON.stringify(err));
  588. });
  589. this._rec_game_portal.onClose(function () {
  590. Utils_1.utils.showLog('close _rec_game_portal');
  591. if (_this._rec_game_portal.isDestroyed) {
  592. return;
  593. }
  594. // 当九宫格关闭之后,再次展示Icon
  595. _this._rec_game_portal.show();
  596. });
  597. // 广告数据加载成功后展示
  598. this._rec_game_portal.show().then(function () {
  599. Utils_1.utils.showLog('show success _rec_game_portal');
  600. });
  601. }
  602. else {
  603. Utils_1.utils.showLog("VIVO 互推九宫格 ID未配置!");
  604. }
  605. };
  606. /**
  607. * 隐藏九宫格
  608. */
  609. YZ_Tool_Vivo.prototype.hideGamePortal = function () {
  610. this._rec_game_portal && this._rec_game_portal.hide().then(function () {
  611. Utils_1.utils.showLog('hideGamePortal success');
  612. }).catch(function (error) {
  613. Utils_1.utils.showLog('hideGamePortal fail with:' + error.errCode + ',' + error.errMsg);
  614. });
  615. };
  616. /**友盟sdk初始化 */
  617. YZ_Tool_Vivo.prototype.umaInit = function () {
  618. if (!this.checkUmeng()) {
  619. Utils_1.utils.showLog("友盟ID未配置,不执行友盟初始化>>>>");
  620. return;
  621. }
  622. uma.init({
  623. appKey: Utils_1.utils.config.vivoconfig.umengId,
  624. useOpenid: false,
  625. debug: CC_DEBUG
  626. });
  627. };
  628. /**
  629. * 友盟游戏开始上报
  630. * @param levelID
  631. */
  632. YZ_Tool_Vivo.prototype.umaOnStart = function (levelID) {
  633. if (!this.checkUmeng())
  634. return;
  635. //@ts-ignore
  636. qg.uma.stage.onStart({
  637. stageId: levelID,
  638. stageName: "\u7B2C" + levelID + "\u5173" // 关卡id
  639. });
  640. };
  641. /**
  642. *
  643. * @returns 是否开启友盟
  644. */
  645. YZ_Tool_Vivo.prototype.checkUmeng = function () {
  646. if (!Utils_1.utils.config.vivoconfig.umengId) {
  647. return false;
  648. }
  649. return true;
  650. };
  651. /**
  652. * 友盟结算上报
  653. * @param levelID 关卡id
  654. * @param stageId
  655. * @param event
  656. */
  657. YZ_Tool_Vivo.prototype.umaReportedLevel = function (levelID, event) {
  658. if (!this.checkUmeng())
  659. return;
  660. //@ts-ignore
  661. qg.uma.stage.onEnd({
  662. stageId: levelID,
  663. stageName: "\u7B2C" + levelID + "\u5173",
  664. event: event
  665. });
  666. };
  667. /**
  668. * 友盟自定义事件
  669. * @param eventId 事件ID,注意:事件ID必须要在后台配置
  670. * @param params 事件内容
  671. */
  672. YZ_Tool_Vivo.prototype.umaTrackEvent = function (eventId, params) {
  673. if (!this.checkUmeng())
  674. return;
  675. //@ts-ignore
  676. qg.uma.trackEvent(eventId, params);
  677. };
  678. YZ_Tool_Vivo = __decorate([
  679. ccclass
  680. ], YZ_Tool_Vivo);
  681. return YZ_Tool_Vivo;
  682. }());
  683. exports.default = YZ_Tool_Vivo;
  684. cc._RF.pop();