当前位置:网站首页>[wechat authorized login] the small program developed by uniapp realizes the function of obtaining wechat authorized login
[wechat authorized login] the small program developed by uniapp realizes the function of obtaining wechat authorized login
2022-07-02 00:32:00 【Ma Xiaotiao's coding advanced road】
One 、 Their thinking :
Wechat authorized login ( Get user information )
1. Get user information first —— After user authorization is allowed , By calling uni.login Can be obtained code.
2. Take what you got code To call —— Login interface , Can be obtained token.
3. hold token Deposited in the cache . You can judge whether you are logged in on the page .
Two 、 Code
<view @click="getUserInfo()"> Click login </view>
<script>
export default {
data() {
return {
localtoken: ''
}
},
onLoad() {
},
onHide() {
},
onShow() {
this.localtoken = uni.getStorageSync('localtoken');
},
methods: {
getUserInfo() {
var that = this;
uni.showLoading({
// Display load box
title: ' Loading ',
});
uni.getUserProfile({
// Get user information
desc: ' Data can be synchronized after login ',
success: async (obj) => {
console.log('obj', obj);
that.nickName = obj.userInfo.nickName // user name
that.avatarUrl = obj.userInfo.avatarUrl // The avatars
// call action , Request login interface
uni.login({
provider: 'weixin',
success: (res) => {
console.log('res-login', res);
// Get code
that.code = res.code;
// console.log('code', res.code);
// Request login interface
if (res.errMsg == 'login:ok') {
var params = {
code: that.code,
nickname: that.nickName,
avatar: that.avatarUrl
}
that.$api.appPlateForm('POST', 'auth/login', params, function(
res) {
if (res.code == 200) {
uni.showToast({
title: ' Login successful ',
icon: 'success',
mask: true,
});
// Get token Deposited in the cache . Pass Yes No token To determine whether to log in
// console.log(' Login interface ',res)
uni.setStorageSync('localtoken', res.data.data.access_token)
that.myProfile() // User information interface
that.getHistoryList() // Footprint interface
}
}, function(err) {
uni.showToast({
icon: 'none',
title: err.msg
})
});
}
},
});
},
fail: () => {
uni.showToast({
title: ' Authorization cancelled ',
icon: 'error',
mask: true,
});
},
complete: () => {
// hide loading
uni.hideLoading();
},
});
},
}
}
</script>
3、 ... and 、 Effect display



ending~
边栏推荐
- Difficult to get up syndrome (bit by bit greed)
- 使用多线程Callable查询oracle数据库
- 13 MySQL constraint
- Qt5.12.9 migration tutorial based on Quanzhi H3
- 九州云与英特尔联合发布智慧校园私有云框架,赋能教育新基建
- Node - generate wechat permission verification configuration
- PWN attack and defense world cgpwn2
- Graduation season is both a farewell and a new beginning
- 在证券账户上买基金安全吗?哪里可以买基金
- B tree and b+tree of MySQL
猜你喜欢

UDS bootloader of s32kxxx bootloader

It's nothing to be utilitarian!

Kuberntes cloud native combat high availability deployment architecture

SQL Server 安裝指南

Leetcode question brushing: stack and queue 07 (maximum value of sliding window)

Intelligent operation and maintenance practice: banking business process and single transaction tracking

数据库--SqlServer详解

Leetcode96 different binary search trees

4. Object mapping Mapstercover
![[opencv450] hog+svm and hog+cascade for pedestrian detection](/img/55/cdf0bb8231ee59e34c8d5a9d6def23.png)
[opencv450] hog+svm and hog+cascade for pedestrian detection
随机推荐
mysql之B tree 以及 B+tree
数据库--SqlServer详解
股票开户哪个证券公司比较安全
牛客-练习赛101-推理小丑
2022拼多多详情/拼多多商品详情/拼多多sku详情
Difficult to get up syndrome (bit by bit greed)
Asp . Text of automatic reply to NETCORE wechat subscription number
Database -- sqlserver details
【CTF】bjdctf_ 2020_ babystack2
UDS bootloader of s32kxxx bootloader
13 MySQL constraint
What is the purpose of ERP project implementation plan?
How to type spaces in latex
Bc35 & bc95 onenet mqtt (old)
Is it safe to choose mobile phone for stock trading account opening in Beijing?
Kuberntes cloud native combat high availability deployment architecture
Leetcode question brushing: stack and queue 07 (maximum value of sliding window)
4. Object mapping Mapstercover
Linux CentOS7安装Oracle11g的超完美新手教程
Leetcode96 different binary search trees