为什么80%的码农都做不了架构师?>>>
以下方法解决第三方应用登录,同时异步登录DX2.5,,已在DX2.5+UC1.6+开发的第三方应用中测试通过。
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);}
}
如果要符合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{$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);}}
/**到这里新增代码结束**/
}
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);}}}}
只是简单实现登录
经过DX 2.5 测试上面之方法,发现用户的邮箱只能写入Ucenter并没有同步到Discuz中,然今日找到解决之方法,共享给兄弟们
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']);$query = DB::query("SELECT uid, username, password FROM ".DB::table('common_member')." WHERE uid='$uid'");if($member = DB::fetch($query)) {dsetCOOKIE('auth', authcode("$member[password]\t$member[uid]", 'ENCODE'), $COOKIEtime);}else{//用户不存在 从UC里取用户$username = $get['username'];$query = DB::query("SELECT uid,username,password,email FROM ".DB::table('ucenter_members')." WHERE username='$username'");$member = DB::fetch($query);$password = $member['password'];$email = $member['email'];$ip = $_SERVER['REMOTE_ADDR'];$time = time();$userdata = array('uid' => $uid,'username' => $username,'password' => $password,'email' => $email,'adminid' => 0,'groupid' => 10,'regdate' => $time,'credits' => 0,'timeoffset' => 9999);DB::insert('common_member', $userdata);$status_data = array('uid' => $uid,'regip' => $ip,'lastip' => $ip,'lastvisit' => $time,'lastactivity' => $time,'lastpost' => 0,'lastsendmail' => 0,);DB::insert('common_member_status', $status_data);DB::insert('common_member_profile', array('uid' => $uid));DB::insert('common_member_field_forum', array('uid' => $uid));DB::insert('common_member_field_home', array('uid' => $uid));DB::insert('common_member_count', array('uid' => $uid));DB::query("UPDATE ".DB::table('common_setting')." SET svalue='$username' WHERE skey='lastmember'");$query = DB::query("SELECT uid, username, password FROM ".DB::table('common_member')." WHERE uid='$uid'");if($member = DB::fetch($query)) {dsetCOOKIE('auth', authcode("$member[password]\t$member[uid]", 'ENCODE'), $COOKIEtime);}}
}