78b0ad25-e0af-4bec-8762-5e7f0b47f612.js 15 KB

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