[采集]Hadsky蓝天采集发布接口

dianzijun 电子菌 关注 五级站长 VIP
发表于编程技术版块
<?php
/**
 * 示例:hadsky发帖
 * 您可参考代码自行开发hadsky的更多功能
 * 您可以使用 thinkphp5的函数
 */
namespace plugin\release\cms;
class HadskyDemoSkycaiji extends BaseCms{
	public function cms_db_hadsky($cmsPath){
		$dbFile=realpath($cmsPath.'/puyuetian/mysql/config.php');
		//转换成thinkphp数据库配置
		include $dbFile;
		$config=$_G['MYSQL'];
		if(preg_match('/set names (\w+)/i', $config['CHARSET'],$charset)){
			$config['CHARSET']=$charset[1];
		}else{
			$config['CHARSET']='utf8';
		}
		
		$cmsDb=array(
			'db_type'  => 'mysql',
			'db_user'  => $config['USERNAME'],
			'db_pwd'   => $config['PASSWORD'],
			'db_host'  => $config['LOCATION'],
			'db_port'  => 3306,
			'db_name'  => $config['DATABASE'],
			'db_charset'  => $config['CHARSET'],
			'db_prefix'  => $config['PREFIX']
		);
		
		return $cmsDb;
	}
	//参数
	public $_params = array (
		'author' => array (
			'name' => '作者账号',
			'require' => 1,
			'tag' => 'text',
		),
		'forum' => array (
			'name' => '版块ID',
			'require' => 1,
			'tag' => 'select',
			'option' => 'function:param_option_forum',
		),
		'title' => array (
			'name' => '帖子标题',
			'require' => 1,
			'tag' => 'select',
			'option' => 'function:param_option_fields',
		),
		'content' => array (
			'name' => '帖子内容',
			'require' => 1,
			'tag' => 'select',
			'option' => 'function:param_option_fields',
		),
	);

	/*
	 * 导入数据
	* 必须以数组形式返回:
	* id(必填)表示入库返回的自增id或状态
	* target(可选)记录入库的数据位置(发布的网址等)
	* desc(可选)记录入库的数据位置附加信息
	* error(可选)记录入库失败的错误信息
	* 入库的信息可在“已采集数据”中查看
	* return array('id'=>0,'target'=>'','desc'=>'','error'=>'');
	*/
	public function runImport($params){
		$uid=$this->db()->table('__USER__')->where(array('username'=>$params['author']))->find();
		if(!empty($uid)){
			$uid=$uid['id'];
		}else{
			return array('id'=>0,'error'=>'用户不存在');
		}
		
		$newRead=array(
			'sortid'=>$params['forum'],
			'uid'=>$uid,
			'title'=>$params['title'],
			'content'=>$params['content'],
			'looknum'=>0,
			'zannum'=>0,
			'posttime'=>time(),
			'readlevel'=>0,
			'replyuid'=>$uid,
			'replycontent'=>null,
			'replytime'=>0,
			'replyip'=>null,
			'postip'=>'',
			'top'=>0,
			'high'=>0,
			'replyafterlook'=>0,
			'data'=>null,
			'del'=>0,
			'activetime'=>time(),
			'replyid'=>0,
			'fs'=>1,
			'label'=>''
		);
		
		$id=$this->db()->table('__READ__')->insert($newRead,false,true);//添加主题并返回id
		if($id>0){
			return array('id'=>$id,'target'=>'文章:'.$id);
		}else{
			return array('id'=>0,'error'=>'添加文章失败');
		}
	}
	
	/*
	 * 参数选项:版块
	 * 必须返回键值对形式的数组
	 */
	public function param_option_forum(){
		$forumsDb=$this->db()->table('__READSORT__')->select();
		$forumList=array();
		foreach ($forumsDb as $forum){
			$forumList[$forum['id']]=auto_convert2utf8($forum['title']);
		}
		return $forumList;
	}
}
?>

评论列表 评论
发布评论

评论: [采集]Hadsky蓝天采集发布接口

已有2次打赏
简单就是美打赏给楼主1天豆,2020-03-30 15:11:47
乐天打赏给楼主27天豆,2020-03-29 21:07:20
(2) 分享
分享

请保存二维码或复制链接进行分享

取消