mirror of
https://github.com/Gongxh0901/kunpolibrary
synced 2025-04-28 14:28:43 +00:00
调整微信和抖音小游戏广告内部实现
This commit is contained in:
parent
d4d71825a1
commit
7e184b9495
2
libs/lib.ali.api.d.ts
vendored
2
libs/lib.ali.api.d.ts
vendored
@ -2552,7 +2552,7 @@ declare namespace AliyMiniprogram {
|
|||||||
/**
|
/**
|
||||||
* 广告加载完成
|
* 广告加载完成
|
||||||
*/
|
*/
|
||||||
onLoad(listener: () => void);
|
onLoad(listener: (res: any) => void);
|
||||||
/**
|
/**
|
||||||
* 监听激励广告加载错误的事件
|
* 监听激励广告加载错误的事件
|
||||||
2 参数类型错误。请确认创建广告时传入的广告单元 ID 合法。 -
|
2 参数类型错误。请确认创建广告时传入的广告单元 ID 合法。 -
|
||||||
|
@ -39,8 +39,8 @@ export class AlipayAds implements IMiniRewardAds {
|
|||||||
}
|
}
|
||||||
this._video_ad.load().then(() => {
|
this._video_ad.load().then(() => {
|
||||||
this._video_ad.show();
|
this._video_ad.show();
|
||||||
}).catch((res: { errMsg: string; errNo: number }) => {
|
}).catch((res: { errorMessage: string; error: number }) => {
|
||||||
this._fail(res.errNo, res.errMsg);
|
this._fail(res.error, res.errorMessage);
|
||||||
this.reset();
|
this.reset();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* @Description: 字节跳动广告
|
* @Description: 字节跳动广告
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { log, warn } from "../../tool/log";
|
import { warn } from "../../tool/log";
|
||||||
import { MiniErrorCode } from "../header";
|
import { MiniErrorCode } from "../header";
|
||||||
import { IMiniRewardAds } from "../interface/IMiniAds";
|
import { IMiniRewardAds } from "../interface/IMiniAds";
|
||||||
|
|
||||||
@ -34,41 +34,36 @@ export class BytedanceAds implements IMiniRewardAds {
|
|||||||
res.fail(MiniErrorCode.AD_NOT_INIT.code, MiniErrorCode.AD_NOT_INIT.msg);
|
res.fail(MiniErrorCode.AD_NOT_INIT.code, MiniErrorCode.AD_NOT_INIT.msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (this._success) {
|
||||||
|
warn(MiniErrorCode.AD_PLAYING.msg);
|
||||||
|
res.fail(MiniErrorCode.AD_PLAYING.code, MiniErrorCode.AD_PLAYING.msg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
this._success = res.success;
|
this._success = res.success;
|
||||||
this._fail = res.fail;
|
this._fail = res.fail;
|
||||||
|
|
||||||
if (!this._video_ad) {
|
if (!this._video_ad) {
|
||||||
this._video_ad = this.createVideoAd();
|
this._video_ad = this.createVideoAd();
|
||||||
}
|
}
|
||||||
log("加载广告");
|
this._video_ad.show();
|
||||||
this._video_ad.load().then(() => {
|
|
||||||
log("广告加载成功");
|
|
||||||
this._video_ad.show();
|
|
||||||
}).catch((res: { errMsg: string; errNo: number }) => {
|
|
||||||
warn(`广告加载失败 errCode:${res.errNo} errMsg:${res.errMsg}`);
|
|
||||||
this._fail(res.errNo, res.errMsg);
|
|
||||||
this.reset();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private createVideoAd(): BytedanceMiniprogram.RewardedVideoAd {
|
private createVideoAd(): BytedanceMiniprogram.RewardedVideoAd {
|
||||||
let videoAd = tt.createRewardedVideoAd({ adUnitId: this._adUnitId, multiton: false });
|
let videoAd = tt.createRewardedVideoAd({ adUnitId: this._adUnitId, multiton: false });
|
||||||
/** 激励视频错误事件的监听函数 */
|
/** 激励视频错误事件的监听函数 */
|
||||||
videoAd.onError((res: { errMsg: string; errCode: number }) => {
|
videoAd.onError((res: { errMsg: string; errCode: number }) => {
|
||||||
warn(`激励视频广告 onError:${res.errCode}:${res.errMsg}`);
|
this._fail?.(res.errCode, res.errMsg);
|
||||||
this._fail(res.errCode, res.errMsg);
|
|
||||||
this.reset();
|
this.reset();
|
||||||
});
|
});
|
||||||
videoAd.onClose((res: { isEnded: boolean, count?: number }) => {
|
videoAd.onClose((res: { isEnded: boolean, count?: number }) => {
|
||||||
if ((res && res.isEnded) || res === undefined) {
|
if (res.count || res.isEnded) {
|
||||||
/** 广告播放完成 */
|
/** 广告播放完成 */
|
||||||
this?._success();
|
this?._success();
|
||||||
this.reset();
|
|
||||||
} else {
|
} else {
|
||||||
/** 中途退出,不发放奖励 */
|
/** 中途退出,不发放奖励 */
|
||||||
this?._fail(MiniErrorCode.AD_EXIT.code, MiniErrorCode.AD_EXIT.msg);
|
this?._fail(MiniErrorCode.AD_EXIT.code, MiniErrorCode.AD_EXIT.msg);
|
||||||
this.reset();
|
|
||||||
}
|
}
|
||||||
|
this.reset();
|
||||||
});
|
});
|
||||||
return videoAd;
|
return videoAd;
|
||||||
}
|
}
|
||||||
|
@ -14,10 +14,14 @@ export const MiniErrorCode = {
|
|||||||
PAY_NOT_IMPLEMENTED: { code: -96003, msg: "当前平台未实现支付" },
|
PAY_NOT_IMPLEMENTED: { code: -96003, msg: "当前平台未实现支付" },
|
||||||
/** 版本号低 */
|
/** 版本号低 */
|
||||||
VERSION_LOW: { code: -96004, msg: "版本号过低" },
|
VERSION_LOW: { code: -96004, msg: "版本号过低" },
|
||||||
|
|
||||||
|
|
||||||
/** 广告未初始化 */
|
/** 广告未初始化 */
|
||||||
AD_NOT_INIT: { code: -97001, msg: "广告未初始化, 需要先调用init方法初始化" },
|
AD_NOT_INIT: { code: -97001, msg: "广告未初始化, 需要先调用init方法初始化" },
|
||||||
/** 广告中途退出*/
|
/** 广告中途退出*/
|
||||||
AD_EXIT: { code: -97002, msg: "广告中途退出" },
|
AD_EXIT: { code: -97002, msg: "广告中途退出" },
|
||||||
|
/** 广告正在播放中 不允许重复调用 */
|
||||||
|
AD_PLAYING: { code: -97003, msg: "广告正在播放中 不允许重复调用" },
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 统一价格限制列表 (微信、支付宝和字节 取交集) */
|
/** 统一价格限制列表 (微信、支付宝和字节 取交集) */
|
||||||
|
@ -34,29 +34,33 @@ export class WechatAds implements IMiniRewardAds {
|
|||||||
res.fail(MiniErrorCode.AD_NOT_INIT.code, MiniErrorCode.AD_NOT_INIT.msg);
|
res.fail(MiniErrorCode.AD_NOT_INIT.code, MiniErrorCode.AD_NOT_INIT.msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (this._success) {
|
||||||
|
warn(MiniErrorCode.AD_PLAYING.msg);
|
||||||
|
res.fail(MiniErrorCode.AD_PLAYING.code, MiniErrorCode.AD_PLAYING.msg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this._success = res.success;
|
this._success = res.success;
|
||||||
this._fail = res.fail;
|
this._fail = res.fail;
|
||||||
|
|
||||||
if (!this._video_ad) {
|
if (!this._video_ad) {
|
||||||
this._video_ad = this.createVideoAd();
|
this._video_ad = this.createVideoAd();
|
||||||
}
|
}
|
||||||
this._video_ad.load().then(() => {
|
this._video_ad.show().catch(() => {
|
||||||
this._video_ad.show();
|
this._video_ad.load().then(() => {
|
||||||
}).catch((res: { errMsg: string; errNo: number }) => {
|
this._video_ad.show().catch((res) => {
|
||||||
warn(`广告加载失败 errCode:${res.errNo} errMsg:${res.errMsg}`);
|
this._fail(res.errCode, res.errMsg);
|
||||||
this._fail(res.errNo, res.errMsg);
|
this.reset();
|
||||||
this.reset();
|
});
|
||||||
|
}).catch((res) => {
|
||||||
|
this._fail(res.errCode, res.errMsg);
|
||||||
|
this.reset();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private createVideoAd(): WechatMiniprogram.RewardedVideoAd {
|
private createVideoAd(): WechatMiniprogram.RewardedVideoAd {
|
||||||
let videoAd = wx.createRewardedVideoAd({ adUnitId: this._adUnitId });
|
let videoAd = wx.createRewardedVideoAd({ adUnitId: this._adUnitId });
|
||||||
/** 激励视频错误事件的监听函数 */
|
|
||||||
videoAd.onError((res: WechatMiniprogram.RewardedVideoAdOnErrorListenerResult) => {
|
|
||||||
warn(`激励视频广告 onError:${res.errCode}:${res.errMsg}`);
|
|
||||||
this._fail(res.errCode, res.errMsg);
|
|
||||||
this.reset();
|
|
||||||
});
|
|
||||||
videoAd.onClose((res: WechatMiniprogram.RewardedVideoAdOnCloseListenerResult) => {
|
videoAd.onClose((res: WechatMiniprogram.RewardedVideoAdOnCloseListenerResult) => {
|
||||||
if ((res && res.isEnded) || res === undefined) {
|
if ((res && res.isEnded) || res === undefined) {
|
||||||
/** 广告播放完成 */
|
/** 广告播放完成 */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user