Commit f2fc3a2c authored by liuxinjun's avatar liuxinjun

修改广告

parent 17bcedcc
/**
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");
...@@ -22,147 +8,71 @@ var adSdk = { ...@@ -22,147 +8,71 @@ 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, videoSuccess: null,
//视频失败回调 //视频失败回调
videoFail:null, videoFail: null,
videoError:null, videoError: null,
//视频成功回调
videoSuccess1:null,
//视频失败回调
videoFail1:null,
videoError1:null,
//视频成功回调
videoSuccess2:null,
//视频失败回调
videoFail2:null,
videoError2:null,
//视频成功回调
videoSuccess3:null,
//视频失败回调
videoFail3:null,
videoError3:null,
/** /**
* @apiGroup C * @param {int} index 视频id的数字编号 1 2 3
* @apiName createBannerAd * @param {string} videoAdUnitId
* @api {微信登录} 创建banner广告组件 createBannerAd(广告)
* @apiParam {String} adUnitId 广告单元id
* @apiParam {String} style banner 广告组件的样式
* *
* @apiSuccessExample {json} 示例: *adSdk.videoSuccess = function(){
* //.参考文档: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} 示例:
* //.参考文档: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.failFunction();` * 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 (cc.sys.platform === cc.sys.WECHAT_GAME) { 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(closeFun1);
this.VideoAd.onError(function(res){ } else if (index == 3) {
//console.log("sdk VideoAd广告错误事件:", res) if (this.VideoAd3) {
// wx.showToast({ return this.VideoAd3;
// title: '暂未开通,请谅解!',
// icon: 'none'
// });
if(self.videoError)
{
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();
* *
*/ */
...@@ -203,195 +113,71 @@ var adSdk = { ...@@ -203,195 +113,71 @@ var adSdk = {
} }
}, },
/** /**
* * 后期会慢慢弃用,因为该方法只适合一个banner广告的情况
* @param {*} videoAdUnitId1 * @param {json} obj
* * var bannerAd =adSdk.createBannerAd({},bannerAdUnitId);
* * bannerAd.show();
*adSdk.videoSuccess1 = function(){
* //视频成功处理逻辑
* this.successFunction();
* };
* adSdk.videoFail1 = function(){
* //视频失败处理逻辑
* this.failFunction();`
* };
* adSdk.videoError1 = function(){
* //视频失败处理逻辑
* this.errorFunction();`
* };
* var videoAd1 = adSdk.createRewardedVideoAd(videoAdUnitId1);
* videoAd1.load().then(() => videoAd1.show());
* *
*/ */
createRewardedVideoAd1(videoAdUnitId1){ createBannerAd(obj){
let self = this;
if (cc.sys.platform === cc.sys.WECHAT_GAME) {
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){ return sdk.createBannerAd(obj);
//console.log("sdk VideoAd广告错误事件:", res)
// wx.showToast({
// title: '暂未开通,请谅解!',
// icon: 'none'
// });
if(self.videoError1)
{
self.videoError1();
}
});
return this.VideoAd1;
}
}
}, },
/** /**
* * 该方法不直接对外提供调用
* @param {*} videoAdUnitId2 * @param {int} index
* * @param {string} videoAdUnitId1
*
*adSdk.videoSuccess2 = function(){
* //视频成功处理逻辑
* this.successFunction();
* };
* adSdk.videoFail2 = function(){
* //视频失败处理逻辑
* this.failFunction();`
* };
* adSdk.videoError2 = function(){
* //视频失败处理逻辑
* this.errorFunction();`
* };
* var videoAd2 = adSdk.createRewardedVideoAd(videoAdUnitId2);
* videoAd2.load().then(() => videoAd2.show());
* *
*/ */
createRewardedVideoAd2(videoAdUnitId2){ createRewardedVideoAd(index, videoAdUnitId1) {
let self = this; let self = this;
if (cc.sys.platform === cc.sys.WECHAT_GAME) { if (cc.sys.platform === cc.sys.WECHAT_GAME) {
if(this.VideoAd2){ let videoAd = wx.createRewardedVideoAd({ adUnitId: videoAdUnitId1 })
return this.VideoAd2; videoAd.onLoad(function (res) {
}else{
this.VideoAd2 = wx.createRewardedVideoAd({ adUnitId: videoAdUnitId2 })
this.VideoAd2.onLoad(function(res){
console.log("sdk VideoAd广告加载事件:", res) console.log("sdk VideoAd广告加载事件:", res)
}); });
var closeFun2 = function(res){ var closeFun1 = function (res) {
// 用户点击了【关闭广告】按钮 // 用户点击了【关闭广告】按钮
// 小于 2.1.0 的基础库版本,res 是一个 undefined // 小于 2.1.0 的基础库版本,res 是一个 undefined
if (res && res.isEnded || res === undefined) { if (res && res.isEnded || res === undefined) {
console.log("sdk 看视频成功"); console.log("sdk 看视频成功");
self.videoSuccess2(); self.videoSuccess();
}else { } else {
console.error("sdk 看视频失败"); console.error("sdk 看视频失败");
self.videoFail2(); self.videoFail();
} }
}; };
this.VideoAd2.onClose(closeFun2); videoAd.onClose(closeFun1);
this.VideoAd2.onError(function(res){ videoAd.onError(function (res) {
//console.log("sdk VideoAd广告错误事件:", res) if (self.videoError) {
// wx.showToast({ self.videoError();
// title: '暂未开通,请谅解!',
// icon: 'none'
// });
if(self.videoError2)
{
self.videoError2();
}
});
return this.VideoAd2;
}
} }
},
/**
*
* @param {*} videoAdUnitId3
*
*
*adSdk.videoSuccess3 = function(){
* //视频成功处理逻辑
* this.successFunction();
* };
* adSdk.videoFail3 = function(){
* //视频失败处理逻辑
* this.failFunction();`
* };
* adSdk.videoError3 = function(){
* //视频失败处理逻辑
* this.errorFunction();`
* };
* var videoAd3 = adSdk.createRewardedVideoAd(videoAdUnitId3);
* videoAd3.load().then(() => videoAd3.show());
*
*/
createRewardedVideoAd3(videoAdUnitId3){
let self = this;
if (cc.sys.platform === cc.sys.WECHAT_GAME) {
if(this.VideoAd3){
return this.VideoAd3;
}else{
this.VideoAd3 = wx.createRewardedVideoAd({ adUnitId: videoAdUnitId3 })
this.VideoAd3.onLoad(function(res){
console.log("sdk VideoAd广告加载事件:", res)
}); });
var closeFun3 = function(res){ if (index == 1) {
// 用户点击了【关闭广告】按钮 this.videoAd1 = videoAd;
// 小于 2.1.0 的基础库版本,res 是一个 undefined
if (res && res.isEnded || res === undefined) {
console.log("sdk 看视频成功");
self.videoSuccess3();
}else {
console.error("sdk 看视频失败");
self.videoFail3();
} }
}; else if (index == 2) {
this.videoAd2 = videoAd;
this.VideoAd3.onClose(closeFun3);
this.VideoAd3.onError(function(res){
//console.log("sdk VideoAd广告错误事件:", res)
// wx.showToast({
// title: '暂未开通,请谅解!',
// icon: 'none'
// });
if(self.videoError3)
{
self.videoError3();
} }
}); else if (index == 3) {
return this.VideoAd3; this.videoAd3 = videoAd;
} }
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