提交 4c5b301b 作者: wj

回滚版本

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