当前位置:网站首页>[wechat applet authorization] obtain the user's mobile number and nickname
[wechat applet authorization] obtain the user's mobile number and nickname
2022-07-22 05:48:00 【Hey, little apple】
<template>
<view>
<view v-if="show == true">
<view>
<view class='header' style="padding-bottom: 80upx;">
<image src='@/static/images/index/logo.jpg'></image>
</view>
<view class='content'>
<view> Request permission to </view>
<text> Get your public information ( nickname , Head portrait 、 Phone number etc. )</text>
</view>
<button class='bottom'
v-if="phoneBtn == false"
@click="getUserProfile"
withCredentials="true" lang="zh_CN">
Authorized login
</button>
<button v-else class="rightBtn" type="primary" open-type="getPhoneNumber"
@getphonenumber="getPhone"> Get cell phone number </button>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
show:false,
code:'',
encryptedData:'',
iv:'',
avatar:'',
nickName:'',
phoneBtn:false
};
},
created() {
},
onLoad(options) {
let that = this
if(uni.getStorageSync('userInfo')){
uni.reLaunch({
url:'/pages/index/index'
})
}else{
uni.hideLoading()
that.show = true
}
// #ifdef MP-WEIXIN
uni.login({
provider: 'weixin',
success(res) {
that.code = res.code
}
})
// #endif
},
methods: {
// Authorize access to user information
getUserProfile(e) {
let that = this
uni.getUserProfile({
desc: ' It is used to improve the membership information ',
success: (res) => {
// console.log(res,' Information obtained ')
that.nickName = res.userInfo.nickName
that.avatar = res.userInfo.avatarUrl
that.phoneBtn = true
}
})
},
getPhone(e){
let that = this
that.encryptedData = e.detail.encryptedData
that.iv = e.detail.iv
that.login()
},
login() {
let that = this;
// User information and login code Pass it to the background
uni.request({
url: 'http://47.111.146.137:8080/gq/' +'api/wechatLogin',
method: 'POST',
header: {
'content-type': 'application/x-www-form-urlencoded'
},
data: {
code:that.code,
nickName:that.nickName,
encryptedData:that.encryptedData,
iv:that.iv,
avatar:that.avatar
},
success: res => {
if(res.data.code == 0){
// uni.showToast({
// title:' Login successful ',
// icon:'success'
// })
uni.showLoading({
title:' Logon ...'
})
uni.setStorageSync('isLogin',true)
uni.setStorage({
key:'userInfo',
data:res.data.data
})
setTimeout(()=>{
uni.reLaunch({
url:'./index'
})
},2000)
}
}
});
}
}
}
</script>
<style lang="scss">
.header {
margin: 220rpx 0 0 50rpx;
text-align: center;
width: 650rpx;
}
.header image {
width: 200rpx;
height: 200rpx;
border-radius: 10rpx;
}
.content {
padding-top: 50upx;
border-top: 1px solid #f5f5f5;
width: 90%;
margin: 0 auto;
margin-bottom: 90rpx;
}
.content text {
display: block;
color: #9d9d9d;
margin-top: 20rpx;
font-size: 28rpx;
}
.bottom {
border-radius: 80rpx;
margin: 70rpx 50rpx;
font-size: 35rpx;
background-color: $uni-color-main;
color: #fff;
}
.rightBtn{
border-radius: 80rpx;
margin: 70rpx 50rpx;
font-size: 35rpx;
color: #fff;
}
</style>
// Other pages determine whether to authorize
onShow(){
let token = uni.getStorageSync('userInfo')
if (!token) {
uni.showModal({
title:' Please log in ',
content:" You haven't signed in yet , Will not function properly , Log in ?",
success:function(res){
if (res.confirm) {
uni.navigateTo({
url:"/pages/index/getCode"
});
} else if (res.cancel) {
uni.navigateTo({
url:"/pages/index/index"
});
}
},
})
}
},
边栏推荐
- Map collection traversal in multiple ways
- 文件操作管理
- 如何使用API接口批量查询图书信息?
- How much commission does CITIC Securities charge for opening an account?? Is it safe to open an account?
- Matlab FCM fuzzy clustering
- ScePT: 为规划的场景一致和基于策略轨迹预测
- [JS foundation] logical judgment (error prone points)
- 容器学习中的简答题
- 【js基础】逻辑判断篇(易错点)
- 函数防抖与函数节流
猜你喜欢
ES6 from introduction to mastery 01:es6 introduction
一次 MySQL 误操作导致P0级事故
爱奇艺抖音和好,微博躺枪?
图片信息用浏览器显示:data:image/png;base64,+图片内容
Tensorflow入门教程(三十七)——DC-VNet
Share an introductory guide to canvas
The darling of "all-optical" era - 400g optical module
Case analysis of building cross department communication system on low code platform
仅需一个依赖给Swagger换上新皮肤,既简单又炫酷
MLX90640 红外热成像传感器测温模块开发笔记(三)
随机推荐
Map collection traversal in multiple ways
js 图片转换base64 base64转换为file对象
npm install 报 -4058错误
写了几段小代码,把系统给搞崩了,被老板爆怼一顿
Those violations in the store will be punished by the official secondary punishment, the most common four
solo 博客 文章的链接编辑提示非法链接
推荐系统之ROC和AUC详解
The pit trodden by real people tells you to avoid the 10 mistakes that novices in automated testing often make
国家互联网信息办公室对滴滴全球股份有限公司依法作出网络安全审查相关行政处罚的决定
[JS foundation] use of random, floor and ceil methods in math
MySQL:MySQL客户端和服务端之间是如何连接的呢?
HTTP cache policy, strong cache, negotiation cache
Matlab FCM fuzzy clustering
启牛可以开户安全吗?
Tensorflow入门教程(三十八)——V2-Net
Matlab least square fitting
Pycocotools installation method - one step~
Write it down once Net analysis of CPU explosion of an intelligent transportation background service
ES6 from getting started to mastering 06: arrow function this direction and precautions
yii2的加密解密那些事儿