当前位置:网站首页>[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~
边栏推荐
- From 20s to 500ms, I used these three methods
- 智能运维实战:银行业务流程及单笔交易追踪
- 股票开户哪个证券公司比较安全
- 【底部弹出-选择器】uniapp Picker组件——底部弹起的滚动选择器
- 2023 Lexus ES products have been announced, which makes great progress this time
- [template] adaptive Simpson integral
- Openvino model performance evaluation tool DL workbench
- Asp . Text of automatic reply to NETCORE wechat subscription number
- ERP项目施行计划的目的是什么?
- Is it safe and reliable to open an account in Caixue school and make new debts?
猜你喜欢
![Window sorting functions rank and deny for SQL data analysis_ rank、raw_ Number and lag, lead window offset function [usage sorting]](/img/3a/cced28a2eea9f9a0d107baabd01119.png)
Window sorting functions rank and deny for SQL data analysis_ rank、raw_ Number and lag, lead window offset function [usage sorting]

如何提升数据质量

Example explanation: move graph explorer to jupyterlab

USB-IF协会与各种接口的由来

Kuberntes cloud native combat high availability deployment architecture

How do Lenovo computers connect Bluetooth headsets?

智能运维实战:银行业务流程及单笔交易追踪

GCC compilation

2022拼多多详情/拼多多商品详情/拼多多sku详情
![[opencv450] hog+svm and hog+cascade for pedestrian detection](/img/55/cdf0bb8231ee59e34c8d5a9d6def23.png)
[opencv450] hog+svm and hog+cascade for pedestrian detection
随机推荐
js 公共库 cdn 推荐
Node——添加压缩文件
Window sorting functions rank and deny for SQL data analysis_ rank、raw_ Number and lag, lead window offset function [usage sorting]
B tree and b+tree of MySQL
LDR6035智能蓝牙音响可对手机设备持续充放电方案
Linux centos7 installation Oracle11g super perfect novice tutorial
Leetcode 96 différents arbres de recherche binaires
mysql之B tree 以及 B+tree
Leetcode question brushing: stack and queue 07 (maximum value of sliding window)
Intelligent operation and maintenance practice: banking business process and single transaction tracking
Three methods of finding inverse numbers
vue 强制清理浏览器缓存
启牛学院开户安全的吗?开户怎么开?
Digital transformation has a long way to go, so how to take the key first step
What does open loop and closed loop mean?
Ldr6035 smart Bluetooth audio can continuously charge and discharge mobile devices
What is the purpose of ERP project implementation plan?
使用htaccess文件禁止目录里的脚本执行权限
Is the securities account given by qiniu business school safe? Where can I open an account
创业团队如何落地敏捷测试,提升质量效能?丨声网开发者创业讲堂 Vol.03