当前位置:网站首页>Wechat authorized login
Wechat authorized login
2022-06-28 12:25:00 【Front end of stairs, Xiaobai】
wx.uploadFile({
filePath: tempFilePaths[0],
name: 'file',
url: api.baseUrl + 'dsms/app/upload',
header: {
"Authorization": wx.getStorageSync('userId') + "_" + wx.getStorageSync('token')
},
formData: {
"file":"file"
},
success(res) {
},
fail(err) {
console.log(err)
}
})wx.getSetting({
success: res => {
if (res.authSetting['scope.userInfo']) {
// Has authorized , Can be called directly getUserInfo Get head nickname , Can't pop the frame
wx.getUserInfo({
success: res => {
const userInfo = res.userInfo
console.log(res)
// Can be res Send it to the background and decode it out unionId
app.globalData.userInfo = res.userInfo
// Get wechat login credentials
wx.login({
success: (res) => {
console.log(res);
if (res.code) {
// Initiate network request
api.fetch({
url: "dsms/open/wx/register",
data: {
"code": res.code,
"nickName": userInfo.nickName,
"avatar": userInfo.avatarUrl,
"gender": userInfo.gender,
"city": userInfo.city
},
})
.then(res => {
showToast({
"title": " Wechat authorization succeeded "
})
wx.switchTab({
url: '/pages/home/home'
})
})
.catch(res => {
console.log(res)
showToast({
"title": res.message
})
})
} else {
console.log(' privilege grant failed !' + res.errMsg)
}
},
fail: err => {
console.log(err)
showToast({
"title": err.errMsg
})
// rekect(err)
},
complete: () => {
wx.hideLoading();
}
})
// because getUserInfo It's a network request , May be in Page.onLoad And then come back
// So add here callback To prevent this
if (this.userInfoReadyCallback) {
this.userInfoReadyCallback(res)
}
},
fail: err => {
console.log(err)
showToast({
"title": err.errMsg
})
// rekect(err)
},
complete: () => {
wx.hideLoading();
}
})
}
},
fail: err => {
console.log(err)
showToast({
"title": err.errMsg
})
// rekect(err)
},
complete: () => {
wx.hideLoading();
}
})边栏推荐
- 性能测试-01-简介
- 张同学回应首场直播带货
- URL append parameter method, considering #$ Situation of
- 分页样式 flex设置成在尾部显示(即使页数加长 也不会因为在末尾而换行)
- What is the difference between internal oscillator, passive crystal oscillator and active crystal oscillator?
- Multi dimensional monitoring: the data base of intelligent monitoring
- 运维思考 | 你知道CMDB与监控是什么关系吗?
- RemoteViews布局和类型限制源码分析
- 杰理之wif 干扰蓝牙【篇】
- cdc同步 如果数据库表的主键发生了变化,会同步成两个数据 还是会同步更新主键呢?
猜你喜欢

内部振荡器、无源晶振、有源晶振有什么区别?

RemoteViews布局和类型限制源码分析

Function and principle of remoteviews

Ugui uses tips (VI) unity to realize vertical line display of string

Bytev builds a dynamic digital twin network security platform -- helping network security development

What is data compliance? How to achieve data compliance?
![[unity Editor Extension Foundation], editorguilayout (I)](/img/f2/42413a4135fd6181bf311b685504b2.png)
[unity Editor Extension Foundation], editorguilayout (I)

【C语言】结构体嵌套二级指针的使用

Tips for using ugui (V) using scroll rect component
Using MySQL database in the express framework of node
随机推荐
【C语言】二叉树的实现及三种遍历
ASP.NET CORE Study11
【Unity编辑器扩展基础】、EditorGUILayout(二)
Prefix and (2D)
[C language] use of file read / write function
UGUI使用小技巧(五) Scroll Rect组件的使用
最新!基于Open3D的点云处理入门与实战教程
Redis 原理 - List
AsyncTask经验小结
pwn入门(1)二进制基础
Given two points and a point with a middle scale, find the coordinates of the point
Prefix and (one dimension)
已知两个点和中间一个比例的点,求该点坐标
关于字符串转换的一些小技巧
AcWing 606. Average 1 (implemented in C language)
[C language] about scanf() and scanf_ Some problems of s()
运维思考 | 你知道CMDB与监控是什么关系吗?
女子高考落榜读专科逆袭买千万别墅,考得不好真的没关系
JNI函数的2种书写方式
攻防世界新手入门hello_pwn