allow(User::modSn, BoLoader::AC_LIST)) { $status = new Status(C_ERROR, 'error.nopower', '对不起,您没有相应的操作权限。'); break; } $loader = new UserLoader(); $loader->_list($inkey); $vali = new UserValidator(); $status = $vali->_list($inkey); if ($status->getLabel() != C_SUCCESS) { break; } $tplSn = TplCenter::SN_LIST; $status = new Status(C_SUCCESS, 'list.success'); $info = $inkey; } while (false); $supervisor->tplSn = $tplSn; $supervisor->status = $status; $supervisor->info = $info; } /** * 添加新的公司信息 * * @param unknown_type $preFix * @param unknown_type $userInfo * @return unknown */ public function display() { /* @var $supervisor Supervisor */ global $supervisor; $inkey = array(); $tplSn = TplCenter::SN_NOTI; $info = null; do { $power = new UserPower(); if (!$power->allow(User::modSn, BoLoader::AC_DISPLAY)) { $status = new Status(C_ERROR, 'error.nopower', '对不起,您没有相应的操作权限。'); break; } if (true) { global /* @var $passport Passport */ $passport; $inkey['userId'] = $passport->userId; $inkey['userPhoneNum'] = 0; } $vali = new UserValidator(); $status = $vali->display($inkey); if ($status->getLabel() != C_SUCCESS) { break; } $recorder = new UserRecorder(); $info = $recorder->display($inkey); if (!$info) { $status = new Status(C_ERROR, 'error.noexists', '用户不存在。'); break; } $status = new Status(C_SUCCESS, 'success.exists', '用户读取成功。'); $tplSn = TplCenter::SN_DISPLAY; } while (false); $supervisor->tplSn = $tplSn; $supervisor->status = $status; $supervisor->info = $info; return $info; } public function login() { /* @var $supervisor Supervisor */ global $supervisor; $inkey = array(); $tplSn = TplCenter::SN_LOGIN; $info = null; global $operationContent; do { $power = new UserPower(); if (!$power->allow(User::modSn, BoLoader::AC_LOGIN)) { $status = new Status(C_ERROR, 'error.nopower', '对不起,您没有相应的操作权限。'); break; } if (!isPosted()) { global /* @var $domainInfo DomainInfo */ $domainInfo; if (isWeixin() && $domainInfo->appid && $domainInfo->secret && $domainInfo->wxAdvInterface == 1) { require_once 'lib/weixin/Sns.php'; $sns = new Sns(trim($domainInfo->appid), trim($domainInfo->secret)); $oauth2 = $sns->oauth2(sprintf('http://%s%s', $_SERVER["SERVER_NAME"], $_SERVER["REQUEST_URI"])); $inkey['appid'] = trim($domainInfo->appid); $inkey['openid'] = $oauth2['openid']; $userOauthWx = UserOauthWx::display(array( 'openId' => $inkey['openid'], )); if ($userOauthWx['id']) { $inkey['userAccount'] = $userOauthWx['userAccount']; $_SESSION['id'] = $userOauthWx['userId']; $_SESSION['account'] = $userOauthWx['userAccount']; $_SESSION['subAccount'] = $userOauthWx['userSubAccountAccount']; $_SESSION['subAccountId'] = $userOauthWx['userSubAccountId']; $_SESSION['password'] = $userOauthWx['userPassword']; if ($userOauthWx['userSubAccountId']) { $_SESSION['password'] = $userOauthWx['userSubAccount']['password']; } if (true) { /** * sso */ $sessionConveyer = new SessionConveyer(); $post = array(); $post['userName'] = $userOauthWx['userAccount']; $post['password'] = $userOauthWx['userPassword']; $post['source'] = $pass; $post['responseTime'] = time(); $sessionConveyer->setData(json_encode($post)); $ticket = $sessionConveyer->getTicket('9ddbedba2863d61be00042e03846a543'); global $GLOBALS; $GLOBALS['ticket'] = $ticket; } $status = new Status(C_SUCCESS, 'success.login', '登录成功。'); $tplSn = TplCenter::SN_NOTI; break; } } $info = $inkey; $status = new Status(C_INIT); break; } if (User::lock()) { $status = new Status(C_ERROR, 'error.lock', '账户已被锁定,请稍后再试。'); break; } $loader = new UserLoader(); $loader->login($inkey); if (true) { global /* @var $domainInfo DomainInfo */ $domainInfo; $inkey['siteId'] = $domainInfo->siteId; } $vali = new UserValidator(); $status = $vali->login($inkey); if ($status->getLabel() != C_SUCCESS) { break; } $recorder = new UserRecorder(); $info = $recorder->login($inkey); if (!$info) { $operationContent = sprintf('登录失败'); ValiError::increace(); /** * 登录失败记录 */ User::loginFailed(); $status = new Status(C_ERROR, 'error.noexists', '用户名或密码错误。'); break; } $pass = $inkey['userPassword']; $inkey['userPassword'] = turnMd5($inkey['userPassword']); $userPassword = ''; if (isset($info['subAccount']) && $info['subAccount']) { $userPassword = $info['subAccount']['password']; } else { $userPassword = $info['userPassword']; } if ($userPassword != $inkey['userPassword']) { if (isset($info['subAccount']) && $info['subAccount']) { $info['userAccount'] = sprintf('%s@%s', $info['subAccount']['account'], $info['userAccount']); } $operationContent = sprintf('登录失败'); ValiError::increace(); /** * 登录失败记录 */ User::loginFailed(); $status = new Status(C_ERROR, 'error.password', '用户名或密码错误。'); break; } if ($inkey['userOauthWx']['openid']) { $userOauthWx = UserOauthWx::add(new Recorder(Conn::getConn()), array( 'openId' => $inkey['userOauthWx']['openid'] , 'appid' => $inkey['userOauthWx']['appid'] , 'userId' => $info['userId'] , 'userAccount' => $info['userAccount'] , 'userSubAccountId' => $info['subAccount']['id'] , 'userSubAccountAccount' => $info['subAccount']['account'], )); } if ($inkey['siteId'] == 139515) { $alive = LoginAlive::count($info['userId'], $info['subAccount']['id']); if ($alive >= Config::ALIVE_COUNT) { $operationContent = sprintf('登录失败'); $status = new Status(C_ERROR, 'error.alive', sprintf('系统只允许同一个帐号同时%s个人登录!', Config::ALIVE_COUNT)); break; } } $inkey['userAccount'] = $info['userAccount']; #用其它方式登录,获取用户名 $_SESSION['id'] = $info['userId']; $_SESSION['account'] = $inkey['userAccount']; $_SESSION['subAccount'] = $info['subAccount']['account']; $_SESSION['subAccountId'] = $info['subAccount']['id']; $_SESSION['password'] = $inkey['userPassword']; if (true) { /** * sso */ $sessionConveyer = new SessionConveyer(); $post = array(); $post['userName'] = $inkey['userAccount']; $post['password'] = $inkey['userPassword']; $post['source'] = $pass; $post['responseTime'] = time(); $sessionConveyer->setData(json_encode($post)); $ticket = $sessionConveyer->getTicket('9ddbedba2863d61be00042e03846a543'); global $GLOBALS; $GLOBALS['ticket'] = $ticket; } /** * 记录最后登录sessionid */ require_once 'modules/SiteConf/SiteConf.php'; SiteConf::setKeyValue( new Recorder(Conn::getConn()) , sprintf('manage_last_session_%s_%s', intval($info['userId']), intval($info['subAccount']['id'])) , session_id() ); SiteConf::setKeyValue( new Recorder(Conn::getConn()) , 'manageLoginFailed' , '' ); $operationContent = sprintf('登录成功'); $status = new Status(C_SUCCESS, 'success.login', '登录成功。'); $tplSn = TplCenter::SN_NOTI; } while (false); $supervisor->tplSn = $tplSn; $supervisor->status = $status; $supervisor->info = $info; return $info; } public function oAuthWx() { /* @var $supervisor Supervisor */ global $supervisor; $inkey = array(); $tplSn = 'OAuthWx'; $info = null; do { $power = new UserPower(); if (!$power->allow(User::modSn, BoLoader::AC_LOGIN)) { $status = new Status(C_ERROR, 'error.nopower', '对不起,您没有相应的操作权限。'); break; } if (!isPosted()) { /* 获取微信授权 */ require_once 'lib/Booen/BoLoader.php'; require_once 'lib/Booen/Agent.php'; require_once 'lib/weixin/WeiXin.php'; $agent = new Agent(); $loader = new BoLoader(); $agentId = $agent->getId(); //$agent->setIdById($agentId); $weixinInfo = $agent->getWeixinInfo(); $weixin = new WeiXin($weixinInfo['weixin_appid'], $weixinInfo['weixin_secret']); if (!isset($_GET['code'])) { header(sprintf('location: %s', $weixin->getOAuthCodeUrl('http://' . getDomain() . '/passport/login.php?userAction=oAuthWx&agent_id=' . $agentId))); exit(); } $inkey['openId'] = $weixin->getOAuthOpenid($_GET['code']); $_SESSION['openId'] = $inkey['openId']; $_SESSION['agentId'] = $agentId; // $_SESSION['openId'] = '886182615'; $recorder = new UserRecorder(); $info = $recorder->isOAuthWx(array( 'openId' => $_SESSION['openId'], )); if ($info) { $status = new Status(C_SUCCESS, 'success.oAuthWx', '绑定成功。'); break; } $status = new Status(C_INIT); break; } $loader = new UserLoader(); $loader->login($inkey); if (!$_SESSION['openId']) { $status = new Status(C_ERROR, 'error.openId', '请重新从微信菜单进入。'); break; } $vali = new UserValidator(); $status = $vali->login($inkey); if ($status->getLabel() != C_SUCCESS) { break; } $recorder = new UserRecorder(); $info = $recorder->login($inkey); if (!$info) { ValiError::increace(); $status = new Status(C_ERROR, 'error.noexists', '用户名或密码错误。'); break; } $pass = $inkey['userPassword']; $inkey['userPassword'] = turnMd5($inkey['userPassword']); if ($info['userPassword'] != $inkey['userPassword']) { ValiError::increace(); $status = new Status(C_ERROR, 'error.password', '用户名或密码错误。'); break; } $inkey['agentId'] = $_SESSION['agentId']; $inkey['openId'] = $_SESSION['openId']; $inkey['userAccount'] = $info['userAccount']; $inkey['userId'] = $info['userId']; $inkey['state'] = 1; $info = $recorder->oAuthWx($inkey); if (!$info) { $status = new Status(C_ERROR, 'error.noexists', '绑定失败。'); break; } $status = new Status(C_SUCCESS, 'success.oAuthWx', '绑定成功。'); } while (false); $supervisor->tplSn = $tplSn; $supervisor->status = $status; $supervisor->info = $info; return $info; } public function unOAuthWx() { /* @var $supervisor Supervisor */ global $supervisor; $inkey = array(); $tplSn = 'UnOAuthWx'; $info = null; do { $power = new UserPower(); if (!$power->allow(User::modSn, BoLoader::AC_LOGIN)) { $status = new Status(C_ERROR, 'error.nopower', '对不起,您没有相应的操作权限。'); break; } if (!isPosted()) { /* 获取微信授权 */ require_once 'lib/Booen/BoLoader.php'; require_once 'lib/Booen/Agent.php'; require_once 'lib/weixin/WeiXin.php'; $agent = new Agent(); $loader = new BoLoader(); $agentId = $agent->getId(); // $agent->setIdById($agentId); $weixinInfo = $agent->getWeixinInfo(); $weixin = new WeiXin($weixinInfo['weixin_appid'], $weixinInfo['weixin_secret']); if (!isset($_GET['code'])) { header(sprintf('location: %s', $weixin->getOAuthCodeUrl(getCurUrl()))); exit(); } $inkey['openId'] = $weixin->getOAuthOpenid($_GET['code']); $_SESSION['openId'] = $inkey['openId']; $_SESSION['agentId'] = $agentId; // $_SESSION['openId'] = '886182615'; $recorder = new UserRecorder(); $info = $recorder->isOAuthWx(array( 'openId' => $_SESSION['openId'], )); if (!$info) { $status = new Status(C_ERROR, 'error.oAuthWx', '对不起,您没有绑定。'); break; } /* 获取站点信息 */ require_once 'modules/UserOauthWx/UserOauthWx.php'; $recorder = new UserOauthWxRecorder(); $info = array(); $info['site'] = $recorder->getOAuthSite(array('openId' => $_SESSION['openId'])); $status = new Status(C_INIT); break; } $inkey['agentId'] = $_SESSION['agentId']; $inkey['openId'] = $_SESSION['openId']; $recorder = new UserRecorder(); $info = $recorder->unOAuthWx($inkey); if (!$info) { $status = new Status(C_ERROR, 'error.noexists', '解绑失败。'); break; } $status = new Status(C_SUCCESS, 'success.unOAuthWx', '解绑成功。'); } while (false); $supervisor->tplSn = $tplSn; $supervisor->status = $status; $supervisor->info = $info; return $info; } /** * 插入用户信息 */ public function add() { /* @var $supervisor Supervisor */ global $supervisor; $inkey = array(); $tplSn = TplCenter::SN_NOTI; $info = null; global $operationContent; do { if(in_array($_SERVER['SERVER_ADDR'], array('172.16.0.17','172.16.0.2'))){ exit(); } $loader = new BoLoader(); $_referer = $loader->getServer('HTTP_REFERER', ''); $email = ''; $phone = ''; $wx = ''; $verifyType = 'phone'; if (strpos($_referer, 'phone') !== false) { $phone = $loader->getGet('phone', 0); if (!isset($_SESSION['verimaInfo'][$phone]['verify']) || $_SESSION['verimaInfo'][$phone]['verify'] != 1) { // header('Location: /passport/login.php?userAction=phoneVerify'); // exit(); } $verifyType = 'phone'; } elseif (strpos($_referer, 'email') !== false) { $email = $loader->getGet('email', 0); if (!isset($_SESSION['verimaInfo'][$email]['verify']) || $_SESSION['verimaInfo'][$email]['verify'] != 1) { // header('Location: /passport/login.php?userAction=emailVerify'); // exit(); } $verifyType = 'email'; } else { if (!$_SESSION['reg_openId']) { // header('Location: /passport/login.php?userAction=wxVerify'); // exit(); } $wx = rand(); $verifyType = 'wx'; } $power = new UserPower(); if (!$power->allow(User::modSn, BoLoader::AC_ADD)) { $status = new Status(C_ERROR, 'error.nopower', '对不起,您没有相应的操作权限。'); break; } if (!isPosted()) { $agent = new Agent(); //$agent->setIdById($loader->getGet('agent_id', 0)); $weixinInfo = $agent->getWeixinInfo(); if ($weixinInfo['weixin_appid'] && $weixinInfo['weixin_secret'] && isWeixin()) { if (!$_SESSION['weixin']['openid']) { require_once 'lib/weixin/WeiXin.php'; $weixin = new WeiXin(trim($weixinInfo['weixin_appid']), trim($weixinInfo['weixin_secret'])); if (!$_GET['code']) { $oAuthCodeUrl = sprintf( 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_base&state=%s#wechat_redirect' , trim($weixinInfo['weixin_appid']) , urlencode(getCurUrl()) , rand(10000, 99999) ); header(sprintf('location: %s', $oAuthCodeUrl)); exit(); } $url = sprintf('https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code', trim($weixinInfo['weixin_appid']), trim($weixinInfo['weixin_secret']), $_GET['code']); $response = $weixin->sendRequest($url); $data = json_decode($response, true); if (!isset($data['access_token'])) { $urls = parse_url(getCurUrl()); parse_str($urls['query'], $query); unset($query['code']); unset($query['state']); header(sprintf('location: %s://%s%s?%s', $urls['scheme'], $urls['host'], $urls['path'], http_build_query($query))); exit(); } $token = $data['access_token']; // $url = sprintf('https://api.weixin.qq.com/sns/userinfo?access_token=%s&openid=%s&lang=zh_CN', $token, trim($weixinInfo['weixin_appid'])); // $response = $weixin->sendRequest($url); // $data = json_decode($response, true); // if (!isset($data['openid'])) { // $urls = parse_url(getCurUrl()); // parse_str($urls['query'], $query); // unset($query['code']); // unset($query['state']); // header(sprintf('location: %s://%s%s?%s', $urls['scheme'], $urls['host'], $urls['path'], http_build_query($query))); // exit(); // exit(); // } $_SESSION['weixin']['appid'] = trim($weixinInfo['weixin_appid']); $_SESSION['weixin']['openid'] = $data['openid']; $_SESSION['weixin']['nickname'] = $data['nickname']; $_SESSION['weixin']['headimgurl'] = $data['headimgurl']; } $recorder = new UserRecorder(); $info = $recorder->isOAuthWx(array( 'openId' => $_SESSION['weixin']['openid'], )); if ($info) { require_once 'modules/UserOauthWx/UserOauthWx.php'; $recorder = new UserOauthWxRecorder(); $site = $recorder->getOAuthSite(array( 'openId' => $_SESSION['weixin']['openid'], )); $nextAction = $loader->getGet('nextAction', null); if ($nextAction == 'swiftpassUnifiedAuth') { require_once 'modules/SwiftpassUnifiedAuth/SwiftpassUnifiedAuth.php'; $recorder = new SwiftpassUnifiedAuthRecorder(); $info = $recorder->display(array('siteId' => $site['siteId'])); if ($info['merchantId']) { } else { header(sprintf('location: /passport/wechat.auto.manage.php?target=swiftpassUnifiedAuth&action=add')); exit(); } } header(sprintf('location: /passport/login.php?userAction=unOAuthWx')); exit(); } } $info = array( 'userPhoneNum' => $phone, 'userEmail' => $email, 'userWx' => $wx, ); $supervisor->info = $info; $tplSn = TplCenter::SN_ADD; # $status = new Status(C_INIT); break; } $loader = new UserLoader(); $loader->add($inkey); if ($inkey['inWeixin'] == 1) { $inkey['weixin'] = $_SESSION['weixin']; } if (true) { global /* @var $domainInfo DomainInfo */ $domainInfo, /* @var $passport Passport */ $passport; $inkey['userSiteId'] = $domainInfo->siteId ? $domainInfo->siteId : 1; } $vali = new UserValidator(); $status = $vali->add($inkey); if ($status->getLabel() != C_SUCCESS) { $tplSn = TplCenter::SN_ADD; break; } $recorder = new UserRecorder(); /* * 判断帐号是否存在 */ $isExist = $recorder->login($inkey); if ($isExist) { $status = new Status(C_ERROR, 'error.exists', '用户名已存在。'); break; } if ($inkey['userPhoneNum']) { $isExist = $recorder->login(array('userAccount' => $inkey['userPhoneNum'])); if ($isExist) { $status = new Status(C_ERROR, 'error.exists', '手机号码已存在。'); break; } } $id = $recorder->add($inkey); # 调用数据库操作函数 if ($id['userId'] == 0) { $status = new Status(C_ERROR, 'error.add', '对不起,信息新增失败!'); break; } $_SESSION['id'] = $id['userId']; $_SESSION['account'] = $inkey['userAccount']; $_SESSION['password'] = turnMd5($inkey['userPassword']); unset($_SESSION['verimaInfo'][$inkey['userPhoneNum']], $_SESSION['reg_openId']); # 删验证信息 $targetDomain = ''; if (isWeixin()) { $targetDomain = sprintf('m.%s.site.jgz.la', $id['siteId']); } else { $targetDomain = sprintf('%s.site.jgz.la', $id['siteId']); } if ($inkey['referer'] == 'unOAuthWx') { unset($_SESSION['id']); # 删验证信息 header(sprintf('location: /passport/login.php?userAction=unOAuthWx')); exit(); } /* 自动跳转到站点后台 */ require_once 'lib/Booen/BoLoader.php'; $session = new SessionConveyer(); $loader = new BoLoader(); $row['id'] = $id['userId']; $row['account'] = $inkey['userAccount']; $row['password'] = turnMd5($inkey['userPassword']); $row['target'] = sprintf('http://%s/manage/%s', $targetDomain, $inkey['referer']); $row['ticket_time'] = time(); $row['ticket_ip'] = $loader->getIp(); $session->setData(json_encode($row)); $ticket = $session->getTicket('ce164f750e5c9d0b00fe58d1c21a01ac'); $info = array('status' => 'success', 'name' => 'get.success', 'ticket' => $ticket); $manageUrl = ''; global $isJson; if ($isJson == 1) { $manageUrl = sprintf('http://%s/manage/api/auto.manage.php?info=%s', $targetDomain, urlencode(json_encode($info))); } else { header(sprintf('Location: http://%s/manage/api/auto.manage.php?info=%s', $targetDomain, urlencode(json_encode($info)))); exit; } $status = new Status(C_SUCCESS, 'success.add', '信息新增成功。'); $info = array( 'id' => $id['userId'] , 'manageUrl' => $manageUrl, ); $operationContent = sprintf('会员注册成功'); } while (false); $supervisor->tplSn = $tplSn; $supervisor->status = $status; $supervisor->info = $info; return; } /** * 验证手机号码 */ public function phoneVerify() { /* @var $supervisor Supervisor */ global $supervisor; $inkey = array(); $tplSn = TplCenter::SN_NOTI; $info = null; do { $power = new UserPower(); if (!$power->allow(User::modSn, BoLoader::AC_PHONE_VERIFY)) { $status = new Status(C_ERROR, 'error.nopower', '对不起,您没有相应的操作权限。'); break; } if (!isPosted()) { $tplSn = TplCenter::SN_PHONE_VERIFY; # $status = new Status(C_INIT); break; } $loader = new UserLoader(); $loader->phoneVerify($inkey); if (true) { global /* @var $domainInfo DomainInfo */ $domainInfo, /* @var $passport Passport */ $passport; $inkey['userSiteId'] = $domainInfo->siteId ? $domainInfo->siteId : 1; } $vali = new UserValidator(); $status = $vali->phoneVerify($inkey); if ($status->getLabel() != C_SUCCESS) { $tplSn = TplCenter::SN_PHONE_VERIFY; break; } $_SESSION['verimaInfo'][$inkey['userPhoneNum']]['verify'] = 1; $status = new Status(C_SUCCESS, 'success.verify', '验证成功。'); header('Location: /passport/login.php?userAction=reg&phone=' . $inkey['userPhoneNum']); exit(); $info = array(); } while (false); $supervisor->tplSn = $tplSn; $supervisor->status = $status; $supervisor->info = $info; return; } /** * 验证微信 */ public function wxVerify() { /* @var $supervisor Supervisor */ global $supervisor; $inkey = array(); $tplSn = 'WxVerify'; $info = null; $status = new Status(C_INIT); do { $power = new UserPower(); if (!$power->allow(User::modSn, BoLoader::AC_ADD)) { $status = new Status(C_ERROR, 'error.nopower', '对不起,您没有相应的操作权限。'); break; } if (true) { global /* @var $domainInfo DomainInfo */ $domainInfo; } unset($_SESSION['reg_openId']); $loader = new Loader(); $scene = $loader->getGet('scene', 0); $agent = new Agent(); $inkey['agentId'] = $agent->getId(); if (!$scene) { $recorder = new UserRecorder(); $info['scene'] = $recorder->setSceneId($inkey); } $qrcodeShow = $loader->getGet('qrcodeShow', 0); if ($qrcodeShow == 1) { $weixinInfo = $agent->getWeixinInfo(); require_once 'lib/weixin/WeiXin.php'; $weixin = new WeiXin($weixinInfo['weixin_appid'], $weixinInfo['weixin_secret']); $qrcode = $weixin->qrcodeCreate('QR_SCENE', $scene); ob_end_clean(); ob_start(); header('Expires: Mon, 26 Jul 1970 05:00:00 GMT'); header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); header('Cache-Control: no-cache, must-revalidate'); header('Pragma: no-cache'); header('Content-Type: image/jpg'); header('Content-Disposition: inline; filename=qrcode.jpg'); echo $qrcode; flush(); ob_flush(); } $verify = $loader->getGet('verify', 0); if ($verify == 1) { $inkey['scene'] = $scene; $recorder = new UserRecorder(); $sceneInfo = $recorder->getSceneId($inkey); $sceneInfo['openId'] && $_SESSION['reg_openId'] = $sceneInfo['openId']; header('Expires: Mon, 26 Jul 1970 05:00:00 GMT'); header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); header('Cache-Control: no-cache, must-revalidate'); header('Pragma: no-cache'); echo json_encode(array('timestamp' => time(), 'openid' => $sceneInfo['openId'] ? 1 : 0)); exit(); } } while (false); $supervisor->tplSn = $tplSn; $supervisor->status = $status; $supervisor->info = $info; return; } /** * 验证邮箱 */ public function emailVerify() { /* @var $supervisor Supervisor */ global $supervisor; $inkey = array(); $tplSn = TplCenter::SN_NOTI; $info = null; do { $power = new UserPower(); if (!$power->allow(User::modSn, BoLoader::AC_EMAIL_VERIFY)) { $status = new Status(C_ERROR, 'error.nopower', '对不起,您没有相应的操作权限。'); break; } if (!isPosted()) { $tplSn = TplCenter::SN_EMAIL_VERIFY; # $status = new Status(C_INIT); break; } $loader = new UserLoader(); $loader->emailVerify($inkey); if (true) { global /* @var $domainInfo DomainInfo */ $domainInfo, /* @var $passport Passport */ $passport; $inkey['userSiteId'] = $domainInfo->siteId ? $domainInfo->siteId : 1; } $vali = new UserValidator(); $status = $vali->emailVerify($inkey); if ($status->getLabel() != C_SUCCESS) { $tplSn = TplCenter::SN_EMAIL_VERIFY; break; } $_SESSION['verimaInfo'][$inkey['userEmail']]['verify'] = 1; $status = new Status(C_SUCCESS, 'success.verify', '验证成功。'); header('Location: /passport/login.php?userAction=reg&email=' . $inkey['userEmail']); exit(); $info = array(); } while (false); $supervisor->tplSn = $tplSn; $supervisor->status = $status; $supervisor->info = $info; return; } /** * 发送验证码 */ public function smsSend() { /* @var $supervisor Supervisor */ global $supervisor; $inkey = array(); $tplSn = TplCenter::SN_NOTI; $info = null; do { $power = new UserPower(); if (!$power->allow(User::modSn, BoLoader::AC_SMS_SEND)) { $status = new Status(C_ERROR, 'error.nopower', '对不起,您没有相应的操作权限。'); break; } if (!isPosted()) { ob_clean(); echo json_encode(array()); exit(); } $loader = new UserLoader(); $loader->smsSend($inkey); if (true) { global /* @var $domainInfo DomainInfo */ $domainInfo, /* @var $passport Passport */ $passport; $inkey['userSiteId'] = $domainInfo->siteId ? $domainInfo->siteId : 1; } $vali = new UserValidator(); $status = $vali->smsSend($inkey); if ($status->getLabel() != C_SUCCESS) { ob_clean(); echo json_encode(array('error' => 2)); exit(); } if (isset($_SESSION['verimaInfo'][$inkey['userPhoneNum']]['time']) && $_SESSION['verimaInfo'][$inkey['userPhoneNum']]['time'] + 180 > time()) { ob_clean(); echo json_encode(array('error' => 1)); exit(); } if (!isset($_SESSION['verimaInfo'][$inkey['userPhoneNum']]) || empty($_SESSION['verimaInfo'][$inkey['userPhoneNum']]) || $_SESSION['verimaInfo'][$inkey['userPhoneNum']]['time'] + 60 * 60 < time() || $_SESSION['verimaInfo'][$inkey['userPhoneNum']]['verify'] == 1) { $_SESSION['verimaInfo'][$inkey['userPhoneNum']]['verima'] = rand(100000, 999999); $_SESSION['verimaInfo'][$inkey['userPhoneNum']]['verify'] = 0; } $_SESSION['verimaInfo'][$inkey['userPhoneNum']]['time'] = time(); require_once 'lib/sms/Chanzor.php'; $chanzor = new Chanzor(); $content = sprintf('%s(手机绑定验证码)60分钟有效。', $_SESSION['verimaInfo'][$inkey['userPhoneNum']]['verima']); if ($chanzor->send($inkey['userPhoneNum'], $content)) { $inkey['state'] = 2; echo json_encode(array('error' => 0, 'code' => 2000)); } else { $inkey['state'] = 1; echo json_encode(array('error' => 1, 'code' => 5000)); } require_once 'modules/SmsLog/SmsLogRecorder.php'; $smsLog = new SmsLogRecorder(); $smsLog->add(array( 'content' => $content , 'phoneNum' => $inkey['userPhoneNum'] , 'state' => $inkey['state'] , 'type' => 'reg' , 'clientIp' => $inkey['clientIp'] , 'createTime' => $inkey['createTime'] , 'editTime' => $inkey['editTime'] , 'siteId' => 0 , 'captcha' => $_SESSION['verimaInfo'][$inkey['userPhoneNum']]['verima'] , 'expireTime' => time() + 60 * 30, )); // require_once 'lib/todaynicSms/TodaynicSms.php'; // // $newclient = new TodaynicSms(); // $content = sprintf('%s(建个站注册验证码),60分钟有效。(布恩网络)', $_SESSION['verimaInfo'][$inkey['userPhoneNum']]['verima']); // $respxml = $newclient->sendSMS($inkey['userPhoneNum'], mb_convert_encoding($content, 'GB2312', 'utf-8')); #本地测试会注释该行,不需要发送短信 // // $code = $newclient->getCode(); // $respArr = $newclient->toArray(); // ob_clean(); // if ($code == 2000) { // $inkey['state'] = 2; // echo json_encode(array('error' => 0, 'code' => $code)); // } else { // $inkey['state'] = 1; // echo json_encode(array('error' => 1, 'code' => $code)); // } // // require_once 'modules/SmsLog/SmsLogRecorder.php'; // $smsLog = new SmsLogRecorder(); // $smsLog->add(array( // 'content' => $content // , 'phoneNum' => $inkey['userPhoneNum'] // , 'state' => $inkey['state'] // , 'type' => 'reg' // , 'clientIp' => $inkey['clientIp'] // , 'createTime' => $inkey['createTime'] // , 'editTime' => $inkey['editTime'] // , 'siteId' => 0 // )); // $recorder = new UserRecorder(); // $id = $recorder->smsSend(array( // 'content' => $content // , 'phoneNum' => $inkey['userPhoneNum'] // , 'state' => $inkey['state'] // , 'type' => 'reg' // , 'clientIp' => $inkey['clientIp'] // , 'createTime' => $inkey['createTime'] // , 'editTime' => $inkey['editTime'] // )); exit(); } while (false); return; } public function minaGetPhoneNumber() { /* @var $supervisor Supervisor */ global $supervisor; $inkey = array(); $tplSn = TplCenter::SN_NOTI; $info = null; do { $power = new UserPower(); if (!$power->allow(User::modSn, BoLoader::AC_SMS_SEND)) { $status = new Status(C_ERROR, 'error.nopower', '对不起,您没有相应的操作权限。'); break; } if (!isPosted()) { ob_clean(); echo json_encode(array()); exit(); } $loader = new UserLoader(); $loader->minaGetPhoneNumber($inkey); if (true) { global /* @var $domainInfo DomainInfo */ $domainInfo, /* @var $passport Passport */ $passport; $inkey['userSiteId'] = $domainInfo->siteId ? $domainInfo->siteId : 1; } $wxMina = array( 'wx754d2e9c1b5e0366' => '86e7267d89ed66935ec54b824295864f', ); $minaAppID = $inkey['appid']; $minaAppSecret = $wxMina[$inkey['appid']]; require_once 'modules/SiteWxMinaJscode2session/SiteWxMinaJscode2session.php'; $sessionKeyInfo = SiteWxMinaJscode2session::getSessionKey(); $sessionKey = $sessionKeyInfo['sessionKey']; if (!$sessionKey) { $status = new Status(C_ERROR, 'error.add', '对不起,session_key无法获取!'); break; } require_once 'lib/weixin/wxBizDataCrypt.php'; $wxBizDataCrypt = new WXBizDataCrypt($minaAppID, $sessionKey); $errCode = $wxBizDataCrypt->decryptData($inkey['encryptedData'], $inkey['iv'], $decryptData); if ($errCode != 0) { $status = new Status(C_ERROR, 'error.add', '对不起,解密失败!'); break; } $inkey = array_merge($inkey, json_decode($decryptData, true)); $inkey['userPhoneNum'] = $inkey['purePhoneNumber']; $vali = new UserValidator(); $status = $vali->minaGetPhoneNumber($inkey); if ($status->getLabel() != C_SUCCESS) { break; } $inkey['verima'] = rand(100000, 999999); require_once 'modules/SmsLog/SmsLogRecorder.php'; $smsLog = new SmsLogRecorder(); $info = $smsLog->add(array( 'content' => '获取微信用户绑定的手机号' , 'phoneNum' => $inkey['userPhoneNum'] , 'state' => 2 , 'type' => 'reg' , 'clientIp' => 0 , 'createTime' => $inkey['createTime'] , 'editTime' => $inkey['editTime'] , 'siteId' => 0 , 'captcha' => $inkey['verima'] , 'expireTime' => time() + 60 * 30, )); if (!$info) { $status = new Status(C_ERROR, 'error.noexists', '读取失败。'); break; } $info = $inkey; $status = new Status(C_SUCCESS, 'success.exists', '读取成功。'); } while (false); $supervisor->tplSn = $tplSn; $supervisor->status = $status; $supervisor->info = $info; return; } /** * 发送验证码 */ public function emailSend() { /* @var $supervisor Supervisor */ global $supervisor; $inkey = array(); $tplSn = TplCenter::SN_NOTI; $info = null; do { $power = new UserPower(); if (!$power->allow(User::modSn, BoLoader::AC_EMAIL_SEND)) { $status = new Status(C_ERROR, 'error.nopower', '对不起,您没有相应的操作权限。'); break; } if (!isPosted()) { ob_clean(); echo json_encode(array()); exit(); } $loader = new UserLoader(); $loader->emailSend($inkey); if (true) { global /* @var $domainInfo DomainInfo */ $domainInfo, /* @var $passport Passport */ $passport; $inkey['userSiteId'] = $domainInfo->siteId ? $domainInfo->siteId : 1; } $vali = new UserValidator(); $status = $vali->emailSend($inkey); if ($status->getLabel() != C_SUCCESS) { ob_clean(); echo json_encode(array('error' => 2)); exit(); } // if (isset($_SESSION['verimaInfo'][$inkey['userEmail']]['time']) && $_SESSION['verimaInfo'][$inkey['userEmail']]['time'] > time()) { // ob_clean(); // echo json_encode(array('error' => 1)); // exit(); // } if (!isset($_SESSION['verimaInfo'][$inkey['userEmail']]) || empty($_SESSION['verimaInfo'][$inkey['userEmail']]) || $_SESSION['verimaInfo'][$inkey['userEmail']]['time'] < time() || $_SESSION['verimaInfo'][$inkey['userEmail']]['verify'] == 1) { $_SESSION['verimaInfo'][$inkey['userEmail']]['verima'] = rand(100000, 999999); $_SESSION['verimaInfo'][$inkey['userEmail']]['verify'] = 0; $_SESSION['verimaInfo'][$inkey['userEmail']]['time'] = time() + 60 * 60; } require_once 'lib/Booen/BoMail.php'; $mailer = new BoMail(); $pass = $mailer->send($inkey['userEmail'], $inkey['userEmail'], '验证码', sprintf('%s(验证码),60分钟有效。(布恩网络)', $_SESSION['verimaInfo'][$inkey['userEmail']]['verima'])); ob_clean(); if ($pass) { echo json_encode(array('error' => 0)); } else { echo json_encode(array('error' => 1, 'msg' => $mailer->getError())); } exit(); } while (false); return; } public function changePsw() { /* @var $supervisor Supervisor */ global $supervisor; $inkey = array(); $tplSn = TplCenter::SN_NOTI; $info = null; $status = new Status(C_INIT); do { $power = new UserPower(); if (!$power->allow(User::modSn, BoLoader::AC_CHANGE_PSW)) { $status = new Status(C_ERROR, 'error.nopower', '对不起,您没有相应的操作权限。'); break; } if (!isPosted()) { $this->display(); $info = $supervisor->info; if (!$info) { $status = new Status(C_ERROR, 'error.noexists', '用户不存在。'); break; } $tplSn = TplCenter::SN_CHANGE_PSW; break; } /* @var $loader UserLoader */ $loader = new UserLoader(); $loader->changePsw($inkey); if (true) { global /* @var $passport Passport */ $passport; $inkey['userId'] = $passport->userId; } /* @var $vali UserValidator */ $vali = new UserValidator(); $status = $vali->changePsw($inkey); if ($status->getLabel() != C_SUCCESS) { $tplSn = TplCenter::SN_CHANGE_PSW; break; } $inkey['userPassword'] = turnMd5($inkey['userPassword']); $inkey['userPassword_New'] = turnMd5($inkey['userPassword_New']); $recorder = new UserRecorder(); $info = $recorder->changePsw($inkey); if (!$info) { $status = new Status(C_ERROR, 'error.edit', '对不起,密码修改失败!'); break; } $status = new Status(C_SUCCESS, 'success.edit', '密码修改成功。'); } while (false); $supervisor->tplSn = $tplSn; $supervisor->status = $status; $supervisor->info = $info; return; } public function changePhoneNum() { /* @var $supervisor Supervisor */ global $supervisor; $inkey = array(); $tplSn = TplCenter::SN_NOTI; $info = null; $status = new Status(C_INIT); do { $power = new UserPower(); if (!$power->allow(User::modSn, BoLoader::AC_CHANGE_PHONE_NUM)) { $status = new Status(C_ERROR, 'error.nopower', '对不起,您没有相应的操作权限。'); break; } if (!isPosted()) { $this->display(); $info = $supervisor->info; if (!$info) { $status = new Status(C_ERROR, 'error.noexists', '用户不存在。'); break; } $tplSn = TplCenter::SN_CHANGE_PHONE_NUM; break; } /* @var $loader UserLoader */ $loader = new UserLoader(); $loader->changePhoneNum($inkey); if (true) { global /* @var $passport Passport */ $passport; $inkey['userId'] = $passport->userId; } /* @var $vali UserValidator */ $vali = new UserValidator(); $status = $vali->changePhoneNum($inkey); if ($status->getLabel() != C_SUCCESS) { $tplSn = TplCenter::SN_CHANGE_PHONE_NUM; break; } $recorder = new UserRecorder(); $info = $recorder->changePhoneNum($inkey); if (!$info) { $status = new Status(C_ERROR, 'error.edit', '对不起,手机号码修改失败!'); break; } $status = new Status(C_SUCCESS, 'success.edit', '手机号码修改成功。'); } while (false); $supervisor->tplSn = $tplSn; $supervisor->status = $status; $supervisor->info = $info; return; } public function changeUserEmail() { /* @var $supervisor Supervisor */ global $supervisor; $inkey = array(); $tplSn = TplCenter::SN_NOTI; $info = null; $status = new Status(C_INIT); do { $power = new UserPower(); if (!$power->allow(User::modSn, BoLoader::AC_CHANGE_PHONE_NUM)) { $status = new Status(C_ERROR, 'error.nopower', '对不起,您没有相应的操作权限。'); break; } if (!isPosted()) { $this->display(); $info = $supervisor->info; if (!$info) { $status = new Status(C_ERROR, 'error.noexists', '用户不存在。'); break; } $tplSn = 'ChangeUserEmail'; break; } /* @var $loader UserLoader */ $loader = new UserLoader(); $loader->changeUserEmail($inkey); if (true) { global /* @var $passport Passport */ $passport; $inkey['userId'] = $passport->userId; } /* @var $vali UserValidator */ $vali = new UserValidator(); $status = $vali->changeUserEmail($inkey); if ($status->getLabel() != C_SUCCESS) { $tplSn = 'ChangeUserEmail'; break; } $recorder = new UserRecorder(); $info = $recorder->changeUserEmail($inkey); if (!$info) { $status = new Status(C_ERROR, 'error.edit', '对不起,安全邮箱修改失败!'); break; } $status = new Status(C_SUCCESS, 'success.edit', '安全邮箱修改成功。'); } while (false); $supervisor->tplSn = $tplSn; $supervisor->status = $status; $supervisor->info = $info; return; } public function logout() { /* @var $supervisor Supervisor */ global $supervisor; $inkey = array(); $tplSn = TplCenter::SN_NOTI; $info = null; $status = new Status(C_INIT); global $operationContent; do { $power = new UserPower(); if (!$power->allow(User::modSn, BoLoader::AC_LOGOUT)) { $status = new Status(C_ERROR, 'error.nopower', '对不起,您没有相应的操作权限。'); break; } /* @var $loader UserLoader */ $loader = new UserLoader(); $loader->logout($inkey); global /* @var $passport Passport */ $passport; LoginAlive::logout(); $operationContent = sprintf('退出成功'); if (!$passport || !$passport->userAccount) { $status = new Status(C_ERROR, 'error.logout', '退出失败,您尚未登录!'); break; } if ($passport->userAccount != $inkey['userAccount']) { $status = new Status(C_ERROR, 'error.logout', '退出失败,退出链接有误!'); break; } if (!session_destroy()) { $status = new Status(C_ERROR, 'error.logout', '对不起,退出失败!'); break; } if ($inkey['cause'] == 'login_success_nopower') { $status = new Status(C_SUCCESS, 'success.logout', '登录成功,但没有相应操作权限,现已退出。'); break; } $status = new Status(C_SUCCESS, 'success.logout', '退出成功。'); } while (false); $supervisor->tplSn = $tplSn; $supervisor->status = $status; $supervisor->info = $info; return; } public function json_check() { /* @var $supervisor Supervisor */ global $supervisor; $inkey = array(); $tplSn = TplCenter::SN_NOTI; $info = null; do { $loader = new UserLoader(); $loader->json_check($inkey); $vali = new UserValidator(); $status = $vali->json_check($inkey); if ($status->getLabel() != C_SUCCESS) { break; } $recorder = new UserRecorder(); $info = $recorder->json_check($inkey); if (!$info) { $status = new Status(C_ERROR, 'error.noexists', '查询错误。'); break; } $status = new Status(C_SUCCESS, 'success.exists', '有查询结果。'); } while (false); $supervisor->tplSn = $tplSn; $supervisor->status = $status; $supervisor->info = $info; return; } public function json_phone_check() { /* @var $supervisor Supervisor */ global $supervisor; $inkey = array(); $tplSn = TplCenter::SN_NOTI; $info = null; do { $loader = new UserLoader(); $loader->json_phone_check($inkey); $vali = new UserValidator(); $status = $vali->json_phone_check($inkey); if ($status->getLabel() != C_SUCCESS) { break; } $recorder = new UserRecorder(); $info = $recorder->json_phone_check($inkey); if (!$info) { $status = new Status(C_ERROR, 'error.noexists', '查询错误。'); break; } $status = new Status(C_SUCCESS, 'success.exists', '有查询结果。'); } while (false); $supervisor->tplSn = $tplSn; $supervisor->status = $status; $supervisor->info = $info; return; } public function json_email_check() { /* @var $supervisor Supervisor */ global $supervisor; $inkey = array(); $tplSn = TplCenter::SN_NOTI; $info = null; do { $loader = new UserLoader(); $loader->json_email_check($inkey); $vali = new UserValidator(); $status = $vali->json_email_check($inkey); if ($status->getLabel() != C_SUCCESS) { break; } $recorder = new UserRecorder(); $info = $recorder->json_email_check($inkey); if (!$info) { $status = new Status(C_ERROR, 'error.noexists', '查询错误。'); break; } $status = new Status(C_SUCCESS, 'success.exists', '有查询结果。'); } while (false); $supervisor->tplSn = $tplSn; $supervisor->status = $status; $supervisor->info = $info; return; } }