import { isEmpty } from './TextUtils.js' const wxAuthLogin = () => { // 判断是否已经登陆 if (getApp().globalData.isLogin) { return new Promise((resolve, reject) => { resolve(getApp().globalData.sysUserSid) }) } return new Promise((resolve, reject) => { // 获取信息 // 获取用户信息 uni.getUserProfile({ desc: '获取基本信息', success: function(infoRes) { _this.data.nickName = infoRes.userInfo.nickName; _this.data.gender = infoRes.userInfo.gender == 1 ? "男" : "女"; _this.data.oauthHeadImg = infoRes.userInfo.avatarUrl; _this.data.fromkey = "WeiXin"; uni.login({ provider: 'weixin', success: function(loginRes) { uni.request({ url: getApp().globalData.wxAuthLoginURL + "?wxCode=" + loginRes .code, method: "GET", header: { // 传参方式 'content-type': "application/x-www-form-urlencoded" }, // 具体参数 data: { "wxCode": loginRes.code }, }).then((res) => { console.log(res) _this.data.openid = res.data.openid; _this.data.unionId = res.data.unionid; // _this.HTTP({ // url: "oauth/afterlogin", // data: { // "openid": _this.data.openid, // "unionId": _this.data.unionId, // "nickName": _this.data.nickName, // "gender": _this.data.gender, // "oauthHeadImg": _this.data // .oauthHeadImg, // "fromkey": _this.data.fromkey // }, // loading: true // }).then((res) => { // // 保存 // _this.WritePreference("memberSid", // res.data // .memberSid) // getApp().globalData.isLogin = true // getApp().globalData.memberSid = res // .data // .memberSid // // $emit 触发事件 (主要返回给webviwew页面) // uni.$emit('login', res.data // .memberSid) // _this.Back() // }, (err) => { // if (err.data != null) { // err.data.cookie = _this // .ReplaceAll(err.data.cookie, // "=", "-") // uni.redirectTo({ // url: "./BdtelephoneActivity?cookie=" + // err.data.cookie // }) // } // }) }, (err) => { // 错误提示 _this.Toast("出错了:" + err.data.errmsg) }) }, fail: function(err) { _this.Toast(err) } }); }, fail: function(err) { // 用户拒绝 _this.Toast(err.errMsg) } }); }) } export default wxAuthLogin