onReady(() => {
if (wx.createRewardedVideoAd) {
videoAd = wx.createRewardedVideoAd({
adUnitId: "adunit-c512b55722889b10",
});
videoAd.onLoad(() => {});
videoAd.onError((err) => {
console.error("激励视频光告加载失败", err);
});
videoAd.onClose(async (res) => {
if (res && res.isEnded) {
// 正常播放结束,可以下发游戏奖励
await uni.$api.basicEnterprise.CreateEnterpriseRepairedCard({
enterpriseId: state.enterpriseId,
userId: user_infos.value.id,
openId: user_info.value.openId,
});
fetchData();
}
});
}
});
const handleRepairedCard = () => {
// 用户触发广告后,显示激励视频广告
if (videoAd) {
videoAd.show().catch(() => {
// 失败重试
videoAd
.load()
.then(() => videoAd.show().catch((err) => console.log(err)))
.catch((err) => {
console.error("激励视频 广告显示失败", err);
});
});
}
};
