前天两终于收到了百度的邮件,百度知道开放平台已经审核过您提交的申请资料,非常高兴的通知您,您的合作申请已经审核通过。百度知道开放平台将在2个工作日内完成和贵站共建合作频道的上线工作,届时请将zhidao.xxxx.com域名使用cname的方式指向到open.zhidao.baidu.com,随后即可使用http://zhidao.xxxx.com访问
由于www.xxxx.com是用dedecms建的一个小站,整合topit.cn整合百度知道开放平台的过程也就是整合dedecms与百度知道开放平台无接口方式统一登录
首先细读了百度发给我的两封邮件,开始我的整合过程
一、将zhidao.xxxx.com域名使用cname的方式指向到open.zhidao.baidu.com
二、首先把dedecms的cookie改成支持二级域名.xxx.com的形式,这个就可以让zhidao.xxx.com也可以访问到.xxx.com的cookie,如果不改默认的cookie域是www.xxx.com,zhidao.xxx.com是无法访问的,具体的更改方法:
找到 include/ common.func.php文件 在里面找到
function PutCookie($key,$value,$kptime=0,$pa="/")
{
global $cfg_cookie_encode;
setcookie($key,$value,time()+$kptime,$pa);
setcookie($key.'__ckMd5',substr(md5($cfg_cookie_encode.$value),0,16),time()+$kptime,$pa);
}
改为
function PutCookie($key,$value,$kptime=0,$pa="/")
{
global $cfg_cookie_encode;
setcookie($key,$value,time()+$kptime,$pa,'.xxxx.com');
setcookie($key.'__ckMd5',substr(md5($cfg_cookie_encode.$value),0,16),time()+$kptime,$pa,'.xxxx.com');
}
三、登录页面,其实dedecms的登录页面什么也不要改动就可以整合
四. 验证
跟我上个文档写的一样
验证地址需要手动创建2个文件,文件名自己定,我把他放在了member目录下面 文件名为auth.php,和 zhidaologin.class.php
在这个文件中要做的就是查询出token所传的值的用户名,这个用户名是要显示到知道里的。
zhidaologin.class.php
<?php
if(!defined('DEDEINC')) exit('Request Error!');
//网站会员登录类
class MemberLogin
{
var $M_ID;
var $M_LoginID;
var $M_MbType;
var $M_Money;
var $M_Scores;
var $M_UserName;
var $M_Rank;
var $M_LoginTime;
var $M_KeepTime;
var $M_Spacesta;
var $fields;
var $isAdmin;
var $M_UpTime;
var $M_ExpTime;
var $M_HasDay;
var $M_Honor = '';
//php5构造函数
function __construct($kptime = -1)
{
global $dsql;
if($kptime==-1){
$this->M_KeepTime = 3600 * 24 * 7;
}else{
$this->M_KeepTime = $kptime;
}
$this->M_ID = $this->GetNum({1}GET['token']);$this->fields = array();$this->isAdmin = false;if(empty($this->M_ID)){$this->ResetUser();}else{$this->M_ID = intval($this->M_ID);$this->fields = $dsql->GetOne("Select * From `#@__member` where mid='{$this->M_ID}' ");if(is_array($this->fields)){$this->M_LoginID = $this->fields['userid'];$this->M_MbType = $this->fields['mtype'];$this->M_Money = $this->fields['money'];$this->M_UserName = $this->fields['uname'];$this->M_Scores = $this->fields['scores'];$this->M_Rank = $this->fields['rank'];$this->M_Spacesta = $this->fields['spacesta'];$sql = "Select titles From #@__scores where integral<={$this->fields['scores']} order by integral desc";$scrow = $dsql->GetOne($sql);$this->fields['honor'] = $scrow['titles'];$this->M_Honor = $this->fields['honor'];if($this->fields['matt']==10) $this->isAdmin = true; $this->M_UpTime = $this->fields['uptime']; $this->M_ExpTime = $this->fields['exptime']; if($this->M_Rank>10 && $this->M_UpTime>0){ $this->M_HasDay = $this->Judgemember(); }}else{$this->ResetUser();}}}function MemberLogin($kptime = -1){$this->__construct($kptime);}//判断会员是否到期function Judgemember(){ global $dsql,$cfg_mb_rank; $nowtime = time(); $mhasDay = $this->M_ExpTime - ceil(($nowtime - $this->M_UpTime)/3600/24) + 1; if($mhasDay <= 0){ $dsql->ExecuteNoneQuery("UPDATE `#@__member` SET uptime='0',exptime='0',rank='$cfg_mb_rank' WHERE mid='".$this->fields['mid']."';"); } return $mhasDay;}//验证用户是否已经登录function IsLogin(){if($this->M_ID > 0) return true;else return false;}//更新用户信息统计表function UpdateUserTj($field,$uptype='add'){global $dsql;$mid = $this->M_ID;$arr = $dsql->GetOne("Select * `#@__member_tj` where mid='$mid' ");if(!is_array($arr)){$arr = array('article'=>0,'album'=>0,'archives'=>0,'homecount'=>0,'pagecount'=>0,'feedback'=>0,'friend'=>0,'stow'=>0);}extract($arr);if(isset($field)){if($uptype=='add'){$field++;}else if($field > 0){$field--;}}$inquery = "INSERT INTO `#@__member_tj` (`mid`,`article`,`album`,`archives`,`homecount`,`pagecount`,`feedback`,`friend`,`stow`) VALUES ('$mid','$article','$album','$archives','$homecount','$pagecount','$feedback','$friend','$stow'); ";$dsql->ExecuteNoneQuery("Delete From `#@__member_tj` where mid='$mid' ");$dsql->ExecuteNoneQuery($inquery);}//重置用户信息function ResetUser(){$this->fields = '';$this->M_ID = 0;$this->M_LoginID = '';$this->M_Rank = 0;$this->M_Money = 0;$this->M_UserName = "";$this->M_LoginTime = 0;$this->M_MbType = '';$this->M_Scores = 0;$this->M_Spacesta = -2;$this->M_UpTime = 0; $this->M_ExpTime = 0; $this->M_HasDay = 0;}//获取整数值function GetNum($fnum){$fnum = ereg_replace("[^0-9\.]",'',$fnum);return $fnum;}}?>
我是用最简单的方式mid没有加密过 或者在这里可以判断下来路是否是百度知道增加一些安全性
auth.php
<?php
require_once(dirname(__FILE__).'/../include/common.inc.php');
require_once(DEDEINC.'/filter.inc.php');
require_once(DEDEINC.'/dedetemplate.class.php');
require_once(dirname(__FILE__)."/zhidaologin.class.php");
AjaxHead();
$z_member=new MemberLogin();
if($z_member->M_ID>0)
{
echo "errno=0&uid=".$z_member->M_ID."&uname=".$z_member->M_LoginID;
}else{
echo "errno=-1";
}
?>
如果想在知道频道中显示的是笔名而不是用户名的话,把红字改为$this->M_UserName
我才刚接触php不久 代码不好看 呵呵 大侠请指点。
至此验证地址结束
五. 登出
找到member/index_do.php 文件的大约在397行
}
#/aip}}
ShowMsg("成功退出登录!","index.php",0,2000);
exit();
这附近 把ShowMsg("成功退出登录!","index.php",0,2000);替换为
if(empty($gourl) || eregi("action|_do",$gourl))
{
ShowMsg("成功登录,5秒钟后转向系统主页...","index.php",0,2000);
}
else
{
header("Location: ".$gourl);
exit;
}
登出结束
六. 注册
首先找到member/templets/reg-new.htm文件
在第98行加入
<input type="hidden" name="gourl" value="<?php if(!empty($_GET['forward'])) echo $_GET['forward'];?>">
找到member/index_do.php 在第5行 也就是
if(empty($dopost)) $dopost = '';
if(empty($fmdo)) $fmdo = '';
下面加代码
if($dopost == ''&&$fmdo == ''&&strstr($_GET['forward'],"zhidao.jk-skf.com"))
{
$step = empty($step)? 1 : intval(preg_replace("/[^\d]/",'', $step));
require_once(dirname(__FILE__)."/reg_new.php");
exit();
}
找到文件/member/templets/reg_new3.htm 在head里
<meta http-equiv="refresh" content="10;url=index.php">
替换为
<meta http-equiv="refresh" content="10;url=<?phpecho empty($gourl)?'index.php':$gourl;?>">
要几秒跳转 自己设置
不想等待可以在 reg_new.php的最下面 require_once(DEDEMEMBER."/templets/reg-new3.htm"); 直接header()走
Ok写完了 还有一点 如果网站默认禁止 admin在前台登录 那么就在后台专门申请个账户 负责管理知道频道 重要的是一定先跟百度管理 说清楚用哪个账户管理
本文介绍如何将DedeCMS系统与百度知道开放平台进行整合,包括域名指向配置、Cookie设置调整、登录验证及退出流程优化等步骤。
5942

被折叠的 条评论
为什么被折叠?



