client.php 23 KB

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