报错:
thirdScriptError
n is not defined;at api login success callback function
ReferenceError: n is not defined
at success (http://127.0.0.1:13473/appservice/pages/message/auth/index.js:54:13)
at Function.o.<computed> (http://127.0.0.1:13473/appservice/__dev__/WAService.js?t=wechat&s=1629340010346&v=2.11.0:2:1522343)
at Object.success (http://127.0.0.1:13473/appservice/__dev__/WAService.js?t=wechat&s=1629340010346&v=2.11.0:2:128047)
at y (http://127.0.0.1:13473/appservice/__dev__/WAService.js?t=wechat&s=1629340010346&v=2.11.0:2:579185)
at v (http://127.0.0.1:13473/appservice/__dev__/WAService.js?t=wechat&s=1629340010346&v=2.11.0:2:579428)
at http://127.0.0.1:13473/appservice/__dev__/WAService.js?t=wechat&s=1629340010346&v=2.11.0:2:580977
at http://127.0.0.1:13473/appservice/__dev__/asdebug.js:1:40283
at I (http://127.0.0.1:13473/appservice/__dev__/asdebug.js:1:39938)
at http://127.0.0.1:13473/appservice/__dev__/asdebug.js:1:2870
at Set.forEach (<anonymous>)(env: Windows,mp,1.05.2108182; lib: 2.11.0)
有谁遇到过呢?
index.js 文件
var e = getApp(), t = require("./../../../utils/core.js");
Page({
data: {
close: 0,
text: "",
imgUrl: ""
},
onLoad: function(t) {
this.setData({
close: t.close,
text: t.text,
imgUrl: e.globalData.approot
});
},
onShow: function() {
var t = e.getCache("sysset").shopname;
wx.setNavigationBarTitle({
title: t || "提示"
});
},
bind: function() {
var n = this, i = setInterval(function() {
wx.getSetting({
success: function(e) {
var t = e.authSetting["scope.userInfo"];
t && (wx.reLaunch({
url: "/pages/index/index"
}), clearInterval(i), n.setData({
userInfo: t
}));
}
});
}, 1e3);
},
getUserProfile(){
wx.getUserProfile({
desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
success: (res) => {
// console.log("获取用户信息成功", res);
// return;
wx.showLoading({
title: "加载中"
}), wx.login({
success: function(t) {
// console.log(t);
// return;
n.post("wxapp/login", {
code: t.code
}, function(t) {
// console.log(t.openid);
// return;
t.error ? n.alert("获取用户登录态失败:" + t.message) : n.get("wxapp/auth", {
data: res.encryptedData,
iv: res.iv,
sessionKey: t.session_key,
openId:t.openid
}, function(n) {
1 == n.isblack && wx.showModal({
title: "无法访问",
检查下在授权的函数里面 n 这个属性有没有被定义
空指针了,贴代码吧。
Page({
data: {
close: 0,
text: "",
imgUrl: ""
},
onLoad: function(t) {
this.setData({
close: t.close,
text: t.text,
imgUrl: e.globalData.approot
});
},
onShow: function() {
var t = e.getCache("sysset").shopname;
wx.setNavigationBarTitle({
title: t || "提示"
});
},
bind: function() {
var n = this, i = setInterval(function() {
wx.getSetting({
success: function(e) {
var t = e.authSetting["scope.userInfo"];
t && (wx.reLaunch({
url: "/pages/index/index"
}), clearInterval(i), n.setData({
userInfo: t
}));
}
});
}, 1e3);
},
getUserProfile(){
wx.getUserProfile({
desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
success: (res) => {
// console.log("获取用户信息成功", res);
// return;
wx.showLoading({
title: "加载中"
}), wx.login({
success: function(t) {
// console.log(t);
// return;
n.post("wxapp/login", {
code: t.code
}, function(t) {
// console.log(t.openid);
// return;
t.error ? n.alert("获取用户登录态失败:" + t.message) : n.get("wxapp/auth", {
data: res.encryptedData,
iv: res.iv,
sessionKey: t.session_key,
openId:t.openid
}, function(n) {
1 == n.isblack && wx.showModal({
title: "无法访问",
content: "您在商城的黑名单中,无权访问!",
success: function(n) {
n.confirm && e.close(), n.cancel && e.close();
}
}), res.userInfo.openid = n.openId, res.userInfo.id = n.id, res.userInfo.uniacid = n.uniacid,
e.setCache("userinfo", res.userInfo), e.setCache("userinfo_openid", res.userInfo.openid),
e.setCache("userinfo_id", n.id), e.getSet(), wx.navigateBack({
changed: !0
});
});
});
},
fail: function() {
n.alert("获取用户信息失败!");
},
complete: function() {
wx.hideLoading();
}
});
},
fail: res => {
// console.log("获取用户信息失败", res)
n.alert("获取用户信息失败!");
}
})
},
cancelLogin: function() {
wx.switchTab({
url: "/pages/index/index"
});
}
});
}), res.userInfo.openid = n.openId, res.userInfo.id = n.id, res.userInfo.uniacid = n.uniacid,
e.setCache("userinfo", res.userInfo), e.setCache("userinfo_openid", res.userInfo.openid),
e.setCache("userinfo_id", n.id), e.getSet(), wx.navigateBack({
changed: !0
});
});
});
},
fail: function() {
n.alert("获取用户信息失败!");
},
complete: function() {
wx.hideLoading();
}
});
},
fail: res => {
// console.log("获取用户信息失败", res)
n.alert("获取用户信息失败!");
}
})
},
cancelLogin: function() {
wx.switchTab({
url: "/pages/index/index"
});
}
});
网上说
更新 php版本可以解决 (这个没有用)