Commit dffa0107 authored by liuxinjun's avatar liuxinjun

添加多视频广告id以及分享与视频切换bug

parent 1fa3c472
/**
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 mta = require("mta");
var sdk_conf = require("sdk_conf");
var sdk = require("sdk");
var adSdk = {
BannerAd: null,
VideoAd: null,
videoAd1: null,
videoAd2: null,
videoAd3: null,
//.即将废弃,请不要操作此变量。
userid: 0,
initFlag:0,
//视频成功回调
videoSuccess:null,
//视频失败回调
videoFail:null,
//视频成功回调
videoSuccess1:null,
//视频失败回调
videoFail1:null,
//视频成功回调
videoSuccess2:null,
//视频失败回调
videoFail2:null,
//视频成功回调
videoSuccess3:null,
//视频失败回调
videoFail3: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} 示例:
* //.参考文档:https://developers.weixin.qq.com/minigame/dev/document/ad/wx.createRewardedVideoAd.html
* sdk.videoSuccess = function(){
* //视频成功处理逻辑
* this.successFunction();
* };
* sdk.videoFail = function(){
* //视频失败处理逻辑
* this.failFunction();`
* };
* var videoAd = sdk.createRewardedVideoAd();
* videoAd.load().then(() => videoAd.show());
*
*/
createRewardedVideoAd(){
return sdk.createRewardedVideoAd();
},
/**
*
* @param {*} obj
* @param {*} bannerAdUnitId
* 多个banner广告id调用如下:
* sdk.createBannerAd({},bannerAdUnitId).destroy();
* sdk.BannerAd =null;
* var bannerAd =sdk.createBannerAd({},bannerAdUnitId2);
* bannerAd.show();
*
*/
createBannerAdByAdId(obj,bannerAdUnitId){
var self = this;
if (cc.sys.platform === cc.sys.WECHAT_GAME) {
if(this.BannerAd){
return this.BannerAd;
}else{
if(!obj.style){
obj.style = {};
var phone = wx.getSystemInfoSync();
this.w = phone.screenWidth / 2;
this.h = phone.screenHeight;
obj.style.left = 0;
obj.style.top = 0;
obj.style.width = 300;
}
this.BannerAd = wx.createBannerAd({
adUnitId: bannerAdUnitId,
style: obj.style,
})
this.BannerAd.onResize(function(res){
console.log("sdk BannerAd广告缩放事件:", res)
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;
});
this.BannerAd.onLoad(function(res){
console.log("sdk BannerAd广告加载事件:", res)
});
this.BannerAd.onError(function(res){
console.log("sdk BannerAd广告错误事件:", res)
});
return this.BannerAd;
}
}
},
/**
*
* @param {*} videoAdUnitId1
*
*
*adSdk.videoSuccess1 = function(){
* //视频成功处理逻辑
* this.successFunction();
* };
* adSdk.videoFail1 = function(){
* //视频失败处理逻辑
* this.failFunction();`
* };
* 特别注意:下面这个videoAd为全局变量
* var videoAd1 = adSdk.createRewardedVideoAd(videoAdUnitId1);
* videoAd1.load().then(() => videoAd1.show());
*
*/
createRewardedVideoAd1(videoAdUnitId1){
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){
//console.log("sdk VideoAd广告错误事件:", res)
wx.showToast({
title: '暂未开通,请谅解!',
icon: 'none'
});
});
return this.VideoAd1;
}
}
},
/**
*
* @param {*} videoAdUnitId2
*
*
*adSdk.videoSuccess2 = function(){
* //视频成功处理逻辑
* this.successFunction();
* };
* adSdk.videoFail2 = function(){
* //视频失败处理逻辑
* this.failFunction();`
* };
* 特别注意:下面这个videoAd为全局变量
* var videoAd2 = adSdk.createRewardedVideoAd(videoAdUnitId2);
* videoAd2.load().then(() => videoAd2.show());
*
*/
createRewardedVideoAd2(videoAdUnitId2){
let self = this;
if (cc.sys.platform === cc.sys.WECHAT_GAME) {
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({
title: '暂未开通,请谅解!',
icon: 'none'
});
});
return this.VideoAd2;
}
}
},
/**
*
* @param {*} videoAdUnitId3
*
*
*adSdk.videoSuccess3 = function(){
* //视频成功处理逻辑
* this.successFunction();
* };
* adSdk.videoFail3 = function(){
* //视频失败处理逻辑
* this.failFunction();`
* };
* 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){
// 用户点击了【关闭广告】按钮
// 小于 2.1.0 的基础库版本,res 是一个 undefined
if (res && res.isEnded || res === undefined) {
console.log("sdk 看视频成功");
self.videoSuccess3();
}else {
console.error("sdk 看视频失败");
self.videoFail3();
}
};
this.VideoAd3.onClose(closeFun3);
this.VideoAd3.onError(function(res){
//console.log("sdk VideoAd广告错误事件:", res)
wx.showToast({
title: '暂未开通,请谅解!',
icon: 'none'
});
});
return this.VideoAd3;
}
}
}
};
window.adSdk = adSdk;
{
"ver": "1.0.5",
"uuid": "097a5e94-b982-44d6-9852-7e2c21605829",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
...@@ -1603,6 +1603,17 @@ var sdk = { ...@@ -1603,6 +1603,17 @@ var sdk = {
/**
*
* @param {*} obj
* @param {*} bannerAdUnitId
* 多个banner广告id调用如下:
* sdk.createBannerAd({},bannerAdUnitId).destroy();
* sdk.BannerAd =null;
* var bannerAd =sdk.createBannerAd({},bannerAdUnitId2);
* bannerAd.show();
*
*/
createBannerAdByAdId(obj,bannerAdUnitId){ createBannerAdByAdId(obj,bannerAdUnitId){
var self = this; var self = this;
...@@ -1743,6 +1754,62 @@ var sdk = { ...@@ -1743,6 +1754,62 @@ var sdk = {
}; };
this.VideoAd.onClose(closeFun);
this.VideoAd.onError(function(res){
//console.log("sdk VideoAd广告错误事件:", res)
wx.showToast({
title: '暂未开通,请谅解!',
icon: 'none'
});
});
return this.VideoAd;
}
}
},
/**
*
* @param {*} videoAdUnitId
*
*
*sdk.VideoAd =null;
*sdk.videoSuccess = function(){
* //视频成功处理逻辑
* this.successFunction();
* };
* sdk.videoFail = function(){
* //视频失败处理逻辑
* this.failFunction();`
* };
* 特别注意:下面这个videoAd为全局变量
* var videoAd = sdk.createRewardedVideoAd(videoAdUnitId2);
* videoAd.load().then(() => videoAd.show());
*
*/
createRewardedVideoAdByAdId(videoAdUnitId){
let self = this;
if (cc.sys.platform === cc.sys.WECHAT_GAME) {
if(this.VideoAd){
return this.VideoAd;
}else{
this.VideoAd = wx.createRewardedVideoAd({ adUnitId: videoAdUnitId })
this.VideoAd.onLoad(function(res){
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.onClose(closeFun);
this.VideoAd.onError(function(res){ this.VideoAd.onError(function(res){
...@@ -2735,7 +2802,7 @@ var sdk = { ...@@ -2735,7 +2802,7 @@ var sdk = {
if(nextCacheVal>=data[nextKey].count) if(nextCacheVal>data[nextKey].count)
{ {
//当前缓存中的记录当前key的次数已经超过配置次数 //当前缓存中的记录当前key的次数已经超过配置次数
......
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