51Testing软件测试论坛
标题:
微信小程序关于启动登录授权更新从直接调用
[打印本页]
作者:
测试积点老人
时间:
2022-4-19 10:53
标题:
微信小程序关于启动登录授权更新从直接调用
微信小程序关于启动登录授权更新从直接调用wx.getuserinfo改到bottom方式后出现一连串错误请专家帮看下
启动登录授权更新从直接调用wx.getuserinfo改到bottom方式后出现一连串错误
var e = require("../../utils/request.js"), t = require("../../utils/navigate.js"), a = require("../../utils/check.js"), n = (require("../../utils/common.js"),
require("../../utils/md5.js")), o = getApp();
Page({
data: {
shouquan:false,
loginWay: 0,
isFirstLogin: !1,
isGet: !1,
time: 120,
phone0: "",
phone1: "",
pwd: "",
code: "",
isLoginBack: !1,
isSetPwd: !0,
userId: ""
},
onLoad: function(e) {
new (getApp().ToastPannel)();
},
onShow: function() {
wx.removeStorageSync("PHPSESSID");
},
onHide: function() {
console.log("onHide");
},
onUnload: function() {
console.log("onUnload");
},
switchNav: function(e) {
var t = e.currentTarget.dataset.nav;
this.setData({
loginWay: Number(t)
});
},
getCode: function() {
var t = this;
if (this.checkedPhone(this.data.phone0)) {
var a = {};
a.type = 3, a.phone = this.data.phone0, a.openid = o.globalData.userInfo.open_id,
o.globalData.userInfo.open_id && e.request("Api/Login/get_phone_code", a, function(e) {
var a = e.data;
if (1 == a.code) {
t.setData({
isGet: !0
});
var n = setInterval(function() {
t.data.time <= 0 && (t.data.time = 120, clearTimeout(n), t.setData({
isGet: !1
})), t.setData({
time: --t.data.time
});
}, 1e3);
} else t.show(a.msg, "", "top");
});
}
},
phoneLogin: function() {
var a = this;
if (this.checkedPhone(this.data.phone0)) if ("" == this.data.code.trim()) this.show("请填写验证码", "", "top"); else {
var n = {};
n.type = 1, n.user_name = this.data.phone0, n.openid = o.globalData.userInfo.open_id,
n.code = this.data.code, console.log(n), e.request("Api/Login/user_login", n, function(e) {
var n = e.data;
if (1 == n.code) if (n.data.is_first_login) a.setData({
isFirstLogin: !0
}), a.data.userId = n.data.user_id; else {
var o = a.storageUser(n.data);
wx.setStorageSync("user", o), a.data.isLoginBack ? t.nav("navigateBack", 1) : t.nav("switchTab", "../index/index");
} else a.show(n.msg, "", "top");
});
}
},
phoneFirstLogin: function(a) {
var s = this, i = a.detail.value.phonePwd;
if (this.checkedPwd(i)) {
var r = {};
r.member_id = this.data.userId, r.password = n.hexMD5(n.hexMD5(i + o.pwdFixedStr)),
console.log(r), e.request("Api/Login/save_user_pwd", r, function(e) {
var a = e.data;
if (1 == a.code) {
var n = s.storageUser(a.data);
wx.setStorageSync("user", n), s.data.isLoginBack ? t.nav("navigateBack", 1) : t.nav("switchTab", "../index/index");
} else s.show(a.msg, "", "top");
});
}
},
userLogin: function() {
var a = this, s = this;
if (this.checkedPhone(this.data.phone1) && this.checkedPwd(this.data.pwd)) {
var i = {};
i.type = 2, i.user_name = this.data.phone1, i.openid = o.globalData.userInfo.open_id,
i.code = this.data.code, i.password = n.hexMD5(n.hexMD5(this.data.pwd + o.pwdFixedStr)),
e.request("Api/Login/user_login", i, function(e) {
var n = e.data;
if (1 == n.code) {
var o = s.storageUser(n.data);
wx.setStorageSync("user", o), s.data.isLoginBack ? t.nav("navigateBack", 1) : t.nav("switchTab", "../index/index");
} else a.show(n.msg, "", "top");
});
}
},
wxLogin: function() {
console.log(1111);
var that = this;
var a = this, n = wx.getStorageSync("wxPersonInfo");
if (console.log(n), n) e.request("Api/Login/user_login_weixin", n, function(e) {
console.log(e);
var n = e.data;
if (1 == n.code) {
var o = a.storageUser(n.data);
console.log(o),
1 == n.data.is_bind_phone ? t.nav("navigateTo", "../bindPhone/bindPhone", o) : (wx.setStorageSync("user", o),
a.data.isLoginBack ? t.nav("navigateBack", 1) : t.nav("switchTab", "../index/index"));
}
}); else {
var o = getApp();
wx.login({
success: function(t) {
var n = {}, s = wx.getStorageSync("wxPersonInfo");
console.log(s), s ? (n.nickname = s.nickname, n.headimgurl = s.headimgurl, n.sex = s.sex,
n.open_id = s.open_id, o.globalData.userInfo = n) : e.request("Api/WeiXin/get_wxopenid", {
code: t.code
}, function(t) {
console.log(t);
n.open_id = t.data.data.openid,
wx.getUserInfo ? wx.getUserInfo({
success: function(t) {
console.log(t), wx.getUserInfo({
success: function(t) {
console.log(t);
var a = JSON.parse(t.rawData);
n.nickname = a.nickName, n.headimgurl = a.avatarUrl, n.sex = a.gender, o.globalData.userInfo = n,
console.log(n);
e.request("Api/WeiXin/save_user_weixin_info", n, function(e) {
e.data.code, wx.setStorageSync("wxPersonInfo", n);
that.wxLogin();
});
},
fail: function(e) {
console.log(e), a.show("授权失败,请确认重新授权!", "", "top");
}
});
},
fail: function(e) {
console.log(e);
that.setData({shouquan:true});
}
}) : wx.showModal({
title: "当前微信版本过低",
content: "当前微信版本过低,有些功能不能使用,请升级到最新微信版本后重试。"
});
// 获取用户信息接口
// queryUsreInfo: function() {
// wx.request({
// url: getApp().globalData.urlPath + 'hstc_interface/queryByOpenid',
// data: {
// openid: getApp().globalData.openid
// },
// header: {
// 'content-type': 'application/json'
// },
// success: function (res) {
// console.log(res.data);
// getApp().globalData.userInfo = res.data;
// }
// })
// }
});
}
});
}
},
// 打开权限设置页提示框
bindGetUserInfo:function(t){
console.log(t);
var o = getApp();
var a = JSON.parse(t.detail.rawData);
var that = this;
this.setData({shouquan:false});
wx.login({
success: function(t) {
var n = {}, s = wx.getStorageSync("wxPersonInfo");
console.log(s), s ? (n.nickname = s.nickname, n.headimgurl = s.headimgurl, n.sex = s.sex,
n.open_id = s.open_id, o.globalData.userInfo = n) : e.request("Api/WeiXin/get_wxopenid", {
code: t.code
}, function(t) {
n.open_id = t.data.data.openid,
n.nickname = a.nickName, n.headimgurl = a.avatarUrl, n.sex = a.gender, o.globalData.userInfo = n,
console.log(n);
e.request("Api/WeiXin/save_user_weixin_info", n, function(e) {
e.data.code, wx.setStorageSync("wxPersonInfo", n);
wx.switchTab({
url: '/pages/index/index'
})
});
});
}
});
setTimeout(function(){
that.wxLogin();
},1000);
},
storageUser: function(e) {
var t = {}, a = wx.getStorageSync("wxPersonInfo");
return t.openid = a.open_id, t.phone = e.phone, t.token = e.token, t.nick_name = e.nick_name,
t.member_name = e.member_name, t.image = e.image, t.id = e.id, t;
},
registorFn: function() {
t.nav("navigateTo", "../register/register");
},
forgetPwd: function() {
t.nav("navigateTo", "../forgetPwd/forgetPwd");
},
getPhoneFn0: function(e) {
this.setData({
phone0: e.detail.value
});
},
getPhoneFn1: function(e) {
this.setData({
phone1: e.detail.value
});
},
getPwdFn: function(e) {
this.setData({
pwd: e.detail.value
});
},
getTxtFn: function(e) {
this.setData({
code: e.detail.value
});
},
checkedPhone: function(e) {
var t = a.checkPhone(e);
if (101 == t.code) return this.show("手机号不能为空", "", "top"), t.status;
switch (t.code) {
case 101:
return this.show("手机号不能为空", "", "top"), t.status;
case 102:
return this.show("手机号过短", "", "top"), t.status;
case 103:
return this.show("手机号过长", "", "top"), t.status;
case 105:
return this.show("手机号格式错误", "", "top"), t.status;
default:
return t.status;
}
},
checkedPwd: function(e) {
var t = a.checkPwd(e);
switch (t.code) {
case 101:
return this.show("密码不能为空", "", "top"), t.status;
case 102:
return this.show("密码过短,格式为数字与字母的6~16位组合", "", "top"), t.status;
case 103:
return this.show("密码过长,格式为数字与字母的6~16位组合", "", "top"), t.status;
case 105:
return this.show("密码格式错误,格式为数字与字母的6~16位组合", "", "top"), t.status;
default:
return t.status;
}
},
checkContrastPwd: function(e, t) {
var n = a.checkContrastPwd(e, t);
return 104 == n.code ? (this.show("两次输入密码不一致", "", "top"), n.status) : n.status;
}
});
复制代码
更改完成后以及下错误及返回结果 :
1.{data: {…}, header: {…}, statusCode: 200, cookies: Array(0), errMsg: "request:ok"}
cookies: []
data: {code: 1, msg: "请求成功。", data: {…}}
errMsg: "request:ok"
header: {Date: "Sun, 17 Apr 2022 11:32:24 GMT", Server: "Apache/2.4.23 (Win32) OpenSSL/1.0.2j mod_fcgid/2.3.9", X-Powered-By: "PHP/5.4.45", Expires: "Thu, 19 Nov 1981 08:52:00 GMT", Cache-Control: "no-store, no-cache, must-revalidate, post-check=0, pre-check=0", …}
statusCode: 200
proto: Object
2.{errMsg: "getUserInfo:fail scope unauthorized"}
errMsg: "getUserInfo:fail scope unauthorized"
proto: Object
3.{type: "getuserinfo", timeStamp: 7906, target: {…}, currentTarget: {…}, mark: {…}, …}
currentTarget: {id: "", offsetLeft: 85, offsetTop: 320, dataset: {…}}
detail: {errMsg: "getUserInfo:ok", rawData: "{"nickName":"~小友","gender":0,"language":"zh_CN","c…f9GN12kHXVXCPbKwwfyxX84Iwe6surlcGKCicibadtg/132"}", signature: "960b61a011af45d710378d4217e4e2950d456339", encryptedData: "RDJHMIkZRF23rhvljsxnyvWA5SNgadJX1ks4WFTLFmTApRQ10g…oKYWT/OSSHhUj6BW/5njaUhmlJb3kBS9w5z6BHAVRAFIcQA==", iv: "AOtsMy2UR4IUSDtpQo/AkA==", …}
mark: {}
mut: false
target: {id: "", offsetLeft: 85, offsetTop: 320, dataset: {…}}
timeStamp: 7906
type: "getuserinfo"
_userTap: false
proto: Object
报错1:
VM3301 WAService.js:2 MiniProgramError
Cannot set property 'userInfo' of undefined
TypeError: Cannot set property 'userInfo' of undefined
athttp://127.0.0.1:52044/appservice/pages/login/login.js:201:136
at success (http://127.0.0.1:52044/appservice/utils/request.js:49:140)
at Function.i. (http://127.0.0.1:52044/appservice/__dev__/WAService.js:2:2911763)
at
athttp://127.0.0.1:52044/appservice/__dev__/WAService.js:2:121992
at u (http://127.0.0.1:52044/appservice/__dev__/WAService.js:2:1539149)
at Function. (http://127.0.0.1:52044/appservice/__dev__/WAService.js:2:1703010)
at
athttp://127.0.0.1:52044/appservice/__dev__/WAService.js:2:121992
athttp://127.0.0.1:52044/appservice/__dev__/WAService.js:2:1677704(env: Windows,mp,1.05.2201240; lib: 2.14.0)
报错2:
VM3301 WAService.js:2 MiniProgramError
Cannot set property 'userInfo' of undefined
TypeError: Cannot set property 'userInfo' of undefined
at success (http://127.0.0.1:52044/appservice/pages/login/login.js:144:114)
at Function.i. (http://127.0.0.1:52044/appservice/__dev__/WAService.js:2:2911763)
at
at Object.success (http://127.0.0.1:52044/appservice/__dev__/WAService.js:2:121992)
at B (http://127.0.0.1:52044/appservice/__dev__/WAService.js:2:1841150)
at B (http://127.0.0.1:52044/appservice/__dev__/WAService.js:2:1841388)
athttp://127.0.0.1:52044/appservice/__dev__/WAService.js:2:1842827
athttp://127.0.0.1:52044/appservice/__dev__/asdebug.js:1:49966
at C (http://127.0.0.1:52044/appservice/__dev__/asdebug.js:1:49621)
athttp://127.0.0.1:52044/appservice/__dev__/asdebug.js:1:3691(env: Windows,mp,1.05.2201240; lib: 2.14.0)
复制代码
求问怎么改后续登录流程
作者:
qqq911
时间:
2022-4-20 10:21
看下报错在那个请求
作者:
bellas
时间:
2022-4-20 10:54
打个断点,看下输出
作者:
jingzizx
时间:
2022-4-20 14:05
没看明白方法,直接一步步调试是否可以
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/)
Powered by Discuz! X3.2