您的位置:首页 > 其它

Discuz使用UCenter实现同步登录、注册、退出

2017-09-19 15:37 716 查看

环境

Win7 x64、IIS 7.5、Discuz! X3.4

目的

实现 Discuz 和 Net Core 项目的同步操作

实现

如果是 Asp.Net 4.0 的项目可以参考:http://www.cnblogs.com/CoreCaiNiao/archive/2011/08/25/2153434.html

里面有Demo 可以直接使用。

如果是 Net 4.0 版本以上的项目直接调用就有问题,当前小编也是手动的将所有文件反编译加入到了项目中,虽然有许多方法不能调用(直接使用)或是没有这个方法,但最终功能还是实现了,如果是Net Core的项目,需要整合 其他 Discuze 进行同步操作可以联系小编。

此外,以上方法虽然小编添加了注册方法(之前是没有的),实际上 UCenter 是没有提供的,所以需要做以下改动(也是参考别人的文章写的,但他的文章里方法都是图片,必须手动敲,不知道是有问题还是什么原因,最后是小编自己一步步调试进行修改得到如下正确的修改):

第一步

/uc_server/control/user.php文件中,onsynlogin方法

// 新增同步注册功能
function onsynregister(){

$this->init_input();
$username = $this->input('username');
$password = $this->input('password');
$email = $this->input('email');
if($this->app['synlogin']) {

$synstr = '';
foreach($this->cache['apps'] as $appid => $app) {
if($app['synlogin']) {
if($app['appid'] != $this->app['appid']) {
$synstr .= '<script type="text/javascript" src="'.$app['url'].'/api/'.$app['apifilename'].'?time='.$this->time.'&code='.urlencode($this->authcode('action=synregister&username='.$username.'&password='.$password.'&email='.$email."&time=".$this->time, 'ENCODE', $app['authkey'])).'" reload="1"></script>';
}
if(is_array($app['extra']['extraurl'])) foreach($app['extra']['extraurl'] as $extraurl) {
$synstr .= '<script type="text/javascript" src="'.$extraurl.'/api/'.$app['apifilename'].'?time='.$this->time.'&code='.urlencode($this->authcode('action=synregister&username='.$username.'&password='.$password.'&email='.$email."&time=".$this->time, 'ENCODE', $app['authkey'])).'" reload="1"></script>';
}
}
}

return $synstr;
}
return '';
}


第二步

/uc_client/client.php文件第365行

function uc_user_synregister($username,$password,$email){
if(@include UC_ROOT.'./data/cache/apps.php') {
if(count($_CACHE['apps']) > 1) {
$return = uc_api_post('user', 'synregister', array('username'=>$username,'password'=>$password,'email'=>$email));
} else {
$return = '';
}
}
return $return;
}


第三步

在/source/class/class_member.php,第923行

注意:在有注释的地方是需要修改的

$param = array('bbname' => $this->setting['bbname'], 'username' => $_G['username'], 'usergroup' => $_G['group']['grouptitle'], 'uid' => $_G['uid']);
if(strpos($url_forward, $this->setting['regname']) !== false || strpos($url_forward, 'buyinvitecode') !== false) {
$url_forward = 'forum.php';
}
// 同步注册
$ucsynregister = $this->setting['allowsynlogin']?uc_user_synregister($_GET['username'],$_GET['password'],$_GET['email']):'';
$href = str_replace("'", "\'", $url_forward);
$extra = array(
'showid' => 'succeedmessage',
'extrajs' => '<script type="text/javascript">'.
'setTimeout("window.location.href =\''.$href.'\';", '.$refreshtime.');'.
'$(\'succeedmessage_href\').href = \''.$href.'\';'.
'$(\'main_message\').style.display = \'none\';'.
'$(\'main_succeed\').style.display = \'\';'.
'$(\'succeedlocation\').innerHTML = \''.lang('message', $locationmessage).'\';'.
'</script>'.$ucsynregister,// 同步注册
'striptags' => false,
);
showmessage($message, $url_forward, $param, $extra);


总结

不同版本不同语言的项目进行用户操作整合,的确是很麻烦,但终归还是可以解决的,一步步慢慢调试就行的。想要 Net Core操作UCenter实现 Discuze项目登录、注册、退出的源码可以留言lemonwrold@aliyun.com。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  discuz UCenter NetCore