Discuzx 2.0/2.5/3.0论坛直接发帖接口,Discuzx 接口POST发帖更省事啦

经过做discuz开发的都遇到,需要直接像论坛发帖,譬如马甲贴,譬如做客户端的时候做的POST数据发帖。主要是为了省事吧。

具体代码如下:


<?php
        //Discuzx 2.0/2.5/3.0论坛直接发帖接口 by jincon
	require_once './source/class/class_core.php';
	C::app()->init_mobile = false;
	C::app()->init();


	/*定义变量,如果post,记得对应上即可。*/	
	$discuz_uid = 2;
	$discuz_user = 'jincon';
	$fid = 2;
	$typeid = 0;
	$subject = "直接发帖测试标题。";   // 主题
	$message = "直接发帖测试内容-------------。
	
	[img]图片[/img]";   // 主题内容。
	$timestamp = $_G['timestamp'];
	$onlineip = $_G['clientip'];
	$ismobile = 4; //微信
	/*变量end*/


	//检查禁言
	$group_id = DB::result_first("SELECT groupid FROM ".DB::table('common_member')." WHERE uid=$discuz_uid");
	if($group_id == 4) {
		return array('error'=>'0','result'=> 0);
	}

	require_once DISCUZ_ROOT.'/source/function/function_forum.php';


	$newthread = array(
		'fid' => $fid,
		'posttableid' => 0,
		'typeid' => $typeid,
		'readperm' => '0',
		'price' => '0',
		'author' => $discuz_user,
		'authorid' => $discuz_uid,
		'subject' => $subject,
		'dateline' => $timestamp,
		'lastpost' => $timestamp,
		'lastposter' => $discuz_user
	);
	$tid = C::t('forum_thread')->insert($newthread, true);

	$subject = addslashes($subject);
	$message = addslashes($message);

	$pid = insertpost(array(
		'fid' => $fid,
		'tid' => $tid,
		'first' => '1',
		'author' => $discuz_user,
		'authorid' => $discuz_uid,
		'subject' => $subject,
		'dateline' => $timestamp,
		'message' => $message,
		'useip' => $_G['clientip']
	));
        //这个可以不管,我增加的其他表。
	DB::query("INSERT INTO ".DB::table('forum_post_mobile')." (pid,tid,uid,ismobile,dateline) VALUES ('$pid','$tid','$discuz_uid','$ismobile','$timestamp')");
		
	DB::query("UPDATE pre_forum_forum SET lastpost='$timestamp', threads=threads+1, posts=posts+1, todayposts=todayposts+1 WHERE fid='$fid'", 'UNBUFFERED');

	DB::query("UPDATE pre_common_member_count SET threads=threads+1 WHERE uid='$discuz_uid'", 'UNBUFFERED');

	DB::query("UPDATE pre_common_member_status SET lastpost='$timestamp' WHERE uid='$discuz_uid'", 'UNBUFFERED');

	//给用户增加积分  增加3个积分?
	DB::query("UPDATE ".DB::table('common_member')." SET credits=credits+3 WHERE uid='$discuz_uid'", 'UNBUFFERED');
	echo "ok";

?>


上一篇: nodejs如何连接Mysql,分享nodejs连接Mysql数据库的方法
下一篇: php采集URL远程图片最高效的方法(Curl版本)

目前还没有人评论,您发表点看法?
发表评论

评论内容 (必填):