client.php 22 KB

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