60a05279-9757-4123-a6b5-d3f12cd48881.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  1. "use strict";
  2. cc._RF.push(module, '60a05J5l1dBI6a10/Es1IiB', 'YZ_Tool_Native');
  3. // common-plugin/Scripts/YZ_Tool_Native.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. Object.defineProperty(exports, "__esModule", { value: true });
  12. var PlatUtils_1 = require("./PlatUtils");
  13. var Utils_1 = require("./Utils");
  14. var YZ_Constant_1 = require("./YZ_Constant");
  15. var YZ_LocalStorage_1 = require("./YZ_LocalStorage");
  16. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  17. var ST_DefaultServerConfig = "";
  18. var ST_ServerUrl = "http://apps.youlesp.com/gss?";
  19. var POST_ServerUrl = "http://report.youlesp.com/gss?";
  20. // const ST_ServerUrl: string = "http://192.168.31.39:8080/GameBoxServer/gss?";
  21. // const POST_ServerUrl: string = "http://192.168.31.39:8080/GameBoxServer/gss?"
  22. var YZ_Tool_Native = /** @class */ (function () {
  23. function YZ_Tool_Native() {
  24. this.className = "";
  25. this._serverConfig = null;
  26. //设备UID
  27. this._uid = "0";
  28. //服务器返回UID
  29. this._service_uid = "0";
  30. /**
  31. * 0:默认互推面板 1: 跳转到原生平台
  32. */
  33. this.moreGameShowType = 0;
  34. /**
  35. * 显示退出游戏弹窗的类型
  36. * 0:不弹窗 1:弹窗
  37. */
  38. this.showGameExitDialogType = 0;
  39. this.appList = "";
  40. this._reportLoginTime = 0;
  41. this._reportLoginInterval = 30;
  42. this.isReport = false;
  43. this._gameExitDialogNode = null;
  44. this.deviceInfo = "";
  45. this._reloadTimes = 6;
  46. this._curloadTimes = 0;
  47. }
  48. Object.defineProperty(YZ_Tool_Native.prototype, "ServerConfig", {
  49. get: function () {
  50. return this._serverConfig;
  51. },
  52. enumerable: false,
  53. configurable: true
  54. });
  55. /**
  56. * 当前版本号
  57. */
  58. YZ_Tool_Native.prototype.gameVersion = function () {
  59. return Utils_1.utils.config.nativeAndroidConfig.version;
  60. };
  61. Object.defineProperty(YZ_Tool_Native.prototype, "uid", {
  62. get: function () {
  63. // if (this._service_uid != "0") return this._uid;
  64. // this._login();
  65. return "0";
  66. },
  67. enumerable: false,
  68. configurable: true
  69. });
  70. Object.defineProperty(YZ_Tool_Native.prototype, "serviceId", {
  71. /**
  72. * 服务器返回UID
  73. */
  74. get: function () {
  75. if (this._service_uid != "0")
  76. return this._service_uid;
  77. this.reportLogin();
  78. return "0";
  79. },
  80. enumerable: false,
  81. configurable: true
  82. });
  83. /**
  84. * 上报登录接口获取UID
  85. */
  86. YZ_Tool_Native.prototype.reportLogin = function () {
  87. var _this = this;
  88. if (this.isReport)
  89. return;
  90. this.isReport = true;
  91. var self = this;
  92. var curTime = new Date().getTime();
  93. var interval = (curTime - this._reportLoginTime) / 1000;
  94. if (interval > 0 && interval < this._reportLoginInterval) {
  95. Utils_1.utils.showLog("\u4E0A\u62A5\u767B\u5F55\u83B7\u53D6UID\u5C0F\u4E8E\uFF1A" + this._reportLoginInterval + "\u79D2");
  96. return;
  97. }
  98. this._reportLoginTime = curTime;
  99. var method = "m=loginv2";
  100. var url = ST_ServerUrl + method + ("&device_data=" + encodeURI(this.deviceInfo));
  101. Utils_1.utils.commomHttpRequest(url, function (ret, data) {
  102. if (ret) {
  103. if (data) {
  104. var result = JSON.parse(data);
  105. Utils_1.utils.showLog(result);
  106. if (result.uid) {
  107. self._service_uid = "" + result.uid;
  108. Utils_1.utils.showLog("服务器请求登录成功! _service_uid=" + self._service_uid);
  109. YZ_LocalStorage_1.default.setItem(YZ_Constant_1.default.ST_SERVICE_UID, self._service_uid);
  110. }
  111. if (result.config) {
  112. _this._serverConfig = Utils_1.utils.aesDecrypt(result.config);
  113. _this.setLocalConfig(JSON.stringify(_this._serverConfig));
  114. }
  115. }
  116. }
  117. else {
  118. Utils_1.utils.showLog("获取数据失败1");
  119. }
  120. _this.isReport = false;
  121. });
  122. };
  123. /**
  124. *
  125. * @param data 配置数据
  126. */
  127. YZ_Tool_Native.prototype.init = function () {
  128. var _this = this;
  129. if (PlatUtils_1.default.IsNativeAndroid) {
  130. ST_DefaultServerConfig = this.getNativeData();
  131. if (ST_DefaultServerConfig) {
  132. var data = JSON.parse(ST_DefaultServerConfig);
  133. this.deviceInfo = data.device_info;
  134. this.moreGameShowType = data.more_game_type;
  135. this.showGameExitDialogType = data.show_game_exit_dialog;
  136. this.appList = data.app_list;
  137. }
  138. else {
  139. Utils_1.utils.showLog("没有获取到本地数据,组件初始化失败!");
  140. return;
  141. }
  142. this._service_uid = YZ_LocalStorage_1.default.getItem(YZ_Constant_1.default.ST_SERVICE_UID);
  143. this._service_uid = this._service_uid ? this._service_uid : "0";
  144. this._loadConfig();
  145. if (PlatUtils_1.default.IsNativeAndroid) {
  146. //初始化时监听返回按钮退出事件
  147. cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, function (event) {
  148. if (event.keyCode == cc.macro.KEY.escape || event.keyCode == cc.macro.KEY.back) {
  149. if (PlatUtils_1.default.IsNativeAndroid) {
  150. if (_this.showGameExitDialogType == 1) {
  151. _this.showGameExitDialog();
  152. }
  153. else {
  154. _this.GameExit();
  155. }
  156. }
  157. }
  158. }, this);
  159. }
  160. }
  161. };
  162. /**
  163. * 显示退出弹窗
  164. */
  165. YZ_Tool_Native.prototype.showGameExitDialog = function () {
  166. if (!Utils_1.utils._isConfigInit) {
  167. Utils_1.utils.showLog("warn:" + "组件配置未初始化!");
  168. return null;
  169. }
  170. if (this._gameExitDialogNode && cc.isValid(this._gameExitDialogNode)) {
  171. Utils_1.utils.showLog("退出窗口还在。");
  172. return;
  173. }
  174. if (Utils_1.utils.config.otherconfig.gameExitDialog) {
  175. // if(utils.getRecommondGameList())
  176. var node = cc.instantiate(Utils_1.utils.config.otherconfig.gameExitDialog);
  177. if (node) {
  178. if (this._gameExitDialogNode && cc.isValid(this._gameExitDialogNode)) {
  179. this._gameExitDialogNode.destroy();
  180. }
  181. this._gameExitDialogNode = node;
  182. this._gameExitDialogNode.group = "default";
  183. cc.director.getScene().addChild(this._gameExitDialogNode, 9999);
  184. }
  185. }
  186. else {
  187. Utils_1.utils.showLog("warn:" + "未找到预制体 GameExitDialog, 请查看CommonUtils组件上是否赋值 !");
  188. }
  189. };
  190. YZ_Tool_Native.prototype.GameExit = function () {
  191. if (PlatUtils_1.default.IsNativeAndroid) {
  192. cc.log("AdAgentNative GameExit");
  193. try {
  194. jsb.reflection.callStaticMethod(this.jniClassName, "gameExit", "()V");
  195. }
  196. catch (error) {
  197. cc.log(error);
  198. }
  199. }
  200. };
  201. /**
  202. * 获取更多游戏显示的类型
  203. * 0:默认互推面板 1: 跳转到原生平台
  204. */
  205. YZ_Tool_Native.prototype.getMoreGameShowType = function () {
  206. try {
  207. this.moreGameShowType = jsb.reflection.callStaticMethod(this.jniClassName, "getMoreGameShowType", "()I");
  208. }
  209. catch (error) {
  210. Utils_1.utils.showLog(error);
  211. }
  212. };
  213. /**
  214. * 获取手机设备信息
  215. *
  216. */
  217. YZ_Tool_Native.prototype.getDeviceInfo = function () {
  218. try {
  219. this.deviceInfo = jsb.reflection.callStaticMethod(this.jniClassName, "getDeviceInfo", "()Ljava/lang/String;");
  220. Utils_1.utils.showLog("获取原生平台手机设备信息:" + this.deviceInfo);
  221. }
  222. catch (error) {
  223. Utils_1.utils.showLog(error);
  224. }
  225. };
  226. /**
  227. * 跳转原生平台的更多游戏
  228. */
  229. YZ_Tool_Native.prototype.showMoreGames = function () {
  230. if (PlatUtils_1.default.IsNativeAndroid) {
  231. Utils_1.utils.showLog("AdAgentNative showMoreGame");
  232. try {
  233. jsb.reflection.callStaticMethod(this.jniClassName, "showNativeMoreGame", "()V");
  234. }
  235. catch (error) {
  236. cc.log(error);
  237. }
  238. }
  239. };
  240. YZ_Tool_Native.prototype._loadConfig = function () {
  241. var _this = this;
  242. if (PlatUtils_1.default.IsNativeAndroid) {
  243. var method = "m=g" + ("&device_data=" + encodeURI(this.deviceInfo) + "&real_name_auth=" + Utils_1.utils.getRealNameAuthLocalData());
  244. this.commomHttpRequest(ST_ServerUrl + method, function (ret, data) {
  245. _this._curloadTimes++;
  246. var recall = false;
  247. if (ret) {
  248. Utils_1.utils.showLog("原生安卓服务器配置数据获取成功: data = " + data);
  249. if (data) {
  250. var result = JSON.parse(data);
  251. if (result) {
  252. if (!Utils_1.utils.DebugLoacalConfig) {
  253. _this._serverConfig = result;
  254. if (_this._serverConfig.is_show_log_view && _this._serverConfig.is_show_log_view == "true") {
  255. Utils_1.utils.showLogView = true;
  256. }
  257. if (result.more_game_type) {
  258. _this.moreGameShowType = result.more_game_type;
  259. }
  260. if (result.show_game_exit_dialog) {
  261. _this.showGameExitDialogType = result.show_game_exit_dialog;
  262. }
  263. }
  264. else {
  265. Utils_1.utils.showLog("开启了本地数据测试,使用本地配置!");
  266. }
  267. }
  268. else {
  269. Utils_1.utils.showLog("原生安卓服务器配置数据不是合法的JSON数据, 使用本地配置!");
  270. }
  271. }
  272. }
  273. else {
  274. Utils_1.utils.showLog("原生安卓服务器配置数据获取失败!");
  275. if (_this._curloadTimes < _this._reloadTimes) {
  276. Utils_1.utils.showLog("请求异常,重新拉取配置!");
  277. recall = true;
  278. }
  279. }
  280. if (!_this._serverConfig) {
  281. _this._serverConfig = JSON.parse(ST_DefaultServerConfig);
  282. }
  283. else {
  284. if (_this._serverConfig.is_local_pos_id
  285. && _this._serverConfig.is_local_pos_id == "false") {
  286. // 使用服务器下发的广告id
  287. Utils_1.utils.showLog("使用服务器下发的广告id");
  288. }
  289. else {
  290. Utils_1.utils.showLog("使用本地配置的广告ID");
  291. }
  292. }
  293. if (recall) {
  294. _this._loadConfig();
  295. }
  296. else if (!recall || _this._curloadTimes >= _this._reloadTimes) {
  297. _this.setLocalConfig(JSON.stringify(_this._serverConfig));
  298. Utils_1.utils.emitServerInitEvent();
  299. }
  300. });
  301. }
  302. };
  303. /**
  304. * 通用http请求,只封装了GET请求
  305. * @param url 请求的url地址
  306. * @param callback Function(ret:boolean, data:string)
  307. * 请求结束回调,成功ret为true, data为返回的数据string。 失败为ret为false, data为空
  308. */
  309. YZ_Tool_Native.prototype.commomHttpRequest = function (url, callback) {
  310. if (!Utils_1.utils._isConfigInit) {
  311. Utils_1.utils.showLog("warn:" + "本地数据未初始化!");
  312. return;
  313. }
  314. var completeCallback = callback;
  315. var xhr = new XMLHttpRequest();
  316. xhr.timeout = 6000; // 单位毫秒
  317. var requestUrl = url + ("&kyx=false&app_id=" + Utils_1.utils.config.nativeAndroidConfig.appID + "&channel=" + Utils_1.utils.config.nativeAndroidConfig.channel + "&device_uid=" + Utils_1.utils.Tool_Native.uid + "&uid=" + Utils_1.utils.Tool_Native.serviceId + "&game_type=2&time_stamp=" + (new Date()).getTime() + "&game_version=" + Utils_1.utils.config.nativeAndroidConfig.version + "&reqv=" + YZ_Constant_1.default.SERVER_VERSION);
  318. Utils_1.utils.showLog("服务器地址:" + requestUrl);
  319. xhr.open('POST', requestUrl);
  320. xhr.send("app_list=" + this.appList);
  321. xhr.onreadystatechange = function () {
  322. Utils_1.utils.showLog("请求状态改变, reaedyState=", xhr.readyState, "; status=", xhr.status);
  323. if (xhr.readyState == 4) {
  324. if (xhr.status == 200) {
  325. if (completeCallback) {
  326. completeCallback(true, Utils_1.utils.aesDecrypt(xhr.responseText));
  327. }
  328. }
  329. else {
  330. if (completeCallback) {
  331. completeCallback(false, "");
  332. }
  333. }
  334. }
  335. if (xhr.status != 200) {
  336. }
  337. };
  338. xhr.ontimeout = function () {
  339. Utils_1.utils.showLog("请求超时!");
  340. if (completeCallback) {
  341. completeCallback(false, "");
  342. }
  343. };
  344. xhr.onerror = function (err) {
  345. if (completeCallback) {
  346. completeCallback(false, "");
  347. }
  348. };
  349. };
  350. /**
  351. * 设置原生客户端数据数据
  352. * @param data
  353. */
  354. YZ_Tool_Native.prototype.setLocalConfig = function (data) {
  355. try {
  356. Utils_1.utils.showLog("设置原生客户端数据数据" + data);
  357. jsb.reflection.callStaticMethod(this.jniClassName, "setLocalConfig", "(Ljava/lang/String;)V", data);
  358. }
  359. catch (error) {
  360. Utils_1.utils.showLog(error);
  361. }
  362. };
  363. /**
  364. * 获取原生客户端数据数据
  365. * @param data
  366. */
  367. YZ_Tool_Native.prototype.getNativeData = function () {
  368. var data = "";
  369. try {
  370. data = jsb.reflection.callStaticMethod(this.jniClassName, "getLocalConfig", "()Ljava/lang/String;");
  371. Utils_1.utils.showLog("获取原生客户端数据数据 : " + data);
  372. }
  373. catch (error) {
  374. Utils_1.utils.showLog(error);
  375. }
  376. return data;
  377. };
  378. /**
  379. *
  380. * @param id 跳转ID
  381. * @param callback 跳转回调
  382. */
  383. YZ_Tool_Native.prototype.navigateToGame = function (jsonData, callback, path) {
  384. if (PlatUtils_1.default.IsNativeAndroid) {
  385. try {
  386. jsb.reflection.callStaticMethod(this.jniClassName, "navigateToGame", "(Ljava/lang/String;)V", jsonData);
  387. }
  388. catch (error) {
  389. Utils_1.utils.showLog(error);
  390. }
  391. }
  392. };
  393. Object.defineProperty(YZ_Tool_Native.prototype, "jniClassName", {
  394. /**
  395. * 获取JNI类名
  396. */
  397. get: function () {
  398. if (this.className)
  399. return this.className;
  400. try {
  401. this.className = jsb.reflection.callStaticMethod("aa.b.c.a", "a", "()Ljava/lang/String;");
  402. }
  403. catch (error) {
  404. }
  405. return this.className;
  406. },
  407. enumerable: false,
  408. configurable: true
  409. });
  410. /**
  411. * 获取交叉推广数据
  412. */
  413. YZ_Tool_Native.prototype.getRecommondGameList = function () {
  414. if (PlatUtils_1.default.IsNativeAndroid
  415. && Utils_1.utils.Tool_Native
  416. && Utils_1.utils.Tool_Native.ServerConfig) {
  417. return Utils_1.utils.Tool_Native.ServerConfig.jump_list;
  418. }
  419. return null;
  420. };
  421. /**
  422. * 上报关卡数据
  423. * @param level 当前关卡ID
  424. * @param levelName 关卡名称
  425. * @param status 状态
  426. */
  427. YZ_Tool_Native.prototype.postLevel = function (level, status, levelName) {
  428. if (2 > 1) {
  429. return;
  430. }
  431. if (PlatUtils_1.default.IsNativeAndroid) {
  432. var method = "m=rlevel";
  433. var url = POST_ServerUrl + method + ("&level_id=" + level + "&level_name=" + encodeURI(levelName) + "&status=" + status);
  434. Utils_1.utils.commomHttpRequest(url, function (ret, data) {
  435. if (ret) {
  436. Utils_1.utils.showLog("关卡数据上报成功!");
  437. // if (status == LevelStatus.GameStart) {
  438. // utils.showLog("配置数据获取成功: data = " + data);
  439. // if (data) {
  440. // let result = JSON.parse(data);
  441. // if (result) {
  442. // let keys = Object.keys(result);
  443. // for (let key in keys) {
  444. // this._serverConfig[key] = result[key];
  445. // utils.showLog("覆盖:#key=" + key, " #value=", result[key]);
  446. // }
  447. // }
  448. // }
  449. // } else {
  450. // utils.showLog("OPPO服务器配置数据获取失败, 使用本地配置!");
  451. // }
  452. }
  453. else {
  454. Utils_1.utils.showLog("关卡数据上报失败!");
  455. }
  456. }.bind(this));
  457. }
  458. };
  459. /**
  460. * 上报互推组件显示位置
  461. * @param otherGameAppId 跳转的ID
  462. * @param location 当前位置
  463. * @param status 0:点击,1:跳转成功
  464. */
  465. YZ_Tool_Native.prototype.postRecommentShowData = function (location) {
  466. if (PlatUtils_1.default.IsNativeAndroid) {
  467. var method = "m=rjumpshow";
  468. var url = ST_ServerUrl + method + ("&location=" + location);
  469. Utils_1.utils.commomHttpRequest(url, function (ret, data) {
  470. if (ret) {
  471. Utils_1.utils.showLog("上报互推组件显示位置成功!");
  472. }
  473. else {
  474. Utils_1.utils.showLog("上报互推组件显示位置失败!");
  475. }
  476. }.bind(this));
  477. }
  478. };
  479. /**
  480. * 上报互推组件数据
  481. * @param otherGameAppId 跳转的ID
  482. * @param location 当前位置
  483. * @param status 0:点击,1:跳转成功
  484. */
  485. YZ_Tool_Native.prototype.postDataByLocation = function (otherGameAppId, location, status) {
  486. if (status === void 0) { status = 0; }
  487. if (2 > 1) {
  488. return;
  489. }
  490. if (PlatUtils_1.default.IsNativeAndroid) {
  491. var method = "m=rjump";
  492. var url = POST_ServerUrl + method + ("&jump_app_id=" + otherGameAppId + "&location=" + location + "&status=" + status);
  493. Utils_1.utils.commomHttpRequest(url, function (ret, data) {
  494. if (ret) {
  495. Utils_1.utils.showLog("\u6570\u636E\u4E0A\u62A5\u6210\u529F");
  496. }
  497. else {
  498. Utils_1.utils.showLog("数据上报失败!");
  499. }
  500. }.bind(this));
  501. }
  502. };
  503. /**
  504. * 上报自定义事件
  505. * @param level 当前关卡ID
  506. * @param levelName 关卡名称
  507. * @param status 状态
  508. */
  509. YZ_Tool_Native.prototype.sendEvent = function (eventName) {
  510. if (2 > 1) {
  511. return;
  512. }
  513. if (PlatUtils_1.default.IsNativeAndroid) {
  514. var method = "m=revent";
  515. var url = POST_ServerUrl + method + ("&event=" + encodeURI(eventName));
  516. Utils_1.utils.commomHttpRequest(url, function (ret, data) {
  517. if (ret) {
  518. Utils_1.utils.showLog("上报自定义事件成功!");
  519. }
  520. else {
  521. Utils_1.utils.showLog("上报自定义事件失败!");
  522. }
  523. }.bind(this));
  524. }
  525. };
  526. /**
  527. * 上报自定义事件
  528. * @param level 当前关卡ID
  529. * @param levelName 关卡名称
  530. * @param status 状态
  531. */
  532. YZ_Tool_Native.prototype.sendEventNew = function (eventName, eventId, eventData, isCallBack) {
  533. var _this = this;
  534. if (eventId === void 0) { eventId = "default"; }
  535. if (isCallBack === void 0) { isCallBack = true; }
  536. if (2 > 1) {
  537. return;
  538. }
  539. if (PlatUtils_1.default.IsNativeAndroid) {
  540. var method = "m=reventv2";
  541. var url = POST_ServerUrl + method + ("&event=" + encodeURI(eventName) + "&event_id=" + eventId);
  542. if (eventData) {
  543. url += "&event_data=" + encodeURI(eventData);
  544. }
  545. Utils_1.utils.showLog("自定义事件上报URL:" + url);
  546. Utils_1.utils.commomHttpRequest(url, function (ret, data) {
  547. if (ret) {
  548. Utils_1.utils.showLog("上报自定义事件成功!");
  549. isCallBack && _this.callBackToEvent(data);
  550. }
  551. else {
  552. Utils_1.utils.showLog("上报自定义事件失败!");
  553. isCallBack && _this.callBackToEvent("false");
  554. }
  555. });
  556. }
  557. };
  558. /**
  559. * 上报自定义事件
  560. * @param level 当前关卡ID
  561. * @param levelName 关卡名称
  562. * @param status 状态
  563. */
  564. YZ_Tool_Native.prototype.sendEventV3 = function (eventName, eventId, eventData) {
  565. var _this = this;
  566. if (eventId === void 0) { eventId = "default"; }
  567. if (PlatUtils_1.default.IsNativeAndroid) {
  568. var method = "m=reventv2";
  569. var url = POST_ServerUrl + method + ("&event=" + encodeURI(eventName) + "&event_id=" + eventId);
  570. if (eventData) {
  571. url += "&event_data=" + encodeURI(eventData);
  572. }
  573. Utils_1.utils.commomHttpRequest(url, function (ret, data) {
  574. if (ret) {
  575. Utils_1.utils.showLog("上报自定义事件成功!");
  576. _this.callBackToEvent(data);
  577. }
  578. else {
  579. Utils_1.utils.showLog("上报自定义事件失败!");
  580. _this.callBackToEvent("false");
  581. }
  582. });
  583. }
  584. };
  585. /**
  586. * 返回事件上报的结果给安卓端
  587. * @param result
  588. */
  589. YZ_Tool_Native.prototype.callBackToEvent = function (result) {
  590. if (PlatUtils_1.default.IsNativeAndroid) {
  591. //@ts-ignore
  592. try {
  593. jsb.reflection.callStaticMethod(this.jniClassName, "callBackToEvent", "(Ljava/lang/String;)V", result);
  594. }
  595. catch (error) {
  596. Utils_1.utils.showLog(error);
  597. }
  598. }
  599. };
  600. /**
  601. * 弹出提示框
  602. * @param msg 消息
  603. */
  604. YZ_Tool_Native.prototype.showToast = function (msg) {
  605. if (PlatUtils_1.default.IsNativeAndroid) {
  606. //@ts-ignore
  607. try {
  608. jsb.reflection.callStaticMethod(this.jniClassName, "showToast", "(Ljava/lang/String;)V", msg);
  609. }
  610. catch (error) {
  611. Utils_1.utils.showLog(error);
  612. }
  613. }
  614. };
  615. /**
  616. * 显示隐私协议页面
  617. */
  618. YZ_Tool_Native.prototype.showPrivacyAgreement = function () {
  619. try {
  620. //@ts-ignore
  621. jsb.reflection.callStaticMethod(this.jniClassName, "showPrivacyAgreement", "()V");
  622. }
  623. catch (error) {
  624. Utils_1.utils.showLog(error);
  625. }
  626. };
  627. YZ_Tool_Native.prototype.showRealNameAuthPanel = function (parmes) {
  628. try {
  629. //@ts-ignore
  630. jsb.reflection.callStaticMethod(this.jniClassName, "showRealNameAuthPanel", "(Ljava/lang/String;)V", parmes);
  631. }
  632. catch (error) {
  633. Utils_1.utils.showLog(error);
  634. }
  635. };
  636. YZ_Tool_Native.prototype.realNameAuthResult = function (parmes) {
  637. try {
  638. //@ts-ignore
  639. jsb.reflection.callStaticMethod(this.jniClassName, "realNameAuthResult", "(Ljava/lang/String;)V", parmes);
  640. }
  641. catch (error) {
  642. Utils_1.utils.showLog(error);
  643. }
  644. };
  645. /**
  646. * 实名认证
  647. */
  648. YZ_Tool_Native.prototype.realNameAuth = function (code, name, callBack) {
  649. if (2 > 1) {
  650. return;
  651. }
  652. if (!Utils_1.utils._isConfigInit) {
  653. Utils_1.utils.showLog("warn:" + "本地数据未初始化!");
  654. return;
  655. }
  656. var method = "m=realNameAuth";
  657. var completeCallback = callBack;
  658. var xhr = new XMLHttpRequest();
  659. xhr.timeout = 15000; // 单位毫秒
  660. var requestUrl = "https://apps.youlesp.com/gss?" + method + ("&time_stamp=" + (new Date()).getTime());
  661. var data = {};
  662. data.kyx = false;
  663. data.app_id = Utils_1.utils.config.nativeAndroidConfig.appID;
  664. data.channel = Utils_1.utils.config.nativeAndroidConfig.channel;
  665. data.device_uid = Utils_1.utils.Tool_Native.uid;
  666. data.uid = Utils_1.utils.Tool_Native.serviceId;
  667. data.game_type = 2;
  668. data.device_data = this.deviceInfo;
  669. data.game_version = Utils_1.utils.config.nativeAndroidConfig.version;
  670. data.reqv = YZ_Constant_1.default.SERVER_VERSION;
  671. data.app_list = this.appList;
  672. data.id_card = code;
  673. data.real_name = name;
  674. Utils_1.utils.showLog("服务器地址:" + requestUrl);
  675. Utils_1.utils.showLog("请求参数:" + JSON.stringify(data));
  676. var requestData = JSON.stringify(data);
  677. xhr.open('POST', requestUrl);
  678. xhr.send("json_data=" + Utils_1.utils.aesEncrypt(requestData));
  679. Utils_1.utils.showLog("json_data=:" + Utils_1.utils.aesEncrypt(requestData));
  680. xhr.onreadystatechange = function () {
  681. Utils_1.utils.showLog("请求状态改变, reaedyState=", xhr.readyState, "; status=", xhr.status);
  682. if (xhr.readyState == 4) {
  683. if (xhr.status == 200) {
  684. if (completeCallback) {
  685. completeCallback(true, Utils_1.utils.aesDecrypt(xhr.responseText));
  686. }
  687. }
  688. else {
  689. if (completeCallback) {
  690. completeCallback(false, "");
  691. }
  692. }
  693. }
  694. if (xhr.status != 200) {
  695. }
  696. };
  697. xhr.ontimeout = function () {
  698. Utils_1.utils.showLog("请求超时!");
  699. if (completeCallback) {
  700. completeCallback(false, "");
  701. }
  702. };
  703. xhr.onerror = function (err) {
  704. if (completeCallback) {
  705. completeCallback(false, "");
  706. }
  707. };
  708. };
  709. /**
  710. * 友盟游戏开始上报
  711. * @param levelID
  712. */
  713. YZ_Tool_Native.prototype.umaOnStart = function (levelID) {
  714. if (!this.checkUmeng())
  715. return;
  716. this.umaTrackEvent("level", "um_plus_game_level", {
  717. game_level: levelID,
  718. game_states: "0"
  719. });
  720. };
  721. /**
  722. *
  723. * @returns 是否开启友盟
  724. */
  725. YZ_Tool_Native.prototype.checkUmeng = function () {
  726. // if (!utils.config.oppoconfig.umengId) {
  727. // return false;
  728. // }
  729. return true;
  730. };
  731. /**
  732. * 友盟结算上报
  733. * @param levelID 关卡id
  734. * @param stageId
  735. * @param event
  736. */
  737. YZ_Tool_Native.prototype.umaReportedLevel = function (levelID, event) {
  738. if (!this.checkUmeng())
  739. return;
  740. var status = 1;
  741. if (event == YZ_Constant_1.LevelStatus.GameFail) {
  742. status = -1;
  743. }
  744. this.umaTrackEvent("level", "um_plus_game_level", {
  745. game_level: levelID,
  746. game_states: "" + status
  747. });
  748. };
  749. /**
  750. * 友盟自定义事件
  751. * @param eventId 事件ID,注意:事件ID必须要在后台配置
  752. * @param params 事件内容
  753. */
  754. YZ_Tool_Native.prototype.umaTrackEvent = function (eventType, eventId, params) {
  755. if (eventType === void 0) { eventType = "custom"; }
  756. if (!this.checkUmeng())
  757. return;
  758. try {
  759. if (params) {
  760. params = JSON.stringify(params);
  761. }
  762. //@ts-ignore
  763. jsb.reflection.callStaticMethod(this.jniClassName, "umaTrackEvent", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", eventType, eventId, params);
  764. }
  765. catch (error) {
  766. Utils_1.utils.showLog(error);
  767. }
  768. };
  769. YZ_Tool_Native = __decorate([
  770. ccclass
  771. ], YZ_Tool_Native);
  772. return YZ_Tool_Native;
  773. }());
  774. exports.default = YZ_Tool_Native;
  775. cc._RF.pop();