908fadaf-ddc6-492f-b6a0-51956dd1a657.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. "use strict";
  2. cc._RF.push(module, '908fa2v3cZJL7agUZVt0aZX', 'YZ_Tool_UC');
  3. // common-plugin/Scripts/YZ_Tool_UC.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. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  53. var ST_DefaultServerConfig = "";
  54. var ST_ServerUrl = "http://apps.youlesp.com/gss?";
  55. var POST_ServerUrl = "http://report.youlesp.com/gss?";
  56. var QTT_ServerUrl = "https://newidea4-gamecenter-backend.1sapp.com/x/open/user/ticket?";
  57. var QTT_Report = "https://newidea4-gamecenter-backend.1sapp.com/x/open/report/round";
  58. /**
  59. * uc工具类
  60. */
  61. var YZ_Tool_UC = /** @class */ (function () {
  62. function YZ_Tool_UC() {
  63. //@ts-ignore
  64. this.uc = window.uc;
  65. this._sysInfo = {};
  66. /**
  67. * 服务器配置信息
  68. */
  69. this._serverConfig = null;
  70. this._shareCallback = null;
  71. this._isShare = false;
  72. //设备UID
  73. this._uid = "0";
  74. //服务器返回UID
  75. this._service_uid = "0";
  76. this._loginTime = 0;
  77. this._loginInterval = 30;
  78. this._reportLoginTime = 0;
  79. this._reportLoginInterval = 30;
  80. this.isReport = false;
  81. }
  82. Object.defineProperty(YZ_Tool_UC.prototype, "SysInfo", {
  83. get: function () {
  84. return this._sysInfo;
  85. },
  86. enumerable: false,
  87. configurable: true
  88. });
  89. /**
  90. * 当前版本号
  91. */
  92. YZ_Tool_UC.prototype.gameVersion = function () {
  93. return Utils_1.utils.config.ucConfig.version;
  94. };
  95. Object.defineProperty(YZ_Tool_UC.prototype, "ServerConfig", {
  96. get: function () {
  97. return this._serverConfig;
  98. },
  99. enumerable: false,
  100. configurable: true
  101. });
  102. Object.defineProperty(YZ_Tool_UC.prototype, "uid", {
  103. get: function () {
  104. // if (this._service_uid != "0") return this._uid;
  105. // this._login();
  106. return "0";
  107. },
  108. enumerable: false,
  109. configurable: true
  110. });
  111. Object.defineProperty(YZ_Tool_UC.prototype, "serviceId", {
  112. /**
  113. * 服务器返回UID
  114. */
  115. get: function () {
  116. if (this._service_uid != "0")
  117. return this._service_uid;
  118. this.reportLogin();
  119. return "0";
  120. },
  121. enumerable: false,
  122. configurable: true
  123. });
  124. YZ_Tool_UC.prototype._login = function () {
  125. return __awaiter(this, void 0, void 0, function () {
  126. var curTime, interval, self;
  127. return __generator(this, function (_a) {
  128. curTime = new Date().getTime();
  129. interval = (curTime - this._loginTime) / 1000;
  130. if (interval > 0 && interval < 30) {
  131. Utils_1.utils.showLog("\u767B\u5F55\u8BF7\u6C42\u95F4\u9694\u5C0F\u4E8E\uFF1A" + this._loginInterval + "\u79D2");
  132. return [2 /*return*/];
  133. }
  134. this._loginTime = curTime;
  135. self = this;
  136. Utils_1.utils.showLog("uc暂时不获取uid,uid全部为0");
  137. this._uid = "0";
  138. return [2 /*return*/];
  139. });
  140. });
  141. };
  142. /**
  143. * 上报登录接口获取UID
  144. */
  145. YZ_Tool_UC.prototype.reportLogin = function () {
  146. var _this = this;
  147. if (this.isReport)
  148. return;
  149. this.isReport = true;
  150. var self = this;
  151. var curTime = new Date().getTime();
  152. var interval = (curTime - self._reportLoginTime) / 1000;
  153. // utils.showLog(interval, " <<<<<<,interval", " _reportLoginTime >>>", self._reportLoginTime);
  154. // console.log(curTime, curTime - self._reportLoginTime, interval)
  155. if (interval > 0 && interval < 30) {
  156. Utils_1.utils.showLog("\u4E0A\u62A5\u767B\u5F55\u83B7\u53D6UID\u5C0F\u4E8E\uFF1A" + self._reportLoginInterval + "\u79D2");
  157. return;
  158. }
  159. self._reportLoginTime = curTime;
  160. var method = "m=login";
  161. var url = ST_ServerUrl + method + "&device_data=0";
  162. Utils_1.utils.commomHttpRequest(url, function (ret, data) {
  163. if (ret) {
  164. if (data) {
  165. var result = JSON.parse(data);
  166. Utils_1.utils.showLog("data=" + data);
  167. Utils_1.utils.showLog("result=" + result);
  168. Utils_1.utils.showLog("result.uid=" + result.uid);
  169. if (result.uid) {
  170. self._service_uid = "" + result.uid;
  171. console.log("self._service_uid:" + self._service_uid);
  172. Utils_1.utils.showLog("服务器请求登录成功! _service_uid=" + self._service_uid);
  173. YZ_LocalStorage_1.default.setItem(YZ_Constant_1.default.ST_SERVICE_UID, self._service_uid);
  174. }
  175. }
  176. }
  177. else {
  178. Utils_1.utils.showLog("获取数据失败1");
  179. }
  180. _this.isReport = false;
  181. });
  182. };
  183. /**
  184. *
  185. * @param data 配置数据
  186. */
  187. YZ_Tool_UC.prototype.init = function (data) {
  188. if (PlatUtils_1.default.ISUC) {
  189. if (data) {
  190. var configObj = JSON.parse(data);
  191. if (configObj && configObj.uc) {
  192. ST_DefaultServerConfig = JSON.stringify(configObj.uc);
  193. }
  194. }
  195. this._service_uid = YZ_LocalStorage_1.default.getItem(YZ_Constant_1.default.ST_SERVICE_UID);
  196. this._service_uid = this._service_uid ? this._service_uid : "0";
  197. try {
  198. this._sysInfo = this.uc.getSystemInfoSync();
  199. if (typeof this._sysInfo === 'string') {
  200. try {
  201. this._sysInfo = JSON.parse(this._sysInfo);
  202. }
  203. catch (e) { }
  204. }
  205. Utils_1.utils.showLog("uc 小游戏平台信息: " + JSON.stringify(this.SysInfo));
  206. }
  207. catch (e) {
  208. Utils_1.utils.showLog("uc 小游戏平台数据获取失败!");
  209. }
  210. this._loadConfig();
  211. }
  212. };
  213. YZ_Tool_UC.prototype._loadConfig = function () {
  214. var _this = this;
  215. if (PlatUtils_1.default.ISUC) {
  216. var method = "m=g";
  217. Utils_1.utils.commomHttpRequest(ST_ServerUrl + method, function (ret, data) {
  218. if (ret) {
  219. Utils_1.utils.showLog("uc服务器配置数据获取成功: data = " + data);
  220. if (data) {
  221. var result = JSON.parse(data);
  222. if (result) {
  223. if (!Utils_1.utils.DebugLoacalConfig) {
  224. _this._serverConfig = result;
  225. if (_this._serverConfig.is_show_log_view && _this._serverConfig.is_show_log_view == "true") {
  226. Utils_1.utils.showLogView = true;
  227. }
  228. }
  229. else {
  230. cc.warn("开启了本地数据测试,使用本地配置!");
  231. }
  232. }
  233. else {
  234. Utils_1.utils.showLog("uc服务器配置数据不是合法的JSON数据, 使用本地配置!");
  235. }
  236. }
  237. }
  238. else {
  239. Utils_1.utils.showLog("uc服务器配置数据获取失败, 使用本地配置!");
  240. }
  241. if (!_this._serverConfig) {
  242. _this._serverConfig = JSON.parse(ST_DefaultServerConfig);
  243. }
  244. else {
  245. if (_this._serverConfig.shares) {
  246. if (_this._serverConfig.shares.sy_title) {
  247. Utils_1.utils.config.otherconfig.shareTitle = _this._serverConfig.shares.sy_title;
  248. }
  249. if (_this._serverConfig.shares.sy_img) {
  250. Utils_1.utils.config.otherconfig.shareImgUrl = _this._serverConfig.shares.sy_img;
  251. }
  252. }
  253. }
  254. Utils_1.utils.emitServerInitEvent();
  255. });
  256. }
  257. };
  258. YZ_Tool_UC.prototype.getSystemInfo = function () {
  259. if (PlatUtils_1.default.ISUC) {
  260. return this._sysInfo;
  261. }
  262. };
  263. YZ_Tool_UC.prototype.share = function (callback) {
  264. if (callback === void 0) { callback = null; }
  265. if (PlatUtils_1.default.ISUC) {
  266. this._shareCallback = callback;
  267. this._isShare = true;
  268. var getShareInfo = {
  269. title: Utils_1.utils.config.otherconfig.shareTitle,
  270. imageUrl: Utils_1.utils.config.otherconfig.shareImgUrl,
  271. success: this._shareCallback,
  272. fail: this._shareCallback
  273. };
  274. //@ts-ignore
  275. this.uc.shareAppMessage(getShareInfo);
  276. }
  277. };
  278. YZ_Tool_UC.prototype.isOverMinVersion = function (minVersion) {
  279. var curVersion = this._sysInfo.SDKVersion;
  280. return this._compareVersion(curVersion, minVersion) >= 0;
  281. };
  282. YZ_Tool_UC.prototype._compareVersion = function (v1, v2) {
  283. if (!v1 || !v2)
  284. return -1;
  285. v1 = v1.split('.');
  286. v2 = v2.split('.');
  287. var len = Math.max(v1.length, v2.length);
  288. while (v1.length < len) {
  289. v1.push('0');
  290. }
  291. while (v2.length < len) {
  292. v2.push('0');
  293. }
  294. for (var i = 0; i < len; i++) {
  295. var num1 = parseInt(v1[i]);
  296. var num2 = parseInt(v2[i]);
  297. if (num1 > num2) {
  298. return 1;
  299. }
  300. else if (num1 < num2) {
  301. return -1;
  302. }
  303. }
  304. return 0;
  305. };
  306. /**
  307. * 上报关卡数据
  308. * @param level 当前关卡ID
  309. * @param levelName 关卡名称
  310. * @param status 状态
  311. */
  312. YZ_Tool_UC.prototype.postLevel = function (level, status, levelName) {
  313. if (PlatUtils_1.default.ISUC) {
  314. var method = "m=rlevel";
  315. var url = POST_ServerUrl + method + ("&level_id=" + level + "&level_name=" + encodeURI(levelName) + "&status=" + status);
  316. Utils_1.utils.commomHttpRequest(url, function (ret, data) {
  317. if (ret) {
  318. Utils_1.utils.showLog("关卡数据上报成功!");
  319. }
  320. else {
  321. Utils_1.utils.showLog("关卡数据上报失败!");
  322. }
  323. }.bind(this));
  324. }
  325. };
  326. /**
  327. * 上报自定义事件
  328. * @param level 当前关卡ID
  329. * @param levelName 关卡名称
  330. * @param status 状态
  331. */
  332. YZ_Tool_UC.prototype.sendEvent = function (eventName) {
  333. if (PlatUtils_1.default.ISUC) {
  334. var method = "m=revent";
  335. var url = POST_ServerUrl + method + ("&event=" + encodeURI(eventName));
  336. Utils_1.utils.commomHttpRequest(url, function (ret, data) {
  337. if (ret) {
  338. Utils_1.utils.showLog("上报自定义事件成功!");
  339. }
  340. else {
  341. Utils_1.utils.showLog("上报自定义事件失败!");
  342. }
  343. }.bind(this));
  344. }
  345. };
  346. YZ_Tool_UC = __decorate([
  347. ccclass
  348. ], YZ_Tool_UC);
  349. return YZ_Tool_UC;
  350. }());
  351. exports.default = YZ_Tool_UC;
  352. cc._RF.pop();