uniapp抖音小程序一鍵獲取用戶手機號的示例代碼
前端部分
點擊按鈕,獲取手機號
<button class="button" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">一鍵獲取</button>
傳入sessionKey和encryptedData、iv
其中sessionKey是通過登錄時,調(diào)用抖音接口https://developer.toutiao.com/api/apps/v2/jscode2session獲得
encryptedData、iv則通過點擊按鈕回傳的事件參數(shù)
getPhoneNumber(e) { if (e.detail) { if (e.detail.errMsg == "getPhoneNumber:fail auth den") { uni.showToast({ title: '小程序通過試運營期,才能一鍵獲取手機號', icon: 'none' }); } this.getUserPhone(e.detail) } else { this.hasPhoneValue = false } }, async getUserPhone(query) { // douyin-ad-1ddba+123456 /admin/dyinAd/answerAd let Authorization = this.$user.token || "none Authorization"; let http_url = this.$config.base_url + '/app/user/login/getDyPhone' let http_data = { sessionKey: this.$user.sessionKey, encryptedData: query.encryptedData, iv: query.iv, "admin": this.$config.admin, } let http_header = { Authorization } let result = await this.$http.post(http_url, http_data, http_header, 'json') .then(async (res) => { if (res && res.data) { let phone = {} Object.assign(phone, JSON.parse(res.data)) this.formPhone = phone.phoneNumber } }) .catch((err) => { }); },
后端部分
解密手機號
async getDyPhone(query){ const decipher = crypto.createDecipheriv( "aes-128-cbc", Buffer.from(query.sessionKey, "base64"), Buffer.from(query.iv, "base64") ); let ret = decipher.update(query.encryptedData, "base64", 'utf8'); ret += decipher.final('utf8'); return ret; }
到此這篇關(guān)于uniapp抖音小程序一鍵獲取用戶手機號的示例代碼的文章就介紹到這了,更多相關(guān)uniapp抖音小程序獲取用戶手機號內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
JS常見疑難點分析之match,charAt,charCodeAt,map,search用法分析
這篇文章主要介紹了JS常見疑難點分析之match,charAt,charCodeAt,map,search用法,結(jié)合實例形式較為詳細的分析了match,charAt,charCodeAt,map,search的功能,使用方法與相關(guān)注意事項,需要的朋友可以參考下2016-12-12webpack組織模塊打包Library的原理及實現(xiàn)
這篇文章主要介紹了webpack組織模塊打包Library的原理及實現(xiàn),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-03-03微信小程序+ECharts實現(xiàn)動態(tài)刷新的過程記錄
這篇文章主要給大家介紹了關(guān)于微信小程序+ECharts實現(xiàn)動態(tài)刷新的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-05-05js parentElement和offsetParent之間的區(qū)別
這里主要說的是 offsetParent 屬性,這個屬性在 MSDN 的文檔中也沒有解釋清楚,這就讓人更難理解這個屬性。 這幾天在網(wǎng)上找了些資料看看,再加上自己的一些測試,對此屬性有了那么一點的了解,在這里總結(jié)一下。2010-03-03