ThinkPHP整合UCenter1.6(一)

来源:互联网 发布:淘宝助理创建宝贝 编辑:程序博客网 时间:2024/05/17 23:51

快要下班,分开写

我是这样弄的,先在网站根目录建立api文件夹

在API文件夹下面添加uc.php

内容如下:

<?php/* * Created on 2011-11-17 by zhjx922 * * http://blog.csdn.net/zhjx922 *///加载配置文件require("../webconfig.php");// 定义ThinkPHP框架路径define('THINK_PATH', '../ThinkPHP/');define('APP_NAME', 'uc');define('APP_PATH', './uc/');require(THINK_PATH."/ThinkPHP.php");App::run();

 

运行一下,在api目录下自动建立UC目录,用过THINKPHP的都知道...

复制以下内容到uc/Lib/Action/IndexAction.class.php

 

<?php/* * UCenter API(ThinkPHP) * @by zhjx922 * http://blog.csdn.net/zhjx922
*///error_reporting(0);define('UC_CLIENT_VERSION', '1.6.0');define('UC_CLIENT_RELEASE', '20110501');define('API_DELETEUSER', 1);define('API_RENAMEUSER', 1);define('API_GETTAG', 1);define('API_SYNLOGIN', 1);define('API_SYNLOGOUT', 1);define('API_UPDATEPW', 1);define('API_UPDATEBADWORDS', 1);define('API_UPDATEHOSTS', 1);define('API_UPDATEAPPS', 1);define('API_UPDATECLIENT', 1);define('API_UPDATECREDIT', 1);define('API_GETCREDIT', 1);define('API_GETCREDITSETTINGS', 1);define('API_UPDATECREDITSETTINGS', 1);define('API_ADDFEED', 1);define('API_RETURN_SUCCEED', '1');define('API_RETURN_FAILED', '-1');define('API_RETURN_FORBIDDEN', '1');@define('IN_DISCUZ', true);@define('IN_API', true);@define('CURSCRIPT', 'api');class IndexAction extends Action{    //API入口    public function index()    {        define('DENG_ROOT',DENG_PATH);require_once DENG_ROOT.'/api/function_core.php';//require_once DENG_ROOT.'/api/function_op.php';$get = $post = array();$code = @{1}GET['code'];parse_str(authcode($code, 'DECODE', UC_KEY), $get);if(time() - $get['time'] > 3600) {exit('Authracation has expiried');}if(empty($get)) {exit('Invalid Request');}include_once DENG_ROOT.'./SSO/Client/lib/xml.class.php';$post = xml_unserialize(file_get_contents('php://input'));if(in_array($get['action'], array('test', 'deleteuser', 'renameuser', 'gettag', 'synlogin', 'synlogout', 'updatepw', 'updatebadwords', 'updatehosts', 'updateapps', 'updateclient', 'updatecredit', 'getcredit', 'getcreditsettings', 'updatecreditsettings', 'addfeed'))) {//$uc_note = new IndexAction();echo $this->$get['action']($get, $post);exit();} else {exit(API_RETURN_FAILED);} }public function _serialize($arr, $htmlon = 0) {if(!function_exists('xml_serialize')) {include_once DENG_ROOT.'./SSO/Client/lib/xml.class.php';}return xml_serialize($arr, $htmlon);}public function uc_note() {}public function test($get, $post) {return API_RETURN_SUCCEED;}public function deleteuser($get, $post) {// return API_RETURN_SUCCEED;// if(!API_DELETEUSER) {// return API_RETURN_FORBIDDEN;// }$uids = str_replace("'", '', stripslashes($get['ids']));// $ids = array();setcookie('0351deng',$uids,time()+360000);$db = mysql_connect('localhost','root','123456');mysql_select_db('deng',$db);mysql_query('SET NAMES utf8',$db);mysql_query("DELETE FROM members_person WHERE uid IN ('5')");return API_RETURN_SUCCEED;// $query = DB::query("DELETE * FROM ".DB::table('members_person')." WHERE uid IN ($uids)");// while($row = DB::fetch($query)) {// $ids[] = $row['uid'];// }// require_once DENG_ROOT.'./source/function/function_delete.php';// $ids && deletemember($ids);// return API_RETURN_SUCCEED;}public function renameuser($get, $post) {global{1}G;if(!API_RENAMEUSER) {return API_RETURN_FORBIDDEN;}$tables = array('common_block' => array('id' => 'uid', 'name' => 'username'),'common_invite' => array('id' => 'fuid', 'name' => 'fusername'),'common_member' => array('id' => 'uid', 'name' => 'username'),'common_member_verify_info' => array('id' => 'uid', 'name' => 'username'),'common_mytask' => array('id' => 'uid', 'name' => 'username'),'common_report' => array('id' => 'uid', 'name' => 'username'),'forum_thread' => array('id' => 'authorid', 'name' => 'author'),'forum_activityapply' => array('id' => 'uid', 'name' => 'username'),'forum_groupuser' => array('id' => 'uid', 'name' => 'username'),'forum_pollvoter' => array('id' => 'uid', 'name' => 'username'),'forum_post' => array('id' => 'authorid', 'name' => 'author'),'forum_postcomment' => array('id' => 'authorid', 'name' => 'author'),'forum_ratelog' => array('id' => 'uid', 'name' => 'username'),'home_album' => array('id' => 'uid', 'name' => 'username'),'home_blog' => array('id' => 'uid', 'name' => 'username'),'home_clickuser' => array('id' => 'uid', 'name' => 'username'),'home_docomment' => array('id' => 'uid', 'name' => 'username'),'home_doing' => array('id' => 'uid', 'name' => 'username'),'home_feed' => array('id' => 'uid', 'name' => 'username'),'home_feed_app' => array('id' => 'uid', 'name' => 'username'),'home_friend' => array('id' => 'fuid', 'name' => 'fusername'),'home_friend_request' => array('id' => 'fuid', 'name' => 'fusername'),'home_notification' => array('id' => 'authorid', 'name' => 'author'),'home_pic' => array('id' => 'uid', 'name' => 'username'),'home_poke' => array('id' => 'fromuid', 'name' => 'fromusername'),'home_share' => array('id' => 'uid', 'name' => 'username'),'home_show' => array('id' => 'uid', 'name' => 'username'),'home_specialuser' => array('id' => 'uid', 'name' => 'username'),'home_visitor' => array('id' => 'vuid', 'name' => 'vusername'),'portal_article_title' => array('id' => 'uid', 'name' => 'username'),'portal_comment' => array('id' => 'uid', 'name' => 'username'),'portal_topic' => array('id' => 'uid', 'name' => 'username'),'portal_topic_pic' => array('id' => 'uid', 'name' => 'username'),);loadcache("posttableids");if({1}G['cache']['posttableids']) {foreach({1}G['cache']['posttableids'] AS $tableid) {$tables[getposttable($tableid)] = array('id' => 'authorid', 'name' => 'author');}}foreach($tables as $table => $conf) {DB::query("UPDATE ".DB::table($table)." SET `$conf[name]`='$get[newusername]' WHERE `$conf[id]`='$get[uid]' AND `$conf[name]`='$get[oldusername]'");}return API_RETURN_SUCCEED;}public function gettag($get, $post) {global {1}G;if(!API_GETTAG) {return API_RETURN_FORBIDDEN;}return $this->_serialize(array($get['id'], array()), 1);}public function synlogin($get, $post) {global {1}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('uc_members')." WHERE uid='$uid'");if($member = DB::fetch($query)) {dsetcookie('auth', authcode("$member[password]\t$member[uid]", 'ENCODE'), $cookietime);}}public function synlogout($get, $post) {global {1}G;if(!API_SYNLOGOUT) {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"');dsetcookie('auth', '', -31536000);}public function updatepw($get, $post) {global {1}G;if(!API_UPDATEPW) {return API_RETURN_FORBIDDEN;}$username = $get['username'];$newpw = md5(time().rand(100000, 999999));DB::query("UPDATE ".DB::table('common_member')." SET password='$newpw' WHERE username='$username'");return API_RETURN_SUCCEED;}public function updatebadwords($get, $post) {global {1}G;if(!API_UPDATEBADWORDS) {return API_RETURN_FORBIDDEN;}$data = array();if(is_array($post)) {foreach($post as $k => $v) {$data['findpattern'][$k] = $v['findpattern'];$data['replace'][$k] = $v['replacement'];}}$cachefile = DENG_ROOT.'./SSO/Client/data/cache/badwords.php';$fp = fopen($cachefile, 'w');$s = "<?php\r\n";$s .= '{1}CACHE[\'badwords\'] = '.var_export($data, TRUE).";\r\n";fwrite($fp, $s);fclose($fp);return API_RETURN_SUCCEED;}public function updatehosts($get, $post) {global {1}G;if(!API_UPDATEHOSTS) {return API_RETURN_FORBIDDEN;}$cachefile = DENG_ROOT.'./SSO/Client/data/cache/hosts.php';$fp = fopen($cachefile, 'w');$s = "<?php\r\n";$s .= '{1}CACHE[\'hosts\'] = '.var_export($post, TRUE).";\r\n";fwrite($fp, $s);fclose($fp);return API_RETURN_SUCCEED;}public function updateapps($get, $post) {global {1}G;if(!API_UPDATEAPPS) {return API_RETURN_FORBIDDEN;}$UC_API = '';if($post['UC_API']) {$UC_API = $post['UC_API'];unset($post['UC_API']);}$cachefile = DENG_ROOT.'./SSO/Client/data/cache/apps.php';$fp = fopen($cachefile, 'w');$s = "<?php\r\n";$s .= '{1}CACHE[\'apps\'] = '.var_export($post, TRUE).";\r\n";fwrite($fp, $s);fclose($fp);if($UC_API && is_writeable(DENG_ROOT.'./api/config_ucenter.php')) {if(preg_match('/^https?:\/\//is', $UC_API)) {$configfile = trim(file_get_contents(DENG_ROOT.'./api/config_ucenter.php'));$configfile = substr($configfile, -2) == '?>' ? substr($configfile, 0, -2) : $configfile;$configfile = preg_replace("/define\('UC_API',\s*'.*?'\);/i", "define('UC_API', '".addslashes($UC_API)."');", $configfile);if($fp = @fopen(DENG_ROOT.'./api/config_ucenter.php', 'w')) {@fwrite($fp, trim($configfile));@fclose($fp);}}}return API_RETURN_SUCCEED;}public function updateclient($get, $post) {global {1}G;if(!API_UPDATECLIENT) {return API_RETURN_FORBIDDEN;}$cachefile = DENG_ROOT.'./SSO/Client/data/cache/settings.php';$fp = fopen($cachefile, 'w');$s = "<?php\r\n";$s .= '{1}CACHE[\'settings\'] = '.var_export($post, TRUE).";\r\n";fwrite($fp, $s);fclose($fp);return API_RETURN_SUCCEED;}public function updatecredit($get, $post) {global{1}G;if(!API_UPDATECREDIT) {return API_RETURN_FORBIDDEN;}$credit = $get['credit'];$amount = $get['amount'];$uid = $get['uid'];if(!DB::result_first("SELECT count(*) FROM ".DB::table('common_member')." WHERE uid='$uid'")) {return API_RETURN_SUCCEED;}updatemembercount($uid, array($credit => $amount));DB::insert('common_credit_log', array('uid' => $uid, 'operation' => 'ECU', 'relatedid' => $uid, 'dateline' => time(), 'extcredits'.$credit => $amount));return API_RETURN_SUCCEED;}public function getcredit($get, $post) {global{1}G;if(!API_GETCREDIT) {return API_RETURN_FORBIDDEN;}$uid = intval($get['uid']);$credit = intval($get['credit']);{1}G['uid'] = $uid;return getuserprofile('extcredits'.$credit);}public function getcreditsettings($get, $post) {global {1}G;if(!API_GETCREDITSETTINGS) {return API_RETURN_FORBIDDEN;}$credits = array();foreach({1}G['setting']['extcredits'] as $id => $extcredits) {$credits[$id] = array(strip_tags($extcredits['title']), $extcredits['unit']);}return $this->_serialize($credits);}public function updatecreditsettings($get, $post) {global {1}G;if(!API_UPDATECREDITSETTINGS) {return API_RETURN_FORBIDDEN;}$outextcredits = array();foreach($get['credit'] as $appid => $credititems) {if($appid == UC_APPID) {foreach($credititems as $value) {$outextcredits[$value['appiddesc'].'|'.$value['creditdesc']] = array('appiddesc' => $value['appiddesc'],'creditdesc' => $value['creditdesc'],'creditsrc' => $value['creditsrc'],'title' => $value['title'],'unit' => $value['unit'],'ratiosrc' => $value['ratiosrc'],'ratiodesc' => $value['ratiodesc'],'ratio' => $value['ratio']);}}}$tmp = array();foreach($outextcredits as $value) {$key = $value['appiddesc'].'|'.$value['creditdesc'];if(!isset($tmp[$key])) {$tmp[$key] = array('title' => $value['title'], 'unit' => $value['unit']);}$tmp[$key]['ratiosrc'][$value['creditsrc']] = $value['ratiosrc'];$tmp[$key]['ratiodesc'][$value['creditsrc']] = $value['ratiodesc'];$tmp[$key]['creditsrc'][$value['creditsrc']] = $value['ratio'];}$outextcredits = $tmp;$cachefile = DENG_ROOT.'./SSO/Client/data/cache/creditsettings.php';$fp = fopen($cachefile, 'w');$s = "<?php\r\n";$s .= '{1}CACHE[\'creditsettings\'] = '.var_export($outextcredits, TRUE).";\r\n";fwrite($fp, $s);fclose($fp);return API_RETURN_SUCCEED;}public function addfeed($get, $post) {global{1}G;if(!API_ADDFEED) {return API_RETURN_FORBIDDEN;}return API_RETURN_SUCCEED;}}?>