123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 |
- <?php
- /**
- * Created by PhpStorm.
- * User: stanley-king
- * Date: 16/4/17
- * Time: 下午6:46
- */
- require_once (BASE_ROOT_PATH . '/helper/algorithm.php');
- require_once (BASE_ROOT_PATH . '/helper/relation_helper.php');
- require_once (BASE_ROOT_PATH . '/helper/account_helper.php');
- require_once (BASE_ROOT_PATH . '/helper/push_helper.php');
- require_once (BASE_ROOT_PATH . '/helper/login_helper.php');
- class session_helper
- {
- const mobile_login = 1;
- const wxopen_login = 2;
- const mobile_len = 11;
- static public function mobile_valid($mobile)
- {
- if(!isset($mobile) || empty($mobile) || strlen($mobile) < self::mobile_len) {
- return false;
- }
- $ret = preg_match('/^1(?:3[0-9]|5[012356789]|8[0256789]|7[0678])(-?)\d{4}\1\d{4}$/', $mobile, $arr);
- if($ret == false || count($arr) <= 0) {
- return false;
- } else {
- $mobile = $arr[0];
- }
- $mobile = str_replace('-','',$mobile);
- $mobile = substr($mobile,-self::mobile_len);
- $validate = new Validator();
- $validate->setValidate(Validator::verify_mobile($mobile));
- $err = $validate->validate();
- if(empty($err)) {
- return $mobile;
- } else {
- return false;
- }
- }
- static public function memberid() {
- return $_SESSION['member_id'];
- }
- static public function nickname()
- {
- if(isset($_SESSION['member_nickname']) && !empty($_SESSION['member_nickname'])) {
- return $_SESSION['member_nickname'];
- }
- if(array_key_exists('wx_author',$_SESSION))
- {
- if(array_key_exists('handled',$_SESSION['wx_author']))
- {
- $user_info = $_SESSION['wx_author']['user_info'];
- return $user_info['nickname'];
- }
- }
- if(isset($_SESSION['member_truename']) && !empty($_SESSION['member_truename'])) {
- return $_SESSION['member_truename'];
- }
- if(isset($_SESSION['member_mobile']) && !empty($_SESSION['member_mobile']))
- {
- $mobile = $_SESSION['member_mobile'];
- if(strlen($mobile) == 11) {
- return substr_replace($mobile, '****', 3, 4);
- }
- }
- return '';
- }
- static public function isLogin() {
- return ($_SESSION['is_login'] == 1);
- }
- static public function logined()
- {
- return ($_SESSION['is_login'] == 1);
- }
- static public function isapp()
- {
- if(isset($_SESSION['is_app'])) {
- return ($_SESSION['is_app'] == true);
- } else {
- return false;
- }
- }
- static public function isVerfiyMobile()
- {
- if(self::isLogin()) {
- return true;
- }
- else
- {
- if(isset($_SESSION['member_mobile']) && !empty($_SESSION['member_mobile'])) {
- return true;
- } else {
- return false;
- }
- }
- }
- static public function is_man() {
- return (intval($_SESSION['member_sex']) == 1);
- }
- static function avatar()
- {
- if(empty($_SESSION['member_avatar']))
- {
- if(array_key_exists('wx_author',$_SESSION))
- {
- if(array_key_exists('handled',$_SESSION['wx_author']))
- {
- $user_info = $_SESSION['wx_author']['user_info'];
- return $user_info['headimgurl'];
- }
- }
- if(self::is_man()) {
- $img = 'male.png';
- } else {
- $img = 'female.png';
- }
- return RESOURCE_SITE_URL . '/mobile/defimg/' . $img;
- }
- else
- {
- $path = $_SESSION['member_avatar'];
- if(strncasecmp($path,"http://",strlen("http://")) == 0) {
- $url = $path;
- } else {
- $url = UPLOAD_SITE_URL . "/shop/avatar{$path}";
- }
- return $url;
- }
- }
- static public function cur_mobile()
- {
- if(self::isVerfiyMobile()) {
- return $_SESSION['member_mobile'];
- } else {
- return '';
- }
- }
- static public function parase_wxinfo($wxinfo)
- {
- $user = urldecode($wxinfo);
- if(empty($user)) return false;
- $user = json_decode($user,true);
- if($user == false) return false;
- $info = array();
- $info['member_nickname'] = $user['nickname'];
- $info['member_avatar'] = $user['headimgurl'];
- $info['member_sex'] = intval($user['sex']);
- return $info;
- }
- static public function filter_info($info)
- {
- $member_info = array();
- if(isset($info['member_nickname']) && !empty($info['member_nickname'])) {
- $member_info['member_nickname'] = $info['member_nickname'];
- }
- if(isset($info['member_truename']) && !empty($info['member_truename'])) {
- if(!isset($member_info['member_nickname'])) {
- $member_info['member_nickname'] = $info['member_truename'];
- }
- $member_info['member_truename'] = $info['member_truename'];
- }
- if(isset($info['member_mobile']) && !empty($info['member_mobile']))
- {
- $mobile = $info['member_mobile'];
- if(!isset($member_info['member_nickname'])) {
- $member_info['member_nickname'] = substr_replace($mobile, '****', 3, 4);
- }
- $member_info['member_mobile'] = $info['member_mobile'];
- }
- return $member_info;
- }
- static public function filter_member_info($member_info,$openid)
- {
- field_helper::validate_null_string($member_info, 'member_mobile,member_wxopenid,member_name,' .
- 'member_truename,member_signname,member_avatar,member_email,member_birthday');
- field_helper::validate_null_string($member_info, 'member_sex', '0');
- field_helper::validate_null_string($member_info, 'member_nickname', substr_replace($openid, '****', 3, 4));
- return $member_info;
- }
- static public function parse_contacts($contacts)
- {
- if(!isset($contacts)) {
- return false;
- }
-
- $contacts = json_decode(urldecode($contacts));
- if($contacts == false) {
- return false;
- }
- $ar_contact = array();
- foreach ($contacts as $mobile)
- {
- $mobile = session_helper::mobile_valid($mobile);
- if($mobile == false) {
- continue;
- }
- if(algorithm::bsearch($mobile,$ar_contact) != -1) {
- continue;
- }
- array_push($ar_contact,$mobile);
- sort($ar_contact);
- }
- return $ar_contact;
- }
- static public function session_id() {
- return empty($_SESSION['MPHPSESSID']) ? "" : $_SESSION['MPHPSESSID'];
- }
- static public function need_wechat_author()
- {
- if(BASE_SITE_URL != 'http://p.lrlz.com') {
- return false;
- }
- if(util::from_wechat() == false) {
- return false;
- }
- else
- {
- if(array_key_exists('wx_author',$_SESSION))
- {
- if(array_key_exists('handled',$_SESSION['wx_author']))
- {
- $user_info = $_SESSION['wx_author']['user_info'];
- $loginer = new \login\unionid_log($user_info['unionid']);
- if(self::logined()) {
- $loginer->bind($user_info);
- $loginer->login();
- unset($_SESSION['wx_author']);
- }
- else
- {
- if($loginer->ismember() == true)
- {
- $loginer->bind($user_info);
- $loginer->login();
- unset($_SESSION['wx_author']);
- }
- }
- }
- return false;
- }
- $author_time = $_SESSION['wxauthor_time'];
- $max_time = 2 * 86400;
- if(time() - $author_time > $max_time) {
- return true;
- }
- if(!empty($_SESSION['member_wxunionid']) && !empty($_SESSION['member_wxopenid']))
- {
- return false;
- }
- else {
- return true;
- }
- }
- }
- static public function pub_openid()
- {
- if(empty($_SESSION['member_wxopenid'])) {
- return false;
- } else {
- return $_SESSION['member_wxopenid'];
- }
- }
- static public function unionid()
- {
- if(!empty($_SESSION['member_wxunionid'])) {
- return $_SESSION['member_wxunionid'];
- }
- if(array_key_exists('wx_author',$_SESSION))
- {
- if(array_key_exists('handled',$_SESSION['wx_author']))
- {
- $user_info = $_SESSION['wx_author']['user_info'];
- return $user_info['unionid'];
- }
- }
- return false;
- }
- }
|