当前位置:网站首页>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();
}
})边栏推荐
- 智联招聘基于 Nebula Graph 的推荐实践分享
- 【C语言】文件读写函数使用
- 【经验分享】Django开发中常用到的数据库操作总结
- UGUI使用小技巧(五) Scroll Rect组件的使用
- [unity Editor Extension practice] find all prefabs referencing this picture
- AsyncTask经验小结
- 吐血推荐17个提升开发效率的“轮子”
- Is tongdaxin stock software reliable? Is it safe to trade stocks on it?
- pwn入门(1)二进制基础
- ASP.NET CORE Study06
猜你喜欢

RemoteViews的作用及原理

ASP.NET CORE Study08

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

智联招聘基于 Nebula Graph 的推荐实践分享

Leetcode 705. 设计哈希集合

ByteV搭建动态数字孪生网络安全平台----助力网络安全发展

SEO优化的许多好处是与流量有直接关系

EMC RS485接口EMC电路设计方案

【C语言】关于scanf()与scanf_s()的一些问题

. Net hybrid development solution 24 webview2's superior advantages over cefsharp
随机推荐
RemoteViews布局和类型限制源码分析
.NET混合开发解决方案24 WebView2对比CefSharp的超强优势
【C语言】随机数文件对其进行三种排序方法
Unity Editor Extension Foundation, editorguilayout (II)
Remoteviews layout and type restriction source code analysis
【Unity编辑器扩展基础】、GUILayout
【Unity编辑器扩展基础】、EditorGUILayout (一)
杰理之wif 干扰蓝牙【篇】
MapReduce project case 1
Zero basic C language (I)
最新!基于Open3D的点云处理入门与实战教程
Some tips on string conversion
AcWing 607. Average 2 (implemented in C language)
【vi/vim】基本使用及命令汇总
我的NVIDIA开发者之旅-Jetson Nano 2gb教你怎么训练模型(完整的模型训练套路)
EMC RS485 interface EMC circuit design scheme
智联招聘基于 Nebula Graph 的推荐实践分享
案例驱动 :从入门到掌握Shell编程详细指南
[C language] three sorting methods for random number files
AcWing 606. Average 1 (implemented in C language)