45157609-be44-47eb-930c-5ca128dec6ad.js 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328
  1. "use strict";
  2. cc._RF.push(module, '45157YJvkRH65MMXKEo3sat', 'YZ_Tool_Oppo');
  3. // common-plugin/Scripts/YZ_Tool_Oppo.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 YouWanAnalytics_1 = require("./YouWanSDK/YouWanAnalytics");
  51. var YZ_Constant_1 = require("./YZ_Constant");
  52. var YZ_LocalStorage_1 = require("./YZ_LocalStorage");
  53. //@ts-ignore
  54. var uma = require('./UMengSDK/quickGame/uma.min.js');
  55. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  56. // http://apps.youlesp.com/gss?m=gconfig&uid=xxx&app_id=xxx&channel=xxx&device_uid=xxx
  57. //获取服务器配置
  58. var ST_ServerUrl = "http://apps.youlesp.com/gss?";
  59. var POST_ServerUrl = "http://report.youlesp.com/gss?";
  60. var ST_DefaultServerConfig = "";
  61. var ST_NativeInsertAdClickTimes = "NativeInsertAdClickTimes";
  62. var ST_LastDateTime = "LastDateTime";
  63. var ST_InsertAdShowCounts = "NativeInsertAdShowCount"; //插屏显示次数
  64. var ST_BannerAdCloseCounts = "ST_BannerAdCloseCounts"; //banner广告关闭次数
  65. var ST_YZBannerShowCounts = "YZBannerShowCounts"; //banner广告关闭次数
  66. var YZ_Tool_Oppo = /** @class */ (function () {
  67. function YZ_Tool_Oppo() {
  68. //@ts-ignore
  69. this.qg = qg;
  70. /*
  71. COREVersion string 版本号
  72. brand string 手机品牌
  73. language string 当前环境设置的语言
  74. model string 手机型号
  75. notchHeight number 凹槽高度(刘海屏高度)
  76. pixelRatio number 设备像素比
  77. platform string 客户端平台
  78. platformVersion number 平台版本号
  79. screenHeight number 屏幕高度
  80. screenWidth number 屏幕宽度
  81. system string 操作系统版本
  82. windowHeight number 可使用窗口高度
  83. windowWidth number 可使用窗口宽度
  84. */
  85. this._sysInfo = null;
  86. //用户来源
  87. this._source = "";
  88. /**
  89. * OPPO服务器配置数据
  90. * {
  91. *
  92. -- "banner_close_full_count_showyz":"true" //banner达到显示次数之后是否显示自定义banner .默认:不填写
  93. --"native_banner_delay_time": 1, //banner和插屏都是原生优先的话,延迟展示banner. 单位:秒 。默认:不填写
  94. -- "statement_auto_refresh": 1, // 结算广告刷新频率。 单位:秒。 默认不填写为3秒。
  95. -- "is_bottom_banner_list":"true" //是否显示自定义的banner 默认:不填写
  96. -- "refresh_ad_time":15 //banner广告刷新的间隔时间。单位:秒 默认:不填写
  97. -- "close_btn_fade_in_time":0 //跳过按钮延迟显示的时间。单位:秒 默认:不填写
  98. -- "st_spare_type": 4, // 结算广告备选类型, 当statement_type为1或者2的时候判断是否显示达到限制。达到限制的时候显示当前备选的组件;值 =(3、4、5)。 默认:不填写
  99. -- "native_banner_delay_time": 1 //如果banner和插屏都优先展示原生就延迟调用。 单位:秒。默认1秒
  100. -- “intersititial_open_close_banner”:0 ,//插屏显示后是操作Banner, 0 :为不开启,1:为销毁,2:隐藏 默认:1
  101. -- "banner_close_count":0 , //banner关闭次数达到限制后不显示 0:不限制次数,>0:限制的次数达到后不再显示banner 默认:5
  102. -- "st_sync":"true" //判断结算广告类型为4、5的时候,是否同时显示,默认true
  103. -- "statement_type": 1、2、3、4、5
  104. 一、游戏结算广告展示
  105. 1.显示默认插屏广告
  106. 2.显示插屏广告 (默认优先或原生优先,也就是目前展示的规则)
  107. 3.显示插屏广告+6个互推 (默认优先或原生优先,也就是目前展示的规则)
  108. 4.显示插屏广告、原生广告(没有互推的单个原生广告) 1:(默认优先或原生优先,也就是目前展示的规则) 2、默认插屏和原生广告同时展示
  109. 5.显示插屏广告、原生广告(有3个互推+原生的广告) 1、(原生优先或者插屏优先,和同时展示) 2、默认插屏和原生广告同时展示
  110. -- "intersititial_max_show_count": 8, //插屏最大显示次数 默认:8
  111. -- "intersititial_interval_time": 60, //插屏显示间隔数 默认:60
  112. -- "intersititial_open_close_banner": "true", //插屏显示的时候是否隐藏banner
  113. -- "reward_first_ad": "video", // 激励视频显示优先级别: video:激励视频,insert:激励互推
  114. -- "is_reward_intersititia": "true",
  115. -- "native_single_pos_id":[], //单个原生广告ID--用于结算组件
  116. -- "is_move_btn":0 //是否开启移动按钮效果 默认不开启 0:显示banner,且按钮在上面。 1: 显示Banner,按钮居底部且移动 3: 大于0的话按照时间移动按钮
  117. -- 暂未覆盖其他游戏
  118. -- "auto_sign": "false", //是否自动弹出签到 默认:false
  119. -- "try_skin_level_count": 5, // 皮肤试用的关卡数量 默认:5关
  120. -- "intersititia_delay_show_time": 0.5, // 插屏广告延时展示时间/秒 默认值0.5
  121. -- "intersititia_close_delay_time": 1, // 关闭按钮延时显示时间/秒,默认 1
  122. -- "intersititia_close_but_alpha": 120, // 关闭按钮alpha, 默认 120
  123. -- "intersititia_close_but_size": 100, // 关闭按钮大小
  124. -- "intersititia_close_but_range": 100, // 关闭按钮点击范围
  125. -- "intersititial_first_ad": "native", // 插屏广告优先展示类型 [default 小游戏广告, native 原生广告]
  126. -- "intersititia_click_count": 1, // 插屏广告点击每天次数控制/次数
  127. -- "intersititia_show_interval": 1, // 插屏广告展示间隔/次数。intersititia_click_count 次数达到后启用
  128. -- "intersititial_click_close": "false" // 点击关闭按钮后是否关闭广告, 默认值 false
  129. -- "banner_show_height": 120, // 广告条的高度,最低160
  130. -- "banner_close_but_show": "true", // 是否显示关闭按钮 [true 显示, false 不显示], 默认值 true
  131. -- "banner_close_but_alpha": 120, // 关闭按钮alpha,默认 120
  132. -- "banner_close_but_size": 33, // 关闭按钮大小, 默认 33
  133. -- "banner_close_but_range": 33, // 关闭按钮点击范围, 默认 33
  134. -- "banner_first_ad": "native", // 广告优先展示类型[default 小游戏广告, native 原生广告, yzbanner 自定义banner]
  135. -- "banner_click_refresh": "true", // 广告点击后是否刷新,默认值 true
  136. "is_local_pos_id": "false", // 是否使用本地广告id
  137. "intersititia_pos_id": "96292", // 小游戏插屏id
  138. "banner_pos_id": "96293", // 小游戏banner id
  139. "video_pos_id": "96294", // 小游戏视频id
  140. "native_intersititial_pos_id": ["96297", "96298"], // 原生插屏id
  141. "native_banner_pos_id": ["96295", "96296"], // 原生banner id
  142. "is_jump": "true", // 是否显示游戏内交叉推广组件,交叉推广挂件刷新频率
  143. "jump_list": [{ // 交叉推广挂件内容信息
  144. "name": "子弹先生狙击战场",
  145. "icon": "https://xcx.youletd.com/xcx/icon/zdxsjjzc.png",
  146. "pkg": "com.yzxx.zdxsjjzc.kyx.nearme.gamecenter"
  147. }, {
  148. "name": "翻滚的香肠",
  149. "icon": "https://xcx.youletd.com/xcx/icon/fgdxc.png",
  150. "pkg": "com.yzxx.fgdxc.kyx.nearme.gamecenter"
  151. }]
  152. }
  153. */
  154. this._serverConfig = null;
  155. this._nativeInsertAdClickTimes = 0;
  156. this._insertAdShowCounts = 0;
  157. this._bannerAdCloseCounts = 0;
  158. this._yzBannerShowCounts = 0;
  159. // 桌面图标是否创建
  160. this._shortcutCreated = false;
  161. //设备UID
  162. this._uid = "0";
  163. //服务器返回UID
  164. this._service_uid = 0;
  165. //设备ID
  166. this._device_id = "";
  167. //本地uuid
  168. this._uuid = "";
  169. //优玩UID
  170. this._yw_uid = -1;
  171. this._reloadTimes = 6;
  172. this._curloadTimes = 0;
  173. this._loginTime = 0;
  174. this._loginInterval = 30;
  175. //是否获取deviceId
  176. this.isGetDeviceId = true;
  177. this._reportLoginTime = 0;
  178. this._reportLoginInterval = 30;
  179. this.isReport = false;
  180. this._rec_is_banner = false;
  181. this._rec_game_banner = null;
  182. this._rec_game_portal = null;
  183. this._gameDrawerAd = null;
  184. this.isReportDevice = false;
  185. }
  186. Object.defineProperty(YZ_Tool_Oppo.prototype, "SysInfo", {
  187. get: function () {
  188. return this._sysInfo;
  189. },
  190. enumerable: false,
  191. configurable: true
  192. });
  193. /**
  194. * 当前版本号
  195. */
  196. YZ_Tool_Oppo.prototype.gameVersion = function () {
  197. return Utils_1.utils.config.oppoconfig.version;
  198. };
  199. Object.defineProperty(YZ_Tool_Oppo.prototype, "ServerConfig", {
  200. get: function () {
  201. return this._serverConfig;
  202. },
  203. enumerable: false,
  204. configurable: true
  205. });
  206. Object.defineProperty(YZ_Tool_Oppo.prototype, "NativeInsertAdClickTimes", {
  207. get: function () {
  208. return this._nativeInsertAdClickTimes;
  209. },
  210. enumerable: false,
  211. configurable: true
  212. });
  213. Object.defineProperty(YZ_Tool_Oppo.prototype, "insertAdShowCounts", {
  214. /**
  215. * 插屏广告展示次数
  216. */
  217. get: function () {
  218. return this._insertAdShowCounts;
  219. },
  220. enumerable: false,
  221. configurable: true
  222. });
  223. Object.defineProperty(YZ_Tool_Oppo.prototype, "bannerAdCloseCounts", {
  224. /**
  225. * banner关闭次数
  226. */
  227. get: function () {
  228. return this._bannerAdCloseCounts;
  229. },
  230. enumerable: false,
  231. configurable: true
  232. });
  233. Object.defineProperty(YZ_Tool_Oppo.prototype, "yzBannerShowCounts", {
  234. /**
  235. * 自定义banner展示次数
  236. */
  237. get: function () {
  238. return this._yzBannerShowCounts;
  239. },
  240. enumerable: false,
  241. configurable: true
  242. });
  243. Object.defineProperty(YZ_Tool_Oppo.prototype, "ShortcutCreated", {
  244. get: function () {
  245. return this._shortcutCreated;
  246. },
  247. enumerable: false,
  248. configurable: true
  249. });
  250. Object.defineProperty(YZ_Tool_Oppo.prototype, "uid", {
  251. get: function () {
  252. if (this._uid != "0")
  253. return this._uid;
  254. this._login();
  255. return "0";
  256. },
  257. enumerable: false,
  258. configurable: true
  259. });
  260. Object.defineProperty(YZ_Tool_Oppo.prototype, "serviceId", {
  261. /**
  262. * 服务器返回UID
  263. */
  264. get: function () {
  265. if (this._service_uid != 0)
  266. return this._service_uid;
  267. this.reportLogin();
  268. return "0";
  269. },
  270. enumerable: false,
  271. configurable: true
  272. });
  273. /**
  274. *
  275. * @param data 配置数据
  276. */
  277. YZ_Tool_Oppo.prototype.init = function (data) {
  278. var _this = this;
  279. if (PlatUtils_1.default.IsOPPO) {
  280. this.umaInit();
  281. //@ts-ignore
  282. this._sysInfo = qg.getSystemInfoSync();
  283. if (this.SysInfo) {
  284. Utils_1.utils.showLog("OPPO 小游戏平台信息: " + JSON.stringify(this.SysInfo));
  285. }
  286. if (data) {
  287. var configObj = JSON.parse(data);
  288. if (configObj && configObj.oppo) {
  289. ST_DefaultServerConfig = JSON.stringify(configObj.oppo);
  290. }
  291. }
  292. this._yw_uid = parseInt(YZ_LocalStorage_1.default.getItem(YZ_Constant_1.default.ST_YOUWAN_UID, "-1"));
  293. this._device_id = YZ_LocalStorage_1.default.getItem(YZ_Constant_1.default.ST_DEVICE_ID);
  294. if (!this._device_id) {
  295. cc.game.on(YZ_Constant_1.default.YZ_PrivacyClose, function () {
  296. _this.initDeviceId();
  297. }, this);
  298. }
  299. //获取小程序启动来源
  300. if (this.isOverMiniVersion("1050")) {
  301. //@ts-ignore
  302. var options = qg.getLaunchOptionsSync();
  303. options && console.log("options>>>", JSON.stringify(options));
  304. if (options && options.referrerInfo && options.referrerInfo.package) {
  305. Utils_1.utils.showLog("获取到小程序启动来源:" + options.referrerInfo.package);
  306. this._source = options.referrerInfo.package;
  307. }
  308. }
  309. else {
  310. Utils_1.utils.showLog("\u5C0F\u7A0B\u5E8F\u7248\u672C\u4F4E\u4E8E1050\uFF0C\u83B7\u53D6\u4E0D\u5230\u5C0F\u7A0B\u5E8F\u542F\u52A8\u6765\u6E90\uFF01");
  311. }
  312. this._login();
  313. var appId = Utils_1.utils.config.oppoconfig.appID + "_";
  314. this._nativeInsertAdClickTimes = YZ_LocalStorage_1.default.getItem(appId + ST_NativeInsertAdClickTimes);
  315. this._insertAdShowCounts = YZ_LocalStorage_1.default.getItem(appId + ST_InsertAdShowCounts);
  316. this._bannerAdCloseCounts = YZ_LocalStorage_1.default.getItem(appId + ST_BannerAdCloseCounts);
  317. this._yzBannerShowCounts = YZ_LocalStorage_1.default.getItem(appId + ST_YZBannerShowCounts);
  318. var day = YZ_LocalStorage_1.default.getItem(appId + ST_LastDateTime);
  319. var curDate = new Date();
  320. if (day != curDate.toDateString()) {
  321. this._nativeInsertAdClickTimes = 0;
  322. this._insertAdShowCounts = 0;
  323. this._bannerAdCloseCounts = 0;
  324. this._yzBannerShowCounts = 0;
  325. YZ_LocalStorage_1.default.setItem(appId + ST_YZBannerShowCounts, 0);
  326. YZ_LocalStorage_1.default.setItem(appId + ST_NativeInsertAdClickTimes, 0);
  327. YZ_LocalStorage_1.default.setItem(appId + ST_InsertAdShowCounts, 0);
  328. YZ_LocalStorage_1.default.setItem(appId + ST_LastDateTime, curDate.toDateString());
  329. YZ_LocalStorage_1.default.setItem(YZ_Constant_1.default.ST_GET_DEVICE_ID, "0");
  330. }
  331. //@ts-ignore
  332. Utils_1.utils.registerServerInitEvent(function () {
  333. //检测桌面图标是否创建
  334. if (_this.isOverMiniVersion("1044")) {
  335. _this.checkHasShortCut(function (res) {
  336. if (!res && Utils_1.utils.ServerConfig && Utils_1.utils.ServerConfig.start_auto_create_short_cut_time) {
  337. Utils_1.utils.showLog("\u7EC4\u4EF6\u521D\u59CB\u5316\u6210\u529F\uFF0C" + Utils_1.utils.ServerConfig.start_auto_create_short_cut_time + "\u79D2\u540E\u5F39\u51FA\u81EA\u52A8\u521B\u5EFA\u684C\u9762\uFF01");
  338. Utils_1.utils.SendEvent("组件初始化成功,弹出自动创建桌面!");
  339. setTimeout(function () {
  340. _this.createShortcut(function (res) {
  341. if (res) {
  342. Utils_1.utils.showLog("自动创建桌面成功!");
  343. }
  344. else {
  345. Utils_1.utils.showLog("自动创建桌面失败!");
  346. }
  347. });
  348. }, Utils_1.utils.ServerConfig.start_auto_create_short_cut_time * 1000);
  349. }
  350. });
  351. }
  352. }, this);
  353. }
  354. this._loadConfig();
  355. };
  356. /**
  357. * 保存服务器配置到本地
  358. * @param data
  359. */
  360. YZ_Tool_Oppo.prototype._saveConfig = function (data) {
  361. };
  362. YZ_Tool_Oppo.prototype._loadConfig = function () {
  363. var _this = this;
  364. if (PlatUtils_1.default.IsOPPO) {
  365. var method = "m=g" + ("&device_data=" + encodeURI(JSON.stringify(this._sysInfo)));
  366. Utils_1.utils.commomHttpRequest(ST_ServerUrl + method, function (ret, data) {
  367. _this._curloadTimes++;
  368. var recall = false;
  369. Utils_1.utils.showLog("\u7B2C" + _this._curloadTimes + "\u6B21\u62C9\u53D6\u670D\u52A1\u5668\u914D\u7F6E!");
  370. if (ret) {
  371. Utils_1.utils.showLog("OPPO服务器配置数据获取成功: data = " + data);
  372. if (data) {
  373. var result = JSON.parse(data);
  374. if (result) {
  375. if (!Utils_1.utils.DebugLoacalConfig) {
  376. _this._serverConfig = result;
  377. if (_this._serverConfig.is_show_log_view && _this._serverConfig.is_show_log_view == "true") {
  378. Utils_1.utils.showLogView = true;
  379. }
  380. }
  381. else {
  382. cc.warn("开启了本地数据测试,使用本地配置!");
  383. }
  384. }
  385. else {
  386. Utils_1.utils.showLog("OPPO服务器配置数据不是合法的JSON数据, 使用本地配置!");
  387. }
  388. }
  389. }
  390. else {
  391. Utils_1.utils.showLog("OPPO服务器配置数据获取失败, 使用本地配置!");
  392. if (_this._curloadTimes < _this._reloadTimes) {
  393. Utils_1.utils.showLog("重新拉取配置!");
  394. recall = true;
  395. }
  396. }
  397. if (!_this._serverConfig) {
  398. _this._serverConfig = JSON.parse(ST_DefaultServerConfig);
  399. }
  400. else if (_this._curloadTimes == 1) {
  401. if (_this._serverConfig.is_local_pos_id
  402. && _this._serverConfig.is_local_pos_id == "false") {
  403. // 使用服务器下发的广告id
  404. Utils_1.utils.showLog("使用服务器下发的广告id");
  405. Utils_1.utils.config.oppoconfig.bannerId = _this.ServerConfig.banner_pos_id;
  406. Utils_1.utils.config.oppoconfig.insertId = _this.ServerConfig.intersititia_pos_id;
  407. Utils_1.utils.config.oppoconfig.videoId = _this.ServerConfig.video_pos_id;
  408. Utils_1.utils.config.oppoconfig.nativeInsertIds = _this.ServerConfig.native_intersititial_pos_id;
  409. Utils_1.utils.config.oppoconfig.nativeBannerIds = _this.ServerConfig.native_banner_pos_id;
  410. Utils_1.utils.config.oppoconfig.nativeTryGameIds = _this.ServerConfig.native_trygame_pos_id;
  411. Utils_1.utils.config.oppoconfig.recGameBannerId = _this.ServerConfig.rec_game_banner_id;
  412. Utils_1.utils.config.oppoconfig.recPortalId = _this.ServerConfig.rec_portal_id;
  413. Utils_1.utils.config.oppoconfig.recGameDrawerId = _this.ServerConfig.rec_game_drawer_id || Utils_1.utils.config.oppoconfig.recGameDrawerId;
  414. Utils_1.utils.config.oppoconfig.nativeSingleAdIds = _this.ServerConfig.native_single_pos_id || Utils_1.utils.config.oppoconfig.nativeSingleAdIds;
  415. Utils_1.utils.config.oppoconfig.intersitialAdConfigs = _this.ServerConfig.intersitial_configs || Utils_1.utils.config.oppoconfig.intersitialAdConfigs;
  416. Utils_1.utils.config.oppoconfig.bannerAdConfigs = _this.ServerConfig.banner_configs || Utils_1.utils.config.oppoconfig.bannerAdConfigs;
  417. }
  418. else {
  419. Utils_1.utils.showLog("使用本地配置的广告ID");
  420. }
  421. if (_this.ServerConfig.get_device_id && _this.ServerConfig.get_device_id == "false") {
  422. _this.isGetDeviceId = false;
  423. }
  424. if (_this.ServerConfig.native_banner_configs) {
  425. for (var i = 0; i < _this.ServerConfig.native_banner_configs.length; i++) {
  426. Utils_1.utils.showLog("获取到原生广告配置:" + _this.ServerConfig.native_banner_configs[i].location, ">>>>", JSON.stringify(_this.ServerConfig.native_banner_configs[i]));
  427. Utils_1.utils.config.oppoconfig.setNativeBannerInfo(_this.ServerConfig.native_banner_configs[i].location, _this.ServerConfig.native_banner_configs[i]);
  428. }
  429. }
  430. }
  431. if (_this._curloadTimes == 1) {
  432. // 只有第一次拉取才会发送事件
  433. Utils_1.utils.emitServerInitEvent();
  434. }
  435. if (recall) {
  436. _this._loadConfig();
  437. }
  438. });
  439. }
  440. };
  441. /**
  442. * 比较当前平台版本是否高于指定的版本号
  443. * @param miniVersion 最低平台版本号
  444. */
  445. YZ_Tool_Oppo.prototype.isOverMiniVersion = function (miniVersion) {
  446. if (PlatUtils_1.default.IsOPPO) {
  447. if (this._sysInfo) {
  448. Utils_1.utils.showLog("curPlatVersion = " + this._sysInfo.platformVersion + "miniVersion = " + miniVersion + "" + (this._sysInfo.platformVersion >= miniVersion));
  449. return this._sysInfo.platformVersion >= miniVersion;
  450. }
  451. }
  452. return false;
  453. };
  454. /**
  455. * 验证桌面快捷方式是否创建过
  456. * @param callBack
  457. */
  458. YZ_Tool_Oppo.prototype.checkHasShortCut = function (callBack) {
  459. var _this = this;
  460. this.qg.hasShortcutInstalled({
  461. success: function (res) {
  462. Utils_1.utils.showLog("检测桌面快捷方式是否已经创建过: result=", res);
  463. if (res == false) {
  464. _this._shortcutCreated = false;
  465. callBack && callBack(false);
  466. }
  467. else {
  468. _this._shortcutCreated = true;
  469. callBack && callBack(true);
  470. }
  471. },
  472. fail: function () {
  473. Utils_1.utils.showLog("检测失败!");
  474. },
  475. complete: function () {
  476. Utils_1.utils.showLog("检测完成!");
  477. }
  478. });
  479. };
  480. YZ_Tool_Oppo.prototype.hideDefaultLoadingPage = function () {
  481. if (PlatUtils_1.default.IsOPPO) {
  482. //@ts-ignore
  483. qg.loadingComplete({
  484. complete: function (res) { }
  485. });
  486. }
  487. };
  488. YZ_Tool_Oppo.prototype.countNativeInserClick = function () {
  489. this._nativeInsertAdClickTimes++;
  490. YZ_LocalStorage_1.default.setItem(Utils_1.utils.config.oppoconfig.appID + "_" + ST_NativeInsertAdClickTimes, this._nativeInsertAdClickTimes);
  491. };
  492. /**
  493. * 增加插屏显示的次数
  494. */
  495. YZ_Tool_Oppo.prototype.countInserShowCount = function () {
  496. this._insertAdShowCounts++;
  497. YZ_LocalStorage_1.default.setItem(Utils_1.utils.config.oppoconfig.appID + "_" + ST_InsertAdShowCounts, this._insertAdShowCounts);
  498. };
  499. /**
  500. * 增加banner的关闭次数
  501. */
  502. YZ_Tool_Oppo.prototype.countBannerCloseCount = function () {
  503. this._bannerAdCloseCounts++;
  504. YZ_LocalStorage_1.default.setItem(Utils_1.utils.config.oppoconfig.appID + "_" + ST_BannerAdCloseCounts, this._bannerAdCloseCounts);
  505. };
  506. /**
  507. * 增加自定义banner的显示次数
  508. */
  509. YZ_Tool_Oppo.prototype.countYzBannerShowCount = function () {
  510. this._yzBannerShowCounts++;
  511. YZ_LocalStorage_1.default.setItem(Utils_1.utils.config.oppoconfig.appID + "_" + ST_YZBannerShowCounts, this._yzBannerShowCounts);
  512. };
  513. /**
  514. * 跳转到指定的小游戏
  515. * @param pkgName 包名
  516. * @param callback Function(ret) 跳转回调. ret: true | false
  517. */
  518. YZ_Tool_Oppo.prototype.navigateToMiniGame = function (pkgName, callback) {
  519. if (PlatUtils_1.default.IsOPPO) {
  520. var completeCallback_1 = callback;
  521. //@ts-ignore
  522. qg.navigateToMiniGame({
  523. pkgName: pkgName,
  524. success: function () {
  525. Utils_1.utils.showLog("跳转成功!");
  526. if (completeCallback_1) {
  527. completeCallback_1(true);
  528. }
  529. },
  530. fail: function (res) {
  531. Utils_1.utils.showLog("跳转失败!");
  532. if (completeCallback_1) {
  533. completeCallback_1(false);
  534. }
  535. }
  536. });
  537. }
  538. };
  539. /**
  540. * 是否可以创建桌面图标
  541. */
  542. YZ_Tool_Oppo.prototype.canCreateShortcut = function () {
  543. if (PlatUtils_1.default.IsOPPO) {
  544. return this.isOverMiniVersion("1040");
  545. }
  546. return false;
  547. };
  548. /**
  549. * 创建桌面快捷方式
  550. */
  551. YZ_Tool_Oppo.prototype.createShortcut = function (callback) {
  552. if (PlatUtils_1.default.IsOPPO) {
  553. var callbackFunc_1 = callback;
  554. var self_1 = this;
  555. //@ts-ignore
  556. qg.installShortcut({
  557. success: function () {
  558. Utils_1.utils.showLog('桌面图标创建成功!');
  559. self_1._shortcutCreated = true;
  560. if (callbackFunc_1) {
  561. callbackFunc_1(true);
  562. }
  563. },
  564. fail: function (err) {
  565. Utils_1.utils.showLog("createShortcut >>>fail");
  566. if (callbackFunc_1) {
  567. callbackFunc_1(false);
  568. }
  569. },
  570. complete: function () {
  571. Utils_1.utils.showLog("createShortcut >>>complete");
  572. }
  573. });
  574. }
  575. };
  576. /**
  577. * 上报数据
  578. */
  579. YZ_Tool_Oppo.prototype.postData = function (otherGameAppId) {
  580. if (PlatUtils_1.default.IsOPPO) {
  581. var method = "m=rjump";
  582. var url = POST_ServerUrl + method + ("&jump_app_id=" + otherGameAppId);
  583. // utils.showLog("上报数据, url=" + url);
  584. Utils_1.utils.commomHttpRequest(url, function (ret, data) {
  585. if (ret) {
  586. Utils_1.utils.showLog("数据上报成功!");
  587. }
  588. else {
  589. Utils_1.utils.showLog("数据上报失败!");
  590. }
  591. }.bind(this));
  592. }
  593. };
  594. /**
  595. * 上报数据
  596. *
  597. */
  598. YZ_Tool_Oppo.prototype.postGameSourece = function (source) {
  599. if (PlatUtils_1.default.IsOPPO) {
  600. var appid = Utils_1.utils.config.oppoconfig.appID;
  601. var uid = this._uid;
  602. var channel = Utils_1.utils.config.oppoconfig.channel ? Utils_1.utils.config.oppoconfig.channel.toLowerCase() : "oppo";
  603. var url = POST_ServerUrl + ("kyx=true&app_id=" + appid + "&channel=" + channel + "&uid=" + this._uid + "&source=" + source);
  604. // let url: string = `http://apps.youlesp.com/gs?m=jump&app_id=${appid}&uid=${uid}&channel=${channel}&jump_app_id=${otherGameAppId}`;
  605. Utils_1.utils.showLog("上报游戏来源数据, url=" + url);
  606. Utils_1.utils.commomHttpRequest(url, function (ret, data) {
  607. if (ret) {
  608. Utils_1.utils.showLog("数据上报成功!");
  609. }
  610. else {
  611. Utils_1.utils.showLog("数据上报失败!");
  612. }
  613. }.bind(this));
  614. }
  615. };
  616. YZ_Tool_Oppo.prototype._login = function () {
  617. var _this = this;
  618. var curTime = new Date().getTime();
  619. var interval = (curTime - this._loginTime) / 1000;
  620. if (interval > 0 && interval < this._loginInterval) {
  621. Utils_1.utils.showLog("\u767B\u5F55\u8BF7\u6C42\u95F4\u9694\u5C0F\u4E8E\uFF1A" + this._loginInterval + "\u79D2");
  622. return;
  623. }
  624. this._loginTime = curTime;
  625. var self = this;
  626. this._uid = YZ_LocalStorage_1.default.getItem(YZ_Constant_1.default.ST_UID);
  627. this._uid = this._uid ? this._uid : "0";
  628. this._service_uid = YZ_LocalStorage_1.default.getItem(YZ_Constant_1.default.ST_SERVICE_UID);
  629. this._service_uid = this._service_uid ? this._service_uid : 0;
  630. Utils_1.utils.showLog("获取本地保存的uid=" + this._uid + ",服务器UID=" + this._service_uid);
  631. if (this._uid == "0") {
  632. if (this.isOverMiniVersion("1040")) {
  633. //@ts-ignore
  634. qg.login({
  635. success: function (res) {
  636. if (res.data.uid) {
  637. self._uid = "" + res.data.uid;
  638. Utils_1.utils.showLog("登录成功! uid=" + self._uid);
  639. YZ_LocalStorage_1.default.setItem(YZ_Constant_1.default.ST_UID, self._uid);
  640. }
  641. },
  642. fail: function (res) {
  643. Utils_1.utils.showLog("登录失败!");
  644. },
  645. complete: function () {
  646. _this.reportLogin();
  647. }
  648. });
  649. }
  650. else {
  651. Utils_1.utils.showLog("快游戏平台版本低于1040,无法登录取UID,直接获取服务器ID");
  652. this.reportLogin();
  653. }
  654. }
  655. else {
  656. var ysxy = YZ_LocalStorage_1.default.getItem(YZ_Constant_1.default.YZ_GAME_YSXY);
  657. if (ysxy) {
  658. this.initDeviceId();
  659. }
  660. }
  661. };
  662. YZ_Tool_Oppo.prototype.initDeviceId = function () {
  663. var _this = this;
  664. Utils_1.utils.showLog("oppo initDeviceId! #isGetDeviceId=" + this.isGetDeviceId);
  665. var todayIsGet = YZ_LocalStorage_1.default.getItem(YZ_Constant_1.default.ST_GET_DEVICE_ID, "0");
  666. //@ts-ignore
  667. if (this.isGetDeviceId && qg.getDeviceId && todayIsGet == 0) {
  668. YZ_LocalStorage_1.default.setItem(YZ_Constant_1.default.ST_GET_DEVICE_ID, "1");
  669. //@ts-ignore
  670. qg.getDeviceId({
  671. success: function (data) {
  672. Utils_1.utils.showLog("getDeviceId success: deviceId=" + data.deviceId);
  673. _this._device_id = data.deviceId;
  674. YZ_LocalStorage_1.default.setItem(YZ_Constant_1.default.ST_DEVICE_ID, data.deviceId);
  675. _this.reportDevice();
  676. },
  677. fail: function (data, code) {
  678. Utils_1.utils.showLog("getDeviceId fail, code = " + code);
  679. },
  680. });
  681. }
  682. else {
  683. this.reportDevice();
  684. }
  685. };
  686. /**
  687. * 上报登录接口获取UID
  688. */
  689. YZ_Tool_Oppo.prototype.reportLogin = function () {
  690. return __awaiter(this, void 0, void 0, function () {
  691. var self, curTime, interval, method, url;
  692. var _this = this;
  693. return __generator(this, function (_a) {
  694. Utils_1.utils.showLog("reportLogin >>>>>>>>>>>");
  695. if (this.isReport)
  696. return [2 /*return*/];
  697. this.isReport = true;
  698. self = this;
  699. curTime = new Date().getTime();
  700. interval = (curTime - this._reportLoginTime) / 1000;
  701. if (interval > 0 && interval < this._reportLoginInterval) {
  702. Utils_1.utils.showLog("\u4E0A\u62A5\u767B\u5F55\u83B7\u53D6UID\u5C0F\u4E8E\uFF1A" + this._reportLoginInterval + "\u79D2");
  703. return [2 /*return*/];
  704. }
  705. this._reportLoginTime = curTime;
  706. method = "m=login";
  707. url = ST_ServerUrl + method + ("&device_data=" + encodeURI(JSON.stringify(this._sysInfo)));
  708. Utils_1.utils.commomHttpRequest(url, function (ret, data) {
  709. if (ret) {
  710. if (data) {
  711. var result = JSON.parse(data);
  712. if (result.uid) {
  713. self._service_uid = result.uid;
  714. Utils_1.utils.showLog("服务器请求登录成功! _service_uid=" + self._service_uid);
  715. YZ_LocalStorage_1.default.setItem(YZ_Constant_1.default.ST_SERVICE_UID, self._service_uid);
  716. }
  717. }
  718. }
  719. _this.isReport = false;
  720. });
  721. return [2 /*return*/];
  722. });
  723. });
  724. };
  725. /**
  726. * 获取交叉推广数据
  727. */
  728. YZ_Tool_Oppo.prototype.getRecommondGameList = function () {
  729. if (PlatUtils_1.default.IsOPPO && Utils_1.utils.oppoTool && Utils_1.utils.oppoTool.ServerConfig) {
  730. return Utils_1.utils.oppoTool.ServerConfig.jump_list;
  731. }
  732. return null;
  733. };
  734. YZ_Tool_Oppo.prototype.showMsg = function (msg) {
  735. if (PlatUtils_1.default.IsOPPO) {
  736. //@ts-ignore
  737. qg.showToast({
  738. title: "" + msg,
  739. icon: 'none',
  740. duration: 2000
  741. });
  742. }
  743. };
  744. /**
  745. * 弹出提示框
  746. * @param msg 消息
  747. */
  748. YZ_Tool_Oppo.prototype.showToast = function (msg) {
  749. if (PlatUtils_1.default.IsOPPO) {
  750. //@ts-ignore
  751. qg.showToast({
  752. title: msg,
  753. icon: "none",
  754. duration: 2000
  755. });
  756. }
  757. };
  758. /**
  759. * 上报互推组件数据
  760. * @param otherGameAppId 跳转的ID
  761. * @param location 当前位置
  762. * @param status 0:点击,1:跳转成功
  763. */
  764. YZ_Tool_Oppo.prototype.postDataByLocation = function (otherGameAppId, location, status) {
  765. if (status === void 0) { status = 0; }
  766. if (PlatUtils_1.default.IsOPPO) {
  767. var method = "m=rjump";
  768. var url = POST_ServerUrl + method + ("&jump_app_id=" + otherGameAppId + "&location=" + location + "&status=" + status);
  769. // utils.showLog("上报数据, url=" + url);
  770. Utils_1.utils.commomHttpRequest(url, function (ret, data) {
  771. if (ret) {
  772. var result = JSON.parse(data);
  773. Utils_1.utils.showLog("\u6570\u636E\u4E0A\u62A5\u6210\u529F");
  774. if (result && result.jump_list && result.jump_list.length > 0) {
  775. Utils_1.utils.oppoTool.ServerConfig.jump_list = result.jump_list;
  776. }
  777. }
  778. else {
  779. Utils_1.utils.showLog("数据上报失败!");
  780. }
  781. }.bind(this));
  782. }
  783. };
  784. /**
  785. * 上报互推组件显示位置
  786. * @param otherGameAppId 跳转的ID
  787. * @param location 当前位置
  788. * @param status 0:点击,1:跳转成功
  789. */
  790. YZ_Tool_Oppo.prototype.postRecommentShowData = function (location) {
  791. if (PlatUtils_1.default.IsOPPO) {
  792. var method = "m=rjumpshow";
  793. var url = POST_ServerUrl + method + ("&location=" + location);
  794. // utils.showLog("上报数据, url=" + url);
  795. Utils_1.utils.commomHttpRequest(url, function (ret, data) {
  796. if (ret) {
  797. Utils_1.utils.showLog("数据上报成功!");
  798. }
  799. else {
  800. Utils_1.utils.showLog("数据上报失败!");
  801. }
  802. }.bind(this));
  803. }
  804. };
  805. /**
  806. * 上报关卡数据
  807. * @param level 当前关卡ID
  808. * @param levelName 关卡名称
  809. * @param status 状态
  810. */
  811. YZ_Tool_Oppo.prototype.postLevel = function (level, status, levelName) {
  812. if (PlatUtils_1.default.IsOPPO) {
  813. var method = "m=rlevelv3";
  814. var url = POST_ServerUrl + method + ("&level_id=" + level + "&level_name=" + encodeURI(levelName) + "&status=" + status);
  815. if (status == YZ_Constant_1.LevelStatus.GameStart) {
  816. url += "&device_data=" + encodeURI(JSON.stringify(this._sysInfo));
  817. }
  818. Utils_1.utils.commomHttpRequest(url, function (ret, data) {
  819. if (ret) {
  820. Utils_1.utils.showLog("关卡数据上报成功!");
  821. }
  822. else {
  823. Utils_1.utils.showLog("关卡数据上报失败!");
  824. }
  825. if (!ret || status != YZ_Constant_1.LevelStatus.GameStart)
  826. return;
  827. if (ret && status == YZ_Constant_1.LevelStatus.GameStart) {
  828. Utils_1.utils.showLog("OPPO服务器配置数据获取成功: data = " + data);
  829. if (data) {
  830. var result = JSON.parse(data);
  831. if (result) {
  832. if (!Utils_1.utils.DebugLoacalConfig) {
  833. this._serverConfig = result;
  834. if (this._serverConfig.is_show_log_view && this._serverConfig.is_show_log_view == "true") {
  835. Utils_1.utils.showLogView = true;
  836. }
  837. }
  838. else {
  839. cc.warn("开启了本地数据测试,使用本地配置!");
  840. }
  841. }
  842. else {
  843. Utils_1.utils.showLog("OPPO服务器配置数据不是合法的JSON数据, 使用本地配置!");
  844. }
  845. }
  846. }
  847. else {
  848. Utils_1.utils.showLog("OPPO服务器配置数据获取失败, 使用本地配置!");
  849. }
  850. if (!this._serverConfig) {
  851. this._serverConfig = JSON.parse(ST_DefaultServerConfig);
  852. }
  853. else if (this._curloadTimes == 1) {
  854. if (this._serverConfig.is_local_pos_id
  855. && this._serverConfig.is_local_pos_id == "false") {
  856. // 使用服务器下发的广告id
  857. Utils_1.utils.showLog("使用服务器下发的广告id 22");
  858. Utils_1.utils.config.oppoconfig.bannerId = this.ServerConfig.banner_pos_id;
  859. Utils_1.utils.config.oppoconfig.insertId = this.ServerConfig.intersititia_pos_id;
  860. Utils_1.utils.config.oppoconfig.videoId = this.ServerConfig.video_pos_id;
  861. Utils_1.utils.config.oppoconfig.nativeInsertIds = this.ServerConfig.native_intersititial_pos_id;
  862. Utils_1.utils.config.oppoconfig.nativeBannerIds = this.ServerConfig.native_banner_pos_id;
  863. Utils_1.utils.config.oppoconfig.nativeTryGameIds = this.ServerConfig.native_trygame_pos_id;
  864. Utils_1.utils.config.oppoconfig.recGameBannerId = this.ServerConfig.rec_game_banner_id;
  865. Utils_1.utils.config.oppoconfig.recPortalId = this.ServerConfig.rec_portal_id;
  866. Utils_1.utils.config.oppoconfig.intersitialAdConfigs = this.ServerConfig.intersitial_configs || Utils_1.utils.config.oppoconfig.intersitialAdConfigs;
  867. Utils_1.utils.config.oppoconfig.bannerAdConfigs = this.ServerConfig.banner_configs || Utils_1.utils.config.oppoconfig.bannerAdConfigs;
  868. }
  869. else {
  870. Utils_1.utils.showLog("使用本地配置的广告ID");
  871. }
  872. if (this.ServerConfig.native_banner_configs) {
  873. Utils_1.utils.config.oppoconfig.nativeBannerInfos.length = 0;
  874. for (var i = 0; i < this.ServerConfig.native_banner_configs.length; i++) {
  875. Utils_1.utils.showLog("获取到原生广告配置:" + this.ServerConfig.native_banner_configs[i].location, ">>>>", JSON.stringify(this.ServerConfig.native_banner_configs[i]));
  876. Utils_1.utils.config.oppoconfig.setNativeBannerInfo(this.ServerConfig.native_banner_configs[i].location, this.ServerConfig.native_banner_configs[i]);
  877. }
  878. }
  879. }
  880. }.bind(this));
  881. }
  882. };
  883. /**
  884. * 是否支持互推
  885. */
  886. YZ_Tool_Oppo.prototype.canShowRecommend = function () {
  887. if (this.isOverMiniVersion("1076")) {
  888. return true;
  889. }
  890. return false;
  891. };
  892. /**
  893. * 是否支持新的互推
  894. */
  895. YZ_Tool_Oppo.prototype.canShowNewRecommend = function () {
  896. if (this.isOverMiniVersion("1090")) {
  897. return true;
  898. }
  899. return false;
  900. };
  901. /**
  902. * 展示OPPO互推banner
  903. */
  904. YZ_Tool_Oppo.prototype.showOppoRecBanner = function (location) {
  905. var _this = this;
  906. if (!this.canShowRecommend()) {
  907. Utils_1.utils.showLog("当前版本不支持显示官方互推!");
  908. return false;
  909. }
  910. if (Utils_1.utils.config.oppoconfig.recGameBannerId) {
  911. this._rec_is_banner = true;
  912. if (this._rec_game_banner) {
  913. this.hideOppoRecBanner();
  914. }
  915. this._rec_game_banner = this.qg.createGameBannerAd({
  916. adUnitId: Utils_1.utils.config.oppoconfig.recGameBannerId
  917. });
  918. this._rec_game_banner.onLoad(function () {
  919. Utils_1.utils.showLog('互推banner加载成功!');
  920. });
  921. // this._rec_game_banner.show().then(() => {
  922. // utils.showLog('互推banner展示成功!')
  923. // }).catch((error) => {
  924. // utils.showLog('互推banner展示失败:' + error.errCode + ',' + error.errMsg)
  925. // })
  926. this._rec_game_banner.onError(function (err) {
  927. Utils_1.utils.showLog('互推banner加载异常!', err.errCode + ',' + err.errMsg);
  928. _this._rec_game_banner.destroy();
  929. _this._rec_game_banner = null;
  930. });
  931. this._rec_game_banner.show().then(function () {
  932. _this.showRecHideNativeAd();
  933. Utils_1.utils.showLog('互推banner展示成功!');
  934. if (location) {
  935. Utils_1.utils.SendEvent("互推Banner展示成功,位置:" + location);
  936. }
  937. }).catch(function (error) {
  938. Utils_1.utils.showLog('互推banner展示失败:' + error.errCode + ',' + error.errMsg);
  939. });
  940. }
  941. else {
  942. Utils_1.utils.showLog("OPPO 互推banner ID未配置!");
  943. }
  944. };
  945. YZ_Tool_Oppo.prototype.showRecHideNativeAd = function () {
  946. if (this.ServerConfig
  947. && this.ServerConfig.show_rec_hide_native_ad
  948. && this.ServerConfig.show_rec_hide_native_ad == "false") {
  949. Utils_1.utils.showLog("互推展示成功之后不执行隐藏原生广告");
  950. return;
  951. }
  952. Utils_1.utils.adManager.HideBanner(0);
  953. Utils_1.utils.adManager.HideSingleNativeAd();
  954. Utils_1.utils.adManager.hideNativeTryGameWidget();
  955. Utils_1.utils.showLog("互推展示成功之后隐藏原生广告");
  956. };
  957. /**
  958. * 展示OPPO互推banner
  959. */
  960. YZ_Tool_Oppo.prototype.showOppoNewRecBanner = function (params) {
  961. var _this = this;
  962. if (params === void 0) { params = null; }
  963. if (!this.canShowNewRecommend()) {
  964. Utils_1.utils.showLog("当前版本不支持显示官方新互推Banner!");
  965. return false;
  966. }
  967. if (Utils_1.utils.config.oppoconfig.recGameBannerId) {
  968. this._rec_is_banner = false;
  969. if (this._rec_game_banner) {
  970. this.hideOppoRecBanner();
  971. }
  972. var style = {};
  973. if (params) {
  974. if (params.orientation === "vertical") {
  975. if (params.left != undefined) {
  976. style.left = params.left / cc.winSize.width * this.SysInfo.screenWidth;
  977. }
  978. else if (params.right != undefined) {
  979. style.left = (this.SysInfo.screenWidth - 155) - (params.right / cc.winSize.width * this.SysInfo.screenWidth);
  980. }
  981. if (params.bottom != undefined) {
  982. style.top = (this.SysInfo.screenHeight - 720) - (params.bottom / cc.winSize.height * this.SysInfo.screenHeight);
  983. }
  984. else {
  985. style.top = params.top / cc.winSize.height * this.SysInfo.screenHeight;
  986. }
  987. }
  988. else {
  989. if (params.left != undefined) {
  990. style.left = params.left / cc.winSize.width * this.SysInfo.screenWidth;
  991. }
  992. else if (params.right != undefined) {
  993. style.left = (this.SysInfo.screenWidth - 720) - (params.right / cc.winSize.width * this.SysInfo.screenWidth);
  994. }
  995. if (params.bottom != undefined) {
  996. style.top = (this.SysInfo.screenHeight - 200) - (params.bottom / cc.winSize.height * this.SysInfo.screenHeight);
  997. }
  998. else {
  999. style.top = params.top / cc.winSize.height * this.SysInfo.screenHeight;
  1000. }
  1001. }
  1002. }
  1003. style.orientation = params.orientation ? params.orientation : "horizontal";
  1004. Utils_1.utils.showLog("rec banner style>>>>>", JSON.stringify(style));
  1005. this._rec_game_banner = this.qg.createGameBannerAd({
  1006. adUnitId: Utils_1.utils.config.oppoconfig.recGameBannerId,
  1007. style: style
  1008. });
  1009. this._rec_game_banner.onLoad(function () {
  1010. Utils_1.utils.showLog('互推banner加载成功!');
  1011. });
  1012. // this._rec_game_banner.show().then(() => {
  1013. // utils.showLog('互推banner展示成功!')
  1014. // }).catch((error) => {
  1015. // utils.showLog('互推banner展示失败:' + error.errCode + ',' + error.errMsg)
  1016. // })
  1017. this._rec_game_banner.onError(function (err) {
  1018. Utils_1.utils.showLog('互推banner加载异常!', err.errCode + ',' + err.errMsg);
  1019. _this._rec_game_banner.destroy();
  1020. _this._rec_game_banner = null;
  1021. });
  1022. this._rec_game_banner.show().then(function () {
  1023. _this.showRecHideNativeAd();
  1024. Utils_1.utils.showLog('互推banner展示成功!');
  1025. if (location) {
  1026. Utils_1.utils.SendEvent("互推Banner展示成功,位置:" + location);
  1027. }
  1028. }).catch(function (error) {
  1029. Utils_1.utils.showLog('互推banner展示失败:' + error.errCode + ',' + error.errMsg);
  1030. });
  1031. }
  1032. else {
  1033. Utils_1.utils.showLog("OPPO 互推banner ID未配置!");
  1034. }
  1035. };
  1036. /**
  1037. * 隐藏互推banner
  1038. */
  1039. YZ_Tool_Oppo.prototype.hideOppoRecBanner = function (callBack) {
  1040. var _this = this;
  1041. if (this._rec_game_banner) {
  1042. this._rec_game_banner.destroy().then(function () {
  1043. callBack && callBack();
  1044. Utils_1.utils.showLog('OPPO 互推banner 隐藏成功!');
  1045. }).catch(function (error) {
  1046. Utils_1.utils.showLog('OPPO 互推banner 隐藏失败:' + error.errCode + ',' + error.errMsg);
  1047. _this._rec_game_banner.hide();
  1048. });
  1049. this._rec_game_banner = null;
  1050. }
  1051. };
  1052. /**
  1053. * 展示OPPO九宫格
  1054. */
  1055. YZ_Tool_Oppo.prototype.showOppoGamePortal = function () {
  1056. var _this = this;
  1057. if (!this.canShowRecommend()) {
  1058. Utils_1.utils.showLog("当前版本不支持显示官方互推!");
  1059. return false;
  1060. }
  1061. if (!Utils_1.utils.adManager.checkShowAdTime()) {
  1062. Utils_1.utils.showLog("显示广告条时间未达限制!");
  1063. return;
  1064. }
  1065. if (Utils_1.utils.config.oppoconfig.recPortalId) {
  1066. if (!this._rec_game_portal) {
  1067. this._rec_game_portal = this.qg.createGamePortalAd({
  1068. adUnitId: Utils_1.utils.config.oppoconfig.recPortalId
  1069. });
  1070. this._rec_game_portal.load().then(function () {
  1071. _this.showRecHideNativeAd();
  1072. Utils_1.utils.showLog('九宫格互推加载成功!');
  1073. }).catch(function (error) {
  1074. _this._rec_game_portal.destroy();
  1075. _this._rec_game_portal = null;
  1076. Utils_1.utils.showLog('九宫格互推加载失败:' + error.errCode + ',' + error.errMsg);
  1077. });
  1078. this._rec_game_portal.onLoad(function () {
  1079. Utils_1.utils.showLog('互推盒子九宫格广告加载成功');
  1080. _this._rec_game_portal.show().then(function () {
  1081. Utils_1.utils.showLog('互推盒子九宫格广告-显示成功!');
  1082. }).catch(function (error) {
  1083. _this._rec_game_portal.destroy();
  1084. _this._rec_game_portal = null;
  1085. Utils_1.utils.showLog('互推盒子九宫格广告-显示失败:' + error.errCode + ',' + error.errMsg);
  1086. });
  1087. });
  1088. this._rec_game_portal.onClose(function () {
  1089. Utils_1.utils.showLog('互推盒子九宫格广告关闭');
  1090. });
  1091. }
  1092. else {
  1093. this._rec_game_portal.load().then(function () {
  1094. _this.showRecHideNativeAd();
  1095. Utils_1.utils.showLog('九宫格互推加载成功!');
  1096. }).catch(function (error) {
  1097. _this._rec_game_portal.destroy();
  1098. _this._rec_game_portal = null;
  1099. Utils_1.utils.showLog('九宫格互推加载失败:' + error.errCode + ',' + error.errMsg);
  1100. });
  1101. }
  1102. }
  1103. else {
  1104. Utils_1.utils.showLog("OPPO 互推九宫格 ID未配置!");
  1105. }
  1106. };
  1107. /**
  1108. * 上报自定义事件
  1109. * @param level 当前关卡ID
  1110. * @param levelName 关卡名称
  1111. * @param status 状态
  1112. */
  1113. YZ_Tool_Oppo.prototype.sendEvent = function (eventName) {
  1114. if (PlatUtils_1.default.IsOPPO) {
  1115. var method = "m=revent";
  1116. var url = POST_ServerUrl + method + ("&event=" + encodeURI(eventName));
  1117. Utils_1.utils.commomHttpRequest(url, function (ret, data) {
  1118. if (ret) {
  1119. Utils_1.utils.showLog("上报自定义事件成功!");
  1120. }
  1121. else {
  1122. Utils_1.utils.showLog("上报自定义事件失败!");
  1123. }
  1124. }.bind(this));
  1125. }
  1126. };
  1127. /**
  1128. * 显示互推盒子广告
  1129. * @param top 顶部距离
  1130. * @returns
  1131. */
  1132. YZ_Tool_Oppo.prototype.showGameDrawerAd = function (params) {
  1133. var _this = this;
  1134. if (!Utils_1.utils.config.oppoconfig.recGameDrawerId) {
  1135. Utils_1.utils.showLog('服务器没有配置互推抽屉样式的ID,请反馈给运营!');
  1136. return;
  1137. }
  1138. if (this.canShowNewRecommend()) {
  1139. if (this._gameDrawerAd) {
  1140. this.hideGameDrawerAd();
  1141. }
  1142. var style = {};
  1143. if (params.bottom != undefined) {
  1144. style.top = (this.SysInfo.screenHeight - 490) - (params.bottom / cc.winSize.height * this.SysInfo.screenHeight);
  1145. }
  1146. else {
  1147. style.top = params.top / cc.winSize.height * this.SysInfo.screenHeight;
  1148. }
  1149. Utils_1.utils.showLog(" rec game drawer style >>>" + JSON.stringify(style));
  1150. this._gameDrawerAd = this.qg.createGameDrawerAd({
  1151. adUnitId: Utils_1.utils.config.oppoconfig.recGameDrawerId,
  1152. style: style
  1153. });
  1154. this._gameDrawerAd.onShow(function () {
  1155. Utils_1.utils.showLog('showGameDrawerAd success');
  1156. this.showRecHideNativeAd();
  1157. });
  1158. this._gameDrawerAd.show().then(function () {
  1159. Utils_1.utils.showLog('showGameDrawerAd success');
  1160. _this.showRecHideNativeAd();
  1161. }).catch(function (error) {
  1162. Utils_1.utils.showLog('showGameDrawerAd fail with:' + error.errCode + ',' + error.errMsg);
  1163. });
  1164. }
  1165. else {
  1166. Utils_1.utils.showLog('快应用平台版本号低于1090,暂不支持互推盒子相关 API');
  1167. }
  1168. };
  1169. /**
  1170. * 隐藏抽屉盒子
  1171. */
  1172. YZ_Tool_Oppo.prototype.hideGameDrawerAd = function (callBack) {
  1173. if (this._gameDrawerAd) {
  1174. this._gameDrawerAd.destroy().then(function () {
  1175. callBack && callBack();
  1176. Utils_1.utils.showLog('hideGameDrawerAd success');
  1177. }).catch(function (error) {
  1178. Utils_1.utils.showLog('hideGameDrawerAd fail with:' + error.errCode + ',' + error.errMsg);
  1179. this._gameDrawerAd.hide();
  1180. });
  1181. this._gameDrawerAd = null;
  1182. }
  1183. };
  1184. /**友盟sdk初始化 */
  1185. YZ_Tool_Oppo.prototype.umaInit = function () {
  1186. if (!this.checkUmeng()) {
  1187. Utils_1.utils.showLog("友盟ID未配置,不执行友盟初始化>>>>");
  1188. return;
  1189. }
  1190. uma.init({
  1191. appKey: Utils_1.utils.config.oppoconfig.umengId,
  1192. useOpenid: false,
  1193. debug: CC_DEBUG
  1194. });
  1195. };
  1196. /**
  1197. * 友盟游戏开始上报
  1198. * @param levelID
  1199. */
  1200. YZ_Tool_Oppo.prototype.umaOnStart = function (levelID) {
  1201. if (!this.checkUmeng())
  1202. return;
  1203. //@ts-ignore
  1204. qg.uma.stage.onStart({
  1205. stageId: levelID,
  1206. stageName: "\u7B2C" + levelID + "\u5173" // 关卡id
  1207. });
  1208. };
  1209. /**
  1210. *
  1211. * @returns 是否开启友盟
  1212. */
  1213. YZ_Tool_Oppo.prototype.checkUmeng = function () {
  1214. if (!Utils_1.utils.config.oppoconfig.umengId) {
  1215. return false;
  1216. }
  1217. return true;
  1218. };
  1219. /**
  1220. * 友盟结算上报
  1221. * @param levelID 关卡id
  1222. * @param stageId
  1223. * @param event
  1224. */
  1225. YZ_Tool_Oppo.prototype.umaReportedLevel = function (levelID, event) {
  1226. if (!this.checkUmeng())
  1227. return;
  1228. //@ts-ignore
  1229. qg.uma.stage.onEnd({
  1230. stageId: levelID,
  1231. stageName: "\u7B2C" + levelID + "\u5173",
  1232. event: event
  1233. });
  1234. };
  1235. /**
  1236. * 友盟自定义事件
  1237. * @param eventId 事件ID,注意:事件ID必须要在后台配置
  1238. * @param params 事件内容
  1239. */
  1240. YZ_Tool_Oppo.prototype.umaTrackEvent = function (eventId, params) {
  1241. if (!this.checkUmeng())
  1242. return;
  1243. //@ts-ignore
  1244. qg.uma.trackEvent(eventId, params);
  1245. };
  1246. /**
  1247. * 退出游戏
  1248. */
  1249. YZ_Tool_Oppo.prototype.GameExit = function () {
  1250. if (PlatUtils_1.default.IsOPPO) {
  1251. Utils_1.utils.showLog("tool oppo GameExit");
  1252. try {
  1253. //@ts-ignore
  1254. qg.exitApplication({
  1255. success: function () {
  1256. console.log("退出成功!");
  1257. },
  1258. fail: function () {
  1259. console.log("退出失败!");
  1260. },
  1261. complete: function () {
  1262. console.log("退出执行完成!");
  1263. }
  1264. });
  1265. }
  1266. catch (error) {
  1267. cc.log("GameExit erro:", JSON.stringify(error));
  1268. }
  1269. }
  1270. };
  1271. YZ_Tool_Oppo.prototype.reportDevice = function () {
  1272. var _this = this;
  1273. if (this.isReportDevice) {
  1274. return;
  1275. }
  1276. this.isReportDevice = true;
  1277. YouWanAnalytics_1.default.login(function (res) {
  1278. _this.isReportDevice = false;
  1279. });
  1280. // let xhr = new XMLHttpRequest();
  1281. // xhr.timeout = 6000; // 单位毫秒
  1282. // xhr.open('POST', requestUrl);
  1283. // xhr.send(`data=${JSON.stringify(data)}`);
  1284. // xhr.onreadystatechange = () => {
  1285. // utils.showLog("请求状态改变, reaedyState=", xhr.readyState, "; status=", xhr.status);
  1286. // if (xhr.readyState == 4) {
  1287. // if (xhr.status == 200) {
  1288. // if (xhr.responseText) {
  1289. // try {
  1290. // let result = JSON.parse(xhr.responseText);
  1291. // if (result.code == 0) {
  1292. // utils.showLog("上报设备ID成功! >>result:" + xhr.responseText + " #uid=" + result.data.uid);
  1293. // localStorage.setItem(YZ_Constant.ST_YOUWAN_UID, result.data.uid);
  1294. // }
  1295. // } catch (error) {
  1296. // utils.showLog("上报设备ID失败,#erro=" + error);
  1297. // }
  1298. // }
  1299. // } else {
  1300. // this.isReportDevice = false;
  1301. // utils.showLog("上报设备ID失败!");
  1302. // }
  1303. // }
  1304. // }
  1305. // xhr.ontimeout = () => {
  1306. // this.isReportDevice = false;
  1307. // utils.showLog("请求超时!");
  1308. // }
  1309. // xhr.onerror = () => {
  1310. // this.isReportDevice = false;
  1311. // utils.showLog("请求异常!");
  1312. // }
  1313. };
  1314. YZ_Tool_Oppo = __decorate([
  1315. ccclass
  1316. ], YZ_Tool_Oppo);
  1317. return YZ_Tool_Oppo;
  1318. }());
  1319. exports.default = YZ_Tool_Oppo;
  1320. cc._RF.pop();