第三方从UC账号免激活异步登录DiscuzX2.5 方法

最近刚好需要一个结合UC并使用了DX2.5的方案,发现DX2.5官方只提供允许登录自动激活的功能(这选项在DX管理中心->站长 -> UCENTER设置),等于通过UC注册的账号,仍必须在DX2.5登录一次,才能自动激活账号,这样其它基于UC的其它应用,才能实现异步登录。

以下方法解决第三方应用登录,同时异步登录DX2.5,,已在DX2.5+UC1.6+开发的第三方应用中测试通过。

非官方解决方法:

修改dx2.5目录下的api/uc.php
找到以下代码

     function synlogin($get, $post) {
                    global $_G;

                    if(!API_SYNLOGIN) {
                            return API_RETURN_FORBIDDEN;
                    }

                    header('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"');

                    $cookietime = 31536000;
                    $uid = intval($get['uid']);
                    if(($member = getuserbyuid($uid, 1))) {
                            dsetcookie('auth', authcode("$member[password]\t$member[uid]", 'ENCODE'), $cookietime);
                    }
            }
 

改成:

     function synlogin($get, $post) {
                    global $_G;

                    if(!API_SYNLOGIN) {
                            return API_RETURN_FORBIDDEN;
                    }

                    header('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"');

                    $cookietime = 31536000;
                    $uid = intval($get['uid']);
                    if(($member = getuserbyuid($uid, 1))) {
                            dsetcookie('auth', authcode("$member[password]\t$member[uid]", 'ENCODE'), $cookietime);
                    }
    /**以下代码是新添加**/
                    else{
                            $init_arr = explode(',',  $_G['setting']['initcredits']);
                            $groupid =  $_G['setting']['regverify'] ? 8 :  $_G['setting']['newusergroupid'];

                            C::t('common_member')->insert($uid, $get['username'], md5(random(10)), $get['email'], $_G['clientip'], $groupid, $init_arr);
                            C::t('common_member_status')->update($uid, array('lastip' => $_G['clientip'], 'lastvisit' =>TIMESTAMP, 'lastactivity' => TIMESTAMP));
                            if(($member = getuserbyuid($uid, 1))) {
                                    dsetcookie('auth', authcode("$member[password]\t$member[uid]", 'ENCODE'), $cookietime);
                            }
                    }
    /**到这里新增代码结束**/
            }
 

如果要符合DX2.5后台的自动激活选项,要改成这样:

     function synlogin($get, $post) {
                    global $_G;

                    if(!API_SYNLOGIN) {
                            return API_RETURN_FORBIDDEN;
                    }

                    header('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"');

                    $cookietime = 31536000;
                    $uid = intval($get['uid']);
                    if(($member = getuserbyuid($uid, 1))) {
                            dsetcookie('auth', authcode("$member[password]\t$member[uid]", 'ENCODE'), $cookietime);
                    }
                    else{
                            if($_G['setting']['fastactivation']){
                                    $init_arr = explode(',',  $_G['setting']['initcredits']);
                                    $groupid =  $_G['setting']['regverify'] ? 8 :  $_G['setting']['newusergroupid'];

                                    C::t('common_member')->insert($uid, $get['username'], md5(random(10)), $get['email'], $_G['clientip'], $groupid, $init_arr);
                                    C::t('common_member_status')->update($uid, array('lastip' => $_G['clientip'], 'lastvisit' =>TIMESTAMP, 'lastactivity' => TIMESTAMP));
                                    if(($member = getuserbyuid($uid, 1))) {
                                            dsetcookie('auth', authcode("$member[password]\t$member[uid]", 'ENCODE'), $cookietime);
                                    }
                            }
                    }
            }
 

只是简单实现登录,不保证有没有其它的风险存在。慎用。后果自负。

你可能感兴趣的:(discuz)