提交 b04b0f5b 编写于 作者: d-u-a's avatar d-u-a

uni-ad: 支持微信小程序服务器回调

上级 568829af
...@@ -27,6 +27,12 @@ export default { ...@@ -27,6 +27,12 @@ export default {
loadnext: { loadnext: {
type: [Boolean, String], type: [Boolean, String],
default: false default: false
},
urlCallback: {
type: Object,
default () {
return {}
}
} }
}, },
data () { data () {
...@@ -58,7 +64,31 @@ export default { ...@@ -58,7 +64,31 @@ export default {
show () { show () {
this.errorMessage = null this.errorMessage = null
this._ad = this.selectComponent('.uniad-plugin') this._ad = this.selectComponent('.uniad-plugin')
this._ad.show() if (this._hasCallback()) {
const userCryptoManager = wx.getUserCryptoManager()
userCryptoManager.getLatestUserKey({
success: ({
encryptKey,
iv,
version,
expireTime
}) => {
this._ad.show({
userId: this.urlCallback.userId || '',
extra: this.urlCallback.extra || '',
encryptKey,
iv,
version,
expireTime
})
},
fail: (err) => {
this._dispatchEvent(EventType.Error, err)
}
})
} else {
this._ad.show()
}
}, },
_onclick () { _onclick () {
...@@ -80,6 +110,10 @@ export default { ...@@ -80,6 +110,10 @@ export default {
return result return result
}, },
_hasCallback () {
return (typeof this.urlCallback === 'object' && Object.keys(this.urlCallback).length > 0)
},
_onmpload (e) { _onmpload (e) {
this.loading = false this.loading = false
this._dispatchEvent(EventType.Load, {}) this._dispatchEvent(EventType.Load, {})
...@@ -87,6 +121,31 @@ export default { ...@@ -87,6 +121,31 @@ export default {
_onmpclose (e) { _onmpclose (e) {
this._dispatchEvent(EventType.Close, e.detail) this._dispatchEvent(EventType.Close, e.detail)
if (e.detail.adsdata) {
const adv = e.detail.adv
const adsdata = e.detail.adsdata
const version = e.detail.version
/* eslint-disable no-undef */
uniCloud.callFunction({
name: 'uniAdCallback',
data: {
adv: adv,
adsdata: adsdata,
version: version
},
secretType: 'both',
success: (res) => {
},
fail: (err) => {
this._dispatchEvent(EventType.Error, err)
}
})
delete e.detail.adv
delete e.detail.adsdata
delete e.detail.version
}
}, },
_onmperror (e) { _onmperror (e) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册