微擎旧版本支付提示下单用户不一致,授权快照问题

应用 · 2023-01-15 · 101 人浏览

由于微信公众号昵称头像授权政策调整,导致微擎打开应用页面跳转授权快照,获取不到用户真实的openid,造成无法支付,提示支付提示下单用户不一致。只需要把微擎默认的自动授权方式,改为引导用户手动点击授权就可以了。下面是修改的方式,需要修改到微擎源码。

1、新建一个手动授权的模板html文件,命名为auth.html,文件里的代码如下:

<!DOCTYPE html>
<html lang="zh-cn">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />
  <title>授权登录-{$_W['account']['name']}</title>
  <meta name="keywords" content="{$_W['account']['name']}">
  <meta name="description" content="{$_W['account']['name']}">
  <style>
    .container {
      padding: 50px 15px;
      text-align: center;
    }
    .logo {
      width: 140px;
      margin: 0 auto 42px;
      text-align: center;
    }
    .logo img {
      max-width: 100%;
      vertical-align: middle;
    }
    .container h2 {
      margin: 0;
      padding: 0;
      line-height: 44px;
      font-size: 24px;
      font-weight: 500;
    }
    .container p {
      margin: 0;
      padding: 0;
      line-height: 34px;
      font-size: 16px;
    }
    .auth-btn {
      width: 98%;
      display: block;
      line-height: 50px;
      background: #0bb20c;
      color: #FFFFFF;
      text-align: center;
      font-size: 20px;
      border-radius: 24px;
      text-decoration: none;
      margin-top: 44px;
    }
    .is-snapshoot {
      display: none;
      width: 100%;
      height: 100%;
      position: absolute;
      top: 0;
      left: 0;
      background-position: center;
      background-size: 100% 100%;
      z-index: 1;
      text-align: center;
    }
  </style>
</head>
<body>
<div class="container">
<!--  <div class="logo">-->
<!--    <img src="{$_W['account']['logo']}" alt="{$_W['account']['name']}">-->
<!--  </div>-->
  <h2>授权登录</h2>
  <p>为了提供更完善的服务,请先授权登录!</p>
  <div class="login-btn">
    <a class="auth-btn" href="{$forward}">点击授权登录</a>
  </div>
</div>
<div class="is-snapshoot" {if isset($_GPC['is_snapshotuser']) && $_GPC['is_snapshotuser']=='1' }style="display:block;" {/if}>请点击右下角【使用完整服务】</div>
</body>
</html>

创建文件后,把它放在目录/app/themes/default/auth/auth.html

2、修改 /app/common/bootstrap.app.inc.php文件,在这块代码大概171行下

if ($oauth_type == 'snsapi_base') {
        $forward = $oauth_account->getOauthCodeUrl($callback, $state);
} else {
    $forward = $oauth_account->getOauthUserInfoUrl($callback, $state);
}

新增如下代码:

template('auth/auth');
exit();

3、修改用户授权SESSION有效期。
/app/common/bootstrap.app.inc.php 文件里的
这段代码
WeSession::start($_W['uniacid'], CLIENT_IP);
替换成:
WeSession::start($_W['uniacid'], CLIENT_IP, (15 * 86400)); //15天有效期

4、在用户不授权的情况,再次进入系统,也会变成虚拟用户;修改文件:/app/source/auth/oauth.ctrl.php
在文件这段代码:

$oauth = $oauth_account->getOauthInfo($code);

下面大概30行新增如下代码:

if( isset($oauth['is_snapshotuser']) &&  intval($oauth['is_snapshotuser']) === 1){
    $_SESSION['oauth_openid'] = '';
    $backUrl = urldecode($_SESSION['dest_url']).'&is_snapshotuser=1'; //设置当前为快照模式,可以在授权页加个箭头引导右下角微信官方授权页面
    header('Location: ' . $backUrl);
    exit();
}

修改结束,最终效果是当用户访问应用的时候,就会先跳转到手动授权登录页面,点击授权按钮后,跳转到应用页面。

微擎 公众号
豫ICP备17047052号-1