这里只有后台代码
首先要从前台 表单获取 提交的数据 获取到以后 存到相应的数据库中 这里我写了两张表
一张是存关键字类型的 一张专门存放类型为text的内容表 有联系的字段是replyid
具体代码如下
public function replyText(){
$mpid = getIsUse();
$data['content']=I('post.content');
$model = M('replytext');
$replyid=$model->add($data);
$text['replyid']=$replyid;
$text['mpid']=$mpid;
$text['type']='text';
$text['keyword']=I('post.keyword');
//关键字
$m=M('replyrule');
$m->add($text);
$this->ajaxReturn(array('msg'=>'成功添加'));
}
写完后台 我使用的是lanewechat 这里相关代码如下
public static function text(&$request){
$mpid=$_GET['id'];//这是获取配置成工那里的ID
$where['mpid']=$mpid;
$where['keyword']=$request['content'];//得到关键字
$data = M('replyrule')->where($where)->find();//根据关键字和id查询记录
if($data){
if($data['type']=='text'){
$a=M('replytext')->find($data['replyid']);
$content = $a['content'];
return ResponsePassive::text($request['fromusername'], $request['tousername'], $content);
}