b78fcb41-7556-4b92-a41e-ee6b26087d35.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. "use strict";
  2. cc._RF.push(module, 'b78fctBdVZLkqQe7msmCH01', 'YZ_Tool_IOS');
  3. // common-plugin/Scripts/YZ_Tool_IOS.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 = "https://apps.youlesp.com/gss?";
  19. var POST_ServerUrl = "https://report.youletd.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_IOS = /** @class */ (function () {
  23. function YZ_Tool_IOS() {
  24. this.className = "JNIHelper";
  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. }
  46. Object.defineProperty(YZ_Tool_IOS.prototype, "ServerConfig", {
  47. get: function () {
  48. return this._serverConfig;
  49. },
  50. enumerable: false,
  51. configurable: true
  52. });
  53. /**
  54. * 当前版本号
  55. */
  56. YZ_Tool_IOS.prototype.gameVersion = function () {
  57. return Utils_1.utils.config.nativeIoSConfig.version;
  58. };
  59. Object.defineProperty(YZ_Tool_IOS.prototype, "uid", {
  60. get: function () {
  61. // if (this._service_uid != "0") return this._uid;
  62. // this._login();
  63. return "0";
  64. },
  65. enumerable: false,
  66. configurable: true
  67. });
  68. Object.defineProperty(YZ_Tool_IOS.prototype, "serviceId", {
  69. /**
  70. * 服务器返回UID
  71. */
  72. get: function () {
  73. if (this._service_uid != "0")
  74. return this._service_uid;
  75. this.reportLogin();
  76. return "0";
  77. },
  78. enumerable: false,
  79. configurable: true
  80. });
  81. /**
  82. * 上报登录接口获取UID
  83. */
  84. YZ_Tool_IOS.prototype.reportLogin = function () {
  85. var _this = this;
  86. if (this.isReport)
  87. return;
  88. this.isReport = true;
  89. var self = this;
  90. var curTime = new Date().getTime();
  91. var interval = (curTime - this._reportLoginTime) / 1000;
  92. if (interval > 0 && interval < this._reportLoginInterval) {
  93. Utils_1.utils.showLog("\u4E0A\u62A5\u767B\u5F55\u83B7\u53D6UID\u5C0F\u4E8E\uFF1A" + this._reportLoginInterval + "\u79D2");
  94. return;
  95. }
  96. this._reportLoginTime = curTime;
  97. var method = "m=login";
  98. var url = ST_ServerUrl + method + ("&device_data=" + encodeURI(this.deviceInfo));
  99. Utils_1.utils.commomHttpRequest(url, function (ret, data) {
  100. if (ret) {
  101. if (data) {
  102. var result = JSON.parse(data);
  103. Utils_1.utils.showLog("data=" + data);
  104. Utils_1.utils.showLog("result=" + result);
  105. Utils_1.utils.showLog("result.uid=" + result.uid);
  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. }
  112. }
  113. else {
  114. Utils_1.utils.showLog("获取数据失败1");
  115. }
  116. _this.isReport = false;
  117. });
  118. };
  119. /**
  120. *
  121. * @param data 配置数据
  122. */
  123. YZ_Tool_IOS.prototype.init = function (data) {
  124. if (PlatUtils_1.default.IsNativeIOS) {
  125. if (data) {
  126. var configObj = JSON.parse(data);
  127. if (configObj && configObj.ios) {
  128. Utils_1.utils.showLog("本地配置数据:" + JSON.stringify(configObj.ios));
  129. ST_DefaultServerConfig = JSON.stringify(configObj.ios);
  130. }
  131. }
  132. this._service_uid = YZ_LocalStorage_1.default.getItem(YZ_Constant_1.default.ST_SERVICE_UID);
  133. this._service_uid = this._service_uid ? this._service_uid : "0";
  134. this._loadConfig();
  135. // if (PlatUtils.IsNativeIOS) {
  136. // //初始化时监听返回按钮退出事件
  137. // cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, (event: any) => {
  138. // if (event.keyCode == cc.macro.KEY.escape || event.keyCode == cc.macro.KEY.back) {
  139. // if (PlatUtils.IsNativeIOS) {
  140. // if (this.showGameExitDialogType == 1) {
  141. // this.showGameExitDialog();
  142. // } else {
  143. // this.GameExit();
  144. // }
  145. // }
  146. // }
  147. // }, this);
  148. // }
  149. }
  150. };
  151. /**
  152. * 显示退出弹窗
  153. */
  154. YZ_Tool_IOS.prototype.showGameExitDialog = function () {
  155. if (!Utils_1.utils._isConfigInit) {
  156. Utils_1.utils.showLog("warn:" + "组件配置未初始化!");
  157. return null;
  158. }
  159. if (this._gameExitDialogNode && cc.isValid(this._gameExitDialogNode)) {
  160. Utils_1.utils.showLog("退出窗口还在。");
  161. return;
  162. }
  163. if (Utils_1.utils.config.otherconfig.gameExitDialog) {
  164. // if(utils.getRecommondGameList())
  165. var node = cc.instantiate(Utils_1.utils.config.otherconfig.gameExitDialog);
  166. if (node) {
  167. if (this._gameExitDialogNode && cc.isValid(this._gameExitDialogNode)) {
  168. this._gameExitDialogNode.destroy();
  169. }
  170. this._gameExitDialogNode = node;
  171. this._gameExitDialogNode.group = "default";
  172. cc.director.getScene().addChild(this._gameExitDialogNode, 9999);
  173. }
  174. }
  175. else {
  176. Utils_1.utils.showLog("warn:" + "未找到预制体 GameExitDialog, 请查看CommonUtils组件上是否赋值 !");
  177. }
  178. };
  179. YZ_Tool_IOS.prototype.GameExit = function () {
  180. if (PlatUtils_1.default.IsNativeIOS) {
  181. cc.log("AdAgentNative GameExit");
  182. try {
  183. jsb.reflection.callStaticMethod(this.className, "gameExit");
  184. }
  185. catch (error) {
  186. cc.log(error);
  187. }
  188. }
  189. };
  190. /**
  191. * 获取更多游戏显示的类型
  192. * 0:默认互推面板 1: 跳转到原生平台
  193. */
  194. YZ_Tool_IOS.prototype.getMoreGameShowType = function () {
  195. try {
  196. this.moreGameShowType = jsb.reflection.callStaticMethod(this.className, "getMoreGameShowType", "()I");
  197. }
  198. catch (error) {
  199. Utils_1.utils.showLog(error);
  200. }
  201. };
  202. /**
  203. * 获取手机设备信息
  204. *
  205. */
  206. YZ_Tool_IOS.prototype.getDeviceInfo = function () {
  207. try {
  208. this.deviceInfo = jsb.reflection.callStaticMethod(this.className, "getDeviceInfo", "()Ljava/lang/String;");
  209. Utils_1.utils.showLog("获取原生平台手机设备信息:" + this.deviceInfo);
  210. }
  211. catch (error) {
  212. Utils_1.utils.showLog(error);
  213. }
  214. };
  215. /**
  216. * 跳转原生平台的更多游戏
  217. */
  218. YZ_Tool_IOS.prototype.showMoreGames = function () {
  219. if (PlatUtils_1.default.IsNativeIOS) {
  220. Utils_1.utils.showLog("AdAgentNative showMoreGame");
  221. try {
  222. jsb.reflection.callStaticMethod(this.className, "showNativeMoreGame", "()V");
  223. }
  224. catch (error) {
  225. cc.log(error);
  226. }
  227. }
  228. };
  229. YZ_Tool_IOS.prototype._loadConfig = function () {
  230. var _this = this;
  231. if (PlatUtils_1.default.IsNativeIOS) {
  232. var method = "m=g";
  233. Utils_1.utils.commomHttpRequest(ST_ServerUrl + method, function (ret, data) {
  234. if (ret) {
  235. Utils_1.utils.showLog("原生IOS服务器配置数据获取成功: data = " + data);
  236. if (data) {
  237. var result = JSON.parse(data);
  238. if (result) {
  239. if (!Utils_1.utils.DebugLoacalConfig) {
  240. _this._serverConfig = result;
  241. if (_this._serverConfig.is_show_log_view && _this._serverConfig.is_show_log_view == "true") {
  242. Utils_1.utils.showLogView = true;
  243. }
  244. }
  245. else {
  246. Utils_1.utils.showLog("开启了本地数据测试,使用本地配置!");
  247. }
  248. }
  249. else {
  250. Utils_1.utils.showLog("原生安卓服务器配置数据不是合法的JSON数据, 使用本地配置!");
  251. }
  252. }
  253. }
  254. else {
  255. Utils_1.utils.showLog("原生安卓服务器配置数据获取失败, 使用本地配置!");
  256. }
  257. if (!_this._serverConfig) {
  258. _this._serverConfig = JSON.parse(ST_DefaultServerConfig);
  259. }
  260. else {
  261. if (_this._serverConfig.is_local_pos_id
  262. && _this._serverConfig.is_local_pos_id == "false") {
  263. // 使用服务器下发的广告id
  264. Utils_1.utils.showLog("使用服务器下发的广告id");
  265. Utils_1.utils.config.nativeIoSConfig.bannerId = _this._serverConfig.banner_pos_id;
  266. Utils_1.utils.config.nativeIoSConfig.insertId = _this._serverConfig.intersititia_pos_id;
  267. Utils_1.utils.config.nativeIoSConfig.videoId = _this._serverConfig.video_pos_id;
  268. }
  269. else {
  270. _this._serverConfig.video_pos_id = Utils_1.utils.config.nativeIoSConfig.videoId;
  271. _this._serverConfig.banner_pos_id = Utils_1.utils.config.nativeIoSConfig.bannerId;
  272. _this._serverConfig.intersititia_pos_id = Utils_1.utils.config.nativeIoSConfig.insertId;
  273. Utils_1.utils.showLog("使用本地配置的广告ID");
  274. }
  275. }
  276. Utils_1.utils.showLog("执行IOS >>> 初始化");
  277. jsb.reflection.callStaticMethod(_this.className, "init:", JSON.stringify(_this._serverConfig));
  278. // this.setLocalConfig(JSON.stringify(this._serverConfig));
  279. Utils_1.utils.emitServerInitEvent();
  280. });
  281. }
  282. };
  283. /**
  284. * 通用http请求,只封装了GET请求
  285. * @param url 请求的url地址
  286. * @param callback Function(ret:boolean, data:string)
  287. * 请求结束回调,成功ret为true, data为返回的数据string。 失败为ret为false, data为空
  288. */
  289. YZ_Tool_IOS.prototype.commomHttpRequest = function (url, callback) {
  290. if (!Utils_1.utils._isConfigInit) {
  291. Utils_1.utils.showLog("warn:" + "本地数据未初始化!");
  292. return;
  293. }
  294. var completeCallback = callback;
  295. var xhr = new XMLHttpRequest();
  296. xhr.timeout = 6000; // 单位毫秒
  297. 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());
  298. Utils_1.utils.showLog("服务器地址:" + requestUrl);
  299. xhr.open('POST', requestUrl);
  300. xhr.send("app_list=" + this.appList);
  301. xhr.onreadystatechange = function () {
  302. Utils_1.utils.showLog("请求状态改变, reaedyState=", xhr.readyState, "; status=", xhr.status);
  303. if (xhr.readyState == 4 && xhr.status == 200) {
  304. if (completeCallback) {
  305. completeCallback(true, xhr.responseText);
  306. }
  307. }
  308. if (xhr.status != 200) {
  309. if (completeCallback) {
  310. completeCallback(false, "");
  311. }
  312. }
  313. };
  314. xhr.ontimeout = function () {
  315. Utils_1.utils.showLog("请求超时!");
  316. if (completeCallback) {
  317. completeCallback(false, "");
  318. }
  319. };
  320. xhr.onerror = function (err) {
  321. if (completeCallback) {
  322. completeCallback(false, "");
  323. }
  324. };
  325. };
  326. /**
  327. * 设置原生客户端数据数据
  328. * @param data
  329. */
  330. YZ_Tool_IOS.prototype.setLocalConfig = function (data) {
  331. try {
  332. Utils_1.utils.showLog("设置原生客户端数据数据" + data);
  333. jsb.reflection.callStaticMethod(this.className, "setLocalConfig", "(Ljava/lang/String;)V", data);
  334. }
  335. catch (error) {
  336. Utils_1.utils.showLog(error);
  337. }
  338. };
  339. /**
  340. * 获取原生客户端数据数据
  341. * @param data
  342. */
  343. YZ_Tool_IOS.prototype.getNativeData = function () {
  344. var data = "";
  345. try {
  346. data = jsb.reflection.callStaticMethod(this.className, "getLocalConfig");
  347. Utils_1.utils.showLog("获取原生客户端数据数据 : " + data);
  348. }
  349. catch (error) {
  350. Utils_1.utils.showLog(error);
  351. }
  352. return data;
  353. };
  354. /**
  355. *
  356. * @param id 跳转ID
  357. * @param callback 跳转回调
  358. */
  359. YZ_Tool_IOS.prototype.navigateToGame = function (appId, callback, path) {
  360. if (PlatUtils_1.default.IsNativeIOS) {
  361. try {
  362. jsb.reflection.callStaticMethod(this.className, "navigateToGame:", appId);
  363. }
  364. catch (error) {
  365. Utils_1.utils.showLog(error);
  366. }
  367. }
  368. };
  369. /**
  370. * 获取交叉推广数据
  371. */
  372. YZ_Tool_IOS.prototype.getRecommondGameList = function () {
  373. if (PlatUtils_1.default.IsNativeIOS
  374. && Utils_1.utils.Tool_IOS
  375. && Utils_1.utils.Tool_IOS.ServerConfig) {
  376. return Utils_1.utils.Tool_IOS.ServerConfig.jump_list;
  377. }
  378. return null;
  379. };
  380. /**
  381. * 上报关卡数据
  382. * @param level 当前关卡ID
  383. * @param levelName 关卡名称
  384. * @param status 状态
  385. */
  386. YZ_Tool_IOS.prototype.postLevel = function (level, status, levelName) {
  387. if (PlatUtils_1.default.IsNativeIOS) {
  388. var method = "m=rlevel";
  389. var url = POST_ServerUrl + method + ("&level_id=" + level + "&level_name=" + encodeURI(levelName) + "&status=" + status);
  390. Utils_1.utils.commomHttpRequest(url, function (ret, data) {
  391. if (ret) {
  392. Utils_1.utils.showLog("关卡数据上报成功!");
  393. }
  394. else {
  395. Utils_1.utils.showLog("关卡数据上报失败!");
  396. }
  397. }.bind(this));
  398. }
  399. };
  400. /**
  401. * 上报自定义事件
  402. * @param level 当前关卡ID
  403. * @param levelName 关卡名称
  404. * @param status 状态
  405. */
  406. YZ_Tool_IOS.prototype.sendEvent = function (eventName) {
  407. if (PlatUtils_1.default.IsNativeIOS) {
  408. var method = "m=revent";
  409. var url = POST_ServerUrl + method + ("&event=" + encodeURI(eventName));
  410. Utils_1.utils.commomHttpRequest(url, function (ret, data) {
  411. if (ret) {
  412. Utils_1.utils.showLog("上报自定义事件成功!");
  413. }
  414. else {
  415. Utils_1.utils.showLog("上报自定义事件失败!");
  416. }
  417. }.bind(this));
  418. }
  419. };
  420. /**
  421. * 弹出提示框
  422. * @param msg 消息
  423. */
  424. YZ_Tool_IOS.prototype.showToast = function (msg) {
  425. if (PlatUtils_1.default.IsNativeIOS) {
  426. console.log("showToast >>>>>");
  427. //@ts-ignore
  428. jsb.reflection.callStaticMethod(this.className, "showToast:", msg);
  429. }
  430. };
  431. /**
  432. * 实名认证
  433. */
  434. YZ_Tool_IOS.prototype.realNameAuth = function (code, name, callBack) {
  435. if (!Utils_1.utils._isConfigInit) {
  436. Utils_1.utils.showLog("warn:" + "本地数据未初始化!");
  437. return;
  438. }
  439. var method = "m=realNameAuth";
  440. var completeCallback = callBack;
  441. var xhr = new XMLHttpRequest();
  442. xhr.timeout = 15000; // 单位毫秒
  443. var requestUrl = "https://apps.youlesp.com/gss?" + method + ("&time_stamp=" + (new Date()).getTime());
  444. var data = {};
  445. data.kyx = false;
  446. data.app_id = Utils_1.utils.config.nativeIoSConfig.appID;
  447. data.channel = "ios";
  448. data.device_uid = this.uid;
  449. data.uid = this.serviceId;
  450. data.game_type = 2;
  451. data.device_data = this.deviceInfo;
  452. data.game_version = Utils_1.utils.config.nativeIoSConfig.version;
  453. data.reqv = YZ_Constant_1.default.SERVER_VERSION;
  454. data.app_list = this.appList;
  455. data.id_card = code;
  456. data.real_name = name;
  457. Utils_1.utils.showLog("服务器地址:" + requestUrl);
  458. Utils_1.utils.showLog("请求参数:" + JSON.stringify(data));
  459. var requestData = JSON.stringify(data);
  460. xhr.open('POST', requestUrl);
  461. xhr.send("json_data=" + Utils_1.utils.aesEncrypt(requestData));
  462. Utils_1.utils.showLog("json_data=:" + Utils_1.utils.aesEncrypt(requestData));
  463. xhr.onreadystatechange = function () {
  464. Utils_1.utils.showLog("请求状态改变, reaedyState=", xhr.readyState, "; status=", xhr.status);
  465. if (xhr.readyState == 4) {
  466. if (xhr.status == 200) {
  467. if (completeCallback) {
  468. completeCallback(true, Utils_1.utils.aesDecrypt(xhr.responseText));
  469. }
  470. }
  471. else {
  472. if (completeCallback) {
  473. completeCallback(false, "");
  474. }
  475. }
  476. }
  477. if (xhr.status != 200) {
  478. }
  479. };
  480. xhr.ontimeout = function () {
  481. Utils_1.utils.showLog("请求超时!");
  482. if (completeCallback) {
  483. completeCallback(false, "");
  484. }
  485. };
  486. xhr.onerror = function (err) {
  487. if (completeCallback) {
  488. completeCallback(false, "");
  489. }
  490. };
  491. };
  492. YZ_Tool_IOS = __decorate([
  493. ccclass
  494. ], YZ_Tool_IOS);
  495. return YZ_Tool_IOS;
  496. }());
  497. exports.default = YZ_Tool_IOS;
  498. cc._RF.pop();