uniapp抖音小程序一鍵獲取用戶手機(jī)號的示例代碼
前端部分
點(diǎn)擊按鈕,獲取手機(jī)號
<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則通過點(diǎn)擊按鈕回傳的事件參數(shù)
getPhoneNumber(e) {
if (e.detail) {
if (e.detail.errMsg == "getPhoneNumber:fail auth den") {
uni.showToast({
title: '小程序通過試運(yùn)營期,才能一鍵獲取手機(jī)號',
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) => {
});
},后端部分
解密手機(jī)號
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抖音小程序一鍵獲取用戶手機(jī)號的示例代碼的文章就介紹到這了,更多相關(guān)uniapp抖音小程序獲取用戶手機(jī)號內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- UNIAPP實(shí)現(xiàn)微信小程序登錄授權(quán)和手機(jī)號授權(quán)功能(uniapp做微信小程序)
- 微信小程序獲取用戶手機(jī)號碼詳細(xì)教程(前端+后端)
- 微信小程序中獲取用戶手機(jī)號授權(quán)登錄詳細(xì)步驟
- uniapp微信小程序授權(quán)登錄并獲取手機(jī)號的方法
- uniapp+.net?core實(shí)現(xiàn)微信小程序獲取手機(jī)號功能
- PHP配合微信小程序?qū)崿F(xiàn)獲取手機(jī)號碼詳解
- 微信小程序登錄方法之授權(quán)登陸及獲取微信用戶手機(jī)號
- 微信小程序獲取用戶手機(jī)號碼的詳細(xì)步驟
- 微信小程序?qū)崿F(xiàn)手機(jī)號碼驗證
- 抖音小程序一鍵獲取手機(jī)號的實(shí)現(xiàn)思路
相關(guān)文章
JS實(shí)現(xiàn)的數(shù)組去除重復(fù)數(shù)據(jù)算法小結(jié)
這篇文章主要介紹了JS實(shí)現(xiàn)的數(shù)組去除重復(fù)數(shù)據(jù)算法,總結(jié)分析了4種比較常見的數(shù)組去重復(fù)算法及相關(guān)使用技巧,需要的朋友可以參考下2017-11-11
微信小程序?qū)崿F(xiàn)的3d輪播圖效果示例【基于swiper組件】
這篇文章主要介紹了微信小程序?qū)崿F(xiàn)的3d輪播圖效果,結(jié)合實(shí)例形式分析了微信小程序基于swiper組件相關(guān)屬性設(shè)置、事件響應(yīng)操作技巧,需要的朋友可以參考下2018-12-12

