client.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. <?php
  2. class client {
  3. private $ps_api_url, $ps_auth_key, $ps_vsersion;
  4. /**
  5. * 析构函数
  6. * @param $ps_api_url 接口域名
  7. * @param $ps_auth_key 加密密匙
  8. */
  9. public function __construct($ps_api_url = '127.0.0.1', $ps_auth_key = '', $ps_vsersion = '1') {
  10. $this->ps_api_url = $ps_api_url;
  11. $this->ps_auth_key = $ps_auth_key;
  12. $this->ps_vsersion = $ps_vsersion;
  13. }
  14. /**
  15. * 用户注册
  16. * @param string $username 用户名
  17. * @param string $password 密码
  18. * @param string $email email
  19. * @param string $regip 注册ip
  20. * @param string $random 密码随机数
  21. * @return int {-1:用户名已经存在 ;-2:email已存在;-3:email格式错误;-4:用户名禁止注册;-5:邮箱禁止注册;int(uid):成功}
  22. */
  23. public function ps_member_register($username, $password, $email, $regip = '', $random = '') {
  24. if (!$this->_is_email($email)) {
  25. return -3;
  26. }
  27. return $this->_ps_send('register', array('username' => $username, 'password' => $password, 'email' => $email, 'regip' => $regip, 'random' => $random));
  28. }
  29. /**
  30. * 用户登陆
  31. * @param string $username 用户名
  32. * @param string $password 密码
  33. * @param int $isemail email
  34. * @return int {-2;密码错误;-1:用户名不存在;array(userinfo):用户信息}
  35. */
  36. public function zhsso_member_login($username, $password, $isemail = 0) {
  37. if ($isemail) {
  38. if (!$this->_is_email($username)) {
  39. return -3;
  40. }
  41. $return = $this->_ps_send('login', array('email' => $username, 'userpasswd' => $password));
  42. } else {
  43. $return = $this->_ps_send('login', array('username' => $username, 'userpasswd' => $password));
  44. }
  45. return $return;
  46. }
  47. /**
  48. * 同步登陆
  49. * @param string $uid
  50. * @return string javascript用户同步登陆js
  51. */
  52. public function ps_member_synlogin($uid) {
  53. $uid = intval($uid);
  54. return $this->_ps_send('synlogin', array('uid' => $uid));
  55. }
  56. /**
  57. * 获取文库信息
  58. */
  59. public function ps_getdoc(){
  60. return $this->_ps_send('getdoc');
  61. }
  62. public function ps_getquestion(){
  63. return $this->_ps_send('getquestion');
  64. }
  65. /**
  66. * 同步退出
  67. * @param string $uid
  68. * @return string javascript用户同步退出js
  69. */
  70. public function ps_member_synlogout() {
  71. return $this->_ps_send('synlogout', array());
  72. }
  73. /**
  74. * 编辑用户
  75. * @param string $username 用户名
  76. * @param string $email email
  77. * @param string $password 旧密码
  78. * @param string $newpassword 新密码
  79. * @param int $uid phpsso用户uid
  80. * @param string $random 密码随机数
  81. * @return int {-1:用户不存在;-2:旧密码错误;-3:email已经存在 ;-4:email格式错误;1:成功;0:未作修改}
  82. */
  83. public function zhsso_member_edit($uid = '', $password = '', $newpassword = '', $useranswer = '') {
  84. /// if ($email && !$this->_is_email($email)) {
  85. // return -4;
  86. // }
  87. // TODO:增加判断输出返回值
  88. return $this->_ps_send('edit', array('uid' => $uid, 'password' => $password, 'newpassword' => $newpassword, 'useranswer' => $useranswer));
  89. }
  90. public function setPayWay($uid, $idcards, $alipay, $tenpay) {
  91. return $this->_ps_send('payway', array('uid' => $uid, 'idbank' => $idcards, 'alipay' => $alipay, 'tenpay' => $tenpay));
  92. }
  93. /**
  94. * 删除用户头像
  95. * @param int $uid phpsso用户uid
  96. * @return int {1:成功;0:失败}
  97. */
  98. public function ps_deleteavatar($uid) {
  99. return $this->_ps_send('deleteavatar', array('uid' => $uid));
  100. }
  101. /**
  102. * 获取用户信息
  103. * @param $mix 用户id/用户名/email
  104. * @param $type {1:用户id;2:用户名;3:email}
  105. * @return $mix {-1:用户不存在;userinfo:用户信息}
  106. */
  107. public function ps_get_member_info($mix, $type = 1) {
  108. if ($type == 1) {
  109. $userinfo = $this->_ps_send('getuserinfo', array('uid' => $mix));
  110. } elseif ($type == 2) {
  111. $userinfo = $this->_ps_send('getuserinfo', array('username' => $mix));
  112. } elseif ($type == 3) {
  113. if (!$this->_is_email($mix)) {
  114. return -4;
  115. }
  116. $userinfo = $this->_ps_send('getuserinfo', array('email' => $mix));
  117. }
  118. if ($userinfo) {
  119. return $userinfo;
  120. } else {
  121. return -1;
  122. }
  123. }
  124. /**
  125. * 删除用户
  126. * @param mix {1:用户id;2:用户名;3:email} 如果是用户id可以为数组
  127. * @return int {-1:用户不存在;1:删除成功}
  128. */
  129. public function ps_delete_member($mix, $type = 1) {
  130. if ($type == 1) {
  131. $res = $this->_ps_send('delete', array('uid' => $mix));
  132. } elseif ($type == 2) {
  133. $res = $this->_ps_send('delete', array('username' => $mix));
  134. } elseif ($type == 3) {
  135. if (!$this->_is_email($mix)) {
  136. return -4;
  137. }
  138. $res = $this->_ps_send('delete', array('email' => $mix));
  139. }
  140. return $res;
  141. }
  142. /**
  143. * 检查用户是否可以注册
  144. * @param string $username
  145. * @return int {-4:用户名禁止注册;-1:用户名已经存在 ;1:成功}
  146. */
  147. public function ps_checkname($username) {
  148. return $this->_ps_send('checkname', array('username' => $username));
  149. }
  150. /**
  151. * 检查邮箱是否可以注册
  152. * @param string $email
  153. * @return int {-1:email已经存在 ;-5:邮箱禁止注册;1:成功}
  154. */
  155. public function ps_checkemail($email) {
  156. return $this->_ps_send('checkemail', array('email' => $email));
  157. }
  158. /**
  159. * 获取用户信息通过COOKIE UID
  160. */
  161. public function zhsso_getuserinfo() {
  162. $uid = $this->authcode($_COOKIE[Doo::conf()->COOKIEPRE_WK . '_userid']);
  163. return $this->_ps_send('getuserinfo', array('uid' => $uid));
  164. }
  165. public function zhsso_checkauth($auth="") {
  166. return $this->_ps_send('checkauth', array('auth' => $auth));
  167. }
  168. /**
  169. * 获取用户信息通过COOKIE UID
  170. */
  171. public function zhsso_getuserinfo_by_uid($uid=0) {
  172. return $this->_ps_send('getuserinfo', array('uid' => $uid));
  173. }
  174. /**
  175. * 获取应用列表信息
  176. */
  177. public function zhsso_getUserbyName($uname) {
  178. return $this->_ps_send('getuserinfo', array('username' => $uname));
  179. }
  180. /**
  181. * 获取应用列表信息
  182. */
  183. public function zhsso_getSerialNumber($SerialNumber) {
  184. return $this->_ps_send('getAuthentication', array('key' => $SerialNumber));
  185. }
  186. public function zhsso_getSerialNumber2($SerialNumber) {
  187. return $this->_ps_send('getAuthenticationBySerial', array('SerialNumber' => $SerialNumber));
  188. }
  189. /**
  190. * 获取积分兑换比例列表
  191. */
  192. public function ps_getcreditlist() {
  193. return $this->_ps_send('getcredit', array());
  194. }
  195. /**
  196. * 兑换积分
  197. * 用于何其他应用之间积分兑换
  198. * @param int $uid phpssouid
  199. * @param int $from 本系统积分类型id
  200. * @param int $toappid 目标系统应用appid
  201. * @param int $to 目标系统积分类型id
  202. * @param int $credit 本系统扣除积分数
  203. * @return bool {1:成功;0:失败}
  204. */
  205. public function ps_changecredit($uid, $from, $toappid, $to, $credit) {
  206. return $this->_ps_send('changecredit', array('uid' => $uid, 'from' => $from, 'toappid' => $toappid, 'to' => $to, 'credit' => $credit));
  207. }
  208. /**
  209. * 根据phpsso uid获取头像url
  210. * @param int $uid 用户id
  211. * @return array 四个尺寸用户头像数组
  212. */
  213. public function ps_getavatar($uid) {
  214. $dir1 = ceil($uid / 10000);
  215. $dir2 = ceil($uid % 10000 / 1000);
  216. $url = $this->ps_api_url . 'data/avatar/' . $dir1 . '/' . $dir2 . '/' . $uid . '/';
  217. $avatar = array('180' => $url . '180x180.jpg', '90' => $url . '90x90.jpg', '45' => $url . '45x45.jpg', '30' => $url . '30x30.jpg');
  218. return $avatar;
  219. }
  220. /**
  221. * 获取上传头像flash的html代码
  222. * @param int $uid 用户id
  223. */
  224. public function ps_getavatar_upload_html($uid) {
  225. $auth_data = $this->authcode($uid, 'ENCODE');
  226. // echo $auth_data;
  227. // list($a, $encodestr) = explode('=', $auth_data);
  228. $upurl = base64_encode($this->ps_api_url . 'api/uploadavatar/' . rawurlencode($auth_data));
  229. // $upurl = base64_encode($this->ps_api_url . '/index.php?m=phpsso&c=index&a=uploadavatar&auth_data=' . $auth_data);
  230. $str = <<<EOF
  231. <div id="phpsso_uploadavatar_flash"></div>
  232. <script language="javascript" type="text/javascript" src="{$this->ps_api_url}global/js/swfobject.js"></script>
  233. <script type="text/javascript">
  234. var flashvars = {
  235. 'upurl':"{$upurl}&callback=return_avatar&"
  236. };
  237. var params = {
  238. 'align':'middle',
  239. 'play':'true',
  240. 'loop':'false',
  241. 'scale':'showall',
  242. 'wmode':'window',
  243. 'devicefont':'true',
  244. 'id':'Main',
  245. 'bgcolor':'#ffffff',
  246. 'name':'Main',
  247. 'allowscriptaccess':'always'
  248. };
  249. var attributes = {
  250. };
  251. swfobject.embedSWF("{$this->ps_api_url}global/swf/main.swf", "phpsso_uploadavatar_flash", "490", "434", "9.0.0","{$this->ps_api_url}global/swf/expressInstall.swf", flashvars, params, attributes);
  252. function return_avatar(data) {
  253. if(data == 1) {
  254. window.location.reload();
  255. }
  256. }
  257. </script>
  258. EOF;
  259. return $str;
  260. }
  261. /**
  262. * 字符串加密、解密函数
  263. *
  264. *
  265. * @param string $txt 字符串
  266. * @param string $operation ENCODE为加密,DECODE为解密,可选参数,默认为ENCODE,
  267. * @param string $key 密钥:数字、字母、下划线
  268. * @param string $expiry 过期时间
  269. * @return string
  270. */
  271. function sys_auth($string, $operation = 'ENCODE', $key = '', $expiry = 0) {
  272. $key_length = 4;
  273. $key = md5($key != '' ? $key : $this->ps_auth_key);
  274. $fixedkey = hash('md5', $key);
  275. $egiskeys = md5(substr($fixedkey, 16, 16));
  276. $runtokey = $key_length ? ($operation == 'ENCODE' ? substr(hash('md5', microtime(true)), -$key_length) : substr($string, 0, $key_length)) : '';
  277. $keys = hash('md5', substr($runtokey, 0, 16) . substr($fixedkey, 0, 16) . substr($runtokey, 16) . substr($fixedkey, 16));
  278. $string = $operation == 'ENCODE' ? sprintf('%010d', $expiry ? $expiry + time() : 0) . substr(md5($string . $egiskeys), 0, 16) . $string : base64_decode(substr($string, $key_length));
  279. $i = 0;
  280. $result = '';
  281. $string_length = strlen($string);
  282. for ($i = 0; $i < $string_length; $i++) {
  283. $result .= chr(ord($string{$i}) ^ ord($keys{$i % 32}));
  284. }
  285. if ($operation == 'ENCODE') {
  286. return $runtokey . str_replace('=', '', base64_encode($result));
  287. } else {
  288. if ((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26) . $egiskeys), 0, 16)) {
  289. return substr($result, 26);
  290. } else {
  291. return '';
  292. }
  293. }
  294. }
  295. /**
  296. * 将数组转换为字符串
  297. *
  298. * @param array $data 数组
  299. * @param bool $isformdata 如果为0,则不使用new_stripslashes处理,可选参数,默认为1
  300. * @return string 返回字符串,如果,data为空,则返回空
  301. */
  302. public function array2string($data, $isformdata = 1) {
  303. if ($data == '')
  304. return '';
  305. if ($isformdata)
  306. $data = new_stripslashes($data);
  307. return var_export($data, TRUE);
  308. }
  309. public function auth_data($data) {
  310. $s = $sep = '';
  311. foreach ($data as $k => $v) {
  312. if (is_array($v)) {
  313. $s2 = $sep2 = '';
  314. foreach ($v as $k2 => $v2) {
  315. $s2 .= "$sep2{$k}[$k2]=" . $this->_ps_stripslashes($v2);
  316. $sep2 = '&';
  317. }
  318. $s .= $sep . $s2;
  319. } else {
  320. $s .= "$sep$k=" . $this->_ps_stripslashes($v);
  321. }
  322. $sep = '&';
  323. }
  324. $s = http_build_query($data);
  325. // $auth_s = 'data=' . urlencode($s);
  326. return $s;
  327. }
  328. /**
  329. * 发送数据
  330. * @param $action 操作
  331. * @param $data 数据
  332. */
  333. private function _ps_send($action, $data = null) {
  334. return $this->_ps_post($this->ps_api_url . "api/" . $action, 500000, $this->auth_data($data));
  335. }
  336. /**
  337. * post数据
  338. * @param string $url post的url
  339. * @param int $limit 返回的数据的长度
  340. * @param string $post post数据,字符串形式username='dalarge'&password='123456'
  341. * @param string $cookie 模拟 cookie,字符串形式username='dalarge'&password='123456'
  342. * @param string $ip ip地址
  343. * @param int $timeout 连接超时时间
  344. * @param bool $block 是否为阻塞模式
  345. * @return string 返回字符串
  346. */
  347. private function _ps_post($url, $limit = 0, $post = '', $cookie = '', $ip = '', $timeout = 15, $block = true) {
  348. $return = '';
  349. $matches = parse_url($url);
  350. $host = $matches['host'];
  351. // $path = $matches['path'] ? $matches['path'] . ($matches['query'] ? '?' . $matches['query'] : '') : '/';
  352. $path = $matches['path'] ? $matches['path'] : '/';
  353. $port = !empty($matches['port']) ? $matches['port'] : 80;
  354. $siteurl = $this->_get_url();
  355. if ($post) {
  356. $out = "POST $path HTTP/1.1\r\n";
  357. $out .= "Accept: */*\r\n";
  358. $out .= "Referer: " . $siteurl . "\r\n";
  359. $out .= "Accept-Language: zh-cn\r\n";
  360. $out .= "Content-Type: application/x-www-form-urlencoded\r\n";
  361. $out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n";
  362. $out .= "Host: $host\r\n";
  363. $out .= 'Content-Length: ' . strlen($post) . "\r\n";
  364. $out .= "Connection: Close\r\n";
  365. $out .= "Cache-Control: no-cache\r\n";
  366. $out .= "Cookie: $cookie\r\n\r\n";
  367. $out .= $post;
  368. } else {
  369. $out = "GET $path HTTP/1.1\r\n";
  370. $out .= "Accept: */*\r\n";
  371. $out .= "Referer: " . $siteurl . "\r\n";
  372. $out .= "Accept-Language: zh-cn\r\n";
  373. $out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n";
  374. $out .= "Host: $host\r\n";
  375. $out .= "Connection: Close\r\n";
  376. $out .= "Cookie: $cookie\r\n\r\n";
  377. }
  378. $fp = @fsockopen(($ip ? $ip : $host), $port, $errno, $errstr, $timeout);
  379. if (!$fp)
  380. return '';
  381. stream_set_blocking($fp, $block);
  382. stream_set_timeout($fp, $timeout);
  383. @fwrite($fp, $out);
  384. $status = stream_get_meta_data($fp);
  385. if ($status['timed_out'])
  386. return '';
  387. while (!feof($fp)) {
  388. if (($header = @fgets($fp)) && ($header == "\r\n" || $header == "\n"))
  389. break;
  390. }
  391. $stop = false;
  392. while (!feof($fp) && !$stop) {
  393. $data = fread($fp, ($limit == 0 || $limit > 8192 ? 8192 : $limit));
  394. $return .= $data;
  395. if ($limit) {
  396. $limit -= strlen($data);
  397. $stop = $limit <= 0;
  398. }
  399. }
  400. @fclose($fp);
  401. //部分虚拟主机返回数值有误,暂不确定原因,过滤返回数据格式
  402. $return_arr = explode("\n", $return);
  403. if (isset($return_arr[1])) {
  404. $return = trim($return_arr[1]);
  405. }
  406. unset($return_arr);
  407. return $return;
  408. }
  409. /**
  410. * 过滤字符串
  411. * @param $string
  412. */
  413. private function _ps_stripslashes($string) {
  414. !defined('MAGIC_QUOTES_GPC') && define('MAGIC_QUOTES_GPC', get_magic_quotes_gpc());
  415. if (MAGIC_QUOTES_GPC) {
  416. return stripslashes($string);
  417. } else {
  418. return $string;
  419. }
  420. }
  421. /**
  422. * 获取当前页面完整URL地址
  423. */
  424. private function _get_url() {
  425. $sys_protocal = isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443' ? 'https://' : 'http://';
  426. $php_self = $_SERVER['PHP_SELF'] ? $this->_safe_replace($_SERVER['PHP_SELF']) : $this->_safe_replace($_SERVER['SCRIPT_NAME']);
  427. $path_info = isset($_SERVER['PATH_INFO']) ? $this->_safe_replace($_SERVER['PATH_INFO']) : '';
  428. $relate_url = isset($_SERVER['REQUEST_URI']) ? $this->_safe_replace($_SERVER['REQUEST_URI']) : $php_self . (isset($_SERVER['QUERY_STRING']) ? '?' . $this->_safe_replace($_SERVER['QUERY_STRING']) : $path_info);
  429. return $sys_protocal . (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '') . $relate_url;
  430. }
  431. /**
  432. * 安全过滤函数
  433. *
  434. * @param $string
  435. * @return string
  436. */
  437. private function _safe_replace($string) {
  438. $string = str_replace('%20', '', $string);
  439. $string = str_replace('%27', '', $string);
  440. $string = str_replace('%2527', '', $string);
  441. $string = str_replace('*', '', $string);
  442. $string = str_replace('"', '&quot;', $string);
  443. $string = str_replace("'", '', $string);
  444. $string = str_replace('"', '', $string);
  445. $string = str_replace(';', '', $string);
  446. $string = str_replace('<', '&lt;', $string);
  447. $string = str_replace('>', '&gt;', $string);
  448. $string = str_replace("{", '', $string);
  449. $string = str_replace('}', '', $string);
  450. $string = str_replace('\\', '', $string);
  451. return $string;
  452. }
  453. /**
  454. * 判断email格式是否正确
  455. * @param $string email
  456. */
  457. private function _is_email($email) {
  458. return strlen($email) > 6 && preg_match("/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/", $email);
  459. }
  460. /**
  461. * 判断email格式是否正确
  462. * @param $string email
  463. */
  464. public function getUserName() {
  465. $username = self::get_cookie('_username');
  466. if ($username) {
  467. return $username;
  468. } else {
  469. return FALSE;
  470. }
  471. }
  472. /**
  473. * 判断email格式是否正确
  474. * @param $string email
  475. */
  476. public function getAuth() {
  477. $auth = self::get_cookie('auth');
  478. if ($auth) {
  479. return $auth;
  480. } else {
  481. return FALSE;
  482. }
  483. }
  484. /**
  485. * 判断email格式是否正确
  486. * @param $string email
  487. */
  488. public function getUserID() {
  489. $userid = self::get_cookie('_userid');
  490. if ($userid) {
  491. return $userid;
  492. } else {
  493. return FALSE;
  494. }
  495. }
  496. public function get_cookie($var, $default = '') {
  497. $varvar = Doo::conf()->COOKIEPRE_WK . $var;
  498. return isset($_COOKIE[$varvar]) ? $this->authcode($_COOKIE[$varvar], 'DECODE') : $default;
  499. }
  500. /**
  501. *
  502. * 网络传输、cookie加密函数
  503. * @param type $string
  504. * @param type $operation
  505. * @param type $key
  506. * @param type $expiry
  507. * @return string
  508. */
  509. function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
  510. $ckey_length = 4;
  511. $key = md5($key != '' ? $key : "");
  512. $keya = md5(substr($key, 0, 16));
  513. $keyb = md5(substr($key, 16, 16));
  514. $keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length) : substr(md5(microtime()), -$ckey_length)) : '';
  515. $cryptkey = $keya . md5($keya . $keyc);
  516. $key_length = strlen($cryptkey);
  517. $string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0) . substr(md5($string . $keyb), 0, 16) . $string;
  518. $string_length = strlen($string);
  519. $result = '';
  520. $box = range(0, 255);
  521. $rndkey = array();
  522. for ($i = 0; $i <= 255; $i++) {
  523. $rndkey[$i] = ord($cryptkey[$i % $key_length]);
  524. }
  525. for ($j = $i = 0; $i < 256; $i++) {
  526. $j = ($j + $box[$i] + $rndkey[$i]) % 256;
  527. $tmp = $box[$i];
  528. $box[$i] = $box[$j];
  529. $box[$j] = $tmp;
  530. }
  531. for ($a = $j = $i = 0; $i < $string_length; $i++) {
  532. $a = ($a + 1) % 256;
  533. $j = ($j + $box[$a]) % 256;
  534. $tmp = $box[$a];
  535. $box[$a] = $box[$j];
  536. $box[$j] = $tmp;
  537. $result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));
  538. }
  539. if ($operation == 'DECODE') {
  540. if ((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26) . $keyb), 0, 16)) {
  541. return substr($result, 26);
  542. } else {
  543. return '';
  544. }
  545. } else {
  546. return $keyc . str_replace('=', '', base64_encode($result));
  547. }
  548. }
  549. public function logoutz() {
  550. // header('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"');
  551. setcookie(Doo::conf()->COOKIEPRE_WK . 'auth', '', 0, '/', Doo::conf()->APP_URL, 0);
  552. setcookie(Doo::conf()->COOKIEPRE_WK . '_username', '', 0, '/', Doo::conf()->APP_URL, 0);
  553. setcookie(Doo::conf()->COOKIEPRE_WK . '_userid', '', 0, '/', Doo::conf()->APP_URL, 0);
  554. }
  555. /**
  556. * 用户登陆
  557. * @param string $username 用户名
  558. * @param string $password 密码
  559. * @param int $isemail email
  560. * @return int {-2;密码错误;-1:用户名不存在;array(userinfo):用户信息}
  561. */
  562. public function ps_member_login($username, $password, $isemail = 0) {
  563. if ($isemail) {
  564. if (!$this->_is_email($username)) {
  565. return -3;
  566. }
  567. $return = $this->_ps_send('login', array('email' => $username, 'password' => $password));
  568. } else {
  569. $return = $this->_ps_send('login', array('username' => $username, 'password' => $password));
  570. }
  571. return $return;
  572. }
  573. // public function wksetcookit($username, $password, $isemail = 0) {
  574. // setcookie(Doo::conf()->COOKIEPRE_WK . 'auth', $client->authcode($ObjUserInfo[0]->id . "\t" . $this->clientIP(), 'ENCODE'), 0, '/', '192.168.1.140', 0);
  575. // setcookie(Doo::conf()->COOKIEPRE_WK . '_userid', $client->authcode($ObjUserInfo[0]->id, 'ENCODE'), 0, '/', '192.168.1.140', 0);
  576. // setcookie(Doo::conf()->COOKIEPRE_WK . '_username', $client->authcode($ObjUserInfo[0]->username, 'ENCODE'), 0, '/', '192.168.1.140', 0);
  577. // }
  578. /**
  579. * 用户登陆
  580. * @param string $username 用户名
  581. * @param string $password 密码
  582. * @param int $isemail email
  583. * @return int {-2;密码错误;-1:用户名不存在;array(userinfo):用户信息}
  584. */
  585. public function zhsso_member_bank($userid) {
  586. if (empty($userid))
  587. return false;
  588. return $this->_ps_send('getBank', array('uid' => $userid));
  589. }
  590. /**
  591. * 用户登陆
  592. * @param string $username 用户名
  593. * @param string $password 密码
  594. * @param int $isemail email
  595. * @return int {-2;密码错误;-1:用户名不存在;array(userinfo):用户信息}
  596. */
  597. public function getPayOrder($userid) {
  598. if (empty($userid))
  599. return false;
  600. return $this->_ps_send('getPayOrder', array('uid' => $userid));
  601. }
  602. /**
  603. * 金额增加
  604. * @param string $userid 用户唯一标示符
  605. * @param string $m 操作金额
  606. * @param int $appid 应用程序ID,标示操作来源{wenku,ask}
  607. * @return int {0;金额增加失败;1:金额增加成功;}
  608. */
  609. public function zhsso_member_madd($userid, $m, $appid) {
  610. if (empty($userid) || empty($m) || empty($appid))
  611. return false;
  612. return $this->_ps_send('madd', array('uid' => $userid, 'bank' => $m, 'appid' => $appid));
  613. }
  614. /**
  615. * 金额减少
  616. * @param string $userid 用户唯一标示符
  617. * @param string $m 操作金额
  618. * @param int $appid 应用程序ID,标示操作来源{wenku,ask}
  619. * @return int {-1;金额不够减;0;金额减少失败;1:金额减少成功;}
  620. */
  621. public function zhsso_member_msub($userid, $m, $appid) {
  622. if (empty($userid) || empty($m) || empty($appid))
  623. return false;
  624. return $this->_ps_send('msub', array('uid' => $userid, 'bank' => $m, 'appid' => $appid));
  625. }
  626. }
  627. ?>