简要介绍(Introduction)
此文介绍如何为您的Chevereto
添加QQ登陆方式,试验性教程,造成的损失由您自己负责!!!

支持环境(Requirement)
- PHP >= 7.0
- Chevereto >= 3.13.0
在执行所有操作前,请先做好数据备份工作,以免造成不必要的损失!!!
食用指南(Usage)
1. 安装社会化登陆库(Install support Library)
站点根目录执行,安装社会化登陆库(需环境支持Composer)
https://github.com/overtrue/socialite
composer require "overtrue/socialite" -vvv
2. 添加QQ登陆方式(Add QQ login method)
修改class.login.php
文件
// app\lib\classes\class.login.php:30 public static $social_services = [ 'facebook' => 'Facebook', 'twitter' => 'Twitter', 'google' => 'Google', 'vk' => 'VK', ]; // 修改为以下内容 public static $social_services = [ 'facebook' => 'Facebook', 'twitter' => 'Twitter', 'google' => 'Google', 'vk' => 'VK', 'qq' => 'QQ', ];
3. 载入社会化登陆库(Load support library)
引入社会化登陆库,增加QQ登陆方式
// app\routes\overrides\route.connect.php:18/19 use Overtrue\Socialite\SocialiteManager;
// app\routes\overrides\route.connect.php:24/25 if (!in_array($doing, ['google', 'facebook', 'twitter', 'vk'])) { return $handler->issue404(); } //修改为以下内容 if (!in_array($doing, ['google', 'facebook', 'twitter', 'vk', 'qq'])) { return $handler->issue404(); }
// 添加以下内容
// app\routes\overrides\route.connect.php:277~279 case 'qq': $config = [ 'qq' => [ 'client_id' => CHV\getSetting('qq_client_id'), 'client_secret' => CHV\getSetting('qq_client_secret'), 'redirect' => G\get_base_url('connect/qq'), ], ]; $client = new SocialiteManager($config); if (isset($_GET['code'])) { $get_user = $client->driver('qq')->user(); $_SESSION['qq']['token'] = $get_user->getAccessToken(); }else{ $response =$client->driver('qq')->redirect(); $response->send(); $get_user = $client->driver('qq')->user(); } if ($_SESSION['qq']['token']) { $get_user->setToken($_SESSION['qq']['token']); } if ($get_user->getAccessToken()) { if ($get_user) { $social_pictures = [ 'avatar' => $get_user->getAvatar(), 'background' => null ]; $connect_user = [ 'id' => $get_user->getId(), 'username' => G\sanitize_string(G\unaccent_string($get_user->getName()), true, true), 'name' => $get_user->getName(), 'avatar' => $get_user->getAvatar(), 'url' => null ]; $connect_tokens = [ 'secret' => $get_user->getAccessToken(), 'token_hash'=> null ]; $do_connect = true; } } else { G\redirect(G\get_base_url('connect/qq')); } break;
4. 添加QQ登陆验证方式(Validate social networks)
添加QQ登陆方式,以便过社交登陆验证
// app\routes\overrides\route.dashboard.php:1049~1054 $social_validate = [ 'facebook' => ['facebook_app_id', 'facebook_app_secret'], 'twitter' => ['twitter_api_key', 'twitter_api_secret'], 'google' => ['google_client_id', 'google_client_secret'], ]; //修改为以下内容 $social_validate = [ 'facebook' => ['facebook_app_id', 'facebook_app_secret'], 'twitter' => ['twitter_api_key', 'twitter_api_secret'], 'google' => ['google_client_id', 'google_client_secret'], 'qq' => ['qq_client_id', 'qq_client_secret'], ];
5. 仪表盘添加社交网络(Add Social Network)
添加QQ互联设置界面
//app\themes\Peafowl\overrides\views\dashboard.php:2818 <div class="input-label"> <label for="qq">QQ</label> <div class="c5 phablet-c1"><select type="text" name="qq" id="qq" class="text-input" data-combo="qq-combo"> <?php echo CHV\Render\get_select_options_html([1 => _s('Enabled'), 0 => _s('Disabled')], get_safe_post() ? get_safe_post()['qq'] : CHV\Settings::get('qq')); ?> </select></div> <div class="input-below"><?php _se('You need a <a href="https://connect.qq.com/manage.html" target="_blank">QQ app</a> for this.'); ?></div> </div> <div id="qq-combo"> <div data-combo-value="1" class="switch-combo c9 phablet-c1<?php if (!(get_safe_post() ? get_safe_post()['qq'] : CHV\Settings::get('qq'))) { echo ' soft-hidden'; } ?>"> <div class="input-label"> <label for="qq_client_id"><?php _se('QQ client id'); ?></label> <input type="text" name="qq_client_id" id="qq_client_id" class="text-input" value="<?php echo get_safe_post() ? get_safe_post()['qq_client_id'] : CHV\Settings::get('qq_client_id', true); ?>"> <div class="input-warning red-warning"><?php echo get_input_errors()['qq_client_id']; ?></div> </div> <div class="input-label"> <label for="qq_client_secret"><?php _se('QQ client secret'); ?></label> <input type="text" name="qq_client_secret" id="qq_client_secret" class="text-input" value="<?php echo get_safe_post() ? get_safe_post()['qq_client_secret'] : CHV\Settings::get('qq_client_secret', true); ?>"> <div class="input-warning red-warning"><?php echo get_input_errors()['qq_client_secret']; ?></div> </div> </div> </div>
6. 添加CSS样式文件(Adding style.css)
// app\themes\Peafowl\custom_hooks\
添加 style.css
7. 【重要】升级数据库(Upgrade database)

