提交 4c5b301b 作者: wj

回滚版本

上级 4aededc9
/**
* 鲸鱼游戏微信小游戏接入库
* @author 推广技术部
* @time: 2023-11-22
* @time: 2023-11-23
*
* 批量初始化视频广告
* 回滚版本
*
*/
class WechatSDK {
private sdkVersion: string = "3.3.4";
private sdkVersion: string = "3.3.5";
public LaunchOptions: Object; // 启动参数对象
public SystemInfo: Object; // 设备信息
......@@ -798,44 +798,39 @@ class WechatSDK {
"1000": "参数错误",
"1003": "米大师Portal错误",
};
// 激励广告
private ADREWARDARR: Array<any> = []; // 微信视频广告对象数组
// 创建视频广告
private videoAd: any = null; // 微信视频广告对象
// 初始化激励视频
public createWxVideoAd = async (unitID: Array<UNITITEM> = []) => {
for (let i = 0; i < unitID.length; i++) {
let reward = await (wx as any).createRewardedVideoAd({
adUnitId: unitID[i].id, // mp后台配置的广告id
});
reward.onError(err => {
console.log('微信激励广告视频播放失败:', err);
unitID[i].onError && unitID[i].onError(err);
});
// 监听广告关闭按钮
reward.onClose(res => {
// 用户点击【关闭广告】按钮
unitID[i].onClose && unitID[i].onClose({ status: res && res.isEnded, type: 'video', sort: i });
reward.offClose();
});
this.ADREWARDARR[i] = reward;
}
public createWxVideoAd = async (adCallBack: AdCallBack) => {
this.videoAd = await (wx as any).createRewardedVideoAd({
adUnitId: SDKConfig.WXADUNITID, // mp后台配置的广告id
});
this.videoAd.onError(err => {
console.log('微信激励广告视频播放失败:', err);
adCallBack.onError && adCallBack.onError(err);
});
// 监听广告关闭按钮
this.videoAd.onClose(res => {
// 用户点击【关闭广告】按钮
adCallBack.onClose && adCallBack.onClose({ status: res && res.isEnded, type: 'video' });
this.videoAd.offClose();
});
};
// 激励视频播放
public playAdVideo = async (index: number, Params: ProductInfo, callback: Function, retry: number = 0) => {
public playAdVideo = async (Params: ProductInfo, callback: Function, retry: number = 0) => {
if (retry > 2) {
callback({ status: false });
return;
}
let reward = this.ADREWARDARR[index];
reward && reward.load()
this.videoAd.load()
.then(() => {
reward.show()
this.videoAd.show()
.then(() => {
console.log('微信激励广告视频播放成功.');
// this.CustomReport({ customeventName: "adVideoReport", customeventData: { ...Params } }); // 上报播放完成
this.CustomReport({ customeventName: "adVideoReport", customeventData: { ...Params } }); // 上报播放完成
callback({ status: true });
})
.catch(err => this.playAdVideo(index, Params, callback, retry++));
.catch(err => this.playAdVideo(Params, callback, retry++));
});
}
......@@ -864,9 +859,8 @@ declare interface ProductInfo {
role_name: string
}
declare interface UNITITEM {
id: string
onError: Function
declare interface AdCallBack {
onError?: Function
onClose: Function
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论