PageRenderTime 91ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/b2b/api/uc.php

http://phpfor.googlecode.com/
PHP | 300 lines | 221 code | 64 blank | 15 comment | 39 complexity | 45b17504d67b136ea8d10dec8400c15b MD5 | raw file
  1. <?php
  2. define('UC_VERSION', '1.0.0'); //UCenter ????
  3. define('API_DELETEUSER', 1); //???? API ????
  4. define('API_RENAMEUSER', 1); //???? API ????
  5. define('API_UPDATEPW', 1); //????? API ????
  6. define('API_GETTAG', 1); //???? API ????
  7. define('API_SYNLOGIN', 1); //???? API ????
  8. define('API_SYNLOGOUT', 1); //???? API ????
  9. define('API_UPDATEBADWORDS', 0); //??????? ??
  10. define('API_UPDATEHOSTS', 0); //???????? ??
  11. define('API_UPDATEAPPS', 0); //?????? ??
  12. define('API_UPDATECLIENT', 1); //??????? ??
  13. define('API_UPDATECREDIT', 1); //?????? ??
  14. define('API_GETCREDITSETTINGS', 1); //? UCenter ?????? ??
  15. define('API_UPDATECREDITSETTINGS', 1); //???????? ??
  16. define('API_RETURN_SUCCEED', '1');
  17. define('API_RETURN_FAILED', '-1');
  18. define('API_RETURN_FORBIDDEN', '-2');
  19. ob_start();
  20. define('PHP_SELF',dirname($_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME']));
  21. if(include(dirname(__FILE__).'/../config/config.php')){
  22. ob_end_clean();
  23. require(CORE_DIR.'/kernel.php');
  24. require(CORE_DIR.'/include/shopCore.php');
  25. require_once(CORE_DIR.'/func_ext.php');
  26. require(CORE_DIR.'/lib/uc_client/lib/xml.class.php');
  27. class ucCore extends shopCore{
  28. function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
  29. $ckey_length = 4;
  30. $key = md5($key ? $key : UC_KEY);
  31. $keya = md5(substr($key, 0, 16));
  32. $keyb = md5(substr($key, 16, 16));
  33. $keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length): substr(md5(microtime()), -$ckey_length)) : '';
  34. $cryptkey = $keya.md5($keya.$keyc);
  35. $key_length = strlen($cryptkey);
  36. $string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0).substr(md5($string.$keyb), 0, 16).$string;
  37. $string_length = strlen($string);
  38. $result = '';
  39. $box = range(0, 255);
  40. $rndkey = array();
  41. for($i = 0; $i <= 255; $i++) {
  42. $rndkey[$i] = ord($cryptkey[$i % $key_length]);
  43. }
  44. for($j = $i = 0; $i < 256; $i++) {
  45. $j = ($j + $box[$i] + $rndkey[$i]) % 256;
  46. $tmp = $box[$i];
  47. $box[$i] = $box[$j];
  48. $box[$j] = $tmp;
  49. }
  50. for($a = $j = $i = 0; $i < $string_length; $i++) {
  51. $a = ($a + 1) % 256;
  52. $j = ($j + $box[$a]) % 256;
  53. $tmp = $box[$a];
  54. $box[$a] = $box[$j];
  55. $box[$j] = $tmp;
  56. $result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));
  57. }
  58. if($operation == 'DECODE') {
  59. if((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26).$keyb), 0, 16)) {
  60. return substr($result, 26);
  61. } else {
  62. return '';
  63. }
  64. } else {
  65. return $keyc.str_replace('=', '', base64_encode($result));
  66. }
  67. }
  68. function dsetcookie($var, $value, $life = 0, $prefix = 1) {
  69. global $cookiedomain, $cookiepath, $timestamp, $_SERVER;
  70. setcookie($var, $value,
  71. $life ? $timestamp + $life : 0, $cookiepath,
  72. $cookiedomain, $_SERVER['SERVER_PORT'] == 443 ? 1 : 0);
  73. }
  74. function dstripslashes($string) {
  75. if(is_array($string)) {
  76. foreach($string as $key => $val) {
  77. $string[$key] = $this->dstripslashes($val);
  78. }
  79. } else {
  80. $string = stripslashes($string);
  81. }
  82. return $string;
  83. }
  84. function uc_serialize($arr, $htmlon = 0) {
  85. return xml_serialize($arr, $htmlon);
  86. }
  87. // function uc_unserialize($s) {
  88. // include_once UC_CLIENT_ROOT.'./lib/xml.class.php';
  89. // return xml_unserialize($s);
  90. // }
  91. function run(){
  92. $this->definevar();
  93. require_once(CORE_DIR.'/lib/uc_client/client.php');
  94. $code = $_GET['code'];
  95. parse_str($this->authcode($code, 'DECODE', UC_KEY), $get);
  96. if(MAGIC_QUOTES_GPC) {
  97. $get = $this->dstripslashes($get);
  98. }
  99. if(time() - $get['time'] > 3600) {
  100. exit('Authracation has expiried');
  101. }
  102. if(empty($get)) {
  103. exit('Invalid Request');
  104. }
  105. $action = $get['action'];
  106. $timestamp = time();
  107. $method = 'action_'.$action;
  108. if(method_exists($this,$method)){
  109. $this->$method($get);
  110. }else{
  111. exit(API_RETURN_FAILED);
  112. }
  113. }
  114. function action_test(){
  115. exit(API_RETURN_SUCCEED);
  116. }
  117. function action_deleteuser($get=''){
  118. !API_DELETEUSER && exit(API_RETURN_FORBIDDEN);
  119. //???? API ??
  120. $account = $this->loadModel('member/account');
  121. $account->PlugUserDelete($get['ids']);
  122. exit(API_RETURN_SUCCEED);
  123. }
  124. function action_renameuser() {
  125. !API_RENAMEUSER && exit(API_RETURN_FORBIDDEN);
  126. //???? API ??
  127. $uid = $get['uid'];
  128. $usernamenew = $get['newusername'];
  129. $db->query("UPDATE {$tablepre}members SET username='$usernamenew' WHERE uid='$uid'");
  130. exit(API_RETURN_SUCCEED);
  131. }
  132. function action_updatepw($get='') {
  133. !API_UPDATEPW && exit(API_RETURN_FORBIDDEN);
  134. //??????
  135. exit(API_RETURN_SUCCEED);
  136. }
  137. function action_gettag() {
  138. !API_GETTAG && exit(API_RETURN_FORBIDDEN);
  139. //???? API ??
  140. $return = array($name, array());
  141. echo $this->uc_serialize($return, 1);
  142. }
  143. function action_synlogin($get='') {
  144. if(time() - $get['time']<=3600){
  145. !API_SYNLOGIN && exit(API_RETURN_FORBIDDEN);
  146. $account = $this->loadModel('member/account');
  147. $o=$this->loadModel('utility/charset');
  148. if (strtoupper(UC_DBCHARSET)<>"UTF8")
  149. $get['username'] = $o->local2utf($get['username'],'zh');
  150. if ($data=uc_get_user($get['username'])){
  151. list($uid, $uname, $email) = $data;
  152. }
  153. $account->PlugUserRegist('',$get['uid'],$get['username'],$get['password'],$email);
  154. }else{
  155. exit(API_RETURN_FAILED);
  156. }
  157. }
  158. function action_synlogout() {
  159. !API_SYNLOGOUT && exit(API_RETURN_FORBIDDEN);
  160. $account = $this->loadModel('member/account');
  161. $account->PlugUserExit();
  162. }
  163. function action_updatebadwords() {
  164. !API_UPDATEBADWORDS && exit(API_RETURN_FORBIDDEN);
  165. //???????
  166. exit(API_RETURN_SUCCEED);
  167. }
  168. function action_updatehosts() {
  169. !API_UPDATEHOSTS && exit(API_RETURN_FORBIDDEN);
  170. //??HOST??
  171. exit(API_RETURN_SUCCEED);
  172. }
  173. function action_updateapps() {
  174. !API_UPDATEAPPS && exit(API_RETURN_FORBIDDEN);
  175. //??????
  176. exit(API_RETURN_SUCCEED);
  177. }
  178. function action_updateclient() {
  179. !API_UPDATECLIENT && exit(API_RETURN_FORBIDDEN);
  180. $post = xml_unserialize(file_get_contents('php://input'));
  181. $cachefile = CORE_DIR . '/lib/uc_client/data/cache/settings.php';
  182. $fp = fopen($cachefile, 'w');
  183. $s = "<?php\r\n";
  184. $s .= '$_CACHE[\'settings\'] = '.var_export($post, TRUE).";\r\n";
  185. fwrite($fp, $s);
  186. fclose($fp);
  187. //???????
  188. exit(API_RETURN_SUCCEED);
  189. }
  190. function action_updatecredit() {
  191. !UPDATECREDIT && exit(API_RETURN_FORBIDDEN);
  192. //??????
  193. exit(API_RETURN_SUCCEED);
  194. }
  195. function action_getcreditsettings() {
  196. !GETCREDITSETTINGS && exit(API_RETURN_FORBIDDEN);
  197. //? UCenter ??????
  198. echo $this->uc_serialize($credits);
  199. }
  200. function action_updatecreditsettings() {
  201. !API_UPDATECREDITSETTINGS && exit(API_RETURN_FORBIDDEN);
  202. //????????
  203. exit(API_RETURN_SUCCEED);
  204. }
  205. function definevar(){
  206. $passport = $this->loadModel('member/passport');
  207. $data = $passport->getOptions('ucenter');
  208. define('UC_CONNECT', 'mysql');
  209. define('UC_DBHOST', $data['ucserver']['value']);
  210. define('UC_DBUSER', $data['ucdbuser']['value']);
  211. define('UC_DBPW', $data['ucdbpass']['value']);
  212. define('UC_DBNAME', $data['ucdbname']['value']);
  213. define('UC_DBCHARSET', $data['ucdbcharset']['value']);
  214. define('UC_DBTABLEPRE', '`'.$data['ucdbname']['value'].'`.'.$data['ucprefix']['value']);
  215. define('UC_DBCONNECT', 0);
  216. define('UC_KEY', $data['uckey']['value']);
  217. define('UC_API', $data['ucapi']['value']);
  218. define('UC_CHARSET', $data['encoding']['value']);
  219. $tmp=parse_url($data['ucapi']['value']);
  220. if (preg_match('/([0-9]{1,3}\.){3}/',$tmp['host'])){
  221. define('UC_IP', $data['ucserver']['value']);
  222. }
  223. else{
  224. define('UC_IP', gethostbyname($data['ucserver']['value']));
  225. }
  226. define('UC_APPID', $data['ucserver']['value']);
  227. define('UC_PPP', $data['ucserver']['value']);
  228. }
  229. }
  230. $system = new ucCore(array());
  231. $system->run();
  232. }else{
  233. header('HTTP/1.1 503 Service Unavailable',true,503);
  234. die('<h1>Service Unavailable</h1>');
  235. }
  236. ?>