Commit 9928db2d authored by liuxinjun's avatar liuxinjun

优化了多视频广告id以及代码变量

parent 2291e1e8
/**
1.安装apidoc,参考链接:
http://apidocjs.com
2.按照格式弄好后,执行命令
apidoc -i ./apiTest/assets/Sdk -o api/
在小程序后台添加合法域名:
https://game.llewan.com:1899
https://login.llewan.com:1799
https://log.llewan.com:1999
https://res.llewan.com:2099
https://glog.aldwx.com
*/
var md5 = require("md5"); var md5 = require("md5");
var mta = require("mta"); var mta = require("mta");
var sdk_conf = require("sdk_conf"); var sdk_conf = require("sdk_conf");
var sdk = require("sdk"); var sdk = require("sdk");
var adSdk = { var adSdk = {
bannerAd: null,
BannerAd: null, videoAd: null,
VideoAd: null,
videoAd1: null, videoAd1: null,
videoAd2: null, videoAd2: null,
videoAd3: null, videoAd3: null,
//.即将废弃,请不要操作此变量。
userid: 0,
initFlag:0,
//视频成功回调
videoSuccess:null,
//视频未看完回调
videoFail:null,
//视频调起失败
videoError:null,
//视频成功回调 //视频成功回调
videoSuccess1:null, videoSuccess: null,
//视频未看完回调 //视频失败回调
videoFail1:null, videoFail: null,
//视频调起失败 videoError: null,
videoError1:null,
/**
//视频成功回调 * @param {int} index 视频id的数字编号 1 2 3
videoSuccess2:null, * @param {string} videoAdUnitId
//视频未看完回调
videoFail2:null,
//视频调起失败
videoError2:null,
//视频成功回调
videoSuccess3:null,
//视频未看完回调
videoFail3:null,
//视频调起失败
videoError3:null,
/**
* @apiGroup C
* @apiName createBannerAd
* @api {微信登录} 创建banner广告组件 createBannerAd(广告)
* @apiParam {String} adUnitId 广告单元id
* @apiParam {String} style banner 广告组件的样式
*
* @apiSuccessExample {json} 示例:
* //.参考文档:https://developers.weixin.qq.com/minigame/dev/document/ad/wx.createBannerAd.html
* //var bannerAd = sdk.createBannerAd({
* // style:{
* // left: 0,
* // top: 0,
* // width: 100,
* // height: 200
* // }
* //});
*
* //.极简版(默认底部Banner)
* var bannerAd = sdk.createBannerAd({});
* bannerAd.show()
*
*/
createBannerAd(obj){
return sdk.createBannerAd(obj);
},
/**
* @apiGroup C
* @apiName createRewardedVideoAd
* @api {微信登录} 创建banner广告组件 createRewardedVideoAd(广告)
* @apiParam {String} adUnitId 广告单元id
* *
* @apiSuccessExample {json} 示例: *adSdk.videoSuccess = function(){
* //.参考文档:https://developers.weixin.qq.com/minigame/dev/document/ad/wx.createRewardedVideoAd.html
* sdk.videoSuccess = function(){
* //视频成功处理逻辑 * //视频成功处理逻辑
* this.successFunction(); * this.successFunction();
* }; * };
* sdk.videoFail = function(){ * adSdk.videoFail = function(){
* //视频失败处理逻辑 * //视频失败处理逻辑
* this.failFunction();` * this.failFunction();`
* }; * };
* sdk.videoError = function(){ * adSdk.videoError = function(){
* //视频失败处理逻辑 * //视频失败处理逻辑
* this.errorFunction();` * this.errorFunction();`
* }; * };
* var videoAd = sdk.createRewardedVideoAd(); * var videoAd = adSdk.createRewardedVideoAd(1,videoAdUnitId);
* videoAd.load().then(() => videoAd.show()); * videoAd.load().then(() => videoAd.show());
* *
*/ */
createRewardedVideoAd(){ createVideoAd(index, videoAdUnitId) {
let self = this; if (index == 1) {
if (true) { if (this.videoAd1) {
if(this.VideoAd){ return this.videoAd1;
return this.VideoAd; }
}else{ } else if (index == 2) {
this.VideoAd = wx.createRewardedVideoAd({ adUnitId: sdk.getConfig4().videoAdUnitId }) if (this.videoAd2) {
this.VideoAd.onLoad(function(res){ return this.videoAd2;
console.log("sdk VideoAd广告加载事件:", res) }
});
var closeFun = function(res){
// 用户点击了【关闭广告】按钮
// 小于 2.1.0 的基础库版本,res 是一个 undefined
if (res && res.isEnded || res === undefined) {
console.log("sdk 看视频成功");
self.videoSuccess();
}else {
console.error("sdk 看视频失败");
self.videoFail();
}
};
this.VideoAd.onClose(closeFun);
this.VideoAd.onError(function(res){ } else if (index == 3) {
if (this.videoAd3) {
if(self.videoError) return this.videoAd3;
{ }
self.videoError(); }
} else {
}); if (this.videoAd) {
return this.VideoAd; return this.videoAd;
} }
} }
return adSdk.createRewardedVideoAd(index, videoAdUnitId);
}, },
/**
/**
* *
* @param {*} obj * @param {json} obj
* @param {*} bannerAdUnitId * @param {string} bannerAdUnitId
* 多个banner广告id调用如下: * 多个banner广告id调用如下:
* sdk.createBannerAd({},bannerAdUnitId).destroy(); * adSdk.createBannerAdByAdId({},bannerAdUnitId).destroy();
* sdk.BannerAd =null; * adSdk.bannerAd =null;
* var bannerAd =sdk.createBannerAd({},bannerAdUnitId2); * var bannerAd =adSdk.createBannerAdByAdId({},bannerAdUnitId2);
* bannerAd.show(); * bannerAd.show();
* *
*/ */
...@@ -170,8 +80,8 @@ var adSdk = { ...@@ -170,8 +80,8 @@ var adSdk = {
createBannerAdByAdId(obj,bannerAdUnitId){ createBannerAdByAdId(obj,bannerAdUnitId){
var self = this; var self = this;
if (true) { if (true) {
if(this.BannerAd){ if(this.bannerAd){
return this.BannerAd; return this.bannerAd;
}else{ }else{
if(!obj.style){ if(!obj.style){
obj.style = {}; obj.style = {};
...@@ -182,216 +92,92 @@ var adSdk = { ...@@ -182,216 +92,92 @@ var adSdk = {
obj.style.top = 0; obj.style.top = 0;
obj.style.width = 300; obj.style.width = 300;
} }
this.BannerAd = wx.createBannerAd({ this.bannerAd = wx.createBannerAd({
adUnitId: bannerAdUnitId, adUnitId: bannerAdUnitId,
style: obj.style, style: obj.style,
}) })
this.BannerAd.onResize(function(res){ this.bannerAd.onResize(function(res){
console.log("sdk BannerAd广告缩放事件:", res) console.log("sdk BannerAd广告缩放事件:", res)
self.BannerAd.style.left = self.w - self.BannerAd.style.realWidth/2+0.1; self.bannerAd.style.left = self.w - self.bannerAd.style.realWidth/2+0.1;
self.BannerAd.style.top = self.h - self.BannerAd.style.realHeight+0.1; self.bannerAd.style.top = self.h - self.bannerAd.style.realHeight+0.1;
}); });
this.BannerAd.onLoad(function(res){ this.bannerAd.onLoad(function(res){
console.log("sdk BannerAd广告加载事件:", res) console.log("sdk BannerAd广告加载事件:", res)
}); });
this.BannerAd.onError(function(res){ this.bannerAd.onError(function(res){
console.log("sdk BannerAd广告错误事件:", res) console.log("sdk BannerAd广告错误事件:", res)
}); });
return this.BannerAd; return this.bannerAd;
} }
} }
}, },
/**
*
* @param {*} videoAdUnitId1
*
*
*adSdk.videoSuccess1 = function(){
* //视频成功处理逻辑
* this.successFunction();
* };
* adSdk.videoFail1 = function(){
* //视频失败处理逻辑
* this.failFunction();`
* };
* sdk.videoError1 = function(){
* //视频失败处理逻辑
* this.errorFunction();`
* };
* var videoAd1 = adSdk.createRewardedVideoAd(videoAdUnitId1);
* videoAd1.load().then(() => videoAd1.show());
*
*/
createRewardedVideoAd1(videoAdUnitId1){
let self = this;
if (true) {
if(this.VideoAd1){
return this.VideoAd1;
}else{
this.VideoAd1 = wx.createRewardedVideoAd({ adUnitId: videoAdUnitId1 })
this.VideoAd1.onLoad(function(res){
console.log("sdk VideoAd广告加载事件:", res)
});
var closeFun1 = function(res){
// 用户点击了【关闭广告】按钮
// 小于 2.1.0 的基础库版本,res 是一个 undefined
if (res && res.isEnded || res === undefined) {
console.log("sdk 看视频成功");
self.videoSuccess1();
}else {
console.error("sdk 看视频失败");
self.videoFail1();
}
};
this.VideoAd1.onClose(closeFun1);
this.VideoAd1.onError(function(res){
//console.log("sdk VideoAd广告错误事件:", res)
// wx.showToast({
// title: '暂未开通,请谅解!',
// icon: 'none'
// });
if(self.videoError1)
{
self.videoError1();
}
});
return this.VideoAd1;
}
}
},
/** /**
* * 后期会慢慢弃用,因为该方法只适合一个banner广告的情况
* @param {*} videoAdUnitId2 * @param {json} obj
* * var bannerAd =adSdk.createBannerAd({},bannerAdUnitId);
* * bannerAd.show();
*adSdk.videoSuccess2 = function(){
* //视频成功处理逻辑
* this.successFunction();
* };
* adSdk.videoFail2 = function(){
* //视频失败处理逻辑
* this.failFunction();`
* };
* sdk.videoError2 = function(){
* //视频失败处理逻辑
* this.errorFunction();`
* };
* var videoAd2 = adSdk.createRewardedVideoAd(videoAdUnitId2);
* videoAd2.load().then(() => videoAd2.show());
* *
*/ */
createRewardedVideoAd2(videoAdUnitId2){ createBannerAd(obj){
let self = this;
if (true) { return sdk.createBannerAd(obj);
if(this.VideoAd2){ },
return this.VideoAd2;
}else{
this.VideoAd2 = wx.createRewardedVideoAd({ adUnitId: videoAdUnitId2 })
this.VideoAd2.onLoad(function(res){
console.log("sdk VideoAd广告加载事件:", res)
});
var closeFun2 = function(res){
// 用户点击了【关闭广告】按钮
// 小于 2.1.0 的基础库版本,res 是一个 undefined
if (res && res.isEnded || res === undefined) {
console.log("sdk 看视频成功");
self.videoSuccess2();
}else {
console.error("sdk 看视频失败");
self.videoFail2();
}
};
this.VideoAd2.onClose(closeFun2);
this.VideoAd2.onError(function(res){ /**
//console.log("sdk VideoAd广告错误事件:", res) * 该方法不直接对外提供调用
// wx.showToast({ * @param {int} index
// title: '暂未开通,请谅解!', * @param {string} videoAdUnitId1
// icon: 'none'
// });
if(self.videoError2)
{
self.videoError2();
}
});
return this.VideoAd2;
}
}
},
/**
*
* @param {*} videoAdUnitId3
*
*
*adSdk.videoSuccess3 = function(){
* //视频成功处理逻辑
* this.successFunction();
* };
* adSdk.videoFail3 = function(){
* //视频失败处理逻辑
* this.failFunction();`
* };
* sdk.videoError3 = function(){
* //视频失败处理逻辑
* this.errorFunction();`
* };
* var videoAd3 = adSdk.createRewardedVideoAd(videoAdUnitId3);
* videoAd3.load().then(() => videoAd3.show());
* *
*/ */
createRewardedVideoAd3(videoAdUnitId3){ createRewardedVideoAd(index, videoAdUnitId1) {
let self = this; let self = this;
if (true) { if (true) {
if(this.VideoAd3){ let videoAd = wx.createRewardedVideoAd({ adUnitId: videoAdUnitId1 })
return this.VideoAd3; videoAd.onLoad(function (res) {
}else{ console.log("sdk VideoAd广告加载事件:", res)
this.VideoAd3 = wx.createRewardedVideoAd({ adUnitId: videoAdUnitId3 }) });
this.VideoAd3.onLoad(function(res){
console.log("sdk VideoAd广告加载事件:", res) var closeFun1 = function (res) {
}); // 用户点击了【关闭广告】按钮
// 小于 2.1.0 的基础库版本,res 是一个 undefined
if (res && res.isEnded || res === undefined) {
console.log("sdk 看视频成功");
self.videoSuccess();
} else {
console.error("sdk 看视频失败");
self.videoFail();
}
};
var closeFun3 = function(res){
// 用户点击了【关闭广告】按钮
// 小于 2.1.0 的基础库版本,res 是一个 undefined
if (res && res.isEnded || res === undefined) {
console.log("sdk 看视频成功");
self.videoSuccess3();
}else {
console.error("sdk 看视频失败");
self.videoFail3();
}
};
videoAd.onClose(closeFun1);
this.VideoAd3.onClose(closeFun3); videoAd.onError(function (res) {
if (self.videoError) {
self.videoError();
}
});
this.VideoAd3.onError(function(res){ if (index == 1) {
//console.log("sdk VideoAd广告错误事件:", res) this.videoAd1 = videoAd;
// wx.showToast({ }
// title: '暂未开通,请谅解!', else if (index == 2) {
// icon: 'none' this.videoAd2 = videoAd;
// }); }
if(self.videoError3) else if (index == 3) {
{ this.videoAd3 = videoAd;
self.videoError3();
}
});
return this.VideoAd3;
} }
else {
this.videoAd = videoAd;
}
return videoAd;
} }
} }
}; };
window.adSdk = adSdk; window.adSdk = adSdk;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment