YZ_Tool_Oppo.ts 51 KB

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