From b04b0f5bb01e1b483df0575b00d79b8a36418d07 Mon Sep 17 00:00:00 2001 From: handongxun Date: Wed, 7 Sep 2022 11:08:15 +0800 Subject: [PATCH] =?UTF-8?q?uni-ad:=20=E6=94=AF=E6=8C=81=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E6=9C=8D=E5=8A=A1=E5=99=A8=E5=9B=9E?= =?UTF-8?q?=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../uni-cli-shared/components/ad.mixin.mp.js | 61 ++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/packages/uni-cli-shared/components/ad.mixin.mp.js b/packages/uni-cli-shared/components/ad.mixin.mp.js index f250d01cd..8c50d3a80 100644 --- a/packages/uni-cli-shared/components/ad.mixin.mp.js +++ b/packages/uni-cli-shared/components/ad.mixin.mp.js @@ -27,6 +27,12 @@ export default { loadnext: { type: [Boolean, String], default: false + }, + urlCallback: { + type: Object, + default () { + return {} + } } }, data () { @@ -58,7 +64,31 @@ export default { show () { this.errorMessage = null 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 () { @@ -80,6 +110,10 @@ export default { return result }, + _hasCallback () { + return (typeof this.urlCallback === 'object' && Object.keys(this.urlCallback).length > 0) + }, + _onmpload (e) { this.loading = false this._dispatchEvent(EventType.Load, {}) @@ -87,6 +121,31 @@ export default { _onmpclose (e) { 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) { -- GitLab