4ad1b308-7f12-44ef-b468-40fad72495b8.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. "use strict";
  2. cc._RF.push(module, '4ad1bMIfxJE77RoQPrXJJW4', 'YZ_Tool_Hago');
  3. // common-plugin/Scripts/YZ_Tool_Hago.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. // const i18n = require('LanguageData');
  53. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  54. var ST_ServerUrl = "http://apps.youlesp.com/gss?";
  55. var POST_ServerUrl = "http://report.youlesp.com/gss?";
  56. var ST_DefaultServerConfig = "";
  57. var YZ_Tool_Hago = /** @class */ (function () {
  58. function YZ_Tool_Hago() {
  59. //@ts-ignore
  60. this.hg = hg;
  61. this._sysInfo = null;
  62. this._serverConfig = null;
  63. //设备UID
  64. this._uid = "0";
  65. //服务器返回UID
  66. this._service_uid = "0";
  67. this._loginTime = 0;
  68. this._loginInterval = 30;
  69. this._reportLoginTime = 0;
  70. this._reportLoginInterval = 30;
  71. this.isReport = false;
  72. }
  73. Object.defineProperty(YZ_Tool_Hago.prototype, "SysInfo", {
  74. get: function () {
  75. return this._sysInfo;
  76. },
  77. enumerable: false,
  78. configurable: true
  79. });
  80. Object.defineProperty(YZ_Tool_Hago.prototype, "ServerConfig", {
  81. get: function () {
  82. return this._serverConfig;
  83. },
  84. enumerable: false,
  85. configurable: true
  86. });
  87. /**
  88. * 当前版本号
  89. */
  90. YZ_Tool_Hago.prototype.gameVersion = function () {
  91. return Utils_1.utils.config.hagoConfig.version;
  92. };
  93. Object.defineProperty(YZ_Tool_Hago.prototype, "uid", {
  94. get: function () {
  95. // if (this._service_uid != "0") return this._uid;
  96. // this._login();
  97. return "0";
  98. },
  99. enumerable: false,
  100. configurable: true
  101. });
  102. Object.defineProperty(YZ_Tool_Hago.prototype, "serviceId", {
  103. /**
  104. * 服务器返回UID
  105. */
  106. get: function () {
  107. if (this._service_uid != "0")
  108. return this._service_uid;
  109. this.reportLogin();
  110. return "0";
  111. },
  112. enumerable: false,
  113. configurable: true
  114. });
  115. YZ_Tool_Hago.prototype._login = function () {
  116. return __awaiter(this, void 0, void 0, function () {
  117. var curTime, interval, self;
  118. return __generator(this, function (_a) {
  119. curTime = new Date().getTime();
  120. interval = (curTime - this._loginTime) / 1000;
  121. if (interval > 0 && interval < this._loginInterval) {
  122. Utils_1.utils.showLog("\u767B\u5F55\u8BF7\u6C42\u95F4\u9694\u5C0F\u4E8E\uFF1A" + this._loginInterval + "\u79D2");
  123. return [2 /*return*/];
  124. }
  125. this._loginTime = curTime;
  126. self = this;
  127. Utils_1.utils.showLog("vivo暂时不获取uid,uid全部为0");
  128. this._uid = "0";
  129. this.reportLogin();
  130. return [2 /*return*/];
  131. });
  132. });
  133. };
  134. /**
  135. * 上报登录接口获取UID
  136. */
  137. YZ_Tool_Hago.prototype.reportLogin = function () {
  138. var _this = this;
  139. if (this.isReport)
  140. return;
  141. this.isReport = true;
  142. var self = this;
  143. var curTime = new Date().getTime();
  144. var interval = (curTime - this._reportLoginTime) / 1000;
  145. if (interval > 0 && interval < this._reportLoginInterval) {
  146. Utils_1.utils.showLog("\u4E0A\u62A5\u767B\u5F55\u83B7\u53D6UID\u5C0F\u4E8E\uFF1A" + this._reportLoginInterval + "\u79D2");
  147. return;
  148. }
  149. this._reportLoginTime = curTime;
  150. var method = "m=login";
  151. var url = ST_ServerUrl + method + ("&device_data=" + encodeURI(JSON.stringify(this._sysInfo)));
  152. Utils_1.utils.commomHttpRequest(url, function (ret, data) {
  153. if (ret) {
  154. if (data) {
  155. var result = JSON.parse(data);
  156. Utils_1.utils.showLog("data=" + data);
  157. Utils_1.utils.showLog("result=" + result);
  158. Utils_1.utils.showLog("result.uid=" + result.uid);
  159. if (result.uid) {
  160. self._service_uid = "" + result.uid;
  161. Utils_1.utils.showLog("服务器请求登录成功! _service_uid=" + self._service_uid);
  162. YZ_LocalStorage_1.default.setItem(YZ_Constant_1.default.ST_SERVICE_UID, self._service_uid);
  163. }
  164. }
  165. }
  166. else {
  167. Utils_1.utils.showLog("获取数据失败1");
  168. }
  169. _this.isReport = false;
  170. });
  171. };
  172. /**
  173. *
  174. * @param data 配置数据
  175. */
  176. YZ_Tool_Hago.prototype.init = function (data) {
  177. Utils_1.utils.showLog("init hago");
  178. if (PlatUtils_1.default.IsHago) {
  179. if (data) {
  180. var configObj = JSON.parse(data);
  181. if (configObj && configObj.hago) {
  182. ST_DefaultServerConfig = JSON.stringify(configObj.hago);
  183. }
  184. }
  185. if (CC_DEBUG) {
  186. //@ts-ignore
  187. hg.initWebDebug({
  188. gameId: "yanshiceshi",
  189. user: 1,
  190. env: "Test",
  191. countryCode: "ID",
  192. language: "id",
  193. success: function (res) {
  194. console.log("hago start webdebug success");
  195. },
  196. fail: function (res) {
  197. console.log("hago start webdebug fail", res);
  198. }
  199. });
  200. }
  201. this._sysInfo = this.hg.getSystemInfoSync();
  202. if (this._sysInfo) {
  203. Utils_1.utils.showLog("Hago 小游戏平台信息: " + JSON.stringify(this.SysInfo));
  204. if (this._sysInfo.language == "en-us") {
  205. //@ts-ignore
  206. i18n.init("en");
  207. }
  208. else if (this._sysInfo.language == "pt-br") {
  209. //@ts-ignore
  210. i18n.init("pt");
  211. }
  212. else {
  213. //@ts-ignore
  214. i18n.init(this._sysInfo.language);
  215. }
  216. }
  217. this._service_uid = YZ_LocalStorage_1.default.getItem(YZ_Constant_1.default.ST_SERVICE_UID);
  218. this._service_uid = this._service_uid ? this._service_uid : "0";
  219. this._loadConfig();
  220. }
  221. };
  222. YZ_Tool_Hago.prototype._loadConfig = function () {
  223. var _this = this;
  224. if (PlatUtils_1.default.IsHago) {
  225. var method = "m=g";
  226. var url = ST_ServerUrl + method;
  227. Utils_1.utils.commomHttpRequest(url, function (ret, data) {
  228. if (ret) {
  229. Utils_1.utils.showLog("Hago服务器配置数据获取成功: data = " + data);
  230. if (data) {
  231. var result = JSON.parse(data);
  232. if (result) {
  233. if (!Utils_1.utils.DebugLoacalConfig) {
  234. _this._serverConfig = result;
  235. if (_this._serverConfig.is_show_log_view && _this._serverConfig.is_show_log_view == "true") {
  236. Utils_1.utils.showLogView = true;
  237. }
  238. }
  239. else {
  240. Utils_1.utils.showLog("开启了本地数据测试,使用本地配置!");
  241. }
  242. }
  243. else {
  244. Utils_1.utils.showLog("Hago服务器配置数据不是合法的JSON数据, 使用本地配置!");
  245. }
  246. }
  247. }
  248. else {
  249. Utils_1.utils.showLog("Hago服务器配置数据获取失败, 使用本地配置!");
  250. }
  251. if (!_this._serverConfig) {
  252. _this._serverConfig = JSON.parse(ST_DefaultServerConfig);
  253. }
  254. else {
  255. if (_this._serverConfig.is_local_pos_id
  256. && _this._serverConfig.is_local_pos_id == "false") {
  257. // 使用服务器下发的广告id
  258. Utils_1.utils.showLog("使用服务器下发的广告id");
  259. Utils_1.utils.config.hagoConfig.videoId = _this._serverConfig.video_pos_id;
  260. }
  261. else {
  262. Utils_1.utils.showLog("使用本地配置的广告ID");
  263. }
  264. }
  265. Utils_1.utils.emitServerInitEvent();
  266. });
  267. }
  268. };
  269. /**
  270. * 比较当前平台版本是否高于指定的版本号
  271. * @param miniVersion 最低平台版本号
  272. */
  273. YZ_Tool_Hago.prototype.isOverMiniVersion = function (miniVersion) {
  274. if (PlatUtils_1.default.IsHago) {
  275. if (this._sysInfo && this._sysInfo.platformVersionCode) {
  276. return this._sysInfo.platformVersionCode >= miniVersion;
  277. }
  278. }
  279. return false;
  280. };
  281. /**
  282. * 上报关卡数据
  283. * @param level 当前关卡ID
  284. * @param levelName 关卡名称
  285. * @param status 状态
  286. */
  287. YZ_Tool_Hago.prototype.postLevel = function (level, status, levelName) {
  288. if (PlatUtils_1.default.IsHago) {
  289. var method = "m=rlevel";
  290. var url = POST_ServerUrl + method + ("&level_id=" + level + "&level_name=" + encodeURI(levelName) + "&status=" + status);
  291. Utils_1.utils.commomHttpRequest(url, function (ret, data) {
  292. if (ret) {
  293. Utils_1.utils.showLog("关卡数据上报成功!");
  294. }
  295. else {
  296. Utils_1.utils.showLog("关卡数据上报失败!");
  297. }
  298. }.bind(this));
  299. }
  300. };
  301. /**
  302. * 上报自定义事件
  303. * @param level 当前关卡ID
  304. * @param levelName 关卡名称
  305. * @param status 状态
  306. */
  307. YZ_Tool_Hago.prototype.sendEvent = function (eventName) {
  308. if (PlatUtils_1.default.IsHago) {
  309. var method = "m=revent";
  310. var url = POST_ServerUrl + method + ("&event=" + encodeURI(eventName));
  311. Utils_1.utils.commomHttpRequest(url, function (ret, data) {
  312. if (ret) {
  313. Utils_1.utils.showLog("上报自定义事件成功!");
  314. }
  315. else {
  316. Utils_1.utils.showLog("上报自定义事件失败!");
  317. }
  318. }.bind(this));
  319. }
  320. };
  321. YZ_Tool_Hago = __decorate([
  322. ccclass
  323. ], YZ_Tool_Hago);
  324. return YZ_Tool_Hago;
  325. }());
  326. exports.default = YZ_Tool_Hago;
  327. cc._RF.pop();