微擎微信公众号授权登录反复登录跳转修复

因为公众号修改了获取用户基本信息的返回字段内容,导致微擎获取用户基本信息时无法获取到nickname,而需要反复跳转。并且特别是电脑端打开都会弹出授权弹窗

通过修改 framework/model/mc.mod.php 

mc_oauth_account_userinfo 函数,以下片段

if (intval($_W['account']['oauth']['level']) < 4 && !in_array($_W['account']['oauth']['level'], array(ACCOUNT_TYPE_APP_NORMAL, ACCOUNT_TYPE_APP_AUTH, ACCOUNT_TYPE_WXAPP_WORK))) {
return error(-3, '公众号非认证服务号, 无法获取用户信息.');}
这个判断以下内容改为下方

if (!empty($_SESSION['openid']) && intval($_W['account']['level']) >= 3) {

$oauth_account = WeAccount::createByUniacid();

$userinfo = $oauth_account->fansQueryInfo($_SESSION['openid']);

//查询用户信息,用于判断是否已保存在粉丝记录

$fan = mc_fansinfo($_SESSION['openid']);

//获取到的用户基础信息未出错,且不为空

if(empty($fan) && !is_error($userinfo) && !empty($userinfo) && !empty($userinfo['openid']) ){

        $record = array();

        $record['updatetime'] = TIMESTAMP;

        $record['nickname'] = '';     
       $record['tag'] = base64_encode(iserializer($userinfo));
        $record['openid'] = $_SESSION['openid'];        $record['acid'] = $_W['acid'];

        $record['uniacid'] = $_W['uniacid'];       
        $record['unionid'] = $userinfo['unionid'];

      $record['user_from'] = $_W['account']->typeSign == 'wxapp' ? 1 : 0;

       pdo_insert('mc_mapping_fans', $record);

}

//获取的用户信息不为空,且已经存在昵称。

else if (!is_error($userinfo) && !empty($fan) && !empty($fan['nickname']) && is_array($userinfo) ){

    //返回粉丝,已有的粉丝信息  ==》这么改之后,系统里的粉丝用户信息就没办法实时最新了。腾讯修改返回信息规则之后只有使用,弹窗授权才能获取到用户的昵称、头像

    $userinfo['nickname'] = stripcslashes($fan['nickname']);

$userinfo['avatar'] = $fan['headimgurl'];

$_SESSION['userinfo'] = base64_encode(iserializer($userinfo));

    $record = array(

'updatetime' => TIMESTAMP,

'follow' => $userinfo['subscribe'],

'followtime' => $userinfo['subscribe_time'],

'unionid' => $userinfo['unionid'],

'tag' => base64_encode(iserializer($userinfo))

);

//更新粉丝的订阅 状态信息

pdo_update('mc_mapping_fans', $record, array('openid' => $_SESSION['openid'], 'uniacid' => $_W['uniacid']));

if (!empty($fan['uid']) || !empty($_SESSION['uid'])) {

$uid = intval($fan['uid']);

if (empty($uid)) {

$uid = intval($_SESSION['uid']);

}

$member = mc_fetch($uid, array('nickname', 'gender', 'residecity', 'resideprovince', 'nationality', 'avatar'));

$record = array();

if (empty($member['nickname']) && !empty($userinfo['nickname'])) {

$record['nickname'] = stripslashes($userinfo['nickname']);

}

if (empty($member['avatar']) && !empty($userinfo['headimgurl'])) {

$record['avatar'] = $userinfo['headimgurl'];

}

if (!empty($record)) {

pdo_update('mc_members', $record, array('uid' => $uid));

cache_build_memberinfo($uid);

}

}return $userinfo;

}

}

替换到这个地方
$state = 'we7sid-' . $_W['session_id'];
$_SESSION['dest_url'] = urlencode($_W['siteurl']);


以上作为记录,备忘。

你可能感兴趣的:(微擎微信公众号授权登录反复登录跳转修复)