63487fe5-04ed-4956-9669-3fc1bf3fe4fc.js 15 KB

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