提交 4aededc9 作者: wj

批量创建视频

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