文件 ewei_shopv2/plugin/app/core/mobile/wxapp.php 对照着这个代码修改或者复制
/**
* 微信小程序登录
*/
public function auth()
{
global $_GPC;
global $_W;
$encryptedData = trim($_GPC["data"]);
$iv = trim($_GPC["iv"]);
$sessionKey = trim($_GPC["sessionKey"]);
//登录修正
$userInfo=$_GPC["userInfo"];
//登录修正
if (empty($encryptedData) || empty($iv)) {
return app_error(AppError::$ParamsError);
}
$pc = new WXBizDataCrypt($this->appid, $sessionKey);
$errCode = $pc->decryptData($encryptedData, $iv, $data);
if ($errCode == 0) {
$data = json_decode($data, true);
$this->refine($data["openId"]);
$member = m("member")->getMember("sns_wa_" . $data["openId"]);
//登录修正
if(is_array($userInfo)){
$data=array_merge($data, $userInfo);
}
//登录修正
if (empty($member)) {
$member = array("uniacid" => $_W["uniacid"], "uid" => 0, "openid" => "sns_wa_" . $data["openId"], "nickname"=>!empty($data["nickName"]) ? $data["nickName"] : "", "avatar" => !empty($data["avatarUrl"]) ? $data["avatarUrl"] : "", "gender" => !empty($data["gender"]) ? $data["gender"] : "-1", "openid_wa" => $data["openId"], "comefrom" => "sns_wa", "createtime" => time(), "status" => 0);
pdo_insert("ewei_shop_member", $member);
$id = pdo_insertid();
$data["id"] = $id;
$data["uniacid"] = $_W["uniacid"];
if (method_exists(m("member"), "memberRadisCountDelete")) {
m("member")->memberRadisCountDelete();
}
} else {
$updateData = array("nickname" => !empty($data["nickName"]) ? $data["nickName"] : "", "avatar" => !empty($data["avatarUrl"]) ? $data["avatarUrl"] : "", "gender" => !empty($data["gender"]) ? $data["gender"] : "-1");
pdo_update("ewei_shop_member", $updateData, array("id" => $member["id"], "uniacid" => $member["uniacid"]));
$data["id"] = $member["id"];
$data["uniacid"] = $member["uniacid"];
$data["isblack"] = $member["isblack"];
}
if (p("commission")) {
p("commission")->checkAgent($member["openid"]);
}
return app_json($data, $data["openId"]);
}
return app_error(AppError::$WxAppError, "登录错误, 错误代码: " . $errCode);
}
小程序前台文件 pages/auth/index.wxml 立即登录按钮需要修改
<button bindtap='bindGetUserInfobu' class='authBtn' >立即登录</button>
小程序前台文件js pages/auth/index.js
在36行处增加
// 登录修正
bindGetUserInfobu(){
//getUserProfile获取用户信息
wx.getUserProfile({
lang:'zh_CN',
desc: '用于完善会员资料',
success: (res) =>{
console.log(res)
//getUserInfo获取认证oid解密
wx.getUserInfo({
lang: 'zh_CN',
}).then(r=>{
console.log(r)
r.userInfo=res.userInfo
let n={
detail:r
}
this.bindGetUserInfo(n)
})
}
})
},
//登录修正
bindGetUserInfo: function (o) {
console.log(o)
wx.showLoading({
title: "加载中"
})
wx.login({
success: function (t) {
console.log(t)
n.post("wxapp/login", {
code: t.code
}, function (tt) {
console.log(tt)
tt.error ? n.alert("获取用户登录态失败:" + tt.message) : n.get("wxapp/auth", {
data: o.detail.encryptedData,
iv: o.detail.iv,
sessionKey: tt.session_key,
userInfo:o.detail.userInfo// 登录修正
}, function (n) {
console.log(n)
1 == n.isblack && wx.showModal({
title: "无法访问",
content: "您在商城的黑名单中,无权访问!",
success: function (n) {
n.confirm && e.close(), n.cancel && e.close()
}
}), o.detail.userInfo.openid = n.openId, o.detail.userInfo.id = n.id, o.detail.userInfo.uniacid = n.uniacid, e.setCache("userinfo", o.detail.userInfo), e.setCache("userinfo_openid", o.detail.userInfo.openid), e.setCache("userinfo_id", n.id), e.getSet(), wx.navigateBack({
changed: !0
})
})
})
},
fail: function () {
n.alert("获取用户信息失败!")
},
complete: function () {
wx.hideLoading()
}
})
},
大概在114行看见bindGetUserInfo: function(n) js语句 往下看到sessionKey: a.session_key,
下一行加userinfo:n.detail.userInfo//登录修正 JS代码