System.register(["cc"], function (_export, _context) { "use strict"; var _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, _decorator, Component, sys, _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _class3, _crd, ccclass, property, WXSdk; function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); } function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; } function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); } return { setters: [function (_cc) { _cclegacy = _cc.cclegacy; __checkObsolete__ = _cc.__checkObsolete__; __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__; _decorator = _cc._decorator; Component = _cc.Component; sys = _cc.sys; }], execute: function () { _crd = true; _cclegacy._RF.push({}, "73835gWGXdG0aw7CghDdY6u", "WXSdk", undefined); __checkObsolete__(['_decorator', 'Component', 'director', 'game', 'Node', 'sys']); ({ ccclass, property } = _decorator); _export("WXSdk", WXSdk = (_dec = ccclass('WXSdk'), _dec2 = property({ displayName: "原生广告uid" }), _dec3 = property({ displayName: "视频奖励广告uid" }), _dec4 = property({ displayName: "插屏广告uid" }), _dec5 = property({ displayName: "分享图url" }), _dec6 = property({ displayName: "分享tile文本" }), _dec(_class = (_class2 = (_class3 = class WXSdk extends Component { constructor() { super(...arguments); _initializerDefineProperty(this, "bannerId", _descriptor, this); _initializerDefineProperty(this, "videoUid", _descriptor2, this); _initializerDefineProperty(this, "interstitialUid", _descriptor3, this); _initializerDefineProperty(this, "shareImageUrl", _descriptor4, this); _initializerDefineProperty(this, "shareTilt", _descriptor5, this); this.bannerAdv = null; this.videoAdv = null; this.interstitialAd = null; this.successCallback = null; } onLoad() { WXSdk.instance = this; } initBanner() { var winSize = wx.getSystemInfoSync(); //获取像素size var bannerWidth = 300; var bannerHeight = 80; // 创建 原生模板 广告实例,提前初始化 var CustomAd = wx.createCustomAd({ adUnitId: 'adunit-dbdd10d1ca3690d2', style: { left: (winSize.windowWidth - bannerWidth) / 2, top: winSize.windowHeight - bannerHeight, width: bannerWidth } }); // // 在适合的场景显示 原生模板 广告 // CustomAd.show() // 监听 原生模板 广告错误事件 CustomAd.onError(err => { console.error(err.errMsg); }); this.bannerAdv = CustomAd; } initVideo() { // 创建激励视频广告实例,提前初始化 this.videoAdv = wx.createRewardedVideoAd({ adUnitId: this.videoUid //传入自己的id,此处为视频广告位ID }); } initInterstitial() { if (wx.createInterstitialAd) { this.interstitialAd = wx.createInterstitialAd({ adUnitId: this.interstitialUid //传入自己的id,此处为插屏广告位ID }); } } init() { if (sys.platform == sys.Platform.WECHAT_GAME) { this.initBanner(); this.initVideo(); // 创建插屏广告实例,提前初始化 this.initInterstitial(); this.passivityShare(); } } // 主动分享 initativeShare(callBack) { var shareTitle = this.shareTilt; var imageUrl = this.shareImageUrl; // 主动拉起转发,进入选择通讯录界面 wx.shareAppMessage({ // 转发标题, 没有则默认使用小游戏的昵称 title: shareTitle, // 图片链接, imageUrl: imageUrl }); } passivityShare(callBack) { // 授权显示菜单 wx.showShareMenu({ withShareTicket: false, // 显示菜单 menus: ['shareAppMessage', 'shareTimeline'], success: res => { console.log("开始被动转发shareMenu成功"); }, fail: () => { console.log("开始被动转发shareMenu失败"); } }); var shareTitle = this.shareTilt; var imageUrl = this.shareImageUrl; // 好友点击回调 wx.onShareAppMessage(() => { return { // 转发标题, 没有则默认使用小游戏的昵称 title: shareTitle, // 图片链接, imageUrl: imageUrl }; }); // 朋友圈点击回调 wx.onShareTimeline(() => { return { title: shareTitle, imageUrl: imageUrl }; }); } showBanner() { this.bannerAdv.show(); } hideBanner() { this.bannerAdv.hide(); } showInterstitial() { // 在适合的场景显示插屏广告 if (this.interstitialAd) { this.interstitialAd.show().catch(err => { console.error(err); }); } } showVideo(successCallback, failCallback) { // 用户触发广告后,显示激励视频广告 if (this.videoUid == "test" || this.videoUid == "") { successCallback(); return; } var self = this; self.videoAdv.show().catch(() => { // 失败重试 self.videoAdv.load().then(() => self.videoAdv.show()).catch(err => { console.log('激励视频 广告显示失败'); failCallback(); }); }); //拉取异常处理 self.videoAdv.onError(err => { console.log(err); failCallback(); }); self.videoAdv.onClose(res => { if (!self.videoAdv) return; self.videoAdv.offClose(); //需要清除回调,否则第N次广告会一次性给N个奖励 //关闭 if (res && res.isEnded || res === undefined) { //正常播放结束,需要下发奖励 successCallback(); } else { //播放退出,不下发奖励 failCallback(); } }); } }, _class3.instance = void 0, _class3), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "bannerId", [_dec2], { configurable: true, enumerable: true, writable: true, initializer: function initializer() { return ""; } }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "videoUid", [_dec3], { configurable: true, enumerable: true, writable: true, initializer: function initializer() { return ""; } }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "interstitialUid", [_dec4], { configurable: true, enumerable: true, writable: true, initializer: function initializer() { return ""; } }), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "shareImageUrl", [_dec5], { configurable: true, enumerable: true, writable: true, initializer: function initializer() { return "https://mmocgame.qpic.cn/wechatgame/fNvVoACuBEOmNhzE802RLqnUuQyZ4rXTicDqz7OlVKypjYcHHo7nyfoYe7Urvdk6T/0"; } }), _descriptor5 = _applyDecoratedDescriptor(_class2.prototype, "shareTilt", [_dec6], { configurable: true, enumerable: true, writable: true, initializer: function initializer() { return "超好玩解压停车场"; } })), _class2)) || _class)); _cclegacy._RF.pop(); _crd = false; } }; }); //# sourceMappingURL=9bb5a494a0ce54031b6a65bb881bfbc74b1b2ceb.js.map