执行http://yourwebsite.com/install-qq
升级数据库,更新QQ登陆方式!
文件下载(Download)
## Hash校验 MD5: FE7BD8CC6B6A3E4F7455A70C205FC568 SHA1: 354F49D7469BBCEF6AC1FAB0F6144D97CE7E8CC5 CRC32: D72A42DD
致谢(Thanks)
貌似在3.16.0的版本上失效了,我这里会直接返回http 500(访问/connect/qq或是/connect/github的时候)
@安忆 看了下,估计是https://github.com/overtrue/socialite 这个库使用方式变了
@安忆 确实,composer require "overtrue/socialite:2.*" 就好了。
@安忆 Chevereto-3.17.0.beta.1 版本已更新,理论上兼容 3.16.x
该环境需要PHP >= 7.4(因为 overtrue/socialite:v3.0 以上版本只支持7.4及以上)
代码或许存在BUG,请先备份所有数据后再尝试使用此教程
请教一下博主!我尝试连接google drive 按照官方的教程 但是一直没有成功 能否指导一下呀
@Pharah google drive???
你说的应该是Google Cloud Storage吧,这个我倒是还没研究过,暂时还不能帮到你
骚松鼠骚操作 ::funny:01::
@陈·锋 ::funny:02:: 没有没有
感谢分享,收藏备用
这是我个人翻译修改的Chevereto简体中文翻译,权当感谢。 ::aru:smile::
链接: https://pan.baidu.com/s/15VtKDqFfnMq-WkozTjHOKg 提取码: e1yz
@安忆 嗯嗯,谢谢 ::twemoji:smile::
建议现在开发环境实验好,再移到生产环境,不保证100%稳定运行,
还有代码可能不大完善,如有bug可以一起探讨哦。
@松鼠大大 成功添加了Github登录,QQ还在等待开发者审核;
更新了一下翻译文件,需要的话重新下载就好了。
我的图床:https://pic.anyi.in/ ::aru:shy2::
@安忆 嗯嗯,刚试了下,正常注册登陆, ::aru:cheer::
@松鼠大大 又修改了一下翻译(应该是最后一次了::aru:pouting::
需要的话还在原来那里下载就好啦