自從微信公眾號平臺更新了用戶授權(quán)的規(guī)則,微擎以前默認(rèn)自動授權(quán)的方式,總是會出現(xiàn)網(wǎng)頁快照,因?yàn)槲⑶婺J(rèn)的方式是打開前端默認(rèn)跳轉(zhuǎn)到微信授權(quán)的那個鏈接;正是因?yàn)闆]有經(jīng)過用戶的點(diǎn)擊就授權(quán),會常常出現(xiàn)網(wǎng)頁快照,導(dǎo)致系統(tǒng)里總是會出現(xiàn)很多“微信用戶”的虛擬用戶,導(dǎo)致用戶在人人商城或其他商城內(nèi)出現(xiàn)下單付款失敗的問題。
現(xiàn)在我們只需要把微擎默認(rèn)的自動授權(quán)方式,改為引導(dǎo)用戶手動點(diǎn)擊授權(quán)就可以了;下面是修改的方式,需要修改到微擎源碼。
第一步,新建一個手動授權(quán)的模板html文件,我這里命名為publicAuth.html
,文件里的代碼如下(可以根據(jù)自己的需要修改):
<!DOCTYPE html> <html> <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>授權(quán)登錄-{$_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: url('resource/images/snapshoot_bg.png') no-repeat; background-position: center; background-size: 100% 100%; z-index: 1; } </style> </head> <body> <div> <div> <img src="{$_W['account']['logo']}" alt="{$_W['account']['name']}"></div> <h2>您好,請先登錄~</h2> <p>授權(quán)登錄后,可以更好的享受我們的服務(wù)!</p> <div> <a href="{$forward}">點(diǎn)擊授權(quán)登錄</a> </div> </div> <div {if isset($_GPC['is_snapshotuser']) && $_GPC['is_snapshotuser'] == '1' }style="display:block;"{/if} > </div> </body> </html>
新建好文件后,我們把它放在目錄:/app/themes/default/auth/publicAuth.html
下
第二步,修改 /app/common/bootstrap.app.inc.php
這個文件,只需要在這塊代碼下
if ($oauth_type == 'snsapi_base') { $forward = $oauth_account->getOauthCodeUrl($callback, $state); } else { $forward = $oauth_account->getOauthUserInfoUrl($callback, $state); }
大概168行附近新增:
template('auth/publicAuth'); exit();
第三步,修改用戶授權(quán)SESSION有效時間;把 /app/common/bootstrap.app.inc.php
文件里的
這段代碼
WeSession::start($_W['uniacid'], CLIENT_IP);
替換成:
WeSession::start($_W['uniacid'], CLIENT_IP, (15 * 86400)); //15天有效期
上面的有效期根據(jù)自己的情況設(shè)置
下面是效果圖
第四步,用戶不授權(quán)的情況,再次進(jìn)入系統(tǒng),也會變成虛擬用戶;修改文件:/app/source/auth/oauth.ctrl.php
在文件這段代碼:
$oauth = $oauth_account->getOauthInfo($code);
下面新增(大概31行左右):
// start //判斷是否是從快照來的,虛擬用戶還是跳轉(zhuǎn)到授權(quán)頁,但是不會入庫新增用戶;一般是用戶未授權(quán)再訪問原來的鏈接,才會進(jìn)入下面這個邏輯 if( isset($oauth['is_snapshotuser']) && intval($oauth['is_snapshotuser']) === 1){ $_SESSION['oauth_openid'] = ''; $backUrl = urldecode($_SESSION['dest_url']).'&is_snapshotuser=1'; //設(shè)置當(dāng)前為快照模式,可以在授權(quán)頁加個箭頭引導(dǎo)右下角微信官方授權(quán)頁面,這里可以自由發(fā)揮 header('Location: ' . $backUrl); exit(); } // end
第五步,把下面這張圖片上傳到 這個目錄下/app/resource/images/snapshoot_bg.png
當(dāng)訪問快照的時候,會顯示下面的那個頁面,不是快照沒有登錄則跳轉(zhuǎn)到登錄頁面。
最終,當(dāng)用戶訪問人人商城或其他插件的時候,就會先跳轉(zhuǎn)到手動授權(quán)登錄頁面,基本避免了用戶打開我們商城就出現(xiàn)快照的模式。
轉(zhuǎn)自:https://www.52pojie.cn/thread-1712109-1-1.html