AdAgentOPPO.ts 107 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419
  1. import AdAgent from "./AdAgent";
  2. import { BannerLocation } from "./YZ_Constant";
  3. import PlatUtils from "./PlatUtils";
  4. import { utils } from "./Utils";
  5. import RewardInsert from "./RewardInsert";
  6. import YZ_StatementRecommentAd from "./YZ_StatementRecommentAd";
  7. import YZ_NativeAdObject from "./YZ_NativeAdObject";
  8. import YZ_NativeItem from "./YZ_NativeItem";
  9. import NativeTryGamesWidget from "./NativeTryGamesWidget";
  10. import YZ_NativeBanner from "./YZ_NativeBanner";
  11. import { BannerIdInfo, NativeBannerInfo } from "./CommonConfig";
  12. import CompatibleTool from "./CompatibleTool";
  13. import YouWanAnalytics from "./YouWanSDK/YouWanAnalytics";
  14. import { AdEventParameter, YwAdStatus, YwAdType } from "./YouWanSDK/EventAdInfo";
  15. const { ccclass, property } = cc._decorator;
  16. @ccclass
  17. export default class AdAgentOPPO extends AdAgent {
  18. _bannerAd: any = null;
  19. _insertAd: any = null;
  20. _videoAd: any = null;
  21. _nativeBannerAd: any[] = [];
  22. _nativeInsertAd: any[] = [];
  23. _nativeSingleAd: any[] = [];
  24. _nativeAd: any = null;
  25. // 广告组件是否初始化成功
  26. _isAdInit: boolean = false;
  27. _isBannerShow: boolean = false;
  28. _isInsertShow: boolean = false;
  29. // 当前位置id的索引
  30. _curPosIdIndexNativeBanner: number = 0;
  31. _curPosIdIndexNativeInser: number = 0;
  32. _curPosIdIndexSingleNative: number = 0;
  33. _nativeData: any = null;
  34. _nativeInsertData: any = null;
  35. _nativeBannerNode: cc.Node = null;
  36. _nativeInsertNode: cc.Node = null;
  37. _videoCallback: Function = null;
  38. _videoLoaded: boolean = null;
  39. _miniBannerHeight: number = 0;
  40. _showBannerCallBack: Function = null;
  41. _nativeAdObject: YZ_NativeAdObject = null;
  42. //插屏显示次数
  43. _insertShowCount: number = 0;
  44. _insertLastShowTime: number = 0;
  45. _curNativeItem: YZ_NativeItem = null;
  46. _isNativeBannerShow: boolean = false; //原生广告展示,调用的隐藏
  47. lastLastShowVideoTime: number = 0; //最后一次显示视频时间
  48. _bannerHideCount: number = 0;
  49. canShowNativeBanner = true; //原生banner是否展示
  50. public get ServerConfig() {
  51. if (utils.oppoTool && utils.oppoTool.ServerConfig) return utils.oppoTool.ServerConfig;
  52. return {};
  53. }
  54. _nativeBannerInfo: NativeBannerInfo = null;
  55. show_ad_by_config: boolean = true;
  56. /**
  57. * 获取当前banner配置
  58. */
  59. getNativeBannerInfo() {
  60. if (this._nativeBannerInfo && this._nativeBannerInfo.location == this._curLocation) {
  61. return this._nativeBannerInfo;
  62. }
  63. return utils.config.oppoconfig.getNativeBannerInfo(this._curLocation);
  64. }
  65. public Init() {
  66. if (PlatUtils.IsOPPO && utils.oppoTool && utils.oppoTool.isOverMiniVersion("1031")) {
  67. utils.registerServerInitEvent(() => {
  68. utils.showLog("OPPO 广告代理组件初始化!");
  69. let self = this;
  70. //@ts-ignore
  71. qg.initAdService({
  72. appId: utils.config.oppoconfig.appID,
  73. isDebug: true,
  74. success: function (res) {
  75. utils.showLog("OPPO 小游戏广告组件初始化成功!");
  76. self._isAdInit = true;
  77. self._initVideoAd();
  78. },
  79. fail: function (res) {
  80. utils.showLog("OPPO 小游戏广告组件初始化失败 :" + res.code + res.msg);
  81. },
  82. complete: function (res) {
  83. }
  84. });
  85. }, this)
  86. }
  87. }
  88. _nativeIsClose: boolean = false;
  89. _showBannerTimerId: number = 0;
  90. _delayShowBannerId: number = 0;
  91. // nbclr:是否开启强制刷新
  92. //当前显示Banner的位置
  93. _curLocation: BannerLocation = BannerLocation.None;
  94. _isTimeRefresh: boolean = false;
  95. //启动定时器的时间
  96. _startBannerTimerTask: number = 0;
  97. _showBannerCount: number = 0;
  98. public ShowBanner(location: BannerLocation = null, args: any = null, isTimeRefresh: boolean = false) {
  99. if (PlatUtils.IsOPPO) {
  100. if (!this.ServerConfig) {
  101. utils.showLog("未请求到配置文件!");
  102. return;
  103. }
  104. this._showBannerCount++;
  105. let oldLocation = this._curLocation;
  106. this._curLocation = location;
  107. this._isTimeRefresh = isTimeRefresh;
  108. //如果跳用位置切换之后,验证是不是通过定时器强制刷新数据,不是则先隐藏banner
  109. if (oldLocation != location) {
  110. this.HideBanner(location);
  111. }
  112. let curTime: number = new Date().getTime();
  113. let refresh_ad_time: number = (curTime - this._startBannerTimerTask) / 1000;
  114. let interval = this.ServerConfig.refresh_ad_time;
  115. // utils.showLog("isTimeRefresh=" + isTimeRefresh);
  116. if (args && args.isRefresh) {
  117. isTimeRefresh = true;
  118. } else if (interval && interval > 0) {
  119. if (refresh_ad_time > interval) {
  120. isTimeRefresh = true;
  121. }
  122. }
  123. YouWanAnalytics.EventAd(YwAdType.BANNER, YwAdStatus.AD_ID_REQUEST);
  124. // utils.showLog("isTimeRefresh=" + isTimeRefresh);
  125. // 判断当前位置是不是显示banner
  126. if (this.getNativeBannerInfo().is_show_banner == -1) {
  127. utils.showLog("当前位置配置为不展示banner!");
  128. this.HideBanner(location);
  129. return;
  130. } else if (this.getNativeBannerInfo().is_show_rec > -1) {
  131. this.HideBanner(location);
  132. utils.showLog("当前位置显示互推banner");
  133. if (utils.oppoTool.canShowRecommend()) {
  134. utils.oppoTool.showOppoRecBanner();
  135. return;
  136. }
  137. utils.showLog("当前平台不支持互推banner");
  138. } else {
  139. if (!isTimeRefresh && !this.show_ad_by_config) {
  140. if (this.ServerConfig.nbclr && this.ServerConfig.nbclr == "true" && this._curNativeBannerInfo.nativeBannerAd) {
  141. utils.showLog("服务器配置定时器刷新数据 ");
  142. utils.showLog(`原生banner延迟显示${this.getNativeBannerInfo().delay_show_time}秒`);
  143. clearTimeout(this._showBannerTimerId);
  144. clearTimeout(this._delayShowBannerId);
  145. //@ts-ignore
  146. this._delayShowBannerId = setTimeout(() => {
  147. this._showNativeBanner(this._curNativeBannerInfo.nativeBannerAd, this._curNativeBannerInfo.data);
  148. }, this.getNativeBannerInfo().delay_show_time * 1000);
  149. utils.showLog("开启定时刷新 >>>>>>>>>" + (interval - refresh_ad_time));
  150. //@ts-ignore
  151. this._showBannerTimerId = setTimeout(() => {
  152. utils.showLog(`定时${interval}秒调用showbanner`);
  153. this.ShowBanner(this._curLocation, {}, true);
  154. }, (interval - refresh_ad_time) * 1000);
  155. return;
  156. }
  157. }
  158. }
  159. this.canShowNativeBanner = true;
  160. this._nativeIsClose = false;
  161. clearTimeout(this._showBannerTimerId);
  162. clearTimeout(this._delayShowBannerId);
  163. utils.showLog("清理定时器");
  164. if (this.ServerConfig) {
  165. if (interval && interval > 0) {
  166. utils.showLog("开启定时刷新 >>>>>>>>>" + interval);
  167. //@ts-ignore
  168. this._showBannerTimerId = setTimeout(() => {
  169. utils.showLog(`定时${interval}秒调用showbanner`);
  170. this.ShowBanner(this._curLocation, {}, true);
  171. }, interval * 1000);
  172. }
  173. if (this.show_ad_by_config) {
  174. this.ShowBannerByConfigs(0);
  175. return;
  176. }
  177. if (this.ServerConfig.banner_first_ad) {
  178. if (this.ServerConfig.banner_first_ad.indexOf("native") > -1) {
  179. utils.showLog("优先展示原生Banner广告!" + isTimeRefresh + " <<<<");
  180. if (!this._isTimeRefresh) {
  181. utils.showLog(`原生banner延迟显示${this.getNativeBannerInfo().delay_show_time}秒`);
  182. //@ts-ignore
  183. this._delayShowBannerId = setTimeout(() => {
  184. this._createNativeBannerAd(this._showNativeBanner);
  185. }, this.getNativeBannerInfo().delay_show_time * 1000);
  186. } else {
  187. this._createNativeBannerAd(this._showNativeBanner);
  188. }
  189. } else {
  190. utils.showLog("优先展示小游戏Banner广告!");
  191. this._createMiniGameBannerAd(location);
  192. }
  193. } else {
  194. utils.showLog("配置数据中没有 banner_first_ad 字段, banner广告不显示!");
  195. }
  196. } else {
  197. utils.showLog("服务器配置数据未初始化!");
  198. }
  199. }
  200. }
  201. private hideMiniGameBanner() {
  202. if (this._bannerAd) {
  203. if (utils.oppoTool.isOverMiniVersion("1050")) {
  204. utils.showLog("销毁小游戏Banner");
  205. this._bannerAd.destroy();
  206. this._bannerAd = null;
  207. } else {
  208. utils.showLog("当前小游戏平台小于1051,只能隐藏小游戏Banner");
  209. this._bannerAd.hide();
  210. }
  211. }
  212. }
  213. private hideNativeBanner() {
  214. if (this._nativeBannerNode) {
  215. utils.showLog("隐藏原生Banner");
  216. this._nativeBannerNode.active = false;
  217. }
  218. }
  219. private hideBanner(type: string) {
  220. switch (type) {
  221. case "default":
  222. this.hideNativeBanner();
  223. //隐藏自定义banner
  224. utils.hideRecommendGamesBanner();
  225. this.hideNativeTemplateBannerAd();
  226. //隐藏互推banner
  227. utils.oppoTool && utils.oppoTool._rec_is_banner && utils.oppoTool.hideOppoRecBanner();
  228. break;
  229. case "native":
  230. this.hideMiniGameBanner();
  231. //隐藏自定义banner
  232. utils.hideRecommendGamesBanner();
  233. this.hideNativeTemplateBannerAd();
  234. //隐藏互推banner
  235. utils.oppoTool && utils.oppoTool._rec_is_banner && utils.oppoTool.hideOppoRecBanner();
  236. break;
  237. case "template":
  238. this.hideMiniGameBanner();
  239. this.hideNativeBanner();
  240. //隐藏自定义banner
  241. utils.hideRecommendGamesBanner();
  242. //隐藏互推banner
  243. utils.oppoTool && utils.oppoTool._rec_is_banner && utils.oppoTool.hideOppoRecBanner();
  244. break;
  245. case "rec":
  246. this.hideMiniGameBanner();
  247. this.hideNativeBanner();
  248. //隐藏自定义banner
  249. utils.hideRecommendGamesBanner();
  250. this.hideNativeTemplateBannerAd();
  251. break;
  252. default:
  253. this.hideMiniGameBanner();
  254. this.hideNativeBanner();
  255. //隐藏自定义banner
  256. utils.hideRecommendGamesBanner();
  257. this.hideNativeTemplateBannerAd();
  258. utils.oppoTool && utils.oppoTool._rec_is_banner && utils.oppoTool.hideOppoRecBanner();
  259. break;
  260. }
  261. }
  262. public HideBanner(location: BannerLocation = null) {
  263. if (PlatUtils.IsOPPO) {
  264. clearTimeout(this._showBannerTimerId);
  265. clearTimeout(this._delayShowBannerId);
  266. this._isBannerShow = false;
  267. this._nativeIsClose = true;
  268. this.canShowNativeBanner = false;
  269. this.hideBanner("");
  270. }
  271. }
  272. /**
  273. * 隐藏快游戏的banner
  274. */
  275. hideKyxBanner() {
  276. this.hideBanner("rec");
  277. }
  278. tryGameAdArr: any[] = [];
  279. public showNativeTryGameWidget(params: any = null) {
  280. if (PlatUtils.IsOPPO) {
  281. utils.showLog("显示原生抖动试玩 nativeNeedChange=", utils.nativeNeedChange, " utils.tryGameDate", utils.tryGameDate, "utils.config.oppoconfig.nativeTryGameIds", utils.config.oppoconfig.nativeTryGameIds)
  282. if (utils.nativeNeedChange || !utils.tryGameDate) {
  283. if (utils.config.oppoconfig.nativeTryGameIds) {
  284. let len = utils.config.oppoconfig.nativeTryGameIds.length;
  285. utils.showLog("len:" + len);
  286. for (let i = 0; i < len; i++) {
  287. if (!this.tryGameAdArr[i]) {
  288. let posId = utils.config.oppoconfig.nativeTryGameIds[i];
  289. utils.showLog("创建原生抖动试玩广告, posId:" + posId);
  290. //@ts-ignore
  291. let tryGameAd = qg.createNativeAd({
  292. posId: posId
  293. });
  294. if (tryGameAd) {
  295. tryGameAd.onLoad((res) => {
  296. utils.nativeNeedChange = false
  297. if (res && res.adList && res.adList.length > 0) {
  298. res = JSON.parse(JSON.stringify(res));
  299. let adId = res.adList[0].adId
  300. utils.showLog("adId:" + adId);
  301. let canAdd = true;
  302. utils.tryGameDate.forEach((element) => {
  303. if (adId == element.date[0].adId) {
  304. canAdd = false;
  305. }
  306. })
  307. if (canAdd) {
  308. utils.tryGameDate.push({ "tryGameAd": tryGameAd, "date": res.adList });
  309. if (utils._nativeTryGameNode) {
  310. utils._nativeTryGameNode.getComponent(NativeTryGamesWidget).init();
  311. }
  312. }
  313. utils.showLog("原生抖动试完广告资源拉取成功,是否可以添加广告" + canAdd);
  314. utils.showLog(JSON.stringify(res));
  315. }
  316. });
  317. tryGameAd.onError((err) => {
  318. utils.showLog("原生抖动广告资源拉取失败!" + err.code + err.msg);
  319. utils.nativeNeedChange = true;
  320. });
  321. tryGameAd.load();
  322. this.tryGameAdArr[i] = tryGameAd;
  323. }
  324. } else {
  325. this.tryGameAdArr[i].load();
  326. }
  327. }
  328. }
  329. }
  330. this.createNativeTryGameWidget(params);
  331. }
  332. }
  333. /**
  334. * 通过配置展示插屏
  335. * @param index 索引
  336. */
  337. public ShowInterstitialByConfigs(index: number) {
  338. utils.showLog("ShowInterstitialByConfigs index=" + index + " #configsLength=" + utils.config.oppoconfig.intersitialAdConfigs.length);
  339. if (index < utils.config.oppoconfig.intersitialAdConfigs.length) {
  340. let adInfo: any = utils.config.oppoconfig.intersitialAdConfigs[index];
  341. utils.showLog("ShowInterstitialByConfigs adInfo:" + JSON.stringify(adInfo));
  342. switch (adInfo.type) {
  343. case "default":
  344. this._createMiniGameInsertAdByConfig(index);
  345. break;
  346. case "native":
  347. this._createNativeInsertAdByConfig(index);
  348. break;
  349. case "template":
  350. this._createNativeTemplateIntersitialAd(index);
  351. break;
  352. }
  353. } else {
  354. YouWanAnalytics.EventAd(YwAdType.INTERSITITIAL, YwAdStatus.AD_ID_REQUEST_FAIL);
  355. utils.showLog("插屏展示失败,所有广告类型都未请求到广告!");
  356. }
  357. }
  358. /**
  359. * 通过索引展示Banner
  360. * @param index 索引
  361. */
  362. public ShowBannerByConfigs(index: number) {
  363. utils.showLog("ShowBannerByConfigs index=" + index + " #configsLength=" + utils.config.oppoconfig.bannerAdConfigs.length);
  364. if (index < utils.config.oppoconfig.bannerAdConfigs.length) {
  365. let adInfo: any = utils.config.oppoconfig.bannerAdConfigs[index];
  366. utils.showLog("ShowBannerByConfigs adInfo:" + JSON.stringify(adInfo));
  367. switch (adInfo.type) {
  368. case "default":
  369. this._createMiniGameBannerAdByConfigs(index);
  370. break;
  371. case "native":
  372. this._createNativeBannerAdByConfigs(index);
  373. break;
  374. case "template":
  375. this._createNativeTemplateBannerAd(index);
  376. break;
  377. }
  378. } else {
  379. YouWanAnalytics.EventAd(YwAdType.BANNER, YwAdStatus.AD_ID_REQUEST_FAIL);
  380. utils.showLog("Banner展示失败,所有广告类型都未请求到广告!");
  381. }
  382. }
  383. public ShowInterstitial(location: BannerLocation = null) {
  384. if (PlatUtils.IsOPPO) {
  385. if (this.ServerConfig) {
  386. if (!this.checkInsertAdShow()) return;
  387. YouWanAnalytics.EventAd(YwAdType.INTERSITITIAL, YwAdStatus.AD_ID_REQUEST);
  388. if (this.show_ad_by_config) {
  389. this.ShowInterstitialByConfigs(0);
  390. return;
  391. }
  392. if (location && location == BannerLocation.Pause) {
  393. if (this.ServerConfig.intersititial_first_ad == "native") {
  394. utils.showLog("暂停界面不延时展示!");
  395. utils.showLog("优先展示原生插屏广告!");
  396. this.nativeInserAdDelayCall();
  397. } else {
  398. utils.showLog("优先展示小游戏插屏广告!");
  399. this._createMiniGameInsertAd();
  400. }
  401. } else {
  402. if (this.ServerConfig.intersititial_first_ad == "native") {
  403. utils.showLog("优先展示原生插屏广告!");
  404. utils.delayCall(this.nativeInserAdDelayCall.bind(this), this.ServerConfig.intersititia_delay_show_time || 0);
  405. } else {
  406. utils.showLog("优先展示小游戏插屏广告!");
  407. this._createMiniGameInsertAd();
  408. // utils.delayCall(this._createMiniGameInsertAd.bind(this), this.ServerConfig.intersititia_delay_show_time || 0);
  409. }
  410. }
  411. } else {
  412. utils.showLog("服务器配置数据未初始化!");
  413. }
  414. }
  415. }
  416. _nativeInsertAdShowCount: number = 0;
  417. public nativeInserAdDelayCall() {
  418. utils.showLog("原生插屏广告: 当前点击次数=" + utils.oppoTool.NativeInsertAdClickTimes + "; 点击次数限制=" + this.ServerConfig.intersititia_click_count + "; 展示次数间隔=" + this.ServerConfig.intersititia_show_interval + "; 展示累计=" + this._nativeInsertAdShowCount);
  419. if (utils.oppoTool.NativeInsertAdClickTimes >= (this.ServerConfig.intersititia_click_count || 0)) {
  420. // 每日点击次数到达上限,限制展示次数
  421. if (this._nativeInsertAdShowCount >= (this.ServerConfig.intersititia_show_interval || 0)) {
  422. // 可以展示
  423. this._createNativeInsertAd(this._showNativeInsert);
  424. } else {
  425. // 不能展示
  426. this._nativeInsertAdShowCount++;
  427. }
  428. } else {
  429. this._createNativeInsertAd(this._showNativeInsert);
  430. }
  431. }
  432. public ShowVideo(callback: Function) {
  433. if (PlatUtils.IsOPPO) {
  434. this._videoCallback = callback;
  435. let curTime: number = new Date().getTime();
  436. let interval: number = (curTime - this.lastLastShowVideoTime) / 1000;
  437. if (interval < 4) {
  438. utils.showLog("视频广告请求间隔小于4秒,直接返回false");
  439. if (this._videoCallback) {
  440. this._videoCallback(false, "暂无视频广告!");
  441. this._videoCallback = null;
  442. }
  443. return;
  444. }
  445. if (this.ServerConfig) {
  446. if (this.checkRewardInsertIsShow() && utils.oppoTool
  447. && utils.oppoTool.ServerConfig
  448. && utils.oppoTool.ServerConfig.reward_first_ad && utils.oppoTool.ServerConfig.reward_first_ad != "video") {
  449. utils.showLog("<<<服务器默认优先展示激励插屏>>>");
  450. this.showRewardInsert();
  451. return;
  452. }
  453. if (utils.oppoTool.isOverMiniVersion("1040")) {
  454. if (!this._videoAd) {
  455. this._initVideoAd();
  456. }
  457. if (this._videoAd && this._videoLoaded) {
  458. this._videoAd.show();
  459. YouWanAnalytics.EventAdWithObj(YwAdType.REWARD_VIDEO, YwAdStatus.SHOW_SUCCESS, new AdEventParameter(utils.config.oppoconfig.videoId));
  460. return;
  461. }
  462. }
  463. }
  464. utils.showLog("暂无视频广告!");
  465. if (this._videoCallback) {
  466. this._videoAd.load();
  467. YouWanAnalytics.EventAdWithObj(YwAdType.REWARD_VIDEO, YwAdStatus.REQUEST, new AdEventParameter(utils.config.oppoconfig.videoId));
  468. // this.showRewardInsert();
  469. this._videoCallback(false, "暂无视频广告!");
  470. this._videoCallback = null;
  471. }
  472. }
  473. }
  474. _initVideoAd() {
  475. if (!this._videoAd) {
  476. if (utils.config.oppoconfig.videoId) {
  477. //@ts-ignore
  478. this._videoAd = qg.createRewardedVideoAd({
  479. posId: utils.config.oppoconfig.videoId
  480. });
  481. let self = this;
  482. if (this._videoAd) {
  483. utils.showLog("初始化注册视频回调!");
  484. this._videoAd.load();
  485. YouWanAnalytics.EventAdWithObj(YwAdType.REWARD_VIDEO, YwAdStatus.REQUEST, new AdEventParameter(utils.config.oppoconfig.videoId));
  486. this._videoAd.onLoad(function () {
  487. YouWanAnalytics.EventAdWithObj(YwAdType.REWARD_VIDEO, YwAdStatus.REQUEST_SUCCESS, new AdEventParameter(utils.config.oppoconfig.videoId));
  488. utils.showLog("激励视频加载成功");
  489. self._videoLoaded = true;
  490. })
  491. this._videoAd.onError((err) => {
  492. YouWanAnalytics.EventAdWithObj(YwAdType.REWARD_VIDEO, YwAdStatus.REQUEST_FAIL, new AdEventParameter(utils.config.oppoconfig.videoId));
  493. utils.showLog("激励视频出错: " + err.code + err.msg);
  494. self._videoLoaded = false;
  495. if (self._videoCallback) {
  496. self._videoCallback(false, "暂无视频广告!");
  497. self._videoCallback = null;
  498. }
  499. });
  500. this._videoAd.onClose((res) => {
  501. setTimeout(() => {
  502. self._videoAd.load();
  503. YouWanAnalytics.EventAdWithObj(YwAdType.REWARD_VIDEO, YwAdStatus.REQUEST, new AdEventParameter(utils.config.oppoconfig.videoId));
  504. utils.showLog("延迟3秒重新加载视频广告");
  505. }, 3000);
  506. if (res.isEnded) {
  507. this.lastLastShowVideoTime = new Date().getTime();
  508. utils.showLog('激励视频广告完成,发放奖励');
  509. if (self._videoCallback) {
  510. self._videoCallback(true, "");
  511. self._videoCallback = null;
  512. }
  513. YouWanAnalytics.EventAdWithObj(YwAdType.REWARD_VIDEO, YwAdStatus.REWARD_SUCCESS, new AdEventParameter(utils.config.oppoconfig.videoId));
  514. } else {
  515. utils.showLog('激励视频广告取消关闭,不发放奖励');
  516. YouWanAnalytics.EventAdWithObj(YwAdType.REWARD_VIDEO, YwAdStatus.REWARD_FAIL, new AdEventParameter(utils.config.oppoconfig.videoId));
  517. if (self._videoCallback) {
  518. self._videoCallback(false, "观看完视频才能获得奖励!");
  519. self._videoCallback = null;
  520. }
  521. }
  522. });
  523. }
  524. } else {
  525. utils.showLog("视频广告Id配置错误!");
  526. }
  527. }
  528. }
  529. /**
  530. * 验证插屏是否能展示
  531. * 1、次数限制 默认每日8次
  532. * 2、时间限制 默认60秒
  533. */
  534. private checkInsertAdShow(): boolean {
  535. let maxShowCount = this.ServerConfig.intersititial_max_show_count;
  536. let intervalTime = this.ServerConfig.intersititial_interval_time;
  537. let curTime: number = new Date().getTime();
  538. let interval: number = (curTime - this._insertLastShowTime) / 1000;
  539. utils.showLog("OPPO服务器插屏最大显示次数为:" + maxShowCount + ",间隔显示时间为:" + intervalTime + "秒!");
  540. utils.showLog("OPPO插屏当前广告显示次数:" + utils.oppoTool.insertAdShowCounts + "次,间隔时间:" + interval + "秒!");
  541. if (maxShowCount > 0 && utils.oppoTool.insertAdShowCounts >= maxShowCount) {
  542. utils.showLog("OPPO插屏广告显示的次数达到" + maxShowCount + "次。插屏不显示");
  543. return false;
  544. }
  545. if (intervalTime > 0 && interval < intervalTime) {
  546. utils.showLog("OPPO插屏广告显示的间隔少于" + intervalTime + "秒。插屏不显示");
  547. return false;
  548. }
  549. return true;
  550. }
  551. /**
  552. * 验证是否第一次创建插屏
  553. */
  554. miniInserAdIsCreate: boolean = false;
  555. // /**
  556. // * 创建小程序插屏广告
  557. // * @param isUnique 是否唯一展示 不轮询显示原生
  558. // */
  559. _createMiniGameInsertAd(isUnique: boolean = false) {
  560. if (PlatUtils.IsOPPO) {
  561. this._isInsertShow = true;
  562. if (this._isAdInit
  563. && utils.config.oppoconfig
  564. && utils.config.oppoconfig.insertId) {
  565. //@ts-ignore
  566. let _insertAd = qg.createInsertAd({
  567. adUnitId: utils.config.oppoconfig.insertId
  568. });
  569. if (_insertAd) {
  570. utils.showLog("注册小游戏插屏广告回调!");
  571. let clearCallBack = () => {
  572. _insertAd.offShow();
  573. _insertAd.offError();
  574. _insertAd.offLoad();
  575. }
  576. _insertAd.onError(((err) => {
  577. utils.showLog("OPPO 小游戏插屏广告出错:" + err.code + err.msg);
  578. if (this._isInsertShow && !isUnique) {
  579. if (this.ServerConfig.intersititial_first_ad == "default") {
  580. this._isInsertShow = false;
  581. utils.showLog("开始显示原生插屏广告!");
  582. this._curPosIdIndexNativeInser = 0;
  583. utils.delayCall(this.nativeInserAdDelayCall.bind(this), this.ServerConfig.intersititia_delay_show_time || 0);
  584. }
  585. }
  586. _insertAd.offError();
  587. clearCallBack();
  588. }).bind(this));
  589. _insertAd.onLoad((() => {
  590. utils.showLog("OPPO 小程序插屏广告加载成功!");
  591. if (this._isInsertShow) {
  592. this._isInsertShow = false;
  593. _insertAd.show();
  594. //onShow
  595. this._isInsertShow = false;
  596. utils.oppoTool.countInserShowCount();
  597. this._insertLastShowTime = new Date().getTime();
  598. let closeType = this.ServerConfig.intersititial_open_close_banner;
  599. if (closeType && closeType > 0) {
  600. utils.showLog("OPPO 配置当前插屏显示成功后" + (closeType == 1 ? "销毁" : "隐藏") + "banner!");
  601. this.HideBanner();
  602. }
  603. }
  604. // _insertAd.offLoad();
  605. // clearCallBack();
  606. }).bind(this));
  607. _insertAd.onShow((() => {
  608. utils.showLog("OPPO 小游戏插屏广告显示成功! ");
  609. // _insertAd.offShow();
  610. clearCallBack();
  611. }).bind(this));
  612. /**
  613. * 第一次调用不需要手动load
  614. */
  615. if (!this.miniInserAdIsCreate) {
  616. this.miniInserAdIsCreate = true;
  617. } else {
  618. _insertAd.load();
  619. }
  620. }
  621. if (!_insertAd) {
  622. utils.showLog("OPPO小游戏插屏广告创建失败!");
  623. if (this.ServerConfig.intersititial_first_ad == "default" && !isUnique) {
  624. utils.showLog("开始显示原生插屏广告!");
  625. this._curPosIdIndexNativeInser = 0;
  626. utils.delayCall(this.nativeInserAdDelayCall.bind(this), this.ServerConfig.intersititia_delay_show_time || 0);
  627. }
  628. }
  629. } else {
  630. utils.showLog("OPPO 小游戏插屏广告配置信息错误!");
  631. if (this.ServerConfig.intersititial_first_ad == "default" && !isUnique) {
  632. utils.showLog("开始显示原生插屏广告!");
  633. this._curPosIdIndexNativeInser = 0;
  634. utils.delayCall(this.nativeInserAdDelayCall.bind(this), this.ServerConfig.intersititia_delay_show_time || 0);
  635. }
  636. }
  637. }
  638. }
  639. // /**
  640. // * 创建小程序插屏广告
  641. // * @param isUnique 是否唯一展示 不轮询显示原生
  642. // */
  643. _createMiniGameInsertAdByConfig(index: number) {
  644. if (PlatUtils.IsOPPO) {
  645. this._isInsertShow = true;
  646. utils.showLog("_createMiniGameInsertAdByIndex: index=" + index);
  647. if (this._isAdInit
  648. && utils.config.oppoconfig
  649. && index < utils.config.oppoconfig.intersitialAdConfigs.length) {
  650. //@ts-ignore
  651. let _insertAd = qg.createInsertAd({
  652. adUnitId: utils.config.oppoconfig.intersitialAdConfigs[index].id
  653. });
  654. YouWanAnalytics.EventAdWithObj(YwAdType.INTERSITITIAL, YwAdStatus.REQUEST, new AdEventParameter(utils.config.oppoconfig.intersitialAdConfigs[index].id));
  655. if (_insertAd) {
  656. utils.showLog("注册小游戏插屏广告回调!");
  657. let clearCallBack = () => {
  658. _insertAd.offShow();
  659. _insertAd.offError();
  660. _insertAd.offLoad();
  661. }
  662. _insertAd.onError(((err) => {
  663. utils.showLog("OPPO 小游戏插屏广告出错:" + err.code + err.msg);
  664. if (this._isInsertShow) {
  665. this.ShowInterstitialByConfigs(index + 1);
  666. }
  667. YouWanAnalytics.EventAdWithObj(YwAdType.INTERSITITIAL, YwAdStatus.REQUEST_FAIL, new AdEventParameter(utils.config.oppoconfig.intersitialAdConfigs[index].id, err.code, err.msg));
  668. _insertAd.offError();
  669. clearCallBack();
  670. }).bind(this));
  671. _insertAd.onLoad((() => {
  672. utils.showLog("OPPO 小程序插屏广告加载成功!");
  673. YouWanAnalytics.EventAdWithObj(YwAdType.INTERSITITIAL, YwAdStatus.REQUEST_SUCCESS, new AdEventParameter(utils.config.oppoconfig.intersitialAdConfigs[index].id));
  674. if (this._isInsertShow) {
  675. this._isInsertShow = false;
  676. _insertAd.show();
  677. //onShow
  678. this._isInsertShow = false;
  679. utils.oppoTool.countInserShowCount();
  680. this._insertLastShowTime = new Date().getTime();
  681. let closeType = this.ServerConfig.intersititial_open_close_banner;
  682. if (closeType && closeType > 0) {
  683. utils.showLog("OPPO 配置当前插屏显示成功后" + (closeType == 1 ? "销毁" : "隐藏") + "banner!");
  684. this.HideBanner();
  685. }
  686. }
  687. // _insertAd.offLoad();
  688. // clearCallBack();
  689. }).bind(this));
  690. _insertAd.onShow((() => {
  691. utils.showLog("OPPO 小游戏插屏广告显示成功! ");
  692. YouWanAnalytics.EventAd(YwAdType.INTERSITITIAL, YwAdStatus.AD_ID_REQUEST_SUCCESS);
  693. YouWanAnalytics.EventAdWithObj(YwAdType.INTERSITITIAL, YwAdStatus.SHOW_SUCCESS, new AdEventParameter(utils.config.oppoconfig.intersitialAdConfigs[index].id));
  694. // _insertAd.offShow();
  695. clearCallBack();
  696. }).bind(this));
  697. /**
  698. * 第一次调用不需要手动load
  699. */
  700. if (!this.miniInserAdIsCreate) {
  701. this.miniInserAdIsCreate = true;
  702. } else {
  703. _insertAd.load();
  704. }
  705. }
  706. if (!_insertAd) {
  707. YouWanAnalytics.EventAdWithObj(YwAdType.INTERSITITIAL, YwAdStatus.REQUEST_FAIL, new AdEventParameter(utils.config.oppoconfig.intersitialAdConfigs[index].id));
  708. utils.showLog("OPPO小游戏插屏广告创建失败!");
  709. this.ShowInterstitialByConfigs(index + 1);
  710. }
  711. } else {
  712. utils.showLog("OPPO 小游戏插屏广告配置信息错误!");
  713. // if (this.ServerConfig.intersititial_first_ad == "default" && !isUnique) {
  714. // utils.showLog("开始显示原生插屏广告!");
  715. // this._curPosIdIndexNativeInser = 0;
  716. // utils.delayCall(this.nativeInserAdDelayCall.bind(this), this.ServerConfig.intersititia_delay_show_time || 0);
  717. // }
  718. }
  719. }
  720. }
  721. _createMiniGameBannerAd(location: BannerLocation = null) {
  722. if (PlatUtils.IsOPPO) {
  723. this._isBannerShow = true;
  724. if (this._isAdInit
  725. && utils.config.oppoconfig
  726. && utils.config.oppoconfig.bannerId) {
  727. let style: any = {
  728. top: 0
  729. }
  730. if (this.getNativeBannerInfo()._alignType === "top") {
  731. style.top = 0;
  732. } else {
  733. style = null;
  734. }
  735. if (!this._bannerAd || true) {
  736. //@ts-ignore
  737. this._bannerAd = qg.createBannerAd({
  738. posId: utils.config.oppoconfig.bannerId,
  739. style
  740. });
  741. if (this._bannerAd) {
  742. utils.showLog("注册小游戏banner回调!");
  743. this._bannerAd.onError(((err) => {
  744. utils.showLog("OPPO 小游戏Banner广告出错: " + err.code + err.msg);
  745. let bannerInfo = this.getNativeBannerInfo();
  746. if (bannerInfo.st_banner_show_back_up == -1) {
  747. utils.showLog("服务器配置不显示备用广告");
  748. return;
  749. }
  750. if (this._isBannerShow) {
  751. this._isBannerShow = false;
  752. if (this.ServerConfig.banner_first_ad.indexOf("default") > -1) {
  753. this._curPosIdIndexNativeBanner = 0;
  754. this._createNativeBannerAd(this._showNativeBanner.bind(this));
  755. } else {
  756. //显示自定义banner
  757. if (utils.isShowRecommondGamesBanner()) {
  758. clearTimeout(this._showBannerTimerId);
  759. utils.showRecommendGamesBanner();
  760. utils.showLog(`小游戏、原生广告条都无法展示,展示自定义banner`);
  761. return;
  762. }
  763. }
  764. }
  765. }).bind(this));
  766. this._bannerAd.onShow((() => {
  767. utils.showLog("OPPO 小游戏Banner显示成功!");
  768. if (this._nativeBannerNode) {
  769. this._nativeBannerNode.active = false;
  770. }
  771. utils.hideRecommendGamesBanner();
  772. // if (this._bannerIsHide) {
  773. // this._bannerAd.hide();
  774. // utils.showLog("当前Banner广告为隐藏状态。调用隐藏!");
  775. // }
  776. this._showBannerCallBack && this._showBannerCallBack();
  777. this._showBannerCallBack = null;
  778. }).bind(this));
  779. // this._bannerAd.onResize((obj) => {
  780. // utils.showLog("on resize >>>>" + JSON.stringify(obj));
  781. // utils.showLog('banner 宽度:' + obj.width + ', banner 高度:' + obj.height + " ,top" + obj.top)
  782. // })
  783. this._bannerAd.onHide(function () {
  784. if (!this._isNativeBannerShow) {
  785. utils.oppoTool.countBannerCloseCount();
  786. utils.showLog("OPPO 小游戏Banner 广告隐藏,当前隐藏次数>" + utils.oppoTool.bannerAdCloseCounts);
  787. } else {
  788. this._isNativeBannerShow = false;
  789. utils.showLog("OPPO 小游戏Banner 广告隐藏,来自原生的显示,不增加隐藏次数,当前隐藏次数>" + utils.oppoTool.bannerAdCloseCounts);
  790. }
  791. })
  792. // _miniBannerHeight
  793. } else {
  794. if (this.ServerConfig.banner_first_ad.indexOf("default") > -1) {
  795. this._curPosIdIndexNativeBanner = 0;
  796. this._createNativeBannerAd(this._showNativeBanner.bind(this));
  797. } else {
  798. //显示自定义banner
  799. if (utils.isShowRecommondGamesBanner()) {
  800. clearTimeout(this._showBannerTimerId);
  801. utils.showRecommendGamesBanner();
  802. utils.showLog(`小游戏、原生广告条都无法展示,展示自定义banner`);
  803. return;
  804. }
  805. }
  806. }
  807. }
  808. if (this._bannerAd) {
  809. if (this.getNativeBannerInfo()._alignType !== "top") {
  810. this._bannerAd.style.top = utils.oppoTool.SysInfo.screenHeight;
  811. }
  812. this._bannerAd.show();
  813. } else {
  814. utils.showLog("OPPO 小游戏Banner广告创建失败!");
  815. if (this.ServerConfig.indexOf("default") > -1) {
  816. this._curPosIdIndexNativeBanner = 0;
  817. this._createNativeBannerAd(this._showNativeBanner.bind(this));
  818. } else {
  819. //显示自定义banner
  820. if (utils.isShowRecommondGamesBanner()) {
  821. clearTimeout(this._showBannerTimerId);
  822. utils.showRecommendGamesBanner();
  823. utils.showLog(`小游戏、原生广告条都无法展示,展示自定义banner`);
  824. return;
  825. }
  826. }
  827. }
  828. } else {
  829. utils.showLog("OPPO 小游戏Banner广告配置信息错误!");
  830. let bannerInfo = this.getNativeBannerInfo();
  831. if (bannerInfo.st_banner_show_back_up == -1) {
  832. utils.showLog("服务器配置不显示备用广告");
  833. return;
  834. }
  835. if (this.ServerConfig.banner_first_ad.indexOf("default") > -1) {
  836. this._curPosIdIndexNativeBanner = 0;
  837. this._createNativeBannerAd(this._showNativeBanner.bind(this));
  838. } else {
  839. //显示自定义banner
  840. if (utils.isShowRecommondGamesBanner()) {
  841. clearTimeout(this._showBannerTimerId);
  842. utils.showRecommendGamesBanner();
  843. utils.showLog(`小游戏、原生广告条都无法展示,展示自定义banner`);
  844. return;
  845. }
  846. }
  847. }
  848. }
  849. }
  850. _createMiniGameBannerAdByConfigs(index: number) {
  851. utils.showLog("_createMiniGameBannerAdByConfigs: #index=" + index);
  852. if (PlatUtils.IsOPPO) {
  853. this._isBannerShow = true;
  854. YouWanAnalytics.EventAdWithObj(YwAdType.BANNER, YwAdStatus.REQUEST, new AdEventParameter(utils.config.oppoconfig.bannerAdConfigs[index].id));
  855. if (this._isAdInit
  856. && utils.config.oppoconfig
  857. && index < utils.config.oppoconfig.bannerAdConfigs.length) {
  858. let style: any = {
  859. top: 0
  860. }
  861. if (this.getNativeBannerInfo()._alignType === "top") {
  862. style.top = 0;
  863. } else {
  864. style = null;
  865. }
  866. //@ts-ignore
  867. this._bannerAd = qg.createBannerAd({
  868. posId: utils.config.oppoconfig.bannerAdConfigs[index].id,
  869. style
  870. });
  871. if (this._bannerAd) {
  872. utils.showLog("注册小游戏banner回调!");
  873. this._bannerAd.onError((err) => {
  874. this._bannerAd.offError();
  875. YouWanAnalytics.EventAdWithObj(YwAdType.BANNER, YwAdStatus.REQUEST_FAIL, new AdEventParameter(utils.config.oppoconfig.bannerAdConfigs[index].id));
  876. utils.showLog("OPPO 小游戏 Configs Banner广告出错: " + err.code + err.msg);
  877. let bannerInfo = this.getNativeBannerInfo();
  878. if (bannerInfo.st_banner_show_back_up == -1) {
  879. utils.showLog("服务器配置不显示备用广告");
  880. YouWanAnalytics.EventAd(YwAdType.BANNER, YwAdStatus.AD_ID_REQUEST_FAIL);
  881. return;
  882. }
  883. if (this._isBannerShow) {
  884. this._isBannerShow = false;
  885. this.ShowBannerByConfigs(index + 1);
  886. }
  887. });
  888. // this._bannerAd.onShow((() => {
  889. // this._bannerAd.offShow();
  890. // utils.showLog("OPPO 小游戏Banner显示成功!");
  891. // this.hideBanner("default");
  892. // this._showBannerCallBack && this._showBannerCallBack();
  893. // this._showBannerCallBack = null;
  894. // }).bind(this));
  895. // this._bannerAd.onResize((obj) => {
  896. // utils.showLog("on resize >>>>" + JSON.stringify(obj));
  897. // utils.showLog('banner 宽度:' + obj.width + ', banner 高度:' + obj.height + " ,top" + obj.top)
  898. // })
  899. this._bannerAd.onHide(() => {
  900. this._bannerAd.offHide();
  901. if (!this._isNativeBannerShow) {
  902. utils.oppoTool.countBannerCloseCount();
  903. utils.showLog("OPPO 小游戏Banner 广告隐藏,当前隐藏次数>" + utils.oppoTool.bannerAdCloseCounts);
  904. } else {
  905. this._isNativeBannerShow = false;
  906. utils.showLog("OPPO 小游戏Banner 广告隐藏,来自原生的显示,不增加隐藏次数,当前隐藏次数>" + utils.oppoTool.bannerAdCloseCounts);
  907. }
  908. })
  909. if (this.getNativeBannerInfo()._alignType !== "top") {
  910. this._bannerAd.style.top = utils.oppoTool.SysInfo.screenHeight;
  911. }
  912. this._bannerAd.show().then(() => {
  913. this._bannerAd.offShow();
  914. utils.showLog("OPPO 小游戏Banner显示成功!");
  915. YouWanAnalytics.EventAdWithObj(YwAdType.BANNER, YwAdStatus.SHOW_SUCCESS, new AdEventParameter(utils.config.oppoconfig.bannerAdConfigs[index].id));
  916. YouWanAnalytics.EventAd(YwAdType.BANNER, YwAdStatus.AD_ID_REQUEST_SUCCESS);
  917. this.hideBanner("default");
  918. this._showBannerCallBack && this._showBannerCallBack();
  919. this._showBannerCallBack = null;
  920. });
  921. } else {
  922. this.ShowBannerByConfigs(index + 1);
  923. YouWanAnalytics.EventAdWithObj(YwAdType.BANNER, YwAdStatus.REQUEST_FAIL, new AdEventParameter(utils.config.oppoconfig.bannerAdConfigs[index].id));
  924. YouWanAnalytics.EventAd(YwAdType.BANNER, YwAdStatus.AD_ID_REQUEST_FAIL);
  925. }
  926. } else {
  927. utils.showLog("OPPO 小游戏Banner广告配置信息错误!");
  928. let bannerInfo = this.getNativeBannerInfo();
  929. if (bannerInfo.st_banner_show_back_up == -1) {
  930. YouWanAnalytics.EventAd(YwAdType.BANNER, YwAdStatus.AD_ID_REQUEST_FAIL);
  931. utils.showLog("服务器配置不显示备用广告");
  932. return;
  933. }
  934. this.ShowBannerByConfigs(index + 1);
  935. }
  936. }
  937. }
  938. _createNativeBannerAdByConfigs(index: number) {
  939. if (PlatUtils.IsOPPO) {
  940. YouWanAnalytics.EventAdWithObj(YwAdType.NATIVE_BANNER, YwAdStatus.REQUEST, new AdEventParameter(utils.config.oppoconfig.bannerAdConfigs[index].id));
  941. utils.showLog("_createNativeBannerAdByConfigs: #index=" + index);
  942. if (this._isAdInit
  943. && utils.config.oppoconfig
  944. && index < utils.config.oppoconfig.bannerAdConfigs.length) {
  945. let nativeBannerAd = utils.config.oppoconfig.bannerAdConfigs[index].nativeBannerAd;
  946. if (!nativeBannerAd) {
  947. utils.showLog("创建原生广告Banner。 posId:" + utils.config.oppoconfig.bannerAdConfigs[index].id);
  948. //@ts-ignore
  949. nativeBannerAd = qg.createNativeAd({
  950. posId: utils.config.oppoconfig.bannerAdConfigs[index].id
  951. });
  952. if (nativeBannerAd) {
  953. utils.config.oppoconfig.bannerAdConfigs[index].nativeBannerAd = nativeBannerAd;
  954. nativeBannerAd.onLoad((res) => {
  955. YouWanAnalytics.EventAdWithObj(YwAdType.NATIVE_BANNER, YwAdStatus.REQUEST_SUCCESS, new AdEventParameter(utils.config.oppoconfig.bannerAdConfigs[index].id));
  956. if (this._nativeIsClose) {
  957. utils.showLog("隐藏了BANNER,不做任何处理!");
  958. return;
  959. }
  960. if (res && res.adList && res.adList.length > 0) {
  961. this._startBannerTimerTask = new Date().getTime();
  962. utils.showLog("原生Banner广告资源拉取成功!");
  963. utils.showLog(JSON.stringify(res));
  964. res = JSON.parse(JSON.stringify(res));
  965. let data = res.adList[0];
  966. //如果当前显示为结算banner,则不做数据验证
  967. if (this._checkNativeDataValid(data) || this.getNativeBannerInfo().show_st_banner == "true") {
  968. if (this.canShowNativeBanner) {
  969. this._curPosIdIndexNativeBanner = 0;
  970. this._showNativeBanner(nativeBannerAd, data);
  971. this._curNativeBannerInfo.nativeBannerAd = nativeBannerAd;
  972. this._curNativeBannerInfo.data = data;
  973. this.hideBanner("native");
  974. YouWanAnalytics.EventAdWithObj(YwAdType.NATIVE_BANNER, YwAdStatus.SHOW_SUCCESS, new AdEventParameter(utils.config.oppoconfig.bannerAdConfigs[index].id));
  975. YouWanAnalytics.EventAd(YwAdType.BANNER, YwAdStatus.AD_ID_REQUEST_SUCCESS);
  976. } else {
  977. utils.showLog("已经隐藏banner不可重复展示")
  978. }
  979. return;
  980. }
  981. }
  982. utils.showLog("原生Banner广告资源出错!");
  983. let bannerInfo = this.getNativeBannerInfo();
  984. if (bannerInfo.st_banner_show_back_up == -1) {
  985. utils.showLog(">>>>>服务器配置不显示备用广告!");
  986. YouWanAnalytics.EventAdWithObj(YwAdType.NATIVE_BANNER, YwAdStatus.REQUEST_FAIL, new AdEventParameter(utils.config.oppoconfig.bannerAdConfigs[index].id));
  987. YouWanAnalytics.EventAd(YwAdType.BANNER, YwAdStatus.AD_ID_REQUEST_FAIL);
  988. return;
  989. }
  990. this.ShowBannerByConfigs(index + 1);
  991. });
  992. nativeBannerAd.onError((err) => {
  993. YouWanAnalytics.EventAdWithObj(YwAdType.NATIVE_BANNER, YwAdStatus.REQUEST_FAIL, new AdEventParameter(utils.config.oppoconfig.bannerAdConfigs[index].id));
  994. if (this._nativeIsClose) {
  995. utils.showLog("隐藏了BANNER,不做任何处理!");
  996. return;
  997. }
  998. utils.showLog("原生Banner广告资源拉取失败!" + err.code + err.msg);
  999. // 原生广告遍历完毕
  1000. let bannerInfo = this.getNativeBannerInfo();
  1001. if (bannerInfo.st_banner_show_back_up == -1) {
  1002. utils.showLog(">>>>>服务器配置不显示备用广告!");
  1003. YouWanAnalytics.EventAd(YwAdType.BANNER, YwAdStatus.AD_ID_REQUEST_FAIL);
  1004. return;
  1005. }
  1006. this.ShowBannerByConfigs(index + 1);
  1007. });
  1008. }
  1009. }
  1010. if (nativeBannerAd) {
  1011. utils.showLog("nativeBannerAd reLoad>>");
  1012. nativeBannerAd.load();
  1013. } else {
  1014. let bannerInfo = this.getNativeBannerInfo();
  1015. if (bannerInfo.st_banner_show_back_up == -1) {
  1016. utils.showLog(">>>>>服务器配置不显示备用广告!");
  1017. YouWanAnalytics.EventAd(YwAdType.BANNER, YwAdStatus.AD_ID_REQUEST_FAIL);
  1018. return;
  1019. }
  1020. this.ShowBannerByConfigs(index + 1);
  1021. }
  1022. }
  1023. }
  1024. }
  1025. _curNativeBannerInfo: any = {};
  1026. _createNativeBannerAd(completeCallback: Function) {
  1027. if (PlatUtils.IsOPPO) {
  1028. let callback = completeCallback;
  1029. utils.showLog("curPosIdIndexNativeBanner:" + this._curPosIdIndexNativeBanner);
  1030. let nativeBannerAd = this._nativeBannerAd[this._curPosIdIndexNativeBanner];
  1031. if (!nativeBannerAd) {
  1032. if (utils.config.oppoconfig.nativeBannerIds
  1033. && utils.config.oppoconfig.nativeBannerIds[this._curPosIdIndexNativeBanner]) {
  1034. utils.showLog("创建原生广告Banner。 posId:" + utils.config.oppoconfig.nativeBannerIds[this._curPosIdIndexNativeBanner]);
  1035. //@ts-ignore
  1036. nativeBannerAd = qg.createNativeAd({
  1037. posId: utils.config.oppoconfig.nativeBannerIds[this._curPosIdIndexNativeBanner]
  1038. });
  1039. if (nativeBannerAd) {
  1040. this._nativeBannerAd.push(nativeBannerAd);
  1041. nativeBannerAd.onLoad((res) => {
  1042. if (this._nativeIsClose) {
  1043. utils.showLog("隐藏了BANNER,不做任何处理!");
  1044. return;
  1045. }
  1046. if (res && res.adList && res.adList.length > 0) {
  1047. this._startBannerTimerTask = new Date().getTime();
  1048. utils.showLog("原生Banner广告资源拉取成功!");
  1049. utils.showLog(JSON.stringify(res));
  1050. res = JSON.parse(JSON.stringify(res));
  1051. let data = res.adList[0];
  1052. //如果当前显示为结算banner,则不做数据验证
  1053. if (this._checkNativeDataValid(data) || this.getNativeBannerInfo().show_st_banner == "true") {
  1054. if (this.canShowNativeBanner) {
  1055. this._curPosIdIndexNativeBanner = 0;
  1056. this._showNativeBanner(nativeBannerAd, data);
  1057. this._curNativeBannerInfo.nativeBannerAd = nativeBannerAd;
  1058. this._curNativeBannerInfo.data = data;
  1059. // 删除当前广告
  1060. if (this._bannerAd) {
  1061. this._isNativeBannerShow = true;
  1062. if (utils.oppoTool.isOverMiniVersion("1050")) {
  1063. utils.showLog("销毁小游戏Banner");
  1064. this._bannerAd.destroy();
  1065. this._bannerAd = null;
  1066. } else {
  1067. utils.showLog("当前小游戏平台小于1051,只能隐藏小游戏Banner");
  1068. this._bannerAd.hide();
  1069. }
  1070. }
  1071. utils.hideRecommendGamesBanner();
  1072. } else {
  1073. cc.warn("已经隐藏banner不可重复展示")
  1074. }
  1075. return;
  1076. }
  1077. }
  1078. utils.showLog("原生Banner广告资源出错!");
  1079. this._curPosIdIndexNativeBanner++;
  1080. if (this._curPosIdIndexNativeBanner < utils.config.oppoconfig.nativeBannerIds.length) {
  1081. this._createNativeBannerAd(callback);
  1082. } else {
  1083. this._curPosIdIndexNativeBanner = 0;
  1084. // 原生广告遍历完毕
  1085. utils.showLog("原生广告条遍历完毕,无法展示!");
  1086. let bannerInfo = this.getNativeBannerInfo();
  1087. if (bannerInfo.st_banner_show_back_up == -1) {
  1088. utils.showLog(">>>>>服务器配置不显示备用广告!");
  1089. return;
  1090. }
  1091. if (this.ServerConfig.banner_first_ad.indexOf("native") > -1) {
  1092. utils.showLog("开始展示小游戏广告条!")
  1093. this._createMiniGameBannerAd();
  1094. } else {
  1095. //显示自定义banner
  1096. if (utils.isShowRecommondGamesBanner()) {
  1097. clearTimeout(this._showBannerTimerId);
  1098. utils.showRecommendGamesBanner();
  1099. utils.showLog(`小游戏、原生广告条都无法展示,展示自定义banner`);
  1100. return;
  1101. }
  1102. }
  1103. }
  1104. });
  1105. nativeBannerAd.onError((err) => {
  1106. if (this._nativeIsClose) {
  1107. utils.showLog("隐藏了BANNER,不做任何处理!");
  1108. return;
  1109. }
  1110. utils.showLog("原生Banner广告资源拉取失败!" + err.code + err.msg);
  1111. this._curPosIdIndexNativeBanner++;
  1112. if (this._curPosIdIndexNativeBanner < utils.config.oppoconfig.nativeBannerIds.length) {
  1113. this._createNativeBannerAd(callback);
  1114. } else {
  1115. this._curPosIdIndexNativeBanner = 0;
  1116. // 原生广告遍历完毕
  1117. utils.showLog("原生广告条遍历完毕,无法展示!");
  1118. let bannerInfo = this.getNativeBannerInfo();
  1119. if (bannerInfo.st_banner_show_back_up == -1) {
  1120. utils.showLog(">>>>>服务器配置不显示备用广告!");
  1121. return;
  1122. }
  1123. if (this.ServerConfig.banner_first_ad.indexOf("native") > -1) {
  1124. utils.showLog("开始展示小游戏广告条!")
  1125. this._createMiniGameBannerAd();
  1126. } else {
  1127. //显示自定义banner
  1128. if (utils.isShowRecommondGamesBanner()) {
  1129. clearTimeout(this._showBannerTimerId);
  1130. utils.showRecommendGamesBanner();
  1131. utils.showLog(`小游戏、原生广告条都无法展示,展示自定义banner`);
  1132. return;
  1133. }
  1134. }
  1135. }
  1136. });
  1137. }
  1138. }
  1139. }
  1140. if (nativeBannerAd) {
  1141. utils.showLog("nativeBannerAd reLoad>>");
  1142. nativeBannerAd.load();
  1143. } else {
  1144. this._curPosIdIndexNativeBanner++;
  1145. if (utils.config.oppoconfig.nativeBannerIds && this._curPosIdIndexNativeBanner < utils.config.oppoconfig.nativeBannerIds.length) {
  1146. this._createNativeBannerAd(callback);
  1147. } else {
  1148. this._curPosIdIndexNativeBanner = 0;
  1149. // 原生广告遍历完毕
  1150. utils.showLog("原生广告条遍历完毕,无法展示!");
  1151. let bannerInfo = this.getNativeBannerInfo();
  1152. if (bannerInfo.st_banner_show_back_up == -1) {
  1153. utils.showLog(">>>>>服务器配置不显示备用广告!");
  1154. return;
  1155. }
  1156. if (this.ServerConfig.banner_first_ad.indexOf("native") > -1) {
  1157. utils.showLog("开始展示小游戏广告条!")
  1158. this._createMiniGameBannerAd();
  1159. } else {
  1160. //显示自定义banner
  1161. if (utils.isShowRecommondGamesBanner()) {
  1162. clearTimeout(this._showBannerTimerId);
  1163. utils.showRecommendGamesBanner();
  1164. utils.showLog(`小游戏、原生广告条都无法展示,展示自定义banner`);
  1165. return;
  1166. }
  1167. }
  1168. }
  1169. }
  1170. }
  1171. }
  1172. _createNativeInsertAd(completeCallback: Function) {
  1173. if (PlatUtils.IsOPPO) {
  1174. let callback = completeCallback;
  1175. utils.showLog("curPosIdIndexNativeInsert:" + this._curPosIdIndexNativeInser);
  1176. let nativeInsertAd = this._nativeInsertAd[this._curPosIdIndexNativeInser];
  1177. if (!nativeInsertAd) {
  1178. if (utils.config.oppoconfig.nativeInsertIds
  1179. && utils.config.oppoconfig.nativeInsertIds[this._curPosIdIndexNativeInser]) {
  1180. utils.showLog("创建原生插屏广告。 posId:" + utils.config.oppoconfig.nativeInsertIds[this._curPosIdIndexNativeInser]);
  1181. //@ts-ignore
  1182. nativeInsertAd = qg.createNativeAd({
  1183. posId: utils.config.oppoconfig.nativeInsertIds[this._curPosIdIndexNativeInser]
  1184. });
  1185. if (nativeInsertAd) {
  1186. this._nativeInsertAd.push(nativeInsertAd);
  1187. nativeInsertAd.onLoad((res) => {
  1188. if (res && res.adList && res.adList.length > 0) {
  1189. utils.showLog("原生插屏广告资源拉取成功!");
  1190. utils.showLog(JSON.stringify(res));
  1191. res = JSON.parse(JSON.stringify(res));
  1192. let data = res.adList[0];
  1193. if (this._checkNativeInsertDataValid(data)) {
  1194. this._curPosIdIndexNativeInser = 0;
  1195. this._showNativeInsert(nativeInsertAd, data);
  1196. return;
  1197. } else {
  1198. utils.showLog("原生插屏广告资源不合法!");
  1199. }
  1200. }
  1201. utils.showLog("原生插屏广告资源出错!");
  1202. this._curPosIdIndexNativeInser++;
  1203. if (this._curPosIdIndexNativeInser < utils.config.oppoconfig.nativeInsertIds.length) {
  1204. this._createNativeInsertAd(callback);
  1205. } else {
  1206. this._curPosIdIndexNativeInser = 0;
  1207. // 原生广告遍历完毕
  1208. utils.showLog("原生插屏广告遍历完毕,无法展示!");
  1209. if (this.ServerConfig.intersititial_first_ad == "native") {
  1210. utils.showLog("开始展示小游戏插屏广告!");
  1211. this._createMiniGameInsertAd();
  1212. }
  1213. }
  1214. });
  1215. nativeInsertAd.onError((err) => {
  1216. utils.showLog("原生插屏广告资源拉取失败!" + err.code + err.msg);
  1217. this._curPosIdIndexNativeInser++;
  1218. if (this._curPosIdIndexNativeInser < utils.config.oppoconfig.nativeInsertIds.length) {
  1219. this._createNativeInsertAd(callback);
  1220. } else {
  1221. this._curPosIdIndexNativeInser = 0;
  1222. // 原生广告遍历完毕
  1223. utils.showLog("原生插屏广告遍历完毕,无法展示!");
  1224. if (this.ServerConfig.intersititial_first_ad == "native") {
  1225. utils.showLog("开始展示小游戏插屏广告!");
  1226. this._createMiniGameInsertAd();
  1227. }
  1228. }
  1229. });
  1230. }
  1231. }
  1232. }
  1233. if (nativeInsertAd) {
  1234. nativeInsertAd.load();
  1235. } else {
  1236. this._curPosIdIndexNativeInser++;
  1237. if (utils.config.oppoconfig.nativeInsertIds && this._curPosIdIndexNativeInser < utils.config.oppoconfig.nativeInsertIds.length) {
  1238. this._createNativeInsertAd(callback);
  1239. } else {
  1240. this._curPosIdIndexNativeInser = 0;
  1241. // 原生广告遍历完毕
  1242. utils.showLog("原生插屏广告遍历完毕,无法展示!");
  1243. if (this.ServerConfig.intersititial_first_ad == "native") {
  1244. utils.showLog("开始展示小游戏插屏广告!");
  1245. this._createMiniGameInsertAd();
  1246. }
  1247. }
  1248. }
  1249. }
  1250. }
  1251. _createNativeInsertAdByConfig(index: number) {
  1252. if (PlatUtils.IsOPPO) {
  1253. utils.showLog("_createNativeInsertAdByConfig: #index=" + index);
  1254. if (this._isAdInit
  1255. && utils.config.oppoconfig
  1256. && index < utils.config.oppoconfig.intersitialAdConfigs.length) {
  1257. let nativeInsertAd = utils.config.oppoconfig.intersitialAdConfigs[index].nativeInsertAd;
  1258. YouWanAnalytics.EventAdWithObj(YwAdType.NATIVE_INTERSITITIAL, YwAdStatus.REQUEST, new AdEventParameter(utils.config.oppoconfig.intersitialAdConfigs[index].id));
  1259. if (!nativeInsertAd) {
  1260. if (utils.config.oppoconfig.intersitialAdConfigs[index].id) {
  1261. utils.showLog("创建原生插屏广告。 posId:" + utils.config.oppoconfig.intersitialAdConfigs[index].id);
  1262. //@ts-ignore
  1263. nativeInsertAd = qg.createNativeAd({
  1264. posId: utils.config.oppoconfig.intersitialAdConfigs[index].id
  1265. });
  1266. if (nativeInsertAd) {
  1267. utils.config.oppoconfig.intersitialAdConfigs[index].nativeInsertAd = nativeInsertAd;
  1268. nativeInsertAd.onLoad((res) => {
  1269. YouWanAnalytics.EventAdWithObj(YwAdType.NATIVE_INTERSITITIAL, YwAdStatus.REQUEST_SUCCESS, new AdEventParameter(utils.config.oppoconfig.intersitialAdConfigs[index].id));
  1270. if (res && res.adList && res.adList.length > 0) {
  1271. utils.showLog("原生插屏广告资源拉取成功!");
  1272. utils.showLog(JSON.stringify(res));
  1273. res = JSON.parse(JSON.stringify(res));
  1274. let data = res.adList[0];
  1275. if (this._checkNativeInsertDataValid(data)) {
  1276. YouWanAnalytics.EventAd(YwAdType.INTERSITITIAL, YwAdStatus.AD_ID_REQUEST_SUCCESS);
  1277. YouWanAnalytics.EventAdWithObj(YwAdType.NATIVE_INTERSITITIAL, YwAdStatus.SHOW_SUCCESS, new AdEventParameter(utils.config.oppoconfig.intersitialAdConfigs[index].id));
  1278. this._showNativeInsert(nativeInsertAd, data);
  1279. return;
  1280. } else {
  1281. utils.showLog("原生插屏广告资源不合法!");
  1282. }
  1283. YouWanAnalytics.EventAdWithObj(YwAdType.NATIVE_INTERSITITIAL, YwAdStatus.REQUEST_FAIL, new AdEventParameter(utils.config.oppoconfig.intersitialAdConfigs[index].id));
  1284. }
  1285. utils.showLog("原生插屏广告资源出错!");
  1286. this.ShowInterstitialByConfigs(index + 1);
  1287. });
  1288. nativeInsertAd.onError((err) => {
  1289. utils.showLog("原生插屏广告资源拉取失败!" + err.code + err.msg);
  1290. YouWanAnalytics.EventAdWithObj(YwAdType.NATIVE_INTERSITITIAL, YwAdStatus.REQUEST_FAIL, new AdEventParameter(utils.config.oppoconfig.intersitialAdConfigs[index].id, err.code, err.msg));
  1291. this.ShowInterstitialByConfigs(index + 1);
  1292. });
  1293. }
  1294. }
  1295. }
  1296. if (nativeInsertAd) {
  1297. nativeInsertAd.load();
  1298. } else {
  1299. YouWanAnalytics.EventAdWithObj(YwAdType.NATIVE_INTERSITITIAL, YwAdStatus.REQUEST_FAIL, new AdEventParameter(utils.config.oppoconfig.intersitialAdConfigs[index].id));
  1300. utils.showLog("创建原生插屏失败:#index=" + index);
  1301. this.ShowInterstitialByConfigs(index + 1);
  1302. }
  1303. }
  1304. }
  1305. }
  1306. /**
  1307. * 获取原生广告数据
  1308. * @param args
  1309. */
  1310. getNativeAdData() {
  1311. if (!this._nativeAdObject) {
  1312. this._nativeAdObject = new YZ_NativeAdObject();
  1313. }
  1314. this._nativeAdObject._nativeObj = this._nativeAd;
  1315. if (this._nativeAdObject.data) {
  1316. if (this._nativeAdObject.data.adId != this._nativeData.adId) {
  1317. this._nativeAdObject.is_reportClick = false;
  1318. this._nativeAdObject.is_reportShow = false;
  1319. }
  1320. }
  1321. this._nativeAdObject.data = this._nativeData;
  1322. // setTimeout(() => {
  1323. // utils.showLog("延迟两秒重新请求原生广告数据");
  1324. // this._createNativeAd(args);
  1325. // }, 2000);
  1326. if (this._nativeData && this._nativeAd) {
  1327. // this._nativeData = null;
  1328. utils.showLog("获取原生数据 >>>", this._nativeData, "...", this._nativeAdObject)
  1329. return this._nativeAdObject;
  1330. }
  1331. return null;
  1332. }
  1333. _singleAdCreateTime: number = 0;
  1334. /**
  1335. * 创建单个原生广告
  1336. * @param completeCallback
  1337. */
  1338. createNativeAd(params: any = null, nativeItem?: YZ_NativeItem) {
  1339. utils.showLog("_createNativeAd >>>>>");
  1340. if (PlatUtils.IsOPPO) {
  1341. if (nativeItem) {
  1342. this._curNativeItem = nativeItem;
  1343. }
  1344. let refreshTime = this.ServerConfig.st_native_ad_refresh_time ? this.ServerConfig.st_native_ad_refresh_time : 0;
  1345. if (this._nativeAdObject && this._nativeAdObject.data && !this._nativeAdObject.is_reportClick && (new Date().getTime() - this._singleAdCreateTime) / 1000 < refreshTime) {
  1346. utils.showLog(`当前原生广告的展示时间${(new Date().getTime() - this._singleAdCreateTime) / 1000}秒,未达刷新时间${refreshTime}秒限制,直接使用上一次数据!`);
  1347. this._showNativeAd();
  1348. return;
  1349. }
  1350. utils.showLog("_curPosIdIndexSingleNative:" + this._curPosIdIndexSingleNative + " #this._nativeSingleAd.length" + this._nativeSingleAd.length);
  1351. let nativeSingleAd = this._nativeSingleAd[this._curPosIdIndexSingleNative];
  1352. if (!nativeSingleAd) {
  1353. if (utils.config.oppoconfig.nativeSingleAdIds
  1354. && utils.config.oppoconfig.nativeSingleAdIds[this._curPosIdIndexSingleNative]) {
  1355. utils.showLog("创建原生广告。 posId:" + utils.config.oppoconfig.nativeSingleAdIds[this._curPosIdIndexSingleNative]);
  1356. //@ts-ignore
  1357. nativeSingleAd = qg.createNativeAd({
  1358. posId: utils.config.oppoconfig.nativeSingleAdIds[this._curPosIdIndexSingleNative]
  1359. });
  1360. if (nativeSingleAd) {
  1361. this._nativeSingleAd.push(nativeSingleAd);
  1362. nativeSingleAd.onLoad((res) => {
  1363. if (res && res.adList && res.adList.length > 0) {
  1364. utils.showLog("原生广告资源拉取成功!");
  1365. utils.showLog(JSON.stringify(res));
  1366. res = JSON.parse(JSON.stringify(res));
  1367. let data = res.adList[0];
  1368. if (this._checkNativeDataValid(data)) {
  1369. this._singleAdCreateTime = new Date().getTime();
  1370. this._curPosIdIndexSingleNative = 0;
  1371. this._nativeData = data;
  1372. this._nativeAd = nativeSingleAd;
  1373. // utils.showLog("callback >>>", callback);
  1374. // callback(this.getNativeAdData());
  1375. this._showNativeAd();
  1376. return;
  1377. } else {
  1378. utils.showLog("原生广告资源不合法!");
  1379. }
  1380. }
  1381. utils.showLog("原生广告资源出错!");
  1382. this._curPosIdIndexSingleNative++;
  1383. if (this._curPosIdIndexSingleNative < utils.config.oppoconfig.nativeSingleAdIds.length) {
  1384. this.createNativeAd();
  1385. } else {
  1386. this._curPosIdIndexSingleNative = 0;
  1387. // 原生广告遍历完毕
  1388. utils.showLog("单个原生广告ID遍历完毕,无法展示!");
  1389. }
  1390. });
  1391. nativeSingleAd.onError((err) => {
  1392. utils.showLog("原生单个广告资源拉取失败!" + err.code + err.msg);
  1393. this._curPosIdIndexSingleNative++;
  1394. if (this._curPosIdIndexSingleNative < utils.config.oppoconfig.nativeSingleAdIds.length) {
  1395. this.createNativeAd();
  1396. } else {
  1397. this._curPosIdIndexSingleNative = 0;
  1398. // 原生广告遍历完毕
  1399. utils.showLog("单个原生广告ID遍历完毕,无法展示!");
  1400. }
  1401. });
  1402. }
  1403. }
  1404. }
  1405. if (nativeSingleAd) {
  1406. utils.showLog("nativeSingleAd reload");
  1407. nativeSingleAd.load();
  1408. } else {
  1409. this._curPosIdIndexSingleNative++;
  1410. if (utils.config.oppoconfig.nativeSingleAdIds && this._curPosIdIndexSingleNative < utils.config.oppoconfig.nativeSingleAdIds.length) {
  1411. this.createNativeAd();
  1412. } else {
  1413. this._curPosIdIndexSingleNative = 0;
  1414. // 原生广告遍历完毕
  1415. utils.showLog("单个原生广告ID 遍历完毕,无法展示!");
  1416. }
  1417. }
  1418. }
  1419. }
  1420. /**
  1421. * 显示原生banner组件
  1422. */
  1423. _showNativeBanner(nativeBannerAd: any, data: any) {
  1424. if (PlatUtils.IsOPPO) {
  1425. if (data) {
  1426. if (cc.isValid(this._nativeBannerNode) && this._nativeBannerNode) {
  1427. this._nativeBannerNode.destroy();
  1428. }
  1429. // if (!cc.isValid(this._nativeBannerNode) || (!this._nativeBannerNode && utils.config.otherconfig.nativeBanner)) {
  1430. this._nativeBannerNode = cc.instantiate(utils.config.otherconfig.nativeBanner);
  1431. this._nativeBannerNode.position = CompatibleTool.position(cc.winSize.width / 2, this._nativeBannerNode.height * this._nativeBannerNode.scaleY / 2);
  1432. cc.director.getScene().addChild(this._nativeBannerNode, 1000);
  1433. // }
  1434. if (this._nativeBannerNode) {
  1435. this._nativeBannerNode.active = true;
  1436. let nativeBanner: YZ_NativeBanner = this._nativeBannerNode.getComponent("YZ_NativeBanner");
  1437. if (nativeBanner) {
  1438. nativeBanner.init(nativeBannerAd, data, this.getNativeBannerInfo());
  1439. } else {
  1440. utils.showLog("NativeBanner组件不存在!");
  1441. }
  1442. this._showBannerCallBack && this._showBannerCallBack();
  1443. this._showBannerCallBack = null;
  1444. } else {
  1445. utils.showLog("原生广告banner位没有创建!");
  1446. }
  1447. }
  1448. }
  1449. }
  1450. /**
  1451. * 显示原生插屏组件
  1452. */
  1453. _showNativeInsert(nativeInsertAd: any, data: any) {
  1454. if (PlatUtils.IsOPPO) {
  1455. if (data) {
  1456. if ((!cc.isValid(this._nativeInsertNode)) || !this._nativeInsertNode && utils.config.otherconfig.nativeInsert) {
  1457. utils.showLog("创建原生插屏广告位");
  1458. this._nativeInsertNode = cc.instantiate(utils.config.otherconfig.nativeInsert);
  1459. this._nativeInsertNode.position = CompatibleTool.position(cc.winSize.width / 2, cc.winSize.height / 2);
  1460. cc.director.getScene().addChild(this._nativeInsertNode, 999999);
  1461. }
  1462. if (this._nativeInsertNode) {
  1463. let nativeInsert = this._nativeInsertNode.getComponent("YZ_NativeInsert");
  1464. if (nativeInsert) {
  1465. this._nativeInsertAdShowCount = 0;
  1466. nativeInsert.init(nativeInsertAd, data);
  1467. this._insertLastShowTime = new Date().getTime();
  1468. utils.oppoTool.countInserShowCount();
  1469. utils.showLog("原生插屏显示成功,当前显示次数=" + utils.oppoTool.insertAdShowCounts);
  1470. let closeType = this.ServerConfig.intersititial_open_close_banner;
  1471. if (closeType && closeType > 0) {
  1472. utils.showLog("OPPO 配置当前插屏显示成功后" + (closeType == 1 ? "销毁" : "隐藏") + "banner!");
  1473. this.HideBanner();
  1474. }
  1475. } else {
  1476. utils.showLog("NativeInsert组件不存在!");
  1477. }
  1478. } else {
  1479. utils.showLog("原生广告插屏位没有创建!");
  1480. }
  1481. }
  1482. }
  1483. }
  1484. /**
  1485. * 隐藏banner
  1486. * @param args
  1487. */
  1488. public HideSingleNativeAd(args?: any) {
  1489. if (this.signleNativeAd && cc.isValid(this.signleNativeAd)) {
  1490. this.signleNativeAd.destroy();
  1491. }
  1492. }
  1493. public ShowCloseBtnBanner(location: BannerLocation = BannerLocation.Home, args: any) {
  1494. utils.showLog("ShowCloseBtnBanner >>>>>>>>>.");
  1495. let isMoveBtn = 0;
  1496. let fadeInTime = 0;
  1497. let btn: cc.Node = args.closeBtn;
  1498. let winHeight = cc.winSize.height;
  1499. btn.opacity = 0;
  1500. if (this.ServerConfig) {
  1501. if (this.ServerConfig.is_move_btn) {
  1502. isMoveBtn = this.ServerConfig.is_move_btn;
  1503. }
  1504. if (this.ServerConfig.close_btn_fade_in_time) {
  1505. fadeInTime = this.ServerConfig.close_btn_fade_in_time;
  1506. }
  1507. utils.showLog(isMoveBtn == 0 ? "显示banner,且按钮在上面" : `显示Banner,按钮居底部且${isMoveBtn}毫秒后移动`);
  1508. setTimeout(() => {
  1509. utils.showLog("延迟调用关闭按钮的Banner >>>>");
  1510. this.ShowBanner(location, args);
  1511. var adY = 240;
  1512. utils.showLog('utils - adY:' + adY);
  1513. if (adY > 0 && btn) {
  1514. btn.y = -(winHeight / 2 - adY) + btn.height;
  1515. utils.showLog("btnClose.y" + btn.y);
  1516. }
  1517. }, isMoveBtn);
  1518. setTimeout(() => {
  1519. btn.runAction(cc.fadeIn(0.3));
  1520. }, fadeInTime * 1000);
  1521. }
  1522. }
  1523. _checkNativeInsertDataValid(data: any) {
  1524. if (!data) {
  1525. return false;
  1526. }
  1527. return data.title && ((data.iconUrlList && data.iconUrlList.length > 0) || (data.imgUrlList && data.imgUrlList.length > 0));
  1528. }
  1529. _checkNativeDataValid(data: any) {
  1530. if (!data) {
  1531. return false;
  1532. }
  1533. return data.imgUrlList && data.imgUrlList.length;
  1534. }
  1535. /**
  1536. * 验证是否显示激励插屏
  1537. */
  1538. private checkRewardInsertIsShow() {
  1539. let jumpList = utils.getRecommondGameList();
  1540. if (utils.isSupportnavigateToMiniGame()) {
  1541. if (utils.oppoTool
  1542. && utils.oppoTool.ServerConfig
  1543. && utils.oppoTool.ServerConfig.is_reward_intersititia) {
  1544. if (utils.oppoTool.ServerConfig.is_reward_intersititia == "true"
  1545. && jumpList && jumpList.length > 0) {
  1546. utils.showLog("激励插屏显示环境验证通过!");
  1547. return true;
  1548. } else {
  1549. utils.showLog("is_reward_intersititia 参数为false,激励插屏组件不显示!");
  1550. return false;
  1551. }
  1552. } else {
  1553. utils.showLog("配置中没有is_reward_intersititia参数,激励插屏组件组件不显示!");
  1554. return false;
  1555. }
  1556. }
  1557. utils.showLog("当前平台不支持小程序跳转!");
  1558. return false;
  1559. }
  1560. _rewardInsertNode: cc.Node = null;
  1561. /**
  1562. * 显示激励插屏组件
  1563. */
  1564. public showRewardInsert() {
  1565. utils.showLog("show reward");
  1566. let self = this;
  1567. if (!this.checkRewardInsertIsShow()) {
  1568. self._videoCallback && self._videoCallback(false, "暂无视频广告!");
  1569. utils.adManager.videoCallBack = null;
  1570. return;
  1571. }
  1572. if (((!cc.isValid(this._rewardInsertNode)) || !this._rewardInsertNode) && utils.config.otherconfig.rewardInsert) {
  1573. utils.showLog("创建激励插屏广告");
  1574. this._rewardInsertNode = cc.instantiate(utils.config.otherconfig.rewardInsert);
  1575. this._rewardInsertNode.position = CompatibleTool.position(cc.winSize.width / 2, cc.winSize.height / 2);
  1576. cc.director.getScene().addChild(this._rewardInsertNode, 9999);
  1577. }
  1578. if (this._rewardInsertNode) {
  1579. let rewardInsert: RewardInsert = this._rewardInsertNode.getComponent("RewardInsert");
  1580. if (rewardInsert) {
  1581. rewardInsert.isShow = false;
  1582. utils.showLog("显示激励插屏组件!");
  1583. } else {
  1584. utils.showLog("RewardInsert组件不存在!");
  1585. }
  1586. } else {
  1587. utils.showLog("激励插屏没有创建!");
  1588. }
  1589. }
  1590. public hideRewardInsert() {
  1591. if (this._rewardInsertNode) {
  1592. let rewardInsert: RewardInsert = this._rewardInsertNode.getComponent("RewardInsert");
  1593. if (rewardInsert) {
  1594. rewardInsert.hide();
  1595. utils.showLog("隐藏激励插屏组件!");
  1596. } else {
  1597. utils.showLog("RewardInsert组件不存在!");
  1598. }
  1599. } else {
  1600. utils.showLog("激励插屏没有创建!");
  1601. }
  1602. }
  1603. // public ShowStatementRecomment(): cc.Node {
  1604. // if (PlatUtils.IsOPPO) {
  1605. // utils.showLog("curPosIdIndexNativeInsert:", this._curPosIdIndexNativeInser);
  1606. // let nativeInsertAd = this._nativeInsertAd[this._curPosIdIndexNativeInser];
  1607. // if (!nativeInsertAd) {
  1608. // if (utils.config.oppoconfig.nativeInsertIds
  1609. // && utils.config.oppoconfig.nativeInsertIds[this._curPosIdIndexNativeInser]) {
  1610. // utils.showLog("创建原生结算页面广告。 posId:", utils.config.oppoconfig.nativeInsertIds[this._curPosIdIndexNativeInser]);
  1611. // nativeInsertAd = qg.createNativeAd({
  1612. // posId: utils.config.oppoconfig.nativeInsertIds[this._curPosIdIndexNativeInser]
  1613. // });
  1614. // if (nativeInsertAd) {
  1615. // this._nativeInsertAd.push(nativeInsertAd);
  1616. // nativeInsertAd.onLoad((res) => {
  1617. // if (res && res.adList && res.adList.length > 0) {
  1618. // utils.showLog("原生原生结算页面资源拉取成功!");
  1619. // utils.showLog(JSON.stringify(res));
  1620. // res = JSON.parse(JSON.stringify(res));
  1621. // let data = res.adList[0];
  1622. // if (this._checkNativeDataValid(data)) {
  1623. // this._curPosIdIndexNativeInser = 0;
  1624. // // this._showNativeInsert(nativeInsertAd, data);
  1625. // // return this.cre;
  1626. // } else {
  1627. // utils.showLog("原生结算页面资源不合法!");
  1628. // }
  1629. // }
  1630. // utils.showLog("原生结算页面资源出错!");
  1631. // this._curPosIdIndexNativeInser++;
  1632. // if (this._curPosIdIndexNativeInser < utils.config.oppoconfig.nativeInsertIds.length) {
  1633. // this.ShowStatementRecomment();
  1634. // } else {
  1635. // this._curPosIdIndexNativeInser = 0;
  1636. // // 原生广告遍历完毕
  1637. // utils.showLog("原生结算页面遍历完毕,无法展示!");
  1638. // }
  1639. // });
  1640. // nativeInsertAd.onError((err) => {
  1641. // utils.showLog("原生结算页面资源拉取失败!", err.code, err.msg);
  1642. // this._curPosIdIndexNativeInser++;
  1643. // if (this._curPosIdIndexNativeInser < utils.config.oppoconfig.nativeInsertIds.length) {
  1644. // this.ShowStatementRecomment();
  1645. // } else {
  1646. // this._curPosIdIndexNativeInser = 0;
  1647. // // 原生广告遍历完毕
  1648. // utils.showLog("原生结算页面遍历完毕,无法展示!");
  1649. // }
  1650. // });
  1651. // }
  1652. // }
  1653. // }
  1654. // if (nativeInsertAd) {
  1655. // nativeInsertAd.load();
  1656. // } else {
  1657. // this._curPosIdIndexNativeInser++;
  1658. // if (utils.config.oppoconfig.nativeInsertIds && this._curPosIdIndexNativeInser < utils.config.oppoconfig.nativeInsertIds.length) {
  1659. // this.ShowStatementRecomment();
  1660. // } else {
  1661. // this._curPosIdIndexNativeInser = 0;
  1662. // // 原生广告遍历完毕
  1663. // utils.showLog("原生插屏广告遍历完毕,无法展示!");
  1664. // }
  1665. // }
  1666. // }
  1667. // return null;
  1668. // }
  1669. private checkIsShowStatementAd() {
  1670. if (utils.isSupportnavigateToMiniGame() && this.ServerConfig) {
  1671. return true;
  1672. }
  1673. utils.showLog("当前平台不支持游戏内跳转,6元素交叉推广组件不显示!");
  1674. return false;
  1675. }
  1676. /**
  1677. * 创建结算页面推广组件
  1678. */
  1679. public ShowStatementRecomment(showNativeAd: boolean = true): cc.Node {
  1680. if (this.checkIsShowStatementAd()) {
  1681. if (!showNativeAd) {
  1682. if (utils.config.otherconfig.crossWidget6) {
  1683. let node = cc.instantiate(utils.config.otherconfig.crossWidget6);
  1684. utils.showLog("只显示结算互推广告");
  1685. return node;
  1686. } else {
  1687. utils.showLog("未找到预制体 crossWidget6, 请查看CommonUtils组件上是否赋值!");
  1688. return null;
  1689. }
  1690. } else {
  1691. if (utils.config.otherconfig.statementRecomment) {
  1692. let node = cc.instantiate(utils.config.otherconfig.statementRecomment);
  1693. let statementRecomment: YZ_StatementRecommentAd = node.getComponent("YZ_StatementRecommentAd");
  1694. statementRecomment.showNativeAd = showNativeAd;
  1695. utils.showLog("显示结算互推和原生广告");
  1696. return node;
  1697. } else {
  1698. utils.showLog("未找到预制体 StatementRecomment, 请查看CommonUtils组件上是否赋值!");
  1699. return null;
  1700. }
  1701. }
  1702. } else {
  1703. return null;
  1704. }
  1705. }
  1706. _showNativeAd() {
  1707. if (this._curNativeItem && cc.isValid(this._curNativeItem.node)) {
  1708. this._curNativeItem.init(this.getNativeAdData());
  1709. }
  1710. }
  1711. signleNativeAd: cc.Node = null;
  1712. /**
  1713. * 创建结算页面推广组件
  1714. */
  1715. public ShowSingleNativeAd(params?: any) {
  1716. if (utils.config.otherconfig.singleNativeAd) {
  1717. if (this.signleNativeAd && cc.isValid(this.signleNativeAd)) {
  1718. this.signleNativeAd.destroy();
  1719. }
  1720. this.signleNativeAd = cc.instantiate(utils.config.otherconfig.singleNativeAd);
  1721. let nativeItem: YZ_NativeItem = this.signleNativeAd.getComponent("YZ_NativeItem");
  1722. nativeItem.showType = 2;
  1723. nativeItem.params = params;
  1724. this._curNativeItem = nativeItem;
  1725. if (params && params.parent) {
  1726. params.parent.addChild(this.signleNativeAd, cc.macro.MAX_ZINDEX);
  1727. }
  1728. this.createNativeAd();
  1729. utils.showLog("单个原生广告创建成功!");
  1730. return this.signleNativeAd;
  1731. } else {
  1732. utils.showLog("未找到预制体 singleNativeAd, 请查看CommonUtils组件上是否赋值!");
  1733. return null;
  1734. }
  1735. }
  1736. /**
  1737. * 显示结算广告
  1738. * @param data
  1739. * @returns json{ type:(1:6元素互推,2:单个原生广告),node:节点}
  1740. */
  1741. showStatementAds(data?: any): any {
  1742. let result: any = { "type": 0, "node": null };
  1743. if (this.ServerConfig && this.ServerConfig.statement_type) {
  1744. if (this.ServerConfig.statement_type === 4) {
  1745. result.type = 2;
  1746. result.node = this.ShowSingleNativeAd();
  1747. utils.showLog("结算广告 >> 单个原生广告>>" + result.node.name);
  1748. } else {
  1749. this.ShowInterstitial();
  1750. }
  1751. return result;
  1752. // let isSycn = this.ServerConfig.st_sync;
  1753. // let node: cc.Node = null;
  1754. // let resType: number = 0;
  1755. // switch (type) {
  1756. // case 1:
  1757. // utils.showLog("结算广告 >> 只显示小游戏插屏广告");
  1758. // if (!this.checkInsertAdShow()) {
  1759. // if (spareType && spareType > 0) {
  1760. // switch (spareType) {
  1761. // case 3:
  1762. // utils.showLog("结算广告 >> 小游戏插屏达到限制的次数 >> 显示备用组件 6个互推");
  1763. // node = this.ShowStatementRecomment(false);
  1764. // resType = 1;
  1765. // break;
  1766. // case 4:
  1767. // utils.showLog("结算广告 >> 小游戏插屏达到限制的次数 >> 显示备用组件 单个原生广告");
  1768. // node = this.ShowSingleNativeAd();
  1769. // resType = 2;
  1770. // break;
  1771. // case 5:
  1772. // utils.showLog("结算广告 >> 小游戏插屏达到限制的次数 >> 显示备用组件 3个互推+单个原生广告");
  1773. // node = this.ShowStatementRecomment();
  1774. // resType = 1;
  1775. // break;
  1776. // }
  1777. // }
  1778. // } else {
  1779. // this._createMiniGameInsertAd(true);
  1780. // }
  1781. // break;
  1782. // case 2:
  1783. // utils.showLog("结算广告 >> 显示插屏广告且判断优先级");
  1784. // if (!this.checkInsertAdShow()) {
  1785. // if (spareType) {
  1786. // switch (spareType) {
  1787. // case 3:
  1788. // utils.showLog("结算广告 >> 小游戏插屏达到限制的次数 >> 显示备用组件 6个互推");
  1789. // node = this.ShowStatementRecomment(false);
  1790. // resType = 1;
  1791. // break;
  1792. // case 4:
  1793. // utils.showLog("结算广告 >> 小游戏插屏达到限制的次数 >> 显示备用组件 单个原生广告");
  1794. // node = this.ShowSingleNativeAd();
  1795. // resType = 2;
  1796. // break;
  1797. // case 5:
  1798. // utils.showLog("结算广告 >> 小游戏插屏达到限制的次数 >> 显示备用组件 3个互推+单个原生广告");
  1799. // node = this.ShowStatementRecomment();
  1800. // resType = 1;
  1801. // break;
  1802. // }
  1803. // }
  1804. // } else {
  1805. // this.ShowInterstitial();
  1806. // }
  1807. // break;
  1808. // case 3:
  1809. // utils.showLog("结算广告 >> 显示插屏广告+6个互推");
  1810. // this.ShowInterstitial();
  1811. // node = this.ShowStatementRecomment(false);
  1812. // resType = 1;
  1813. // break;
  1814. // case 4:
  1815. // if (isSycn && isSycn == "true") {
  1816. // utils.showLog("结算广告 >> 显示插屏广告+单个原生广告");
  1817. // this.ShowInterstitial();
  1818. // node = this.ShowSingleNativeAd();
  1819. // } else {
  1820. // node = this.ShowSingleNativeAd();
  1821. // utils.showLog("结算广告 >> 只显示单个原生广告");
  1822. // }
  1823. // resType = 2;
  1824. // break;
  1825. // case 5:
  1826. // if (isSycn && isSycn == "true") {
  1827. // utils.showLog("结算广告 >> 显示插屏广告+ 3个互推+单个原生广告");
  1828. // this.ShowInterstitial();
  1829. // node = this.ShowStatementRecomment();
  1830. // } else {
  1831. // utils.showLog("结算广告 >> 只显示 3个互推+单个原生广告");
  1832. // node = this.ShowStatementRecomment();
  1833. // }
  1834. // resType = 1;
  1835. // break;
  1836. // case 6:
  1837. // if (isSycn && isSycn == "true") {
  1838. // utils.showLog("结算广告 >> 显示滚动互推+原生广告");
  1839. // node = this.ShowStatementRecomment(true);
  1840. // } else {
  1841. // utils.showLog("结算广告 >> 只显示滚动互推");
  1842. // node = this.ShowStatementRecomment();
  1843. // }
  1844. // resType = 1;
  1845. // break;
  1846. // default:
  1847. // utils.showLog("非法的结算广告类型,:" + type)
  1848. // break;
  1849. // }
  1850. // result.type = resType;
  1851. // result.node = node;
  1852. // return result;
  1853. } else {
  1854. utils.showLog("没有配置结算广告!");
  1855. return result;
  1856. }
  1857. }
  1858. _nativeTryGameNode: cc.Node = null;
  1859. /**
  1860. * 显示浮窗广告挂件
  1861. * @param params
  1862. * ```
  1863. * {
  1864. * group:string
  1865. * left:number
  1866. * bottom:number
  1867. * scale:number
  1868. * parent:cc.Node
  1869. * }
  1870. * ```
  1871. * @returns 生成的组件
  1872. */
  1873. public createNativeTryGameWidget(params: any = null) {
  1874. if (this._nativeTryGameNode && cc.isValid(this._nativeTryGameNode)) {
  1875. this._nativeTryGameNode.destroy();
  1876. }
  1877. let node = cc.instantiate(utils.config.otherconfig.nativeTryGameWidget);
  1878. if (node) {
  1879. this._nativeTryGameNode = node;
  1880. this._nativeTryGameNode.zIndex = 9999;
  1881. }
  1882. node = this._nativeTryGameNode;
  1883. let widget: cc.Widget = node.getComponent(cc.Widget);
  1884. if (params) {
  1885. if (params.group) {
  1886. node.group = params.group;
  1887. }
  1888. if (params.scale != null) {
  1889. node.scale = params.scale;
  1890. }
  1891. if (params.top != null) {
  1892. widget.isAlignTop = true;
  1893. widget.isAlignBottom = false;
  1894. widget.top = params.top;
  1895. } else if (params.bottom != null) {
  1896. widget.isAlignTop = false;
  1897. widget.isAlignBottom = true;
  1898. widget.bottom = params.bottom;
  1899. }
  1900. if (params.left != null) {
  1901. widget.isAlignLeft = true;
  1902. widget.isAlignRight = false;
  1903. widget.left = params.left;
  1904. } else if (params.right != null) {
  1905. widget.isAlignLeft = false;
  1906. widget.isAlignRight = true;
  1907. widget.right = params.right;
  1908. }
  1909. if (params.parent != null) {
  1910. node.parent = params.parent;
  1911. }
  1912. }
  1913. widget.updateAlignment();
  1914. node.active = true;
  1915. if (this._nativeTryGameNode) {
  1916. this._nativeTryGameNode.getComponent(NativeTryGamesWidget).init();
  1917. }
  1918. }
  1919. /**
  1920. * 隐藏浮动试玩挂件
  1921. */
  1922. public hideNativeTryGameWidget() {
  1923. if (this._nativeTryGameNode && cc.isValid(this._nativeTryGameNode)) {
  1924. this._nativeTryGameNode.destroy();
  1925. }
  1926. }
  1927. /**
  1928. * 是否支持原生模版广告
  1929. * @returns
  1930. */
  1931. private canShowNativeTemplateAd() {
  1932. //@ts-ignore
  1933. return qg.createCustomAd;
  1934. }
  1935. /**
  1936. * 获取原生模版广告对象
  1937. * @param type 广告类型:1:banner 2:插屏
  1938. * @param id 广告ID
  1939. */
  1940. private getNativeTemplateAdStyle(type: number) {
  1941. let style: any = {};
  1942. let systemInfo = utils.oppoTool.SysInfo;
  1943. switch (type) {
  1944. case 1:
  1945. style.width = "";
  1946. style.top = "";
  1947. style.left = "";
  1948. break;
  1949. case 2:
  1950. style.width = "";
  1951. style.top = (systemInfo.screenHeight - 400) / 2;
  1952. style.left = "";
  1953. break;
  1954. }
  1955. return style;
  1956. }
  1957. nativeTemplateBannerAd: any = null;
  1958. /**
  1959. * 创建原生模版Banner广告
  1960. * @param index
  1961. * @returns
  1962. */
  1963. private _createNativeTemplateBannerAd(index: number) {
  1964. utils.showLog("_createNativeTemplateBannerAd : #index=" + index);
  1965. YouWanAnalytics.EventAdWithObj(YwAdType.NATIVE_TEMPLATE_BANNER, YwAdStatus.REQUEST, new AdEventParameter(utils.config.oppoconfig.bannerAdConfigs[index].id));
  1966. if (!this.canShowNativeTemplateAd()) {
  1967. utils.showLog("当前快应用版本不支持原生模版广告!");
  1968. return;
  1969. }
  1970. if (index < utils.config.oppoconfig.bannerAdConfigs.length) {
  1971. //@ts-ignore
  1972. this.nativeTemplateBannerAd = qg.createCustomAd({
  1973. adUnitId: utils.config.oppoconfig.bannerAdConfigs[index].id,
  1974. style: this.getNativeTemplateAdStyle(1)
  1975. });
  1976. this.nativeTemplateBannerAd.onLoad(() => {
  1977. this.nativeTemplateBannerAd.offLoad();
  1978. utils.showLog("NativeTemplateBannerAd 广告加载成功");
  1979. YouWanAnalytics.EventAdWithObj(YwAdType.NATIVE_TEMPLATE_BANNER, YwAdStatus.REQUEST_SUCCESS, new AdEventParameter(utils.config.oppoconfig.bannerAdConfigs[index].id));
  1980. });
  1981. this.nativeTemplateBannerAd.onError((err) => {
  1982. this.nativeTemplateBannerAd.offError();
  1983. YouWanAnalytics.EventAdWithObj(YwAdType.NATIVE_TEMPLATE_BANNER, YwAdStatus.REQUEST_FAIL, new AdEventParameter(utils.config.oppoconfig.bannerAdConfigs[index].id));
  1984. utils.showLog("NativeTemplateBannerAd 广告异常:#erro=" + JSON.stringify(err));
  1985. if (this._nativeIsClose) {
  1986. utils.showLog("隐藏了BANNER,不做任何处理!");
  1987. YouWanAnalytics.EventAd(YwAdType.NATIVE_TEMPLATE_BANNER, YwAdStatus.AD_ID_REQUEST_FAIL);
  1988. return;
  1989. }
  1990. let bannerInfo = this.getNativeBannerInfo();
  1991. if (bannerInfo.st_banner_show_back_up == -1) {
  1992. YouWanAnalytics.EventAd(YwAdType.NATIVE_TEMPLATE_BANNER, YwAdStatus.AD_ID_REQUEST_FAIL);
  1993. utils.showLog(">>>>>服务器配置不显示备用广告!");
  1994. return;
  1995. }
  1996. this.ShowBannerByConfigs(index + 1);
  1997. });
  1998. this.nativeTemplateBannerAd
  1999. .show()
  2000. .then(() => {
  2001. YouWanAnalytics.EventAdWithObj(YwAdType.NATIVE_TEMPLATE_BANNER, YwAdStatus.SHOW_SUCCESS, new AdEventParameter(utils.config.oppoconfig.bannerAdConfigs[index].id));
  2002. YouWanAnalytics.EventAd(YwAdType.NATIVE_TEMPLATE_BANNER, YwAdStatus.AD_ID_REQUEST_SUCCESS);
  2003. this.nativeTemplateBannerAd.offShow();
  2004. utils.showLog("NativeTemplateBannerAd show success");
  2005. this.hideBanner("template");
  2006. })
  2007. .catch((error) => {
  2008. utils.showLog("NativeTemplateBannerAd show fail with:" + error.errCode + "," + error.errMsg);
  2009. });
  2010. }
  2011. }
  2012. /**
  2013. * 隐藏原生模版Banner
  2014. */
  2015. private hideNativeTemplateBannerAd() {
  2016. utils.showLog("hideNativeTemplateBannerAd ");
  2017. this.nativeTemplateBannerAd && this.nativeTemplateBannerAd.destroy();
  2018. this.nativeTemplateBannerAd = null;
  2019. }
  2020. /**
  2021. * 创建原生模版插屏广告
  2022. * @param index
  2023. * @returns
  2024. */
  2025. private _createNativeTemplateIntersitialAd(index: number) {
  2026. utils.showLog("_createNativeTemplateIntersitialAd : #index=" + index);
  2027. if (!this.canShowNativeTemplateAd()) {
  2028. utils.showLog("当前快应用版本不支持原生模版广告!");
  2029. return;
  2030. }
  2031. if (index < utils.config.oppoconfig.intersitialAdConfigs.length) {
  2032. utils.showLog("nativetemplate style=" + this.getNativeTemplateAdStyle(2));
  2033. //@ts-ignore
  2034. let customAd = qg.createCustomAd({
  2035. adUnitId: utils.config.oppoconfig.intersitialAdConfigs[index].id,
  2036. style: this.getNativeTemplateAdStyle(2)
  2037. });
  2038. customAd.onLoad(() => {
  2039. YouWanAnalytics.EventAdWithObj(YwAdType.INTERSITITIAL, YwAdStatus.REQUEST_SUCCESS, new AdEventParameter(utils.config.oppoconfig.intersitialAdConfigs[index].id));
  2040. utils.showLog("NativeTemplateIntersitialAd 广告加载成功");
  2041. });
  2042. customAd.onError((err) => {
  2043. utils.showLog("NativeTemplateIntersitialAd 广告异常:" + + JSON.stringify(err));
  2044. this.ShowInterstitialByConfigs(index + 1);
  2045. });
  2046. customAd
  2047. .show()
  2048. .then(() => {
  2049. utils.showLog("NativeTemplateIntersitialAd show success");
  2050. this._insertLastShowTime = new Date().getTime();
  2051. let closeType = this.ServerConfig.intersititial_open_close_banner;
  2052. if (closeType && closeType > 0) {
  2053. utils.showLog("OPPO 配置当前插屏显示成功后" + (closeType == 1 ? "销毁" : "隐藏") + "banner!");
  2054. this.HideBanner();
  2055. }
  2056. YouWanAnalytics.EventAd(YwAdType.INTERSITITIAL, YwAdStatus.AD_ID_REQUEST_SUCCESS);
  2057. YouWanAnalytics.EventAdWithObj(YwAdType.INTERSITITIAL, YwAdStatus.SHOW_SUCCESS, new AdEventParameter(utils.config.oppoconfig.intersitialAdConfigs[index].id));
  2058. })
  2059. .catch((error) => {
  2060. utils.showLog("NativeTemplateIntersitialAd show fail with:" + error.errCode + "," + error.errMsg);
  2061. });
  2062. }
  2063. }
  2064. public GameExit() { }
  2065. public Share() { }
  2066. }