7a489dc6-b3ef-4ea4-b48a-ddf4455cd083.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  1. "use strict";
  2. cc._RF.push(module, '7a4893Gs+9OpLSK3fRFXNCD', 'YZ_Tool_HuaWei');
  3. // common-plugin/Scripts/YZ_Tool_HuaWei.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_HuaWei = /** @class */ (function () {
  61. function YZ_Tool_HuaWei() {
  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. //启动来源类型:shortcut、url、app、quickapp、deeplink、other
  98. this._luanchType = "";
  99. //启动参数
  100. this._luanchData = "";
  101. //是否上报激活
  102. this.isReportActive = false;
  103. //回传类型 === activate:用户首次打开 app login:用户完成登陆行为 subscribe:闯一关(用户完成某项服务/频道订阅行为)
  104. this.yz_conversion_type = "";
  105. this.passCount = 0; //通关数据
  106. this.playCount = 0; //开始关卡数据
  107. this._is_login = false;
  108. this._isShowLogin = false;
  109. this._loging = false;
  110. this.isRequestLogin = false;
  111. }
  112. Object.defineProperty(YZ_Tool_HuaWei.prototype, "SysInfo", {
  113. get: function () {
  114. return this._sysInfo;
  115. },
  116. enumerable: false,
  117. configurable: true
  118. });
  119. Object.defineProperty(YZ_Tool_HuaWei.prototype, "ServerConfig", {
  120. get: function () {
  121. return this._serverConfig;
  122. },
  123. enumerable: false,
  124. configurable: true
  125. });
  126. Object.defineProperty(YZ_Tool_HuaWei.prototype, "NativeInsertAdClickTimes", {
  127. get: function () {
  128. return this._nativeInsertAdClickTimes;
  129. },
  130. enumerable: false,
  131. configurable: true
  132. });
  133. Object.defineProperty(YZ_Tool_HuaWei.prototype, "ShortcutCreated", {
  134. get: function () {
  135. return this._shortcutCreated;
  136. },
  137. enumerable: false,
  138. configurable: true
  139. });
  140. Object.defineProperty(YZ_Tool_HuaWei.prototype, "uid", {
  141. get: function () {
  142. // if (this._service_uid != "0") return this._uid;
  143. // this._login();
  144. return "0";
  145. },
  146. enumerable: false,
  147. configurable: true
  148. });
  149. Object.defineProperty(YZ_Tool_HuaWei.prototype, "serviceId", {
  150. /**
  151. * 服务器返回UID
  152. */
  153. get: function () {
  154. if (this._service_uid != "0")
  155. return this._service_uid;
  156. this.reportLogin();
  157. return "0";
  158. },
  159. enumerable: false,
  160. configurable: true
  161. });
  162. YZ_Tool_HuaWei.prototype._login = function () {
  163. return __awaiter(this, void 0, void 0, function () {
  164. var curTime, interval, self;
  165. return __generator(this, function (_a) {
  166. curTime = new Date().getTime();
  167. interval = (curTime - this._loginTime) / 1000;
  168. if (interval > 0 && interval < this._loginInterval) {
  169. Utils_1.utils.showLog("\u767B\u5F55\u8BF7\u6C42\u95F4\u9694\u5C0F\u4E8E\uFF1A" + this._loginInterval + "\u79D2");
  170. return [2 /*return*/];
  171. }
  172. this._loginTime = curTime;
  173. self = this;
  174. this._uid = "0";
  175. this.reportLogin();
  176. return [2 /*return*/];
  177. });
  178. });
  179. };
  180. /**
  181. * 上报登录接口获取UID
  182. */
  183. YZ_Tool_HuaWei.prototype.reportLogin = function () {
  184. var _this = this;
  185. if (this.isReport)
  186. return;
  187. this.isReport = true;
  188. var self = this;
  189. var curTime = new Date().getTime();
  190. var interval = (curTime - this._reportLoginTime) / 1000;
  191. if (interval > 0 && interval < this._reportLoginInterval) {
  192. Utils_1.utils.showLog("\u4E0A\u62A5\u767B\u5F55\u83B7\u53D6UID\u5C0F\u4E8E\uFF1A" + this._reportLoginInterval + "\u79D2");
  193. return;
  194. }
  195. this._reportLoginTime = curTime;
  196. var method = "m=login";
  197. var url = ST_ServerUrl + method + ("&device_data=" + encodeURI(JSON.stringify(this._sysInfo)));
  198. Utils_1.utils.commomHttpRequest(url, function (ret, data) {
  199. if (ret) {
  200. if (data) {
  201. var result = JSON.parse(data);
  202. Utils_1.utils.showLog("data=" + data);
  203. Utils_1.utils.showLog("result=" + result);
  204. Utils_1.utils.showLog("result.uid=" + result.uid);
  205. if (result.uid) {
  206. self._service_uid = "" + result.uid;
  207. Utils_1.utils.showLog("服务器请求登录成功! _service_uid=" + self._service_uid);
  208. YZ_LocalStorage_1.default.setItem(YZ_Constant_1.default.ST_SERVICE_UID, self._service_uid);
  209. if (_this.yz_conversion_type == "activate") {
  210. self.reportUserActive();
  211. }
  212. if (_this.yz_conversion_type == "login" && _this._is_login) {
  213. Utils_1.utils.showLog("用户完成登陆行为!");
  214. _this.reportUserActive();
  215. }
  216. }
  217. }
  218. }
  219. else {
  220. Utils_1.utils.showLog("获取数据失败1");
  221. }
  222. _this.isReport = false;
  223. });
  224. };
  225. /**
  226. * 上报用户激活,用于回传
  227. */
  228. YZ_Tool_HuaWei.prototype.reportUserActive = function () {
  229. Utils_1.utils.showLog("上报用户激活!!");
  230. if (!this.isReportActive) {
  231. this.isReportActive = true;
  232. this.reportAttributedEvent(YZ_Constant_1.AttributedType.Active, YZ_Constant_1.AttributedKey.Active, YZ_Constant_1.AttributedValue.Active);
  233. }
  234. };
  235. /**
  236. *
  237. * @param data 配置数据
  238. */
  239. YZ_Tool_HuaWei.prototype.init = function (data) {
  240. if (PlatUtils_1.default.IsHuaWei) {
  241. this.umaInit();
  242. if (data) {
  243. var configObj = JSON.parse(data);
  244. if (configObj && configObj.huawei) {
  245. ST_DefaultServerConfig = JSON.stringify(configObj.huawei);
  246. }
  247. }
  248. this._service_uid = YZ_LocalStorage_1.default.getItem(YZ_Constant_1.default.ST_SERVICE_UID);
  249. this._service_uid = this._service_uid ? this._service_uid : "0";
  250. this._sysInfo = this.qg.getSystemInfoSync();
  251. if (this._sysInfo) {
  252. Utils_1.utils.showLog("huawei 小游戏平台信息: " + JSON.stringify(this.SysInfo));
  253. }
  254. var options = this.qg.getLaunchOptionsSync();
  255. this._luanchData = YZ_LocalStorage_1.default.getItem(YZ_Constant_1.default.ST_LUANCH_DATA);
  256. this._luanchType = YZ_LocalStorage_1.default.getItem(YZ_Constant_1.default.ST_LUANCH_TYPE);
  257. if (this._luanchData && this._luanchType) {
  258. Utils_1.utils.showLog("获取到本地缓存数据启动类型:" + this._luanchType);
  259. Utils_1.utils.showLog("获取到本地缓存数据启动参数:" + this._luanchData);
  260. }
  261. else if (options) {
  262. try {
  263. if (options.referrerInfo && JSON.stringify(options.referrerInfo) != "{}") {
  264. var referrerInfo = options.referrerInfo;
  265. Utils_1.utils.showLog("获取到小程序启动来源信息:" + JSON.stringify(referrerInfo));
  266. this._luanchType = referrerInfo.type;
  267. YZ_LocalStorage_1.default.setItem(YZ_Constant_1.default.ST_LUANCH_TYPE, this._luanchType);
  268. }
  269. if (options.query && JSON.stringify(options.query) != "{}") {
  270. var query = JSON.parse(options.query);
  271. var queryData = JSON.stringify(query);
  272. this._luanchData = queryData;
  273. this.yz_conversion_type = query.yz_conversion_type;
  274. YZ_LocalStorage_1.default.setItem(YZ_Constant_1.default.ST_LUANCH_DATA, this._luanchData);
  275. Utils_1.utils.showLog("获取到小程序启动参数:" + queryData + " 回传类型:" + this.yz_conversion_type);
  276. }
  277. }
  278. catch (erro) {
  279. Utils_1.utils.showLog("获取到小程序启动参数异常");
  280. }
  281. }
  282. this._loadConfig();
  283. this._nativeInsertAdClickTimes = YZ_LocalStorage_1.default.getItem(ST_NativeInsertAdClickTimes);
  284. var day = YZ_LocalStorage_1.default.getItem(ST_LastDateTime);
  285. var curDate = new Date();
  286. if (day != curDate.toDateString()) {
  287. this._nativeInsertAdClickTimes = 0;
  288. YZ_LocalStorage_1.default.setItem(ST_NativeInsertAdClickTimes, 0);
  289. }
  290. // utils.registerServerInitEvent(() => {
  291. // if (this.yz_conversion_type == "game_time_report") {
  292. // utils.scheduleOnce(() => {
  293. // this.reportAttributedEvent(AttributedType.GameAddiction, AttributedKey.GameAddiction, AttributedValue.GameTimeAction);
  294. // }, utils.getConfigByKey("game_time_report"));
  295. // }
  296. // }, this);
  297. }
  298. };
  299. // _buildServerUrl() {
  300. // if (PlatUtils.IsHuaWei) {
  301. // let url: string = "";
  302. // if (utils.config.huaweiConfig && utils.config.huaweiConfig.appID) {
  303. // url = ST_ServerUrl + "kyx=true&app_id=" + utils.config.huaweiConfig.appID.trim() + "&" + "channel=vivo";
  304. // } else {
  305. // utils.showLog("VIVO APPID配置出错!");
  306. // }
  307. // return url;
  308. // }
  309. // return null;
  310. // }
  311. YZ_Tool_HuaWei.prototype._loadConfig = function () {
  312. var _this = this;
  313. if (PlatUtils_1.default.IsHuaWei) {
  314. var method = "m=g";
  315. Utils_1.utils.commomHttpRequest(ST_ServerUrl + method, function (ret, data) {
  316. if (ret) {
  317. Utils_1.utils.showLog("Huawei服务器配置数据获取成功: data = " + data);
  318. if (data) {
  319. var result = JSON.parse(data);
  320. if (result) {
  321. if (!Utils_1.utils.DebugLoacalConfig) {
  322. _this._serverConfig = result;
  323. if (_this._serverConfig.is_show_log_view && _this._serverConfig.is_show_log_view == "true") {
  324. Utils_1.utils.showLogView = true;
  325. }
  326. }
  327. else {
  328. Utils_1.utils.showLog("开启了本地数据测试,使用本地配置!");
  329. }
  330. }
  331. else {
  332. Utils_1.utils.showLog("Huawei服务器配置数据不是合法的JSON数据, 使用本地配置!");
  333. }
  334. }
  335. }
  336. else {
  337. Utils_1.utils.showLog("Huawei服务器配置数据获取失败, 使用本地配置!");
  338. }
  339. if (!_this._serverConfig) {
  340. _this._serverConfig = JSON.parse(ST_DefaultServerConfig);
  341. }
  342. else {
  343. if (_this._serverConfig.is_local_pos_id
  344. && _this._serverConfig.is_local_pos_id == "false") {
  345. // 使用服务器下发的广告id
  346. Utils_1.utils.showLog("使用服务器下发的广告id");
  347. Utils_1.utils.config.huaweiConfig.bannerId = _this._serverConfig.banner_pos_id;
  348. Utils_1.utils.config.huaweiConfig.insertId = _this._serverConfig.intersititia_pos_id;
  349. Utils_1.utils.config.huaweiConfig.videoId = _this._serverConfig.video_pos_id;
  350. Utils_1.utils.config.huaweiConfig.nativeInsertIds = _this.ServerConfig.native_intersititial_pos_id;
  351. Utils_1.utils.config.huaweiConfig.nativeBannerIds = _this.ServerConfig.native_banner_pos_id;
  352. Utils_1.utils.config.huaweiConfig.nativeTryGameIds = _this.ServerConfig.native_trygame_pos_id;
  353. Utils_1.utils.config.huaweiConfig.nativeSplashId = _this.ServerConfig.native_splash_id;
  354. }
  355. else {
  356. Utils_1.utils.showLog("使用本地配置的广告ID");
  357. }
  358. if (_this.ServerConfig.native_banner_configs) {
  359. for (var i = 0; i < _this.ServerConfig.native_banner_configs.length; i++) {
  360. Utils_1.utils.showLog("获取到原生广告配置:" + _this.ServerConfig.native_banner_configs[i].location, ">>>>", JSON.stringify(_this.ServerConfig.native_banner_configs[i]));
  361. Utils_1.utils.config.huaweiConfig.setNativeBannerInfo(_this.ServerConfig.native_banner_configs[i].location, _this.ServerConfig.native_banner_configs[i]);
  362. }
  363. }
  364. if (_this.ServerConfig.yz_conversion_type) {
  365. _this.yz_conversion_type = _this.ServerConfig.yz_conversion_type;
  366. Utils_1.utils.showLog("回传类型:" + _this.yz_conversion_type);
  367. }
  368. if (_this.ServerConfig.is_login && _this.ServerConfig.is_login == "false") {
  369. _this._is_login = true;
  370. }
  371. _this._isShowLogin = true;
  372. _this.isRequestLogin && _this.login();
  373. }
  374. cc.director.emit("IsDataInit");
  375. // utils.registerPrivacyCloseEvent(() => {
  376. Utils_1.utils.emitServerInitEvent();
  377. // }, this);
  378. });
  379. }
  380. };
  381. /**
  382. * 比较当前平台版本是否高于指定的版本号
  383. * @param miniVersion 最低平台版本号
  384. */
  385. YZ_Tool_HuaWei.prototype.isOverMiniVersion = function (miniVersion) {
  386. if (PlatUtils_1.default.IsHuaWei) {
  387. if (this._sysInfo && this._sysInfo.platformVersionCode) {
  388. return this._sysInfo.platformVersionCode >= miniVersion;
  389. }
  390. }
  391. return false;
  392. };
  393. /**
  394. * 创建桌面图标
  395. */
  396. YZ_Tool_HuaWei.prototype.createShortcut = function (callback) {
  397. var callbackFunc = callback;
  398. if (PlatUtils_1.default.IsHuaWei && this.canCreateShortcut()) {
  399. var self_1 = this;
  400. self_1.qg.installShortcut({
  401. success: function () {
  402. Utils_1.utils.showLog('桌面图标创建成功!');
  403. self_1._shortcutCreated = true;
  404. if (callbackFunc) {
  405. callbackFunc(true);
  406. }
  407. },
  408. fail: function (err) {
  409. self_1._shortcutCreated = true;
  410. cc.log('vivo创建失败err' + err);
  411. if (callbackFunc) {
  412. callbackFunc(false);
  413. }
  414. },
  415. complete: function () {
  416. }
  417. });
  418. }
  419. else {
  420. cc.log("不能创建");
  421. if (callbackFunc) {
  422. callbackFunc(false);
  423. }
  424. }
  425. };
  426. /**
  427. * 是否可以创建桌面图标, 当前平台是否支持创建快捷方式
  428. */
  429. YZ_Tool_HuaWei.prototype.canCreateShortcut = function () {
  430. if (PlatUtils_1.default.IsHuaWei) {
  431. return this.isOverMiniVersion("1041");
  432. }
  433. return false;
  434. };
  435. YZ_Tool_HuaWei.prototype.countNativeInserClick = function () {
  436. this._nativeInsertAdClickTimes++;
  437. YZ_LocalStorage_1.default.setItem(ST_NativeInsertAdClickTimes, this._nativeInsertAdClickTimes);
  438. };
  439. /**
  440. * 分享事件
  441. * @param callback 分享回调
  442. */
  443. YZ_Tool_HuaWei.prototype.share = function (callback) {
  444. if (!this.isOverMiniVersion("1052")) {
  445. callback && callback(false, "当前平台不支持");
  446. return;
  447. }
  448. this.qg.share();
  449. callback && callback(true);
  450. return;
  451. };
  452. /**
  453. * 验证桌面快捷方式是否创建过
  454. * @param callBack
  455. */
  456. YZ_Tool_HuaWei.prototype.checkHasShortCut = function (callBack) {
  457. var _this = this;
  458. this.qg.hasShortcutInstalled({
  459. success: function (res) {
  460. Utils_1.utils.showLog("检测桌面快捷方式是否已经创建过: result=", res);
  461. if (res == false) {
  462. _this._shortcutCreated = false;
  463. callBack && callBack(false);
  464. }
  465. else {
  466. _this._shortcutCreated = true;
  467. callBack && callBack(true);
  468. }
  469. },
  470. fail: function () {
  471. Utils_1.utils.showLog("检测失败!");
  472. },
  473. complete: function () {
  474. Utils_1.utils.showLog("检测完成!");
  475. }
  476. });
  477. };
  478. /**
  479. * 上报关卡数据
  480. * @param level 当前关卡ID
  481. * @param levelName 关卡名称
  482. * @param status 状态
  483. */
  484. YZ_Tool_HuaWei.prototype.postLevel = function (level, status, levelName) {
  485. if (PlatUtils_1.default.IsHuaWei) {
  486. if (this.yz_conversion_type == "subscribe") {
  487. Utils_1.utils.showLog("用户完成某项服务/频道订阅行为");
  488. this.reportUserActive();
  489. }
  490. if (status == YZ_Constant_1.LevelStatus.GameWin) {
  491. this.passCount++;
  492. if (this.passCount === Utils_1.utils.getConfigByKey("pass_level_count_active")) {
  493. this.reportAttributedEvent(YZ_Constant_1.AttributedType.GameAddiction, YZ_Constant_1.AttributedKey.GameAddiction, YZ_Constant_1.AttributedValue.PassLevelCountAction);
  494. }
  495. }
  496. else if (status === YZ_Constant_1.LevelStatus.GameStart) {
  497. this.playCount++;
  498. if (this.playCount == Utils_1.utils.getConfigByKey("play_level_count_active")) {
  499. this.reportAttributedEvent(YZ_Constant_1.AttributedType.GameAddiction, YZ_Constant_1.AttributedKey.GameAddiction, YZ_Constant_1.AttributedValue.PlayLevelCountAction);
  500. }
  501. }
  502. var method = "m=rlevel";
  503. var url = POST_ServerUrl + method + ("&level_id=" + level + "&level_name=" + encodeURI(levelName) + "&status=" + status);
  504. Utils_1.utils.commomHttpRequest(url, function (ret, data) {
  505. if (ret) {
  506. Utils_1.utils.showLog("关卡数据上报成功!");
  507. }
  508. else {
  509. Utils_1.utils.showLog("关卡数据上报失败!");
  510. }
  511. }.bind(this));
  512. }
  513. };
  514. /**
  515. * 上报自定义事件
  516. * @param level 当前关卡ID
  517. * @param levelName 关卡名称
  518. * @param status 状态
  519. */
  520. YZ_Tool_HuaWei.prototype.sendEvent = function (eventName) {
  521. if (PlatUtils_1.default.IsHuaWei) {
  522. var method = "m=revent";
  523. var url = POST_ServerUrl + method + ("&event=" + encodeURI(eventName));
  524. Utils_1.utils.commomHttpRequest(url, function (ret, data) {
  525. if (ret) {
  526. Utils_1.utils.showLog("上报自定义事件成功!");
  527. }
  528. else {
  529. Utils_1.utils.showLog("上报自定义事件失败!");
  530. }
  531. }.bind(this));
  532. }
  533. };
  534. /**
  535. * 弹出提示框
  536. * @param msg 消息
  537. */
  538. YZ_Tool_HuaWei.prototype.showToast = function (msg) {
  539. if (PlatUtils_1.default.IsHuaWei) {
  540. //@ts-ignore
  541. qg.showToast({
  542. message: msg,
  543. duration: 2000
  544. });
  545. }
  546. };
  547. /**
  548. * 上报归因事件
  549. * @param eventType 事件类型 0 激活, 25:关键行为
  550. * @param eventValue 事件描述
  551. */
  552. YZ_Tool_HuaWei.prototype.reportAttributedEvent = function (eventType, eventKey, eventValue) {
  553. if (this._luanchType != "deeplink") {
  554. Utils_1.utils.showLog("luanchType=" + this._luanchType + ",不进行归因上报");
  555. return;
  556. }
  557. Utils_1.utils.showLog("上报归因事件: #eventType=" + eventType + "#eventKey=" + eventKey + "#eventValue=" + eventValue);
  558. if (eventType == YZ_Constant_1.AttributedType.Active && YZ_LocalStorage_1.default.getItem(YZ_Constant_1.default.ST_IS_REPORT_USER_ACTIVE)) {
  559. Utils_1.utils.showLog("用户已经上报过激活,不再进行激活上报!");
  560. return;
  561. }
  562. else if (eventType == YZ_Constant_1.AttributedType.GameAddiction && YZ_LocalStorage_1.default.getItem(YZ_Constant_1.default.ST_IS_REPORT_GAME_ADDICTION)) {
  563. Utils_1.utils.showLog("用户已经上报过关键行为,不再进行激活上报!");
  564. return;
  565. }
  566. var xhr = new XMLHttpRequest();
  567. xhr.timeout = 15000; // 单位毫秒
  568. var data = {};
  569. data.app_id = Utils_1.utils.config.huaweiConfig.appID;
  570. data.channel = "huawei_kyx";
  571. data.uid = this._service_uid;
  572. data.event_type = eventType;
  573. data.event_key = eventKey;
  574. data.event_value = eventValue;
  575. data.app_version = Utils_1.utils.config.huaweiConfig.version;
  576. data.luanchDate = encodeURI(this._luanchData);
  577. Utils_1.utils.showLog("归因请求参数:" + JSON.stringify(data));
  578. var requestData = JSON.stringify(data);
  579. Utils_1.utils.showLog("归因 > json_data=" + Utils_1.utils.aesEncrypt(requestData));
  580. var requestUrl = "https://track.youletd.com/wechatcounterpart/dockingreturn?json=" + Utils_1.utils.aesEncrypt(requestData) + "&time_stamp=" + (new Date()).getTime();
  581. Utils_1.utils.showLog("归因服务器地址:" + requestUrl);
  582. xhr.open('GET', requestUrl);
  583. xhr.send();
  584. xhr.onreadystatechange = function () {
  585. Utils_1.utils.showLog("请求状态改变, reaedyState=", xhr.readyState, "; status=", xhr.status);
  586. if (xhr.readyState == 4) {
  587. if (xhr.status == 200) {
  588. if (eventType == YZ_Constant_1.AttributedType.Active)
  589. YZ_LocalStorage_1.default.setItem(YZ_Constant_1.default.ST_IS_REPORT_USER_ACTIVE, "true");
  590. if (eventType == YZ_Constant_1.AttributedType.GameAddiction)
  591. YZ_LocalStorage_1.default.setItem(YZ_Constant_1.default.ST_IS_REPORT_GAME_ADDICTION, "true");
  592. Utils_1.utils.showLog("归因上报成功:", xhr.responseText);
  593. }
  594. else {
  595. Utils_1.utils.showLog("归因上报失败!");
  596. }
  597. }
  598. };
  599. xhr.ontimeout = function () {
  600. Utils_1.utils.showLog("归因请求超时!");
  601. };
  602. xhr.onerror = function (err) {
  603. Utils_1.utils.showLog("归因请求失败!");
  604. };
  605. };
  606. /**
  607. * 退出游戏
  608. */
  609. YZ_Tool_HuaWei.prototype.GameExit = function () {
  610. if (PlatUtils_1.default.IsHuaWei) {
  611. Utils_1.utils.showLog("GameExit");
  612. try {
  613. //@ts-ignore
  614. qg.exitApplication({
  615. success: function () {
  616. console.log("exitApplication success");
  617. },
  618. fail: function () {
  619. console.log("exitApplication fail");
  620. },
  621. complete: function () {
  622. console.log("exitApplication complete");
  623. }
  624. });
  625. }
  626. catch (error) {
  627. cc.log(error);
  628. }
  629. }
  630. };
  631. /**
  632. * 登录
  633. */
  634. YZ_Tool_HuaWei.prototype.login = function () {
  635. var _this = this;
  636. Utils_1.utils.showLog("huawei login");
  637. this.isRequestLogin = true;
  638. if (!this._isShowLogin || this._loging)
  639. return;
  640. this._loging = true;
  641. if (this._is_login) {
  642. this._loging = false;
  643. this.showToast("登录成功!");
  644. cc.game.emit(YZ_Constant_1.default.ST_LOGIN_SUCCESS);
  645. Utils_1.utils.showLog("已经登录过不再重新登录!");
  646. if (this.yz_conversion_type == "login") {
  647. this.reportUserActive();
  648. }
  649. return;
  650. }
  651. this.qg.gameLogin({
  652. forceLogin: 1,
  653. appid: Utils_1.utils.config.huaweiConfig.appID,
  654. success: function (data) {
  655. _this._loging = false;
  656. _this.showToast("登录成功!");
  657. cc.game.emit(YZ_Constant_1.default.ST_LOGIN_SUCCESS);
  658. Utils_1.utils.showLog("Game login success:" + data);
  659. _this._is_login = true;
  660. if (_this.yz_conversion_type == "login") {
  661. Utils_1.utils.showLog("用户完成登陆行为!");
  662. _this.reportUserActive();
  663. }
  664. },
  665. fail: function (data, code) {
  666. _this._loging = false;
  667. _this.showToast("登录失败!");
  668. cc.game.emit(YZ_Constant_1.default.ST_LOGIN_FAIL);
  669. Utils_1.utils.showLog("Game login fail:" + data + ", code:" + code);
  670. }
  671. });
  672. this.isRequestLogin = false;
  673. };
  674. /**友盟sdk初始化 */
  675. YZ_Tool_HuaWei.prototype.umaInit = function () {
  676. if (!this.checkUmeng()) {
  677. Utils_1.utils.showLog("友盟ID未配置,不执行友盟初始化>>>>");
  678. return;
  679. }
  680. Utils_1.utils.showLog("umeng init #id=" + Utils_1.utils.config.huaweiConfig.umengId);
  681. uma.init({
  682. appKey: Utils_1.utils.config.huaweiConfig.umengId,
  683. useOpenid: false,
  684. debug: true
  685. });
  686. };
  687. /**
  688. * 友盟游戏开始上报
  689. * @param levelID
  690. */
  691. YZ_Tool_HuaWei.prototype.umaOnStart = function (levelID) {
  692. if (!this.checkUmeng())
  693. return;
  694. //@ts-ignore
  695. qg.uma.stage.onStart({
  696. stageId: levelID,
  697. stageName: "\u7B2C" + levelID + "\u5173" // 关卡id
  698. });
  699. };
  700. /**
  701. *
  702. * @returns 是否开启友盟
  703. */
  704. YZ_Tool_HuaWei.prototype.checkUmeng = function () {
  705. if (!Utils_1.utils.config.huaweiConfig.umengId) {
  706. return false;
  707. }
  708. return true;
  709. };
  710. /**
  711. * 友盟结算上报
  712. * @param levelID 关卡id
  713. * @param stageId
  714. * @param event
  715. */
  716. YZ_Tool_HuaWei.prototype.umaReportedLevel = function (levelID, event) {
  717. if (!this.checkUmeng())
  718. return;
  719. //@ts-ignore
  720. qg.uma.stage.onEnd({
  721. stageId: levelID,
  722. stageName: "\u7B2C" + levelID + "\u5173",
  723. event: event
  724. });
  725. };
  726. /**
  727. * 友盟自定义事件
  728. * @param eventId 事件ID,注意:事件ID必须要在后台配置
  729. * @param params 事件内容
  730. */
  731. YZ_Tool_HuaWei.prototype.umaTrackEvent = function (eventId, params) {
  732. if (!this.checkUmeng())
  733. return;
  734. //@ts-ignore
  735. qg.uma.trackEvent(eventId, params);
  736. };
  737. YZ_Tool_HuaWei = __decorate([
  738. ccclass
  739. ], YZ_Tool_HuaWei);
  740. return YZ_Tool_HuaWei;
  741. }());
  742. exports.default = YZ_Tool_HuaWei;
  743. cc._RF.pop();