Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
llewan-laya-sdk
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
llewan
llewan-laya-sdk
Commits
9928db2d
Commit
9928db2d
authored
Nov 30, 2018
by
liuxinjun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化了多视频广告id以及代码变量
parent
2291e1e8
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
75 additions
and
289 deletions
+75
-289
ad_sdk.js
assets/llewan-laya-sdk/ad_sdk.js
+75
-289
No files found.
assets/llewan-laya-sdk/ad_sdk.js
View file @
9928db2d
/**
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"
);
...
...
@@ -21,148 +7,72 @@ var sdk = require("sdk");
var
adSdk
=
{
BannerAd
:
null
,
VideoAd
:
null
,
bannerAd
:
null
,
videoAd
:
null
,
videoAd1
:
null
,
videoAd2
:
null
,
videoAd3
:
null
,
//.即将废弃,请不要操作此变量。
userid
:
0
,
initFlag
:
0
,
//视频成功回调
videoSuccess
:
null
,
//视频未看完回调
videoFail
:
null
,
//视频调起失败
videoError
:
null
,
//视频成功回调
videoSuccess1
:
null
,
//视频未看完回调
videoFail1
:
null
,
//视频调起失败
videoError1
:
null
,
//视频成功回调
videoSuccess2
:
null
,
//视频未看完回调
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
){
videoSuccess
:
null
,
//视频失败回调
videoFail
:
null
,
videoError
:
null
,
return
sdk
.
createBannerAd
(
obj
);
},
/**
* @apiGroup C
* @apiName createRewardedVideoAd
* @api {微信登录} 创建banner广告组件 createRewardedVideoAd(广告)
* @apiParam {String} adUnitId 广告单元id
* @param {int} index 视频id的数字编号 1 2 3
* @param {string} videoAdUnitId
*
* @apiSuccessExample {json} 示例:
* //.参考文档:https://developers.weixin.qq.com/minigame/dev/document/ad/wx.createRewardedVideoAd.html
* sdk.videoSuccess = function(){
*adSdk.videoSuccess = function(){
* //视频成功处理逻辑
* this.successFunction();
* };
*
s
dk.videoFail = function(){
*
adS
dk.videoFail = function(){
* //视频失败处理逻辑
* this.failFunction();`
* };
*
s
dk.videoError = function(){
*
adS
dk.videoError = function(){
* //视频失败处理逻辑
* this.errorFunction();`
* };
*
var videoAd = sdk.createRewardedVideoAd(
);
*
var videoAd = adSdk.createRewardedVideoAd(1,videoAdUnitId
);
* videoAd.load().then(() => videoAd.show());
*
*/
createRewardedVideoAd
(){
let
self
=
this
;
if
(
true
)
{
if
(
this
.
VideoAd
){
return
this
.
VideoAd
;
}
else
{
this
.
VideoAd
=
wx
.
createRewardedVideoAd
({
adUnitId
:
sdk
.
getConfig4
().
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
();
createVideoAd
(
index
,
videoAdUnitId
)
{
if
(
index
==
1
)
{
if
(
this
.
videoAd1
)
{
return
this
.
videoAd1
;
}
}
else
if
(
index
==
2
)
{
if
(
this
.
videoAd2
)
{
return
this
.
videoAd2
;
}
};
this
.
VideoAd
.
onClose
(
closeFun
);
this
.
VideoAd
.
onError
(
function
(
res
){
if
(
self
.
videoError
)
{
self
.
videoError
()
;
}
else
if
(
index
==
3
)
{
if
(
this
.
videoAd3
)
{
return
this
.
videoAd3
;
}
});
return
this
.
VideoAd
;
}
else
{
if
(
this
.
videoAd
)
{
return
this
.
videoAd
;
}
}
return
adSdk
.
createRewardedVideoAd
(
index
,
videoAdUnitId
);
},
/**
*
* @param {
*
} obj
* @param {
*
} bannerAdUnitId
* @param {
json
} obj
* @param {
string
} bannerAdUnitId
* 多个banner广告id调用如下:
*
sdk.createBannerA
d({},bannerAdUnitId).destroy();
*
sdk.B
annerAd =null;
* var bannerAd =
sdk.createBannerA
d({},bannerAdUnitId2);
*
adSdk.createBannerAdByAdI
d({},bannerAdUnitId).destroy();
*
adSdk.b
annerAd =null;
* var bannerAd =
adSdk.createBannerAdByAdI
d({},bannerAdUnitId2);
* bannerAd.show();
*
*/
...
...
@@ -170,8 +80,8 @@ var adSdk = {
createBannerAdByAdId
(
obj
,
bannerAdUnitId
){
var
self
=
this
;
if
(
true
)
{
if
(
this
.
B
annerAd
){
return
this
.
B
annerAd
;
if
(
this
.
b
annerAd
){
return
this
.
b
annerAd
;
}
else
{
if
(
!
obj
.
style
){
obj
.
style
=
{};
...
...
@@ -182,216 +92,92 @@ var adSdk = {
obj
.
style
.
top
=
0
;
obj
.
style
.
width
=
300
;
}
this
.
B
annerAd
=
wx
.
createBannerAd
({
this
.
b
annerAd
=
wx
.
createBannerAd
({
adUnitId
:
bannerAdUnitId
,
style
:
obj
.
style
,
})
this
.
B
annerAd
.
onResize
(
function
(
res
){
this
.
b
annerAd
.
onResize
(
function
(
res
){
console
.
log
(
"sdk BannerAd广告缩放事件:"
,
res
)
self
.
BannerAd
.
style
.
left
=
self
.
w
-
self
.
B
annerAd
.
style
.
realWidth
/
2
+
0.1
;
self
.
BannerAd
.
style
.
top
=
self
.
h
-
self
.
B
annerAd
.
style
.
realHeight
+
0.1
;
self
.
bannerAd
.
style
.
left
=
self
.
w
-
self
.
b
annerAd
.
style
.
realWidth
/
2
+
0.1
;
self
.
bannerAd
.
style
.
top
=
self
.
h
-
self
.
b
annerAd
.
style
.
realHeight
+
0.1
;
});
this
.
B
annerAd
.
onLoad
(
function
(
res
){
this
.
b
annerAd
.
onLoad
(
function
(
res
){
console
.
log
(
"sdk BannerAd广告加载事件:"
,
res
)
});
this
.
B
annerAd
.
onError
(
function
(
res
){
this
.
b
annerAd
.
onError
(
function
(
res
){
console
.
log
(
"sdk BannerAd广告错误事件:"
,
res
)
});
return
this
.
B
annerAd
;
return
this
.
b
annerAd
;
}
}
},
/**
*
* @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());
* 后期会慢慢弃用,因为该方法只适合一个banner广告的情况
* @param {json} obj
* var bannerAd =adSdk.createBannerAd({},bannerAdUnitId);
* bannerAd.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
);
createBannerAd
(
obj
){
this
.
VideoAd1
.
onError
(
function
(
res
){
//console.log("sdk VideoAd广告错误事件:", res)
// wx.showToast({
// title: '暂未开通,请谅解!',
// icon: 'none'
// });
if
(
self
.
videoError1
)
{
self
.
videoError1
();
}
});
return
this
.
VideoAd1
;
}
}
return
sdk
.
createBannerAd
(
obj
);
},
/**
*
* @param {*} videoAdUnitId2
*
*
*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());
* 该方法不直接对外提供调用
* @param {int} index
* @param {string} videoAdUnitId1
*
*/
createRewardedVideoAd
2
(
videoAdUnitId2
)
{
createRewardedVideoAd
(
index
,
videoAdUnitId1
)
{
let
self
=
this
;
if
(
true
)
{
if
(
this
.
VideoAd2
){
return
this
.
VideoAd2
;
}
else
{
this
.
VideoAd2
=
wx
.
createRewardedVideoAd
({
adUnitId
:
videoAdUnitId2
})
this
.
VideoAd2
.
onLoad
(
function
(
res
){
let
videoAd
=
wx
.
createRewardedVideoAd
({
adUnitId
:
videoAdUnitId1
})
videoAd
.
onLoad
(
function
(
res
)
{
console
.
log
(
"sdk VideoAd广告加载事件:"
,
res
)
});
var
closeFun2
=
function
(
res
)
{
var
closeFun1
=
function
(
res
)
{
// 用户点击了【关闭广告】按钮
// 小于 2.1.0 的基础库版本,res 是一个 undefined
if
(
res
&&
res
.
isEnded
||
res
===
undefined
)
{
console
.
log
(
"sdk 看视频成功"
);
self
.
videoSuccess2
();
}
else
{
self
.
videoSuccess
();
}
else
{
console
.
error
(
"sdk 看视频失败"
);
self
.
videoFail2
();
self
.
videoFail
();
}
};
this
.
VideoAd2
.
onClose
(
closeFun2
);
videoAd
.
onClose
(
closeFun1
);
this
.
VideoAd2
.
onError
(
function
(
res
){
//console.log("sdk VideoAd广告错误事件:", res)
// wx.showToast({
// title: '暂未开通,请谅解!',
// icon: 'none'
// });
if
(
self
.
videoError2
)
{
self
.
videoError2
();
}
});
return
this
.
VideoAd2
;
}
videoAd
.
onError
(
function
(
res
)
{
if
(
self
.
videoError
)
{
self
.
videoError
();
}
},
/**
*
* @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
){
let
self
=
this
;
if
(
true
)
{
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
();
if
(
index
==
1
)
{
this
.
videoAd1
=
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
==
2
)
{
this
.
videoAd2
=
videoAd
;
}
});
return
this
.
VideoAd3
;
else
if
(
index
==
3
)
{
this
.
videoAd3
=
videoAd
;
}
else
{
this
.
videoAd
=
videoAd
;
}
return
videoAd
;
}
}
};
window
.
adSdk
=
adSdk
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment