1、授權(quán)獲取code,換取open_id
wx.login({
success(res) {
console.log(res.code)
if (res.code) {
//調(diào)自己后臺(tái)接口換取open_id
}
}
})
微信文檔
2、獲取手機(jī)號(hào)
1)需要將 button 組件 open-type 的值設(shè)置為 getPhoneNumber,當(dāng)用戶點(diǎn)擊并同意之后,通過(guò) getphonenumber 事件獲取回調(diào)信息;
2)將 getphonenumber 事件回調(diào)中的動(dòng)態(tài)令牌code傳到開發(fā)者后臺(tái),并在開發(fā)者后臺(tái)調(diào)用微信后臺(tái)提供的 phonenumber.getPhoneNumber 接口,消費(fèi)code來(lái)?yè)Q取用戶手機(jī)號(hào)。每個(gè)code有效期為5分鐘,且只能消費(fèi)一次。
<button class="add" open-type="getPhoneNumber" @getphonenumber="getphonenumber">微信用戶一鍵登錄</button>
getphonenumber(e) {
console.log(e.detail.code)
console.log(e)
//調(diào)用自己后臺(tái)接口獲取手機(jī)號(hào)
}
微信文檔
3、用戶頭像
需要將 button 組件 open-type 的值設(shè)置為 chooseAvatar,當(dāng)用戶選擇需要使用的頭像之后,可以通過(guò) chooseavatar 事件回調(diào)獲取到頭像信息的臨時(shí)路徑。
<button plain="true" class="button" open-type="chooseAvatar" @chooseavatar="chooseAvatar">
<image :src="userInfo.accountImg"></image>
</button>
chooseAvatar(e) {
console.log(e.detail.avatarUrl)
this.userInfo.accountImg = e.detail.avatarUrl
},
4、用戶昵稱
需要將 input 組件 type 的值設(shè)置為 nickname,當(dāng)用戶在此input進(jìn)行輸入時(shí),鍵盤上方會(huì)展示微信昵稱。文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-734981.html
<input v-model="userInfo.name" type="nickname" placeholder="請(qǐng)?zhí)顚戧欠Q" />
微信文檔文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-734981.html
到了這里,關(guān)于微信小程序:授權(quán)登錄獲取手機(jī)號(hào)及獲取基本信息等的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!