增加激励视频广告

This commit is contained in:
唐明明
2022-06-29 18:08:50 +08:00
parent 8235720d27
commit f2e01ae412
14 changed files with 13022 additions and 12723 deletions

View File

@@ -11,10 +11,11 @@
}).then(res => { }).then(res => {
if (res.update) { if (res.update) {
uni.showModal({ uni.showModal({
title: "更新提示", title : "更新提示",
content: res.note || '版本更新信息', content : res.note || '版本更新信息',
confirmText: "更新", confirmText : "更新",
success: modalRes => { showCancel : false,
success : modalRes => {
if (modalRes.confirm) { if (modalRes.confirm) {
if (plus.os.name == "Android") { if (plus.os.name == "Android") {
uni.showToast({ uni.showToast({

Submodule gl-agent deleted from 223893686d

View File

@@ -2,7 +2,7 @@
"name" : "共力生态", "name" : "共力生态",
"appid" : "__UNI__DE7B0E6", "appid" : "__UNI__DE7B0E6",
"description" : "共力生态", "description" : "共力生态",
"versionName" : "1.0.30", "versionName" : "1.0.31",
"versionCode" : 100, "versionCode" : 100,
"transformPx" : false, "transformPx" : false,
/* 5+App */ /* 5+App */
@@ -81,7 +81,7 @@
"payment" : { "payment" : {
"weixin" : { "weixin" : {
"__platform__" : [ "android" ], "__platform__" : [ "android" ],
"appid" : "wxcb85e48d044bc5ee", "appid" : "wx466a4663da346e09",
"UniversalLinks" : "" "UniversalLinks" : ""
}, },
"alipay" : { "alipay" : {
@@ -90,7 +90,7 @@
}, },
"share" : { "share" : {
"weixin" : { "weixin" : {
"appid" : "wxcb85e48d044bc5ee", "appid" : "wx466a4663da346e09",
"UniversalLinks" : "" "UniversalLinks" : ""
} }
}, },

View File

@@ -104,6 +104,7 @@
<script> <script>
import { life, sign } from '@/apis/interfaces/life.js' import { life, sign } from '@/apis/interfaces/life.js'
import AD from '@/utils/ad.js'
var account; var account;
export default { export default {
data() { data() {
@@ -201,19 +202,38 @@
this.$Router.push({name: 'Capacity'}) this.$Router.push({name: 'Capacity'})
return return
} }
uni.showLoading({ // 激励视频广告
title: '签到中..' AD.show({
}) adpid : 1428308887,
sign().then(res => { adType : 'RewardedVideo',
urlCallback : {
userId: 'TMMM',
}
},(res) => {
const detail = e.detail
if (detail && detail.isEnded) {
uni.showLoading({
title: '签到中..'
})
sign().then(res => {
uni.showToast({
title: '签到成功',
icon : 'none'
})
this.getLife()
}).catch(err => {
uni.showToast({
title: err.message,
icon : 'none'
})
})
} else {
console.log('用户主动关闭')
console.log("onadclose " + detail.isEnded);
}
},(err) => {
uni.showToast({ uni.showToast({
title: '签到成功', title: e.detail
icon : 'none'
})
this.getLife()
}).catch(err => {
uni.showToast({
title: err.message,
icon : 'none'
}) })
}) })
}, },

View File

@@ -0,0 +1,8 @@
'use strict';
exports.main = async (event, context) => {
//event为客户端上传的参数
console.log('event : ', event)
//返回数据给客户端
return event
};

View File

@@ -0,0 +1,7 @@
{
"name": "gl-ad",
"dependencies": {},
"extensions": {
"uni-cloud-jql": {}
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

253
utils/ad.js Normal file
View File

@@ -0,0 +1,253 @@
// ad.js
const ADType = {
RewardedVideo: "RewardedVideo",
FullScreenVideo: "FullScreenVideo"
}
class AdHelper {
constructor() {
this._ads = {}
}
load(options, onload, onerror) {
let ops = this._fixOldOptions(options)
let {
adpid
} = ops
if (!adpid || this.isBusy(adpid)) {
return
}
this.get(ops).load(onload, onerror)
}
show(options, onsuccess, onfail) {
let ops = this._fixOldOptions(options)
let {
adpid
} = ops
if (!adpid) {
return
}
uni.showLoading({
mask: true
})
var ad = this.get(ops)
ad.load(() => {
uni.hideLoading()
ad.show((e) => {
onsuccess && onsuccess(e)
})
}, (err) => {
uni.hideLoading()
onfail && onfail(err)
})
}
isBusy(adpid) {
return (this._ads[adpid] && this._ads[adpid].isLoading)
}
get(options) {
const {
adpid,
singleton = true
} = options
if (singleton === false) {
if (this._ads[adpid]) {
this._ads[adpid].destroy()
delete this._ads[adpid]
}
}
delete options.singleton
if (!this._ads[adpid]) {
this._ads[adpid] = this._createAdInstance(options)
}
return this._ads[adpid]
}
_createAdInstance(options) {
const adType = options.adType || ADType.RewardedVideo
delete options.adType
let ad = null;
if (adType === ADType.RewardedVideo) {
ad = new RewardedVideo(options)
} else if (adType === ADType.FullScreenVideo) {
ad = new FullScreenVideo(options)
}
return ad
}
_fixOldOptions(options) {
return (typeof options === "string") ? {
adpid: options
} : options
}
}
const EXPIRED_TIME = 1000 * 60 * 30
const ProviderType = {
CSJ: 'csj',
GDT: 'gdt'
}
const RETRY_COUNT = 1
class AdBase {
constructor(adInstance, options = {}) {
this._isLoad = false
this._isLoading = false
this._lastLoadTime = 0
this._lastError = null
this._retryCount = 0
this._loadCallback = null
this._closeCallback = null
this._errorCallback = null
const ad = this._ad = adInstance
ad.onLoad((e) => {
this._isLoading = false
this._isLoad = true
this._lastLoadTime = Date.now()
this.onLoad()
})
ad.onClose((e) => {
this._isLoad = false
this.onClose(e)
})
ad.onVerify && ad.onVerify((e) => {
// e.isValid
})
ad.onError(({
code,
message
}) => {
this._isLoading = false
const data = {
code: code,
errMsg: message
}
if (code === -5008) {
this._loadAd()
return
}
if (this._retryCount < RETRY_COUNT) {
this._retryCount += 1
this._loadAd()
return
}
this._lastError = data
this.onError(data)
})
}
get isExpired() {
return (this._lastLoadTime !== 0 && (Math.abs(Date.now() - this._lastLoadTime) > EXPIRED_TIME))
}
get isLoading() {
return this._isLoading
}
getProvider() {
return this._ad.getProvider()
}
load(onload, onerror) {
this._loadCallback = onload
this._errorCallback = onerror
if (this._isLoading) {
return
}
if (this._isLoad) {
this.onLoad()
return
}
this._retryCount = 0
this._loadAd()
}
show(onclose) {
this._closeCallback = onclose
if (this._isLoading || !this._isLoad) {
return
}
if (this._lastError !== null) {
this.onError(this._lastError)
return
}
const provider = this.getProvider()
if (provider === ProviderType.CSJ && this.isExpired) {
this._loadAd()
return
}
this._ad.show()
}
onLoad(e) {
if (this._loadCallback != null) {
this._loadCallback()
}
}
onClose(e) {
if (this._closeCallback != null) {
this._closeCallback({
isEnded: e.isEnded
})
}
}
onError(e) {
if (this._errorCallback != null) {
this._errorCallback(e)
}
}
destroy() {
this._ad.destroy()
}
_loadAd() {
this._isLoad = false
this._isLoading = true
this._lastError = null
this._ad.load()
}
}
class RewardedVideo extends AdBase {
constructor(options = {}) {
super(plus.ad.createRewardedVideoAd(options), options)
}
}
class FullScreenVideo extends AdBase {
constructor(options = {}) {
super(plus.ad.createFullScreenVideoAd(options), options)
}
}
export default new AdHelper()