789d349a-3ad2-43fb-9190-0e14f4c943b1.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. "use strict";
  2. cc._RF.push(module, '789d3SaOtJD+5GQDhT0yUOx', 'YZ_Tool_FaceBook');
  3. // common-plugin/Scripts/YZ_Tool_FaceBook.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 = "https://apps.youlesp.com/gss?";
  55. var POST_ServerUrl = "https://report.youletd.com/gss?";
  56. var ST_DefaultServerConfig = "";
  57. var YZ_Tool_FaceBook = /** @class */ (function () {
  58. function YZ_Tool_FaceBook() {
  59. //@ts-ignore
  60. // hg: any = 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_FaceBook.prototype, "SysInfo", {
  74. get: function () {
  75. return this._sysInfo;
  76. },
  77. enumerable: false,
  78. configurable: true
  79. });
  80. Object.defineProperty(YZ_Tool_FaceBook.prototype, "ServerConfig", {
  81. get: function () {
  82. return this._serverConfig;
  83. },
  84. enumerable: false,
  85. configurable: true
  86. });
  87. /**
  88. * 当前版本号
  89. */
  90. YZ_Tool_FaceBook.prototype.gameVersion = function () {
  91. return Utils_1.utils.config.faceBookConfig.version;
  92. };
  93. Object.defineProperty(YZ_Tool_FaceBook.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_FaceBook.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_FaceBook.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("facebook暂时不获取uid,uid全部为0");
  128. this._uid = "0";
  129. this.reportLogin();
  130. return [2 /*return*/];
  131. });
  132. });
  133. };
  134. /**
  135. * 上报登录接口获取UID
  136. */
  137. YZ_Tool_FaceBook.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_FaceBook.prototype.init = function (data) {
  177. Utils_1.utils.showLog("init faceBook");
  178. if (PlatUtils_1.default.IsFaceBook) {
  179. if (data) {
  180. var configObj = JSON.parse(data);
  181. if (configObj && configObj.facebook) {
  182. ST_DefaultServerConfig = JSON.stringify(configObj.facebook);
  183. }
  184. }
  185. this._service_uid = YZ_LocalStorage_1.default.getItem(YZ_Constant_1.default.ST_SERVICE_UID);
  186. this._service_uid = this._service_uid ? this._service_uid : "0";
  187. this._loadConfig();
  188. }
  189. };
  190. YZ_Tool_FaceBook.prototype._loadConfig = function () {
  191. var _this = this;
  192. if (PlatUtils_1.default.IsFaceBook) {
  193. var method = "m=g";
  194. var url = ST_ServerUrl + method;
  195. Utils_1.utils.commomHttpRequest(url, function (ret, data) {
  196. if (ret) {
  197. Utils_1.utils.showLog("faceBook服务器配置数据获取成功: data = " + data);
  198. if (data) {
  199. var result = JSON.parse(data);
  200. if (result) {
  201. if (!Utils_1.utils.DebugLoacalConfig) {
  202. _this._serverConfig = result;
  203. if (_this._serverConfig.is_show_log_view && _this._serverConfig.is_show_log_view == "true") {
  204. Utils_1.utils.showLogView = true;
  205. }
  206. }
  207. else {
  208. Utils_1.utils.showLog("开启了本地数据测试,使用本地配置!");
  209. }
  210. }
  211. else {
  212. Utils_1.utils.showLog("faceBook服务器配置数据不是合法的JSON数据, 使用本地配置!");
  213. }
  214. }
  215. }
  216. else {
  217. Utils_1.utils.showLog("facebook服务器配置数据获取失败, 使用本地配置!");
  218. }
  219. if (!_this._serverConfig) {
  220. _this._serverConfig = JSON.parse(ST_DefaultServerConfig);
  221. }
  222. else {
  223. if (_this._serverConfig.is_local_pos_id
  224. && _this._serverConfig.is_local_pos_id == "false") {
  225. // 使用服务器下发的广告id
  226. Utils_1.utils.showLog("使用服务器下发的广告id");
  227. Utils_1.utils.config.faceBookConfig.videoId = _this._serverConfig.video_pos_id || Utils_1.utils.config.faceBookConfig.videoId;
  228. Utils_1.utils.config.faceBookConfig.insertId = _this._serverConfig.intersititia_pos_id || Utils_1.utils.config.faceBookConfig.insertId;
  229. Utils_1.utils.config.faceBookConfig.bannerId = _this._serverConfig.banner_pos_id || Utils_1.utils.config.faceBookConfig.bannerId;
  230. }
  231. else {
  232. Utils_1.utils.showLog("使用本地配置的广告ID");
  233. }
  234. }
  235. Utils_1.utils.emitServerInitEvent();
  236. });
  237. }
  238. };
  239. /**
  240. * 比较当前平台版本是否高于指定的版本号
  241. * @param miniVersion 最低平台版本号
  242. */
  243. YZ_Tool_FaceBook.prototype.isOverMiniVersion = function (miniVersion) {
  244. if (PlatUtils_1.default.IsFaceBook) {
  245. if (this._sysInfo && this._sysInfo.platformVersionCode) {
  246. return this._sysInfo.platformVersionCode >= miniVersion;
  247. }
  248. }
  249. return false;
  250. };
  251. /**
  252. * 上报关卡数据
  253. * @param level 当前关卡ID
  254. * @param levelName 关卡名称
  255. * @param status 状态
  256. */
  257. YZ_Tool_FaceBook.prototype.postLevel = function (level, status, levelName) {
  258. if (PlatUtils_1.default.IsFaceBook) {
  259. var method = "m=rlevel";
  260. var url = POST_ServerUrl + method + ("&level_id=" + level + "&level_name=" + encodeURI(levelName) + "&status=" + status);
  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. }.bind(this));
  269. }
  270. };
  271. /**
  272. * 上报自定义事件
  273. * @param level 当前关卡ID
  274. * @param levelName 关卡名称
  275. * @param status 状态
  276. */
  277. YZ_Tool_FaceBook.prototype.sendEvent = function (eventName) {
  278. if (PlatUtils_1.default.IsFaceBook) {
  279. var method = "m=revent";
  280. var url = POST_ServerUrl + method + ("&event=" + encodeURI(eventName));
  281. Utils_1.utils.commomHttpRequest(url, function (ret, data) {
  282. if (ret) {
  283. Utils_1.utils.showLog("上报自定义事件成功!");
  284. }
  285. else {
  286. Utils_1.utils.showLog("上报自定义事件失败!");
  287. }
  288. }.bind(this));
  289. }
  290. };
  291. YZ_Tool_FaceBook = __decorate([
  292. ccclass
  293. ], YZ_Tool_FaceBook);
  294. return YZ_Tool_FaceBook;
  295. }());
  296. exports.default = YZ_Tool_FaceBook;
  297. cc._RF.pop();