4e11a65b-6d75-4b1d-a70e-b297cdd8045f.js 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140
  1. "use strict";
  2. cc._RF.push(module, '4e11aZbbXVLHacOspfN2ARf', 'AdAgentWechat');
  3. // common-plugin/Scripts/AdAgentWechat.ts
  4. "use strict";
  5. var __extends = (this && this.__extends) || (function () {
  6. var extendStatics = function (d, b) {
  7. extendStatics = Object.setPrototypeOf ||
  8. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  9. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  10. return extendStatics(d, b);
  11. };
  12. return function (d, b) {
  13. extendStatics(d, b);
  14. function __() { this.constructor = d; }
  15. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  16. };
  17. })();
  18. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  19. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  20. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  21. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  22. return c > 3 && r && Object.defineProperty(target, key, r), r;
  23. };
  24. Object.defineProperty(exports, "__esModule", { value: true });
  25. var AdAgent_1 = require("./AdAgent");
  26. var YZ_Constant_1 = require("./YZ_Constant");
  27. var PlatUtils_1 = require("./PlatUtils");
  28. var Utils_1 = require("./Utils");
  29. var CompatibleTool_1 = require("./CompatibleTool");
  30. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  31. var AdAgentWechat = /** @class */ (function (_super) {
  32. __extends(AdAgentWechat, _super);
  33. function AdAgentWechat() {
  34. var _this = _super !== null && _super.apply(this, arguments) || this;
  35. _this._curBannerAd = null;
  36. _this._videoAd = null;
  37. _this._videoCallback = null;
  38. _this._insertAd = null;
  39. _this._rewardInsertNode = null;
  40. _this._sysInfo = null;
  41. _this._bannerSizePercent = 0.1;
  42. _this._bannerBottom = 0;
  43. _this._oldBannerLocation = YZ_Constant_1.BannerLocation.None;
  44. _this._showBannerTimerId = 0;
  45. _this.isFirstShowInsertAd = true; //首次展示广告
  46. _this._customAdObjs = [];
  47. _this._nativeCustomAdObjs = [];
  48. _this.nativeBannerAd = null;
  49. _this.nativeIntersititialAd = null;
  50. return _this;
  51. }
  52. Object.defineProperty(AdAgentWechat.prototype, "ServerConfig", {
  53. get: function () {
  54. return Utils_1.utils.wechatTool.ServerConfig;
  55. },
  56. enumerable: false,
  57. configurable: true
  58. });
  59. Object.defineProperty(AdAgentWechat.prototype, "sysInfo", {
  60. get: function () {
  61. if (this._sysInfo)
  62. return this._sysInfo;
  63. this._sysInfo = Utils_1.utils.wechatTool.getSystemInfo();
  64. return this._sysInfo;
  65. },
  66. enumerable: false,
  67. configurable: true
  68. });
  69. AdAgentWechat.prototype.Init = function () {
  70. var _this = this;
  71. if (PlatUtils_1.default.IsWechat) {
  72. Utils_1.utils.registerServerInitEvent(function () {
  73. _this._initVideoAd();
  74. _this._initInsertAd();
  75. if (Utils_1.utils.getConfigByKey("game_time_report")) {
  76. Utils_1.utils.scheduleOnce(function () {
  77. Utils_1.utils.wechatTool.reportAttributedEvent(YZ_Constant_1.AttributedType.GameAddiction, YZ_Constant_1.AttributedKey.GameAddiction, YZ_Constant_1.AttributedValue.GameTimeAction);
  78. }, Utils_1.utils.getConfigByKey("game_time_report"));
  79. }
  80. }, this);
  81. }
  82. };
  83. AdAgentWechat.prototype._initVideoAd = function () {
  84. if (PlatUtils_1.default.IsWechat) {
  85. if (!Utils_1.utils.wechatTool.isOverMinVersion("2.0.4")) {
  86. Utils_1.utils.showLog("当前版本不支持视频广告!");
  87. return;
  88. }
  89. if (!this._videoAd) {
  90. Utils_1.utils.showLog("初始化视频!");
  91. if (!Utils_1.utils.config.wechatconfig.videoId) {
  92. Utils_1.utils.showLog("视频ID配置错误!");
  93. return;
  94. }
  95. Utils_1.utils.showLog("视频广告ID:", Utils_1.utils.config.wechatconfig.videoId.trim());
  96. //@ts-ignore
  97. this._videoAd = wx.createRewardedVideoAd({
  98. adUnitId: Utils_1.utils.config.wechatconfig.videoId
  99. });
  100. var self_1 = this;
  101. if (this._videoAd) {
  102. Utils_1.utils.showLog("初始化注册视频回调!");
  103. this._videoAd.onLoad(function () {
  104. Utils_1.utils.showLog("激励视频加载成功");
  105. // this._isVideoLoaded = true;
  106. }.bind(this));
  107. this._videoAd.onError(function (err) {
  108. Utils_1.utils.showLog("激励视频加载失败!", err.code, err.msg);
  109. // this._isVideoLoaded = false;
  110. }.bind(this));
  111. this._videoAd.onClose(function (res) {
  112. // this._isVideoLoaded = false;
  113. if (res && res.isEnded || res === undefined) {
  114. // 正常播放结束,可以下发游戏奖励
  115. Utils_1.utils.showLog('激励视频广告完成,发放奖励');
  116. if (self_1._videoCallback) {
  117. self_1._videoCallback(true, "");
  118. self_1._videoCallback = null;
  119. }
  120. }
  121. else {
  122. // 播放中途退出,不下发游戏奖励
  123. Utils_1.utils.showLog('激励视频广告取消关闭,不发放奖励');
  124. if (self_1._videoCallback) {
  125. self_1._videoCallback(false, "观看完视频才能获得奖励!");
  126. self_1._videoCallback = null;
  127. }
  128. }
  129. }.bind(this));
  130. }
  131. else {
  132. Utils_1.utils.showLog("激励视频初始化失败!");
  133. }
  134. }
  135. }
  136. };
  137. AdAgentWechat.prototype._createBanner = function (location, args) {
  138. var _this = this;
  139. if (args === void 0) { args = null; }
  140. if (PlatUtils_1.default.IsWechat) {
  141. var locationTmp = location;
  142. var argsTmp = args;
  143. if (argsTmp && argsTmp.width) {
  144. this._bannerSizePercent = argsTmp.width < 0 ? 0 : argsTmp.width;
  145. this._bannerSizePercent = argsTmp.width > 1 ? 1 : argsTmp.width;
  146. }
  147. if (argsTmp && argsTmp.bottom) {
  148. this._bannerBottom = argsTmp.bottom < 0 ? 0 : argsTmp.bottom;
  149. this._bannerBottom = argsTmp.bottom > cc.winSize.height ? cc.winSize.height : argsTmp.bottom;
  150. }
  151. var params = {
  152. adUnitId: Utils_1.utils.config.wechatconfig.getBannerId(locationTmp),
  153. style: {
  154. left: 0,
  155. width: 300,
  156. top: 0
  157. }
  158. };
  159. if (this._oldBannerLocation != locationTmp && this._curBannerAd) {
  160. this._curBannerAd.destroy();
  161. this._oldBannerLocation = locationTmp;
  162. }
  163. //@ts-ignore
  164. var curBannerAd_1 = wx.createBannerAd(params);
  165. if (curBannerAd_1) {
  166. curBannerAd_1.onError(function (err) {
  167. Utils_1.utils.showLog("广告条加载失败! ", JSON.stringify(err));
  168. if (curBannerAd_1) {
  169. curBannerAd_1.destroy();
  170. }
  171. if (_this.ServerConfig.banner_first_ad && _this.ServerConfig.banner_first_ad == "default") {
  172. _this.showNativeBannerAd(location, args);
  173. }
  174. });
  175. var self_2 = this;
  176. curBannerAd_1.onLoad(function () {
  177. curBannerAd_1.show().then(function () {
  178. var old = self_2._curBannerAd;
  179. if (old) {
  180. old.destroy();
  181. }
  182. self_2._curBannerAd = curBannerAd_1;
  183. Utils_1.utils.showLog("默认Banner广告显示成功!");
  184. _this.HideNativeBanner();
  185. }).catch(function (err) {
  186. Utils_1.utils.showLog("Banner广告出错", JSON.stringify(err));
  187. if (curBannerAd_1) {
  188. curBannerAd_1.destroy();
  189. }
  190. if (_this.ServerConfig.banner_first_ad && _this.ServerConfig.banner_first_ad == "default") {
  191. _this.showNativeBannerAd(location, args);
  192. }
  193. });
  194. });
  195. curBannerAd_1.onResize(function (res) {
  196. curBannerAd_1.style.width = Utils_1.utils.wechatTool.getSystemInfo().screenWidth * self_2._bannerSizePercent;
  197. curBannerAd_1.style.left = (Utils_1.utils.wechatTool.getSystemInfo().screenWidth - res.width) * 0.5;
  198. if (self_2._bannerBottom == cc.winSize.height) {
  199. curBannerAd_1.style.top = 0;
  200. }
  201. else {
  202. curBannerAd_1.style.top = Utils_1.utils.wechatTool.getSystemInfo().screenHeight - res.height - self_2._bannerBottom;
  203. }
  204. });
  205. }
  206. else {
  207. Utils_1.utils.showLog("广告条创建失败!");
  208. }
  209. }
  210. };
  211. AdAgentWechat.prototype.createCustomADBanner = function (location, args) {
  212. if (location === void 0) { location = YZ_Constant_1.BannerLocation.Game; }
  213. if (args === void 0) { args = null; }
  214. if (PlatUtils_1.default.IsWechat) {
  215. var locationTmp_1 = location;
  216. if (!Utils_1.utils.config.wechatconfig.getBannerId(locationTmp_1)) {
  217. locationTmp_1 = YZ_Constant_1.BannerLocation.Home;
  218. }
  219. var argsTmp_1 = args;
  220. if (argsTmp_1 && argsTmp_1.width) {
  221. this._bannerSizePercent = argsTmp_1.width < 0 ? 0 : argsTmp_1.width;
  222. this._bannerSizePercent = argsTmp_1.width > 1 ? 1 : argsTmp_1.width;
  223. }
  224. if (argsTmp_1 && argsTmp_1.bottom) {
  225. this._bannerBottom = argsTmp_1.bottom < 0 ? 0 : argsTmp_1.bottom;
  226. this._bannerBottom = argsTmp_1.bottom > cc.winSize.height ? cc.winSize.height : argsTmp_1.bottom;
  227. }
  228. var params = {
  229. adUnitId: Utils_1.utils.config.wechatconfig.getBannerId(locationTmp_1),
  230. style: {
  231. left: 0,
  232. width: 300,
  233. top: 0
  234. }
  235. };
  236. if (this._oldBannerLocation != locationTmp_1 && this._curBannerAd) {
  237. this._curBannerAd.destroy();
  238. this._oldBannerLocation = locationTmp_1;
  239. }
  240. //@ts-ignore
  241. var curBannerAd_2 = wx.createBannerAd(params);
  242. if (curBannerAd_2) {
  243. curBannerAd_2.onError(function (err) {
  244. Utils_1.utils.showLog("广告条加载失败! ", JSON.stringify(err));
  245. if (curBannerAd_2) {
  246. curBannerAd_2.destroy();
  247. }
  248. });
  249. var self_3 = this;
  250. curBannerAd_2.onLoad(function () {
  251. cc.director.on("CloseCustomADPanel", (function () {
  252. curBannerAd_2.show().then(function () {
  253. var old = self_3._curBannerAd;
  254. if (old) {
  255. old.destroy();
  256. }
  257. self_3._curBannerAd = curBannerAd_2;
  258. Utils_1.utils.showLog("Banner广告显示成功!");
  259. var interval = 18;
  260. if (Utils_1.utils.wechatTool.ServerConfig.refresh_ad_time) {
  261. interval = Utils_1.utils.wechatTool.ServerConfig.refresh_ad_time;
  262. }
  263. clearInterval(self_3._showBannerTimerId);
  264. //@ts-ignore
  265. self_3._showBannerTimerId = setInterval(function () {
  266. Utils_1.utils.showLog("\u663E\u793ABanner\u5E7F\u544A\uFF01location:" + locationTmp_1 + "; args:" + JSON.stringify(argsTmp_1) + "; \u95F4\u9694\u65F6\u95F4:" + Utils_1.utils.wechatTool.ServerConfig.refresh_ad_time);
  267. self_3._showBannerTimer(locationTmp_1, argsTmp_1);
  268. }.bind(self_3), interval * 1000);
  269. }).catch(function (err) {
  270. Utils_1.utils.showLog("Banner广告出错", JSON.stringify(err));
  271. if (curBannerAd_2) {
  272. curBannerAd_2.destroy();
  273. }
  274. });
  275. cc.director.targetOff(self_3);
  276. }), self_3);
  277. });
  278. curBannerAd_2.onResize(function (res) {
  279. curBannerAd_2.style.width = Utils_1.utils.wechatTool.getSystemInfo().screenWidth * self_3._bannerSizePercent;
  280. curBannerAd_2.style.left = (Utils_1.utils.wechatTool.getSystemInfo().screenWidth - res.width) * 0.5;
  281. if (self_3._bannerBottom == cc.winSize.height) {
  282. curBannerAd_2.style.top = 0;
  283. }
  284. else {
  285. curBannerAd_2.style.top = Utils_1.utils.wechatTool.getSystemInfo().screenHeight - res.height - self_3._bannerBottom;
  286. }
  287. });
  288. }
  289. else {
  290. Utils_1.utils.showLog("广告条创建失败!");
  291. }
  292. }
  293. };
  294. AdAgentWechat.prototype._initInsertAd = function () {
  295. var _this = this;
  296. if (PlatUtils_1.default.IsWechat) {
  297. if (!Utils_1.utils.wechatTool.isOverMinVersion("2.6.0")) {
  298. Utils_1.utils.showLog("当前版本不支持插屏广告!");
  299. return;
  300. }
  301. if (!this._insertAd) {
  302. Utils_1.utils.showLog("初始化插屏广告!");
  303. if (!Utils_1.utils.config.wechatconfig.insertId) {
  304. Utils_1.utils.showLog("插屏广告ID配置错误!");
  305. return;
  306. }
  307. Utils_1.utils.showLog("插屏广告ID:", Utils_1.utils.config.wechatconfig.insertId.trim());
  308. //@ts-ignore
  309. this._insertAd = wx.createInterstitialAd({
  310. adUnitId: Utils_1.utils.config.wechatconfig.insertId.trim()
  311. });
  312. if (this._insertAd) {
  313. this._insertAd.onLoad(function () {
  314. Utils_1.utils.showLog("插屏广告拉取成功!");
  315. });
  316. this._insertAd.onError(function (err) {
  317. Utils_1.utils.showLog("插屏广告拉取失败!", JSON.stringify(err));
  318. if (_this.ServerConfig.intersititial_first_ad && _this.ServerConfig.intersititial_first_ad == "default") {
  319. _this.showNativeIntersititialAd();
  320. }
  321. });
  322. this._insertAd.onClose(function () {
  323. Utils_1.utils.showLog("插屏广告被关闭!");
  324. });
  325. }
  326. else {
  327. Utils_1.utils.showLog("插屏组件初始化失败!");
  328. }
  329. }
  330. }
  331. };
  332. AdAgentWechat.prototype._showBannerTimer = function (location, args) {
  333. var locationTmp = location;
  334. var argsTmp = args;
  335. Utils_1.utils.showLog("\u663E\u793ABanner\u5E7F\u544Axxx\uFF01location:" + locationTmp + "; args:" + JSON.stringify(argsTmp) + "; \u95F4\u9694\u65F6\u95F4:" + Utils_1.utils.wechatTool.ServerConfig.refresh_ad_time + ";\u4F18\u5148\u7EA7\uFF1A" + this.ServerConfig.banner_first_ad);
  336. if (this.ServerConfig.banner_first_ad && this.ServerConfig.banner_first_ad == "native") {
  337. this.showNativeBannerAd(location, args);
  338. }
  339. else {
  340. if (locationTmp == YZ_Constant_1.BannerLocation.None) {
  341. Utils_1.utils.showLog("未定义的BannerLocation,", locationTmp);
  342. }
  343. else {
  344. if (Utils_1.utils.config.wechatconfig.getBannerId(locationTmp)) {
  345. this._createBanner(locationTmp, argsTmp);
  346. }
  347. else {
  348. Utils_1.utils.showLog("\u672A\u627E\u5230\u4F4D\u7F6E\u4E3A " + locationTmp + " \u7684\u5E7F\u544AID!");
  349. this._createBanner(YZ_Constant_1.BannerLocation.Home, argsTmp);
  350. }
  351. }
  352. }
  353. };
  354. AdAgentWechat.prototype.ShowBanner = function (location, args) {
  355. if (location === void 0) { location = YZ_Constant_1.BannerLocation.Home; }
  356. if (args === void 0) { args = null; }
  357. if (PlatUtils_1.default.IsWechat) {
  358. if (!Utils_1.utils.wechatTool.isOverMinVersion("2.0.4")) {
  359. Utils_1.utils.showLog("当前版本不支持Banner广告!");
  360. return;
  361. }
  362. if (Utils_1.utils.wechatTool.ServerConfig) {
  363. var locationTmp_2 = location;
  364. var argsTmp_2 = args;
  365. this._showBannerTimer(locationTmp_2, argsTmp_2);
  366. var interval = 18;
  367. if (Utils_1.utils.wechatTool.ServerConfig.refresh_ad_time) {
  368. interval = Utils_1.utils.wechatTool.ServerConfig.refresh_ad_time;
  369. }
  370. clearInterval(this._showBannerTimerId);
  371. //@ts-ignore
  372. this._showBannerTimerId = setInterval(function () {
  373. Utils_1.utils.showLog("\u663E\u793ABanner\u5E7F\u544A\uFF01location:" + locationTmp_2 + "; args:" + JSON.stringify(argsTmp_2) + "; \u95F4\u9694\u65F6\u95F4:" + Utils_1.utils.wechatTool.ServerConfig.refresh_ad_time);
  374. this._showBannerTimer(locationTmp_2, argsTmp_2);
  375. }.bind(this), interval * 1000);
  376. }
  377. else {
  378. Utils_1.utils.showLog("服务器配置数据未初始化!");
  379. }
  380. }
  381. };
  382. AdAgentWechat.prototype.HideBanner = function (location) {
  383. if (location === void 0) { location = YZ_Constant_1.BannerLocation.Home; }
  384. if (PlatUtils_1.default.IsWechat) {
  385. Utils_1.utils.showLog("隐藏广告条");
  386. clearInterval(this._showBannerTimerId);
  387. this.HideDefaultBanner();
  388. this.HideNativeBanner();
  389. }
  390. };
  391. AdAgentWechat.prototype.HideDefaultBanner = function () {
  392. this._curBannerAd && this._curBannerAd.hide();
  393. };
  394. AdAgentWechat.prototype.HideNativeBanner = function () {
  395. this.nativeBannerAd && this.nativeBannerAd.hide();
  396. };
  397. AdAgentWechat.prototype.ShowInterstitial = function (location) {
  398. var _this = this;
  399. if (location === void 0) { location = YZ_Constant_1.BannerLocation.Home; }
  400. if (PlatUtils_1.default.IsWechat) {
  401. if (!Utils_1.utils.wechatTool.isOverMinVersion("2.6.0")) {
  402. Utils_1.utils.showLog("当前版本不支持插屏广告!");
  403. return;
  404. }
  405. var delayTime = 0;
  406. if (Utils_1.utils.wechatTool
  407. && Utils_1.utils.wechatTool.ServerConfig
  408. && Utils_1.utils.wechatTool.ServerConfig.intersititia_delay_show_time) {
  409. delayTime = Utils_1.utils.wechatTool.ServerConfig.intersititia_delay_show_time;
  410. }
  411. Utils_1.utils.showLog("\u63D2\u5C4F\u5E7F\u544A\u5EF6\u65F6\u5C55\u793A\uFF01 delayTime:" + delayTime + "\u79D2");
  412. setTimeout(function () {
  413. if (_this.ServerConfig && _this.ServerConfig.intersititial_first_ad && _this.ServerConfig.intersititial_first_ad == "box") {
  414. Utils_1.utils.showLog("优先展示盒子插屏广告!");
  415. if (_this.canShowBoxInsertAd()) {
  416. _this._createBoxInsertAd();
  417. }
  418. else {
  419. Utils_1.utils.showLog("盒子插屏广告展示失败,展示默认插屏!");
  420. _this._createMiniGameInsertAd();
  421. }
  422. }
  423. else if (_this.ServerConfig && _this.ServerConfig.intersititial_first_ad && _this.ServerConfig.intersititial_first_ad == "native") {
  424. _this.showNativeIntersititialAd();
  425. }
  426. else {
  427. Utils_1.utils.showLog("优先展示小游戏插屏广告!");
  428. _this._createMiniGameInsertAd();
  429. }
  430. }, delayTime * 1000);
  431. }
  432. };
  433. AdAgentWechat.prototype._createBoxInsertAd = function () {
  434. Utils_1.utils.rewardCallFunc = null;
  435. Utils_1.utils.rewardCloseFunc = null;
  436. if (Utils_1.utils.config && Utils_1.utils.config.otherconfig.beforGameOverRecGamesPanel && Utils_1.utils.getRecommondGameList()) {
  437. var panel = cc.instantiate(Utils_1.utils.config.otherconfig.beforGameOverRecGamesPanel);
  438. panel.zIndex = 999999;
  439. var morePanel = panel.getComponent("BeforGameOverRecGamesPanel");
  440. cc.director.getScene().addChild(panel);
  441. morePanel._location = YZ_Constant_1.SubLocation.isBoxInsertAd;
  442. morePanel.init(Utils_1.utils.getRecommondGameList());
  443. morePanel.show();
  444. }
  445. else {
  446. Utils_1.utils.showLog("互推插屏展示失败!");
  447. }
  448. };
  449. /**
  450. * 是否能够显示互推插屏
  451. */
  452. AdAgentWechat.prototype.canShowBoxInsertAd = function () {
  453. var jumpList = Utils_1.utils.getRecommondGameList();
  454. if (jumpList && jumpList.length > 0) {
  455. return true;
  456. }
  457. return false;
  458. };
  459. AdAgentWechat.prototype._createMiniGameInsertAd = function () {
  460. var _this = this;
  461. if (this._insertAd) {
  462. this._insertAd.show().then(function () {
  463. Utils_1.utils.showLog("插屏广告展示成功!");
  464. if (_this.isFirstShowInsertAd && Utils_1.utils.getConfigByKey("insert_ad_first_show_active") == "true") {
  465. _this.isFirstShowInsertAd = false;
  466. Utils_1.utils.wechatTool.reportAttributedEvent(YZ_Constant_1.AttributedType.GameAddiction, YZ_Constant_1.AttributedKey.GameAddiction, YZ_Constant_1.AttributedValue.InsertAdFirstShowAction);
  467. }
  468. }).catch(function (err) {
  469. Utils_1.utils.showLog("插屏广告展示失败!", JSON.stringify(err));
  470. if (_this.ServerConfig.intersititial_first_ad && _this.ServerConfig.intersititial_first_ad == "default") {
  471. _this.showNativeIntersititialAd();
  472. }
  473. // if (this.ServerConfig && this.ServerConfig.intersititial_first_ad == "default") {
  474. // utils.showLog("优先展示默认插屏,显示备选盒子插屏!");
  475. // if (this.canShowBoxInsertAd()) {
  476. // this._createBoxInsertAd();
  477. // }
  478. // }
  479. });
  480. }
  481. else {
  482. Utils_1.utils.showLog("插屏广告未初始化");
  483. if (this.ServerConfig.intersititial_first_ad && this.ServerConfig.intersititial_first_ad == "default") {
  484. this.showNativeIntersititialAd();
  485. }
  486. // if (this.ServerConfig && this.ServerConfig.intersititial_first_ad == "default") {
  487. // utils.showLog("优先展示默认插屏,显示备选盒子插屏!");
  488. // if (this.canShowBoxInsertAd()) {
  489. // this._createBoxInsertAd();
  490. // }
  491. // }
  492. }
  493. };
  494. AdAgentWechat.prototype.ShowVideo = function (callback) {
  495. if (PlatUtils_1.default.IsWechat) {
  496. this._videoCallback = callback;
  497. if (this.checkRewardInsertIsShow() && Utils_1.utils.wechatTool
  498. && Utils_1.utils.wechatTool.ServerConfig
  499. && Utils_1.utils.wechatTool.ServerConfig.reward_first_ad && Utils_1.utils.wechatTool.ServerConfig.reward_first_ad != "video") {
  500. Utils_1.utils.showLog("<<<服务器默认优先展示激励插屏>>>");
  501. this.showRewardInsert();
  502. return;
  503. }
  504. if (!Utils_1.utils.wechatTool.isOverMinVersion("2.0.4")) {
  505. Utils_1.utils.showLog("当前版本不支持视频广告!");
  506. if (this._videoCallback) {
  507. // this._videoCallback(false, "暂无视频广告!");
  508. this.showRewardInsert();
  509. }
  510. return;
  511. }
  512. if (this._videoAd) {
  513. this._videoAd.show().then(function () {
  514. Utils_1.utils.showLog("视频显示成功!");
  515. }.bind(this)).catch(function (err) {
  516. Utils_1.utils.showLog("视频未加载!");
  517. this._videoAd.load();
  518. if (this._videoCallback) {
  519. // this._videoCallback(false, "暂无视频广告!");
  520. this.showRewardInsert();
  521. }
  522. }.bind(this));
  523. }
  524. else {
  525. Utils_1.utils.showLog("视频未初始化!");
  526. if (this._videoCallback) {
  527. // this._videoCallback(false, "暂无视频广告!");
  528. this.showRewardInsert();
  529. }
  530. }
  531. }
  532. };
  533. /**
  534. * 验证是否显示激励插屏
  535. */
  536. AdAgentWechat.prototype.checkRewardInsertIsShow = function () {
  537. var jumpList = Utils_1.utils.getRecommondGameList();
  538. if (Utils_1.utils.isSupportnavigateToMiniGame()) {
  539. if (Utils_1.utils.wechatTool
  540. && Utils_1.utils.wechatTool.ServerConfig
  541. && Utils_1.utils.wechatTool.ServerConfig.is_reward_intersititia) {
  542. if (Utils_1.utils.wechatTool.ServerConfig.is_reward_intersititia == "true"
  543. && jumpList && jumpList.length > 0) {
  544. Utils_1.utils.showLog("激励插屏显示环境验证通过!");
  545. return true;
  546. }
  547. else {
  548. cc.warn("is_reward_intersititia 参数为false,激励插屏组件不显示!");
  549. return false;
  550. }
  551. }
  552. else {
  553. cc.warn("配置中没有is_reward_intersititia参数,激励插屏组件组件不显示!");
  554. return false;
  555. }
  556. }
  557. Utils_1.utils.showLog("当前平台不支持小程序跳转!");
  558. return false;
  559. };
  560. /**
  561. * 显示激励插屏组件
  562. */
  563. AdAgentWechat.prototype.showRewardInsert = function () {
  564. Utils_1.utils.showLog("show reward");
  565. if (!this.checkRewardInsertIsShow()) {
  566. Utils_1.utils.adManager.videoCallBack && Utils_1.utils.adManager.videoCallBack(false, "暂无视频广告!");
  567. Utils_1.utils.adManager.videoCallBack = null;
  568. return;
  569. }
  570. if (((!cc.isValid(this._rewardInsertNode)) || !this._rewardInsertNode) && Utils_1.utils.config.otherconfig.rewardInsert) {
  571. Utils_1.utils.showLog("创建激励插屏广告");
  572. this._rewardInsertNode = cc.instantiate(Utils_1.utils.config.otherconfig.rewardInsert);
  573. this._rewardInsertNode.position = CompatibleTool_1.default.position(cc.winSize.width / 2, cc.winSize.height / 2);
  574. cc.director.getScene().addChild(this._rewardInsertNode, 9999);
  575. }
  576. if (this._rewardInsertNode) {
  577. var rewardInsert = this._rewardInsertNode.getComponent("RewardInsert");
  578. if (rewardInsert) {
  579. rewardInsert.isShow = false;
  580. Utils_1.utils.showLog("显示激励插屏组件!");
  581. }
  582. else {
  583. Utils_1.utils.showLog("RewardInsert组件不存在!");
  584. }
  585. }
  586. else {
  587. Utils_1.utils.showLog("激励插屏没有创建!");
  588. }
  589. };
  590. AdAgentWechat.prototype.hideRewardInsert = function () {
  591. if (this._rewardInsertNode) {
  592. var rewardInsert = this._rewardInsertNode.getComponent("RewardInsert");
  593. if (rewardInsert) {
  594. rewardInsert.hide();
  595. Utils_1.utils.showLog("隐藏激励插屏组件!");
  596. }
  597. else {
  598. Utils_1.utils.showLog("RewardInsert组件不存在!");
  599. }
  600. }
  601. else {
  602. Utils_1.utils.showLog("激励插屏没有创建!");
  603. }
  604. };
  605. AdAgentWechat.prototype.ShowCloseBtnBanner = function (location, args) {
  606. if (location === void 0) { location = YZ_Constant_1.BannerLocation.Home; }
  607. if (PlatUtils_1.default.IsWechat) {
  608. if (Utils_1.utils.wechatTool && !Utils_1.utils.wechatTool.isOverMinVersion("2.0.4")) {
  609. Utils_1.utils.showLog("当前版本不支持Banner广告!");
  610. return;
  611. }
  612. if (Utils_1.utils.wechatTool.ServerConfig && (!Utils_1.utils.wechatTool.ServerConfig.isMoveBtn || Utils_1.utils.wechatTool.ServerConfig.isMoveBtn != "true")) {
  613. Utils_1.utils.showLog("服务器没有开启移动按钮,不显示广告!");
  614. return;
  615. }
  616. if (Utils_1.utils.wechatTool && Utils_1.utils.wechatTool.ServerConfig) {
  617. if (PlatUtils_1.default.IsWechat) {
  618. var locationTmp = location;
  619. // let argsTmp: any = args;
  620. var params = {
  621. adUnitId: Utils_1.utils.config.wechatconfig.getBannerId(locationTmp),
  622. style: {
  623. left: 0,
  624. width: 300,
  625. top: 0
  626. }
  627. };
  628. if (this._oldBannerLocation != locationTmp && this._curBannerAd) {
  629. this._curBannerAd.destroy();
  630. this._oldBannerLocation = locationTmp;
  631. }
  632. //@ts-ignore
  633. var curBannerAd_3 = wx.createBannerAd(params);
  634. if (curBannerAd_3) {
  635. curBannerAd_3.onError(function (err) {
  636. Utils_1.utils.showLog("广告条加载失败! ", JSON.stringify(err));
  637. if (curBannerAd_3) {
  638. curBannerAd_3.destroy();
  639. }
  640. });
  641. var self_4 = this;
  642. curBannerAd_3.onLoad(function () {
  643. curBannerAd_3.show().then(function () {
  644. var old = self_4._curBannerAd;
  645. if (old) {
  646. old.destroy();
  647. }
  648. self_4._curBannerAd = curBannerAd_3;
  649. var closeBtn = args.closeBtn;
  650. if (!closeBtn) {
  651. return;
  652. }
  653. // closeBtn.active = true;
  654. //调整关闭按钮位置
  655. var winHeight = cc.winSize.height;
  656. var adY = self_4.getBannerAdHeight();
  657. Utils_1.utils.showLog('utils - adY:', adY);
  658. if (adY > 0) {
  659. closeBtn.y = -(winHeight / 2 - adY) + closeBtn.height;
  660. Utils_1.utils.showLog("btnClose.y", closeBtn.y);
  661. }
  662. Utils_1.utils.showLog("关闭按钮---Banner广告显示成功!");
  663. }).catch(function (err) {
  664. Utils_1.utils.showLog("Banner广告出错", JSON.stringify(err));
  665. if (curBannerAd_3) {
  666. curBannerAd_3.destroy();
  667. }
  668. });
  669. });
  670. curBannerAd_3.onResize(function (res) {
  671. curBannerAd_3.style.width = Utils_1.utils.wechatTool.getSystemInfo().screenWidth * 0.6;
  672. curBannerAd_3.style.left = (Utils_1.utils.wechatTool.getSystemInfo().screenWidth - res.width) * 0.5;
  673. // if (self._bannerBottom == cc.winSize.height) {
  674. // curBannerAd.style.top = 0;
  675. // } else {
  676. curBannerAd_3.style.top = Utils_1.utils.wechatTool.getSystemInfo().screenHeight - res.height;
  677. // }
  678. });
  679. }
  680. else {
  681. Utils_1.utils.showLog("广告条创建失败!");
  682. }
  683. }
  684. }
  685. else {
  686. Utils_1.utils.showLog("服务器配置数据未初始化!");
  687. }
  688. }
  689. };
  690. /**
  691. * 是否能显示6个元素的交叉推广组件
  692. */
  693. AdAgentWechat.prototype.canShowCrossWidget6 = function () {
  694. if (PlatUtils_1.default.IsWechat) {
  695. if (Utils_1.utils.isSupportnavigateToMiniGame()) {
  696. return true;
  697. }
  698. else {
  699. cc.warn("当前平台不支持游戏内跳转,6元素交叉推广组件不显示!");
  700. return false;
  701. }
  702. }
  703. };
  704. /**
  705. * 显示6元素交叉推广组件
  706. */
  707. AdAgentWechat.prototype.showCrossWidget6 = function () {
  708. if (this.canShowCrossWidget6()) {
  709. if (Utils_1.utils.config.otherconfig.crossWidget6) {
  710. return cc.instantiate(Utils_1.utils.config.otherconfig.crossWidget6);
  711. }
  712. else {
  713. Utils_1.utils.showLog("未找到预制体 CrossWidget6, 请查看CommonUtils组件上是否赋值!");
  714. }
  715. }
  716. return null;
  717. };
  718. /**
  719. * 显示结算广告
  720. * @param data 参数: closeBtn:
  721. * statement_type
  722. * 1:只显示小游戏插屏广告
  723. * 2:只显示6个互推广告
  724. * 3:显示插屏广告+6个互推
  725. */
  726. AdAgentWechat.prototype.showStatementAds = function (data) {
  727. var result = { "type": 0, "node": null };
  728. var node = null;
  729. this.ShowInterstitial();
  730. if (Utils_1.utils.canShowCrossWidget6()) {
  731. Utils_1.utils.showLog("服务器配置显示6个互推组件");
  732. node = this.showCrossWidget6();
  733. result.type = 1;
  734. result.node = node;
  735. return result;
  736. }
  737. return result;
  738. // if (this.ServerConfig && this.ServerConfig.statement_type) {
  739. // // let type = this.ServerConfig.statement_type;
  740. // let node: cc.Node = null;
  741. // let resType: number = 0;
  742. // this.ShowInterstitial();
  743. // if (this.canShowCrossWidget6()) {
  744. // node = this.showCrossWidget6();
  745. // resType = 1;
  746. // }
  747. // // switch (type) {
  748. // // case 1:
  749. // // utils.showLog("结算广告 >> 只显示小游戏插屏广告");
  750. // // this.ShowInterstitial();
  751. // // break;
  752. // // case 2:
  753. // // utils.showLog("结算广告 >> 只显示6个互推广告");
  754. // // node = this.showCrossWidget6();
  755. // // resType = 1;
  756. // // break;
  757. // // case 3:
  758. // // utils.showLog("结算广告 >> 显示插屏广告+6个互推");
  759. // // this.ShowInterstitial();
  760. // // node = this.showCrossWidget6();
  761. // // resType = 1;
  762. // // break;
  763. // // default:
  764. // // utils.showLog("非法的结算广告类型,:", type)
  765. // // break;
  766. // // }
  767. // result.type = resType;
  768. // result.node = node;
  769. // return result;
  770. // } else {
  771. // cc.warn("配置未初始化!");
  772. // return result;
  773. // }
  774. };
  775. /**
  776. * 获取banner广告高度
  777. */
  778. AdAgentWechat.prototype.getBannerAdHeight = function () {
  779. if (this._curBannerAd) {
  780. var i = this._curBannerAd.style.realHeight * 2;
  781. if (i === null || i === undefined || isNaN(i)) {
  782. return 0;
  783. }
  784. else {
  785. return i;
  786. }
  787. }
  788. return 0;
  789. };
  790. AdAgentWechat.prototype.showNativeTryGameWidget = function (params) {
  791. if (params === void 0) { params = null; }
  792. if (!Utils_1.utils.wechatTool.isOverMinVersion("2.11.1")) {
  793. Utils_1.utils.showLog("当前版本不支持原生广告!");
  794. return;
  795. }
  796. if (!this.ServerConfig) {
  797. Utils_1.utils.showLog("组件未初始化!");
  798. return;
  799. }
  800. if (!Utils_1.utils.config.wechatconfig.bannerBoxId) {
  801. Utils_1.utils.showLog("原生广告ID不存在");
  802. return;
  803. }
  804. var top = 0;
  805. var left = 0;
  806. if (params.top) {
  807. top = params.top / cc.winSize.height * this.sysInfo.screenHeight;
  808. }
  809. else {
  810. top = this.sysInfo.screenHeight - 112 - params.bottom / cc.winSize.height * this.sysInfo.screenHeight;
  811. }
  812. if (params.left) {
  813. left = params.left / cc.winSize.width * this.sysInfo.screenWidth;
  814. }
  815. else if (params.right) {
  816. left = this.sysInfo.screenWidth - 70 - params.right / cc.winSize.width * this.sysInfo.screenWidth;
  817. }
  818. //@ts-ignore
  819. var customAd = wx.createCustomAd({
  820. // adUnitId: utils.config.wechatconfig.bannerBoxId,
  821. adUnitId: Utils_1.utils.config.wechatconfig.bannerBoxId,
  822. adIntervals: 30,
  823. style: {
  824. left: left,
  825. top: top
  826. }
  827. });
  828. customAd.onError(function (erro) {
  829. Utils_1.utils.showLog("原生广告异常!>>>>> #code=" + erro.errCode + " #msg=" + erro.errMsg);
  830. if (params.onError) {
  831. Utils_1.utils.showLog("执行微信原生广告异常回调!");
  832. params.onError();
  833. }
  834. });
  835. customAd.onLoad(function () {
  836. Utils_1.utils.showLog("微信原生广告加载成功!");
  837. customAd.show().then(function () {
  838. if (params.onSuccess) {
  839. Utils_1.utils.showLog("执行微信原生广告显示成功回调!");
  840. params.onSuccess();
  841. }
  842. Utils_1.utils.showLog("微信原生广告显示成功!");
  843. }).catch(function (err) {
  844. Utils_1.utils.showLog("微信原生广告显示失败!");
  845. });
  846. });
  847. this._customAdObjs.push(customAd);
  848. };
  849. AdAgentWechat.prototype.showCustomAd = function (params) {
  850. if (params === void 0) { params = null; }
  851. if (!Utils_1.utils.wechatTool.isOverMinVersion("2.11.1")) {
  852. Utils_1.utils.showLog("当前版本不支持原生模版广告!");
  853. return;
  854. }
  855. if (!this.ServerConfig) {
  856. Utils_1.utils.showLog("组件未初始化!");
  857. return;
  858. }
  859. if (Utils_1.utils.config.wechatconfig.customAdInfos.length < 1) {
  860. Utils_1.utils.showLog("原生广告配置不存在");
  861. return;
  862. }
  863. var customAdInfo = Utils_1.utils.config.wechatconfig.getCustomAdInfoInfo(params.location);
  864. if (!customAdInfo) {
  865. Utils_1.utils.showLog("当前位置未配置模版广告!");
  866. return;
  867. }
  868. // utils.showLog("显示原生模版广告:位置:" + params.location + ",配置:" + customAdInfo.toStrong);
  869. var top = 0;
  870. var left = 0;
  871. // about:左右居中
  872. // updown:上下
  873. // all:上下和左右居中
  874. // false:自定义对齐方式
  875. if (customAdInfo.is_center == "false") {
  876. if (customAdInfo.top > -1) {
  877. top = customAdInfo.top / cc.winSize.height * this.sysInfo.screenHeight;
  878. }
  879. else {
  880. top = this.sysInfo.screenHeight - customAdInfo.height - customAdInfo.bottom / cc.winSize.height * this.sysInfo.screenHeight;
  881. }
  882. if (customAdInfo.left > -1) {
  883. left = customAdInfo.left / cc.winSize.width * this.sysInfo.screenWidth;
  884. }
  885. else {
  886. left = this.sysInfo.screenWidth - customAdInfo.width - customAdInfo.right / cc.winSize.width * this.sysInfo.screenWidth;
  887. }
  888. }
  889. else if (customAdInfo.is_center == "updown") {
  890. Utils_1.utils.showLog("原生模版上下居中对齐!");
  891. if (customAdInfo.left > -1) {
  892. left = customAdInfo.left / cc.winSize.width * this.sysInfo.screenWidth;
  893. }
  894. else {
  895. left = this.sysInfo.screenWidth - customAdInfo.width - customAdInfo.right / cc.winSize.width * this.sysInfo.screenWidth;
  896. }
  897. top = (this.sysInfo.screenHeight - customAdInfo.height) / 2;
  898. }
  899. else if (customAdInfo.is_center == "about") {
  900. Utils_1.utils.showLog("原生模版左右居中对齐!");
  901. left = (this.sysInfo.screenWidth - customAdInfo.width) / 2;
  902. if (customAdInfo.top > -1) {
  903. top = customAdInfo.top / cc.winSize.height * this.sysInfo.screenHeight;
  904. }
  905. else {
  906. top = this.sysInfo.screenHeight - customAdInfo.height - customAdInfo.bottom / cc.winSize.height * this.sysInfo.screenHeight;
  907. }
  908. }
  909. else {
  910. Utils_1.utils.showLog("原生模版上下左右居中对齐!");
  911. left = (this.sysInfo.screenWidth - customAdInfo.width) / 2;
  912. top = (this.sysInfo.screenHeight - customAdInfo.height) / 2;
  913. }
  914. //@ts-ignore
  915. var customAd = wx.createCustomAd({
  916. adUnitId: customAdInfo.id,
  917. adIntervals: customAdInfo.refresh_time,
  918. style: {
  919. left: left,
  920. top: top,
  921. width: customAdInfo.width
  922. }
  923. });
  924. customAd.location = params.location;
  925. Utils_1.utils.showLog("customAd style left=" + left + ",top=" + top + "; screenWidth=" + this.sysInfo.screenWidth + ", screenHeight=" + this.sysInfo.screenHeight);
  926. customAd.onError(function (erro) {
  927. Utils_1.utils.showLog("原生广告异常!>>>>> #code=" + erro.errCode + " #msg=" + erro.errMsg);
  928. if (params.onError) {
  929. Utils_1.utils.showLog("执行微信原生广告异常回调!");
  930. params.onError();
  931. }
  932. });
  933. customAd.onLoad(function () {
  934. Utils_1.utils.showLog("微信原生广告加载成功!");
  935. customAd.show().then(function () {
  936. if (params.onSuccess) {
  937. Utils_1.utils.showLog("执行微信原生广告显示成功回调!");
  938. params.onSuccess();
  939. }
  940. Utils_1.utils.showLog("微信原生广告显示成功!");
  941. }).catch(function (err) {
  942. Utils_1.utils.showLog("微信原生广告显示失败!");
  943. });
  944. });
  945. this._customAdObjs.push(customAd);
  946. };
  947. /**
  948. * 隐藏原生模版广告
  949. */
  950. AdAgentWechat.prototype.hideCustomAd = function (params) {
  951. for (var i = 0; i < this._customAdObjs.length; i++) {
  952. if (this._customAdObjs[i]) {
  953. if (params && "location" in params) {
  954. if (this._customAdObjs[i].location == params.location) {
  955. Utils_1.utils.showLog("隐藏位置:" + params.location + "的原生模版广告");
  956. this._customAdObjs[i].destroy();
  957. this._customAdObjs.splice(i, 1);
  958. }
  959. }
  960. else {
  961. this._customAdObjs[i].destroy();
  962. this._customAdObjs.splice(i, 1);
  963. }
  964. }
  965. }
  966. if (!params || !("location" in params))
  967. Utils_1.utils.showLog("隐藏所有位置的原生模版广告");
  968. };
  969. /**
  970. * 隐藏原生试玩广告
  971. */
  972. AdAgentWechat.prototype.hideNativeTryGameWidget = function () {
  973. for (var i = 0; i < this._customAdObjs.length; i++) {
  974. if (this._customAdObjs[i]) {
  975. this._customAdObjs[i].destroy();
  976. }
  977. }
  978. for (var i = 0; i < this._customAdObjs.length; i++) {
  979. this._customAdObjs.splice(i, 1);
  980. }
  981. };
  982. AdAgentWechat.prototype.showNativeBannerAd = function (location, args) {
  983. var _this = this;
  984. if (args === void 0) { args = null; }
  985. Utils_1.utils.showLog("展示原生banner广告!");
  986. if (!Utils_1.utils.wechatTool.isOverMinVersion("2.11.1")) {
  987. Utils_1.utils.showLog("当前版本不支持原生模版广告!");
  988. return;
  989. }
  990. if (!this.ServerConfig) {
  991. Utils_1.utils.showLog("组件未初始化!");
  992. return;
  993. }
  994. if (!Utils_1.utils.config.wechatconfig.nativeBannerId) {
  995. Utils_1.utils.showLog("原生Banner广告ID配置不存在");
  996. return;
  997. }
  998. var bannerWidth = 325;
  999. var bannerHeight = 100;
  1000. var left = (this.sysInfo.screenWidth - bannerWidth) / 2;
  1001. var top = this.sysInfo.screenHeight - bannerHeight;
  1002. if (this.nativeBannerAd) {
  1003. if (this.nativeBannerAd.isShow()) {
  1004. Utils_1.utils.showLog("原生Banner正在显示,不重新创建!");
  1005. }
  1006. else {
  1007. this.nativeBannerAd.show().then(function () {
  1008. Utils_1.utils.showLog("原生Banner广告显示成功!");
  1009. _this.HideDefaultBanner();
  1010. }).catch(function (err) {
  1011. Utils_1.utils.showLog("原生Banner广告显示失败!");
  1012. _this.nativeBannerAd && _this.nativeBannerAd.destroy();
  1013. _this.nativeBannerAd = null;
  1014. if (_this.ServerConfig.banner_first_ad && _this.ServerConfig.banner_first_ad == "native") {
  1015. _this._createBanner(location, args);
  1016. }
  1017. });
  1018. }
  1019. return;
  1020. }
  1021. //@ts-ignore
  1022. var customAd = wx.createCustomAd({
  1023. adUnitId: Utils_1.utils.config.wechatconfig.nativeBannerId,
  1024. adIntervals: Utils_1.utils.wechatTool.ServerConfig.refresh_ad_time || 30,
  1025. style: {
  1026. left: left,
  1027. top: top,
  1028. width: bannerWidth
  1029. }
  1030. });
  1031. Utils_1.utils.showLog("native nanner ad style left=" + left + ",top=" + top + "; screenWidth=" + this.sysInfo.screenWidth + ", screenHeight=" + this.sysInfo.screenHeight);
  1032. customAd.onError(function (erro) {
  1033. Utils_1.utils.showLog("原生Banner广告异常!>>>>> #code=" + erro.errCode + " #msg=" + erro.errMsg);
  1034. _this.nativeBannerAd && _this.nativeBannerAd.destroy();
  1035. _this.nativeBannerAd = null;
  1036. if (_this.ServerConfig.banner_first_ad && _this.ServerConfig.banner_first_ad == "native") {
  1037. _this._createBanner(location, args);
  1038. }
  1039. });
  1040. customAd.onLoad(function () {
  1041. Utils_1.utils.showLog("原生Banner广告加载成功!");
  1042. customAd.show().then(function () {
  1043. _this.nativeBannerAd && _this.nativeBannerAd.destroy();
  1044. _this.nativeBannerAd = customAd;
  1045. Utils_1.utils.showLog("原生Banner广告显示成功!");
  1046. _this.HideDefaultBanner();
  1047. }).catch(function (err) {
  1048. Utils_1.utils.showLog("原生Banner广告显示失败!");
  1049. _this.nativeBannerAd && _this.nativeBannerAd.destroy();
  1050. _this.nativeBannerAd = null;
  1051. if (_this.ServerConfig.banner_first_ad && _this.ServerConfig.banner_first_ad == "native") {
  1052. _this._createBanner(location, args);
  1053. }
  1054. });
  1055. });
  1056. };
  1057. AdAgentWechat.prototype.showNativeIntersititialAd = function () {
  1058. var _this = this;
  1059. Utils_1.utils.showLog("展示原生插屏广告!");
  1060. if (!Utils_1.utils.wechatTool.isOverMinVersion("2.11.1")) {
  1061. Utils_1.utils.showLog("当前版本不支持原生模版广告!");
  1062. return;
  1063. }
  1064. if (!this.ServerConfig) {
  1065. Utils_1.utils.showLog("组件未初始化!");
  1066. return;
  1067. }
  1068. if (!Utils_1.utils.config.wechatconfig.nativeInsertIds) {
  1069. Utils_1.utils.showLog("原生插屏广告ID配置不存在");
  1070. return;
  1071. }
  1072. var insertWidth = 345;
  1073. var insertHeight = 420;
  1074. if (cc.winSize.width > cc.winSize.height) {
  1075. insertHeight = 300;
  1076. }
  1077. var left = (this.sysInfo.screenWidth - insertWidth) / 2;
  1078. var top = (this.sysInfo.screenHeight - insertHeight) / 2;
  1079. if (this.nativeIntersititialAd) {
  1080. if (this.nativeIntersititialAd.isShow()) {
  1081. Utils_1.utils.showLog("原生插屏正在显示,不重新创建!");
  1082. }
  1083. else {
  1084. this.nativeIntersititialAd.show().then(function () {
  1085. Utils_1.utils.showLog("原生插屏广告显示成功!");
  1086. }).catch(function (err) {
  1087. Utils_1.utils.showLog("原生插屏广告显示失败!");
  1088. _this.nativeIntersititialAd && _this.nativeIntersititialAd.destroy();
  1089. _this.nativeIntersititialAd = null;
  1090. if (_this.ServerConfig.intersititial_first_ad && _this.ServerConfig.intersititial_first_ad == "native") {
  1091. _this._createMiniGameInsertAd();
  1092. }
  1093. });
  1094. }
  1095. return;
  1096. }
  1097. //@ts-ignore
  1098. var customAd = wx.createCustomAd({
  1099. adUnitId: Utils_1.utils.config.wechatconfig.nativeInsertIds,
  1100. adIntervals: 60,
  1101. style: {
  1102. left: left,
  1103. top: top,
  1104. width: insertWidth
  1105. }
  1106. });
  1107. Utils_1.utils.showLog("native insert ad style left=" + left + ",top=" + top + "; screenWidth=" + this.sysInfo.screenWidth + ", screenHeight=" + this.sysInfo.screenHeight);
  1108. customAd.onError(function (erro) {
  1109. Utils_1.utils.showLog("原生插屏广告异常!>>>>> #code=" + erro.errCode + " #msg=" + erro.errMsg);
  1110. _this.nativeIntersititialAd && _this.nativeIntersititialAd.destroy();
  1111. _this.nativeIntersititialAd = null;
  1112. if (_this.ServerConfig.intersititial_first_ad && _this.ServerConfig.intersititial_first_ad == "native") {
  1113. _this._createMiniGameInsertAd();
  1114. }
  1115. });
  1116. customAd.onLoad(function () {
  1117. Utils_1.utils.showLog("原生插屏广告加载成功!");
  1118. customAd.show().then(function () {
  1119. _this.nativeIntersititialAd && _this.nativeIntersititialAd.destroy();
  1120. _this.nativeIntersititialAd = customAd;
  1121. Utils_1.utils.showLog("原生插屏广告显示成功!");
  1122. }).catch(function (err) {
  1123. Utils_1.utils.showLog("原生插屏广告显示失败!");
  1124. _this.nativeIntersititialAd && _this.nativeIntersititialAd.destroy();
  1125. _this.nativeIntersititialAd = null;
  1126. if (_this.ServerConfig.intersititial_first_ad && _this.ServerConfig.intersititial_first_ad == "native") {
  1127. _this._createMiniGameInsertAd();
  1128. }
  1129. });
  1130. });
  1131. };
  1132. AdAgentWechat = __decorate([
  1133. ccclass
  1134. ], AdAgentWechat);
  1135. return AdAgentWechat;
  1136. }(AdAgent_1.default));
  1137. exports.default = AdAgentWechat;
  1138. cc._RF.pop();