微信小游戏广告


微信小游戏广告

  • 广告类
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
let WxAD = cc.Class({
properties: {
videoAd : null,
},
load(type, loadcb, showcb) {
if (cc.sys.platform != cc.sys.WECHAT_GAME){
if(loadcb) loadcb("failed");
return;
}
if (type == 3) {
if(this.videoAd){
this.videoAd.offLoad();
this.videoAd.offError();
this.videoAd.offClose();
this.videoAd = null;
}
this.videoAd = wx.createRewardedVideoAd({
adUnitId: 'xxxxxxxxx'
});
this.videoAd.onLoad(() => {
});
this.videoAd.onError((err) => {
});
this.videoAd.load()
.then(() => {
if(loadcb) loadcb("success");
})
.catch((err) => {
if(loadcb) loadcb("failed");
})
}

},
//1 banner;2 插屏;3 激励视频;4 盒子广告
show(type, cb) {
if (cc.sys.platform != cc.sys.WECHAT_GAME){
if(cb) cb("failed");
return;
}
if (type == 3) {
this.videoAd.offClose();
this.videoAd.onClose((res) => {
if (res && res.isEnded) {
if(cb) cb("complete");// 正常播放结束
} else {
if(cb) cb("failed");// 播放中途退出
}
});
this.videoAd.show().catch(() => {
// 失败重试
this.videoAd.load()
.then(() => {
this.videoAd.show();
})
.catch((err) => {
if(cb) cb("failed");
})
});
}else if(type == 4){ // 盒子广告
this.appbox = qq.createAppBox({
adUnitId: 'xxxxxxxx'
});
this.appbox.load().then(()=>{
this.appbox.show();
});
}
},

});
WxAD = module.exports = new WxAD();