Thinkphp integration ucenter1.6 (1)

Source: Internet
Author: User

Close to work, write separately

In this way, create an API folder in the root directory of the website.

Add UC. php under the API folder

The content is as follows:

<? PHP/** created on 2011-11-17 by zhjx922 ** http://blog.csdn.net/zhjx922 * // load the configuration file require (".. /webconfig. PHP "); // define the thinkphp framework path define ('Think _ path ','.. /thinkphp/'); define ('app _ name', 'uc'); define ('app _ path ','. /uC/'); require (think_path. "/thinkphp. PHP "); app: Run ();

 

Run the command to automatically create the UC directory under the API directory. Anyone who has used thinkphp knows this...

Copy the following content to 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', '000000'); 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 _ updatebadword', 1); define ('api _ updatehosts', 1 ); define ('api _ updateapps ', 1); define ('api _ updateclient', 1); define ('api _ updatecredi T', 1); define ('api _ getcredentials', 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 Entry 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 (Fi Le_get_contents ('php: // input'); If (in_array ($ get ['action'], array ('test', 'deleteuser', 'renameuser ', 'gettag', 'synlogin', 'synloout', 'updatepw', 'updatebadword', 'updatehosts', 'updateapp', 'updateclient', 'updatecredit ', 'getcredentials ', 'getcreditsettings', 'updatecreditsettings', 'addfeed') {// $ uc_note = new indexaction (); echo $ this-> $ get ['action'] ($ get, $ post); exit ();} else {exit (api_retur N_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 ['id']); // $ IDs = array (); setcookie ('0351deng', $ UIDs, time () + 360000); $ db = mysql_connect ('localhost', 'root ', '000000'); 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 * fro M ". 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 _ activityapplication' => 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 _ domain' => 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'] ['posttablekids']) {foreach ({1} G ['cache'] ['posttablekids'] 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,999 999); 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 ['credentials']; $ 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' => 'ecs', '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 ['credentials']); {1} G ['uid'] = $ uid; return getuserprofile ('extcredit '. $ credit);} public function getcreditsettings ($ get, $ post) {Global {1} g; If (! Api_getcreditsettings) {return api_return_forbidden;} $ credits = array (); foreach ({1} G ['setting'] ['extcredents'] 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 ['credentials'] as $ appid => $ credititems) {if ($ appid = uc_appid) {foreach ($ credititems as $ value) {$ outextcredits [$ value ['appiddesc']. '| '. $ value ['creditdesc'] = array ('appiddesc' => $ value ['appiddesc'], 'creditdesc' => $ value ['creditdesc'], 'credentisrc' => $ value ['credentisrc'], 'title' => $ value ['title'], 'unit '=> $ Value ['unit '], 'ratiossrc' => $ value ['ratiossrc'], 'ratiosdesc' => $ value ['ratiosdesc'], '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] ['rdatiossrc'] [$ value ['creditsrc'] = $ value ['rdatiossrc']; $ TMP [$ key] ['rdatiossc'] [$ value ['creditsrc'] = $ value ['rdatiossc']; $ TMP [$ key] ['creditsrc'] [$ value ['creditsrc'] = $ value ['ratio '];} $ outextcredits = $ TMP; $ cachefile = deng_root. '. /SSO/client/data/Cache/creditsettings. php'; $ fp = fopen ($ cachefil E, '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 ;}}?>

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.