client.php 24 KB

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