Commit 275e33e2 authored by SeekArt's avatar SeekArt
Browse files

提交初始版本

parent c3ec1241
Showing with 930 additions and 0 deletions
+930 -0
<?php
<?php
use application\core\utils\Cache;
use application\core\utils\IBOS;
use application\core\utils\String;
use application\modules\main\model\Setting;
function getScriptUrl() {
$phpSelf = '';
$scriptName = basename( $_SERVER['SCRIPT_FILENAME'] );
if ( basename( $_SERVER['SCRIPT_NAME'] ) === $scriptName ) {
$phpSelf = $_SERVER['SCRIPT_NAME'];
} else if ( basename( $_SERVER['PHP_SELF'] ) === $scriptName ) {
$phpSelf = $_SERVER['PHP_SELF'];
} else if ( isset( $_SERVER['ORIG_SCRIPT_NAME'] ) && basename( $_SERVER['ORIG_SCRIPT_NAME'] ) === $scriptName ) {
$phpSelf = $_SERVER['ORIG_SCRIPT_NAME'];
} else if ( ($pos = strpos( $_SERVER['PHP_SELF'], '/' . $scriptName )) !== false ) {
$phpSelf = substr( $_SERVER['SCRIPT_NAME'], 0, $pos ) . '/' . $scriptName;
} else if ( isset( $_SERVER['DOCUMENT_ROOT'] ) && strpos( $_SERVER['SCRIPT_FILENAME'], $_SERVER['DOCUMENT_ROOT'] ) === 0 ) {
$phpSelf = str_replace( '\\', '/', str_replace( $_SERVER['DOCUMENT_ROOT'], '', $_SERVER['SCRIPT_FILENAME'] ) );
$phpSelf[0] != '/' && $phpSelf = '/' . $phpSelf;
} else {
throw new Exception( IBOS::lang( 'Request tainting', 'error' ) );
}
return $phpSelf;
}
function geturl() {
$phpself = getScriptUrl();
$isHTTPS = (isset( $_SERVER['HTTPS'] ) && strtolower( $_SERVER['HTTPS'] ) != 'off') ? true : false;
$url = String::ihtmlSpecialChars( 'http' . ($isHTTPS ? 's' : '') . '://' . $_SERVER['HTTP_HOST'] . $phpself );
return $url;
}
// 根目录
define( 'PATH_ROOT', dirname( __FILE__ ) . '/../../' );
define( 'TIMESTAMP', time() );
define( 'YII_DEBUG', true );
$defines = PATH_ROOT . '/system/defines.php';
$yii = PATH_ROOT . '/library/yii.php';
$config = PATH_ROOT . '/system/config/common.php';
require_once ( $defines );
require_once ( $yii );
Yii::setPathOfAlias( 'application', PATH_ROOT . DIRECTORY_SEPARATOR . 'system' );
$ibos = Yii::createApplication( 'application\core\components\Application', $config );
$value = Setting::model()->fetchSettingValueByKey( 'im' );
$im = unserialize( $value );
$imCfg = $im['qq'];
define( 'OAUTH2_TOKEN', 'https://openapi.b.qq.com/oauth2/token' );
define( 'OPEN_CALLBACKURL', geturl() ); //此URL需要登记到企业QQ
if ( isset( $_GET['code'] ) ) {
$code = $_GET['code'];
$query = array(
'grant_type' => 'authorization_code',
'app_id' => $imCfg['appid'],
'app_secret' => $imCfg['appsecret'],
'code' => $code,
'state' => md5( rand() ),
'redirect_uri' => OPEN_CALLBACKURL,
);
$options = array(
CURLOPT_RETURNTRANSFER => true, // 返回页面内容
CURLOPT_HEADER => false, // 不返回头部
CURLOPT_ENCODING => "", // 处理所有编码
CURLOPT_USERAGENT => "spider", //
CURLOPT_AUTOREFERER => true, // 自定重定向
CURLOPT_CONNECTTIMEOUT => 15, // 链接超时时间
CURLOPT_TIMEOUT => 120, // 超时时间
CURLOPT_MAXREDIRS => 10, // 超过十次重定向后停止
CURLOPT_POST => 0, // 是否post提交数据
CURLOPT_POSTFIELDS => "", // post的值
CURLOPT_SSL_VERIFYHOST => 0, // 不检查ssl链接
CURLOPT_SSL_VERIFYPEER => false, //
CURLOPT_VERBOSE => 1 //
);
$url = OAUTH2_TOKEN . '?' . http_build_query( $query );
$curl = curl_init( $url );
if ( curl_setopt_array( $curl, $options ) ) {
$result = curl_exec( $curl );
}
curl_close( $curl );
if ( false !== $result ) {
$company_info = json_decode( $result, true );
if ( $company_info['ret'] == 0 ) {
$data = $company_info['data'];
$imCfg['id'] = $data['open_id'];
$imCfg['token'] = $data['access_token'];
$imCfg['refresh_token'] = $data['refresh_token'];
$imCfg['expires_in'] = $data['expires_in'];
$imCfg['time'] = time();
$im['qq'] = $imCfg;
Setting::model()->updateSettingValueByKey( 'im', $im );
Cache::update( array( 'setting' ) );
echo json_encode( array( 'ret' => 0 ) );
die();
}
}
}
echo json_encode( array( 'ret' => -1 ) );
die();
<?php
use application\core\utils\Env;
use application\core\utils\String;
use application\modules\main\model\Setting;
use application\modules\message\core\BQQApi;
use application\modules\user\model\UserBinding;
// 根目录
define( 'PATH_ROOT', dirname( __FILE__ ) . '/../../' );
define( 'TIMESTAMP', time() );
define( 'YII_DEBUG', true );
$defines = PATH_ROOT . '/system/defines.php';
$yii = PATH_ROOT . '/library/yii.php';
$config = PATH_ROOT . '/system/config/common.php';
require_once ( $defines );
require_once ( $yii );
require_once '../login.php';
Yii::setPathOfAlias( 'application', PATH_ROOT . DIRECTORY_SEPARATOR . 'system' );
Yii::createApplication( 'application\core\components\Application', $config );
$value = Setting::model()->fetchSettingValueByKey( 'im' );
$im = unserialize( $value );
$imCfg = $im['qq'];
$cid = Env::getRequest( 'company_id' );
$openId = Env::getRequest( 'open_id' );
$hashskey = Env::getRequest( 'hashskey' );
$hashkey = Env::getRequest( 'hashkey' );
$returnurl = Env::getRequest( 'returnurl' );
if ( empty( $openId ) || empty( $hashskey ) || empty( $cid ) ) {
exit( '参数错误' );
}
$uid = UserBinding::model()->fetchUidByValue( String::filterCleanHtml( $openId ), 'bqq' );
if ( $uid ) {
$properties = array(
'company_id' => $cid,
'company_token' => $imCfg['token'],
'app_id' => $imCfg['appid'],
'client_ip' => Env::getClientIp()
);
$api = new BQQApi( $properties );
$status = $api->getVerifyStatus( array( 'open_id' => $openId, 'hashskey' => $hashskey ) );
if ( $status['ret'] == 0 ) {
dologin( $uid, 'bqqsso' );
if ( $returnurl == 'index' ) {
header( 'Location: ../../index.php', true );
} else {
$url = parse_url( $returnurl );
if ( isset( $url['scheme'] ) ) {
header( 'Location:' . $returnurl, true );
} else {
header( 'Location:../../' . $returnurl, true );
}
}
} else {
Env::iExit( $status['msg'] );
}
} else {
Env::iExit( '该用户未绑定企业QQ' );
}
<?php
use application\core\utils\Env;
use application\core\utils\String;
use application\modules\main\model\Setting;
use application\modules\user\model\User;
// 程序根目录路径
define( 'PATH_ROOT', dirname( __FILE__ ) . '/../../' );
$defines = PATH_ROOT . '/system/defines.php';
define( 'YII_DEBUG', true );
define( 'TIMESTAMP', time() );
define( 'CALLBACK', true );
$yii = PATH_ROOT . '/library/yii.php';
$mainConfig = require_once PATH_ROOT . '/system/config/common.php';
require_once ( $defines );
require_once ( $yii );
require_once ( '../login.php' );
Yii::setPathOfAlias( 'application', PATH_ROOT . DIRECTORY_SEPARATOR . 'system' );
Yii::createApplication( 'application\core\components\Application', $mainConfig );
// 接收信息处理
$result = trim( file_get_contents( "php://input" ), " \t\n\r" );
// 解析
if ( !empty( $result ) ) {
$msg = json_decode( $result, true );
switch ( $msg['op'] ) {
case 'verify':
$res = doverify( $msg['username'], $msg['password'] );
if ( $res['isSuccess'] == true ) {
$aeskey = Setting::model()->fetchSettingValueByKey( 'aeskey' );
$res['aeskey'] = $aeskey;
}
break;
default:
$res = array( 'isSuccess' => false, 'msg' => '未知操作' );
break;
}
Env::iExit( json_encode( $res ) );
}
/**
*
* @param string $userName 用户名
* @param string $password 密码
* @return array
*/
function doverify( $userName, $password ) {
if ( String::isMobile( $userName ) ) {
$loginField = 'mobile';
} else if ( String::isEmail( $userName ) ) {
$loginField = 'email';
} else {
$loginField = 'username';
}
$user = User::model()->fetch( $loginField . ' = :name', array( ':name' => $userName ) );
if ( !empty( $user ) ) {
$password = md5( $password . $user['salt'] );
if ( strcmp( $user['password'], $password ) != 0 ) {
return array( 'isSuccess' => false, 'msg' => '身份验证失败' );
}
if ( !$user['isadministrator'] ) {
return array( 'isSuccess' => false, 'msg' => '非管理员身份不能进行此操作' );
}
return array( 'isSuccess' => true );
}
return array( 'isSuccess' => false, 'msg' => '身份验证失败' );
}
<?php
use application\core\utils\Env;
use application\core\utils\String;
use application\modules\main\model\Setting;
use application\modules\user\model\User;
use application\modules\user\model\UserBinding;
// CORS 设置
header( 'Access-Control-Allow-Headers: Origin, Accept, Content-Type, Authorization, ISCORS' );
header( 'Access-Control-Allow-Credentials: true' );
header( 'Access-Control-Allow-Methods: POST, GET, PUT, OPTIONS, DELETE' );
if ( isset( $_SERVER['HTTP_ORIGIN'] ) ) {
header( 'Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN'] );
}
if ( $_SERVER['REQUEST_METHOD'] == 'OPTIONS' ) {
exit();
}
// 程序根目录路径
define( 'PATH_ROOT', dirname( __FILE__ ) . '/../../../' );
$defines = PATH_ROOT . '/system/defines.php';
define( 'YII_DEBUG', true );
define( 'TIMESTAMP', time() );
$yii = PATH_ROOT . '/library/yii.php';
$mainConfig = require_once PATH_ROOT . '/system/config/common.php';
require_once ( $defines );
require_once ( $yii );
require_once '../../login.php';
Yii::setPathOfAlias( 'application', PATH_ROOT . DIRECTORY_SEPARATOR . 'system' );
Yii::createApplication( 'application\core\components\Application', $mainConfig );
$userId = Env::getRequest( 'userid' );
$timestamp = Env::getRequest( 'timestamp' );
$redirect = Env::getRequest( 'redirect' );
$signature = Env::getRequest( 'signature' );
$op = Env::getRequest( 'op' );
$aeskey = Setting::model()->fetchSettingValueByKey( 'aeskey' );
if ( strcmp( $signature, sha1( $aeskey . $timestamp ) ) != 0 ) {
Env::iExit( '签名验证错误' );
}
if ( $op == "bind" ) {
$from = "co";
$userName = Env::getRequest( 'username' );
$password = Env::getRequest( 'password' );
$replace = Env::getRequest( 'replace' );
$check = checkAndBind( $userName, $password, $userId, $from, $replace );
if ( $check == 1 ) {
$msg = "用户已绑定,你可以输入新的账号绑定或者检查你的酷办公账号是否正确<br />";
$url = "?userid={$userId}&timestamp={$timestamp}&redirect={$redirect}&signature={$signature}&username={$userName}&password={$password}&op=bind&replace=1";
showBind( $msg, $url );
exit();
}
if ( $check > 1 ) {
$msg = "用户名或密码错误,请核对后重新输入<br />";
showBind( $msg );
exit();
}
}
checkBind( $userId, $redirect );
function checkBind( $userId, $redirect ) {
$isSuccess = false;
if ( !empty( $userId ) ) {
$uid = UserBinding::model()->fetchUidByValue( $userId, 'co' );
if ( !empty( $uid ) ) {
dologin( $uid );
$isSuccess = true;
}
}
if ( !empty( $redirect ) ) {
$url = rawurldecode( $redirect );
$parse = parse_url( $url );
if ( $isSuccess ) {
if ( isset( $parse['scheme'] ) ) {
header( 'Location:' . $url, true );
exit();
} else {
header( 'Location:../../../' . $url, true );
exit();
}
} else {
$msg = "你的IBOS帐号可能还没有与酷办公绑定,请输入你的IBOS用户名密码来绑定你的帐户<br />";
showBind( $msg );
exit();
}
}
Env::iExit( json_encode( array( 'isSuccess' => $isSuccess ) ) );
}
function showBind( $msg, $url = "" ) {
$str = '<!DOCTYPE html><html><head><meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width"><meta http-equiv="content-type" content="text/html;charset=utf-8"></head><body>';
$str .= ' <style>';
$str .= ' body {background: #eee; line-height:1.4em;padding-top:20px;}';
$str .= ' .spacer{clear:both; height:1px;}';
$str .= ' .myform{margin:0 auto;width:400px;padding:14px;}';
$str .= ' #stylized{border:solid 2px #cde;background:#f9fcff;}';
$str .= ' h1 {font-size:18px;font-weight:bold;margin-bottom:8px;}';
$str .= ' p{font-size:14px;color:#F95;margin-bottom:20px;border-bottom:solid 1px #b7ddf2;padding-bottom:10px;}';
$str .= ' label{font-weight:bold;text-align:right;width:140px;float:left;clear:left;}';
$str .= ' .small{display:block; text-align:right; color:#9bc; font-size:11px; font-weight: 400;}';
$str .= ' input{ float:left; width:200px; margin:2px 0 20px 10px; padding:8px; border:solid 1px #aacfe4; border-radius:5px; font-size:18px;}';
$str .= ' button{ clear:both; display: block; margin-left:150px; width:125px; padding: 10px; border: 0 none; background:#6ac;color:#FFF;font-size:14px;font-weight:bold;border-radius:5px;}button:hover{background:#49c}';
$str .= ' @media(max-width:430px){';
$str .= ' body{padding-top: 0; height: 800px;}';
$str .= ' .myform{ width: auto }';
$str .= ' label{ text-align: left; width: auto; float: none; }';
$str .= ' .small{ display: inline; text-align: left; }';
$str .= ' input{ box-sizing: border-box; width: 100%; float: none; display: block; margin-left: 0; }';
$str .= ' button{ box-sizing: border-box; width: 100%; margin-left: 0; padding-top: 15px; padding-bottom: 15px; } }';
$str .= ' </style>';
if ( $url ) {
$str .= ' <script> if(confirm("用户已被绑定其它酷办公帐号,确定重新绑定新帐号吗?")){location.href="' . $url . '";}';
$str .= ' </script>';
}
$str .= '<div id="stylized" class="myform"><form name="form" method="post" ><h1>绑定酷办公</h1><p>' . $msg . '</p>';
$str .= '<label>用户名<span class="small">填写你的IBOS用户名</span></label><input type="text" name="username" />';
$str .= '<label>密码<span class="small">输入你登录IBOS的密码</span></label><input type="password" name="password" />';
$str .= '<div class="spacer"></div><input type="hidden" name="op" value="bind" /><button type="submit">验证并绑定</button></form></div>';
$str .='</body></html>';
echo $str;
}
/**
*
* @param string $userName 用户名
* @param string $password 密码
* @return 0 成功,1 用户已绑定,2 密码错误,3用户不存在
*/
function checkAndBind( $userName, $password, $guid, $from, $replace = FALSE ) {
// 登录类型
if ( String::isMobile( $userName ) ) {
$loginField = 'mobile';
} else if ( String::isEmail( $userName ) ) {
$loginField = 'email';
} else {
$loginField = 'username';
};
$user = User::model()->fetch( $loginField . ' = :name', array( ':name' => $userName ) );
if ( !empty( $user ) ) {
$password = md5( md5( $password ) . $user['salt'] );
if ( strcmp( $user['password'], $password ) == 0 ) {
$userBind = UserBinding::model()->fetch( 'uid = :uid AND app = :app', array( ':uid' => $user['uid'], ':app' => $from ) );
if ( empty( $userBind ) ) {
//绑定与第三方对接,如酷办公
UserBinding::model()->add( array( 'uid' => $user['uid'], 'bindvalue' => $guid, 'app' => $from ) );
return 0;
} elseif ( $replace ) {
UserBinding::model()->modify( $userBind['id'], array( 'uid' => $user['uid'], 'bindvalue' => $guid, 'app' => $from ) );
return 0;
} else {
return 1; //用户已绑定
}
}
return 2;
//密码错误
}
return 3; //用户不存在
}
<?php
use application\core\utils\Cache as CacheUtil;
use application\core\utils\Env;
use application\core\utils\IBOS;
use application\core\utils\Org;
use application\core\utils\String;
use application\modules\dashboard\model\Syscache;
use application\modules\main\model\Setting;
use application\modules\user\model\User;
use application\modules\user\model\UserBinding;
use application\modules\user\model\UserCount;
use application\modules\user\model\UserProfile;
use application\modules\user\model\UserStatus;
use application\modules\user\utils\User as UserUtil;
// 程序根目录路径
define( 'PATH_ROOT', dirname( __FILE__ ) . '/../../' );
$defines = PATH_ROOT . '/system/defines.php';
define( 'YII_DEBUG', true );
define( 'TIMESTAMP', time() );
define( 'CALLBACK', true );
$yii = PATH_ROOT . '/library/yii.php';
$mainConfig = require_once PATH_ROOT . '/system/config/common.php';
require_once ( $defines );
require_once ( $yii );
require_once ( '../login.php' );
Yii::setPathOfAlias( 'application', PATH_ROOT . DIRECTORY_SEPARATOR . 'system' );
Yii::createApplication( 'application\core\components\Application', $mainConfig );
// 接收的参数
$signature = rawurldecode( Env::getRequest( 'signature' ) );
$timestamp = Env::getRequest( 'timestamp' );
$aeskey = Setting::model()->fetchSettingValueByKey( 'aeskey' );
if ( strcmp( $signature, sha1( $aeskey . $timestamp ) ) != 0 ) {
Env::iExit( '签名验证错误' );
}
// 接收信息处理
$result = trim( file_get_contents( "php://input" ), " \t\n\r" );
// 解析
if ( !empty( $result ) ) {
$msg = json_decode( $result, true );
switch ( $msg['op'] ) {
case 'getuser':
$res = getUserList();
break;
case 'getbinding':
$res = getBindingList();
break;
case 'set':
$res = setBinding( $msg['data'] );
break;
case 'unbind':
$res = setUnbind();
break;
case 'creatuser' :
$res = setCreat( $msg['data'] );
break;
default:
$res = array( 'isSuccess' => false, 'msg' => '未知操作' );
break;
}
Env::iExit( json_encode( $res ) );
}
/**
*
* @return array
*/
function getUserList() {
$users = array();
$cache = Syscache::model()->fetchAllCache( 'users' );
if ( !empty( $cache['users'] ) ) {
foreach ( $cache['users'] as $user ) {
$users[] = array(
'uid' => $user['uid'],
'realname' => $user['realname']
);
}
}
return array(
'isSuccess' => true,
'data' => $users
);
}
/**
* 获取绑定用户数组
* @return array
*/
function getBindingList() {
$bindings = UserBinding::model()->fetchAllByApp( 'co' );
$users = array();
if ( !empty( $bindings ) ) {
foreach ( $bindings as $row ) {
$user = User::model()->findByPk( $row['uid'] );
if ( !empty( $user ) ) {
$users[] = array(
'uid' => $row['uid'],
'bindvalue' => $row['bindvalue'],
'realname' => $user->realname,
);
}
}
}
return array(
'isSuccess' => true,
'data' => $users
);
}
/**
* 设置绑定用户列表
* @param array $list
* @return array
*/
function setBinding( $list ) {
UserBinding::model()->deleteAllByAttributes( array( 'app' => 'co' ) );
$count = 0;
foreach ( $list as $row ) {
$res = UserBinding::model()->add( array( 'uid' => $row['uid'], 'bindvalue' => $row['guid'], 'app' => 'co' ) );
$res and $count++;
}
// 设置绑定标识
if ( $count > 0 ) {
Setting::model()->updateSettingValueByKey( 'cobinding', '1' );
}
return array( 'isSuccess' => true );
}
/**
* 解除绑定
* @return
*/
function setUnbind() {
UserBinding::model()->deleteAllByAttributes( array( 'app' => 'co' ) );
Setting::model()->updateSettingValueByKey( 'cobinding', '0' );
Setting::model()->updateSettingValueByKey( 'coinfo', '' );
return array( 'isSuccess' => true );
}
/**
* 创建并绑定用户
* @param array $param
* @return array
*/
function setCreat( $param ) {
$param['salt'] = !empty( $param['salt'] ) ? $param['salt'] : String::random( 6 );
$param['password'] = !empty( $param['password'] ) ? $param['password'] : md5( $param['mobile'] . $param['salt'] );
$param['groupid'] = !empty( $param['groupid'] ) ? $param['groupid'] : '2';
$param['createtime'] = TIMESTAMP;
$data = User::model()->create( $param );
$newId = User::model()->add( $data, true );
if ( $newId ) {
UserCount::model()->add( array( 'uid' => $newId ) );
$ip = IBOS::app()->setting->get( 'clientip' );
UserStatus::model()->add(
array(
'uid' => $newId,
'regip' => $ip,
'lastip' => $ip
)
);
UserProfile::model()->add( array( 'uid' => $newId ) );
// 创建绑定
$res = UserBinding::model()->add( array( 'uid' => $newId, 'bindvalue' => $param['guid'], 'app' => 'co' ) );
// 重建缓存,给新加的用户生成缓存
// $newUser = User::model()->fetchByPk($newId);
// $users = UserUtil::loadUser();
// $users[$newId] = UserUtil::wrapUserInfo($newUser);
// User::model()->makeCache($users);
// 更新组织架构js调用接口
// Org::update();
// 同步用户钩子
// Org::hookSyncUser($newId, $origPass, 1);
// CacheUtil::update();
} else {
return array( 'isSuccess' => FALSE );
}
return array( 'isSuccess' => true );
}
<?php
use application\core\model\Log;
use application\core\utils\Env;
use application\core\utils\IBOS;
use application\core\utils\String;
use application\modules\dashboard\model\Syscache;
use application\modules\main\utils\Main;
use application\modules\user\components\UserIdentity;
use application\modules\user\model\User;
use application\modules\user\utils\User as UserUtil;
/**
* 执行登录操作
* @param type $uid
* @throws Exception
*/
function dologin( $uid, $log = '' ) {
$config = @include PATH_ROOT . '/system/config/config.php';
if ( empty( $config ) ) {
throw new Exception( IBOS::Lang( 'Config not found', 'error' ) );
} else {
define( 'IN_MOBILE', Env::checkInMobile() );
$global = array(
'clientip' => Env::getClientIp(),
'config' => $config,
'timestamp' => time()
);
IBOS::app()->setting->copyFrom( $global );
LoadSysCache();
if ( IBOS::app()->user->isGuest ) {
$saltkey = Main::getCookie( 'saltkey' );
if ( empty( $saltkey ) ) {
$saltkey = String::random( 8 );
Main::setCookie( 'saltkey', $saltkey, 86400 * 30, 1, 1 );
}
$curUser = User::model()->fetchByUid( $uid );
// 开始登录
// 登录类型
if ( String::isMobile( $curUser['username'] ) ) {
$loginType = 4;
} else if ( String::isEmail( $curUser['username'] ) ) {
$loginType = 2;
} else {
$loginType = 1;
};
$identity = new UserIdentity( $curUser['username'], $curUser['password'], $loginType );
$identity->setId( $uid );
$identity->setPersistentStates( $curUser );
$ip = IBOS::app()->setting->get( 'clientip' );
// 先删除cookie,否则初始化user组件会出错
foreach ( $_COOKIE as $k => $v ) {
$cookiePath = $config['cookie']['cookiepath'];
$cookieDomain = $config['cookie']['cookiedomain'];
$secure = $_SERVER['SERVER_PORT'] == 443 ? 1 : 0;
@setcookie( $k, "", time() - 86400, $cookiePath, $cookieDomain, $secure, false );
}
// 是否允许多个账户同时登录
$account = IBOS::app()->setting->get( 'setting/account' );
$user = IBOS::app()->user;
if ( $account['allowshare'] != 1 ) {
$user->setStateKeyPrefix( IBOS::app()->setting->get( 'sid' ) );
}
$user->login( $identity );
if ( !empty( $log ) ) {
$logArr = array(
'terminal' => $log,
'password' => '',
'ip' => $ip,
'user' => $curUser['username'],
'loginType' => $identity::LOGIN_BY_USERNAME,
'address' => '',
'gps' => ''
);
Log::write( $logArr, 'login', sprintf( 'module.user.%d', $uid ) );
$rule = UserUtil::updateCreditByAction( 'daylogin', $uid );
if ( !$rule['updateCredit'] ) {
UserUtil::checkUserGroup( $uid );
}
}
}
}
}
/**
* 加载系统设置
* @param mixed $event
*/
function LoadSysCache() {
$caches = Syscache::model()->fetchAll();
foreach ( $caches as $cache ) {
$value = $cache['type'] == '1' ? unserialize( $cache['value'] ) : $cache['value'];
if ( $cache['name'] == 'setting' ) {
IBOS::app()->setting->set( 'setting', $value );
} else {
IBOS::app()->setting->set( 'cache/' . $cache['name'], $value );
}
}
}
<?php
use application\core\utils\Attach;
use application\core\utils\Env;
use application\core\utils\File;
use application\core\utils\IBOS;
use application\core\utils\String;
use application\modules\calendar\model\Tasks;
use application\modules\file\core\FileCloud;
use application\modules\message\core\wx\WxApi;
define( 'PATH_ROOT', dirname( __FILE__ ) . '/../../' );
$defines = PATH_ROOT . '/system/defines.php';
define( 'TIMESTAMP', time() );
define( 'YII_DEBUG', true );
$yii = PATH_ROOT . '/library/yii.php';
$mainConfig = require_once PATH_ROOT . '/system/config/common.php';
require_once ( $defines );
require_once ( $yii );
require_once '../login.php';
Yii::setPathOfAlias( 'application', PATH_ROOT . DIRECTORY_SEPARATOR . 'system' );
Yii::createApplication( 'application\core\components\Application', $mainConfig );
// callback类型
$type = Env::getRequest( 'type' );
// callback参数
$param = Env::getRequest( 'param' );
$config = @include PATH_ROOT . '/system/config/config.php';
if ( empty( $config ) ) {
close( IBOS::Lang( 'Config not found', 'error' ) );
} else {
define( 'IN_MOBILE', Env::checkInMobile() );
$global = array(
'clientip' => Env::getClientIp(),
'config' => $config,
'timestamp' => time()
);
IBOS::app()->setting->copyFrom( $global );
// 加载系统缓存以初始化用户组件
LoadSysCache();
if ( !IBOS::app()->user->isGuest ) {
switch ( $type ) {
case 'attach':
$userId = Env::getRequest( 'userid' );
$appId = Env::getRequest( 'appid' );
doAttachDownload( $userId, $appId, $param );
break;
case 'todo':
completeTodo( $param );
break;
case 'quicklogin':
doquicklogin( $param );
break;
default:
break;
}
} else {
close( '身份信息已经过期,请重新请求' );
}
}
function close( $msg ) {
$exit = <<<EOT
<script>
document.addEventListener("WeixinJSBridgeReady", function(){
if(window.confirm('{$msg}')){
WeixinJSBridge.invoke('closeWindow',{},function(res){
});
}
}, false);
</script>
EOT;
Env::iExit( $exit );
}
/**
* 完成一个待办
* @param mixed $id
* @return void
*/
function completeTodo( $id ) {
Tasks::model()->modifyTasksComplete( $id, 1 );
Tasks::model()->updateCalendar( $id, 1 );
return close( '已经完成该任务,需要关闭页面吗?' );
}
/**
* 执行快速登录触发操作:写入内容给监听的txt文件,然后前端可触发事件
* @param string $code
* @return void
*/
function doquicklogin( $code ) {
$file = PATH_ROOT . './data/temp/login_' . $code . '.txt';
$uid = IBOS::app()->user->uid;
file_put_contents( $file, String::authCode( $uid, 'ENCODE', $code ) );
return close( '登录成功,请关闭窗口' );
}
/**
* 处理附件下载
* @param string $userId 微信用户ID
* @param integer $appId 应用ID
* @param string $aid 带附件类型的附件ID字符串
* @return mixed
*/
function doAttachDownload( $userId, $appId, $aid ) {
$agent = strtolower( $_SERVER['HTTP_USER_AGENT'] );
$isIphone = (strpos( $agent, 'iphone' )) ? true : false;
list($type, $id) = explode( '/', $aid );
if ( $type == 'cloud' ) {
list($id, $cloud) = explode( '-', $id );
} else {
$cloud = 0;
}
$attachs = Attach::getAttachData( $id );
$attach = array_shift( $attachs );
if ( $attach['uid'] != IBOS::app()->user->uid ) {
return close( '您没有权限下载此文件' );
}
$filepath = File::getAttachUrl() . '/' . $attach['attachment'];
if ( $cloud ) {
$core = new FileCloud( $cloud );
$url = $core->getRealUrl( $filepath );
} else {
$url = IBOS::app()->request->getHostInfo() . '/' . $filepath;
}
if ( $isIphone ) {
header( 'Location:' . $url, true );
exit();
} else {
Env::iExit( "<h1>微信现只支持IOS系统在微信内打开下载,请长按链接选择打开或者复制下载链接到手机浏览器下载<br/>$url</h1>" );
}
}
<?php
use application\core\utils\Env;
use application\modules\message\core\wx\Factory;
use application\modules\message\core\wx\WxApi;
use application\modules\user\model\UserBinding;
// 程序根目录路径
define( 'PATH_ROOT', dirname( __FILE__ ) . '/../../' );
$defines = PATH_ROOT . '/system/defines.php';
define( 'TIMESTAMP', time() );
define( 'YII_DEBUG', true );
define( 'CALLBACK', true );
$yii = PATH_ROOT . '/library/yii.php';
$mainConfig = require_once PATH_ROOT . '/system/config/common.php';
require_once ( $defines );
require_once ( $yii );
require_once ( '../login.php' );
Yii::setPathOfAlias( 'application', PATH_ROOT . DIRECTORY_SEPARATOR . 'system' );
Yii::createApplication( 'application\core\components\Application', $mainConfig );
// 接收的参数
$msgSignature = rawurldecode( Env::getRequest( 'msgSignature' ) );
$timestamp = rawurldecode( Env::getRequest( 'timestamp' ) );
$aeskey = WxApi::getInstance()->getAeskey();
$echoStr = rawurldecode( Env::getRequest( 'echoStr' ) );
if ( strcmp( $msgSignature, md5( $aeskey . $timestamp ) ) != 0 ) {
Env::iExit( 'access denied' );
}
if ( !empty( $echoStr ) ) {
WxApi::getInstance()->resetCorp();
Env::iExit( $echoStr );
}
// 接收信息处理
$result = trim( file_get_contents( "php://input" ), " \t\n\r" );
// 解析
if ( !empty( $result ) ) {
$msg = json_decode( $result, true );
if ( !empty( $msg ) ) {
$uid = UserBinding::model()->fetchUidByValue( $msg['properties']['userId'], 'wxqy' );
if ( $uid ) {
dologin( $uid );
$factory = new Factory();
$res = $factory->createHandle( $msg['class'], $msg['properties'] )->handle();
} else {
$res = resByText( $userId, $corpId, $newTime, '您的账号尚未绑定,无法进行任何操作' );
}
Env::iExit( $res );
} else {
Env::iExit( '' );
}
}
/**
* 以文本格式回复
* @param string $userId
* @param string $corpId
* @param integer $newTime
* @param string $text
* @return string
*/
function resByText( $userId, $corpId, $newTime, $text = '' ) {
return "<xml>
<ToUserName><![CDATA[{$userId}]]></ToUserName>
<FromUserName><![CDATA[{$corpId}]]></FromUserName>
<CreateTime>{$newTime}</CreateTime>
<MsgType><![CDATA[text]]></MsgType>
<Content><![CDATA[{$text}]]></Content>
</xml>";
}
<?php
use application\core\utils\Env;
use application\core\utils\IBOS;
use application\modules\main\model\Setting;
use application\modules\user\model\UserBinding;
// 程序根目录路径
define( 'PATH_ROOT', dirname( __FILE__ ) . '/../../../' );
define( 'YII_DEBUG', true );
$defines = PATH_ROOT . '/system/defines.php';
defined( 'TIMESTAMP' ) or define( 'TIMESTAMP', time() );
$yii = PATH_ROOT . '/library/yii.php';
$mainConfig = require_once PATH_ROOT . '/system/config/common.php';
require_once ( $defines );
require_once ( $yii );
require_once '../../login.php';
Yii::setPathOfAlias( 'application', PATH_ROOT . DIRECTORY_SEPARATOR . 'system' );
Yii::createApplication( 'application\core\components\Application', $mainConfig );
$signature = Env::getRequest( 'signature' );
$aeskey = Setting::model()->fetchSettingValueByKey( 'aeskey' );
$userId = Env::getRequest( 'userid' );
if ( strcmp( $signature, md5( $aeskey . $userId ) ) != 0 ) {
Env::iExit( "签名错误" );
}
if ( !empty( $userId ) ) {
$uid = UserBinding::model()->fetchUidByValue( $userId, 'wxqy' );
if ( $uid ) {
dologin( $uid );
if ( !IBOS::app()->user->isGuest ) {
$redirect = Env::getRequest( 'redirect' );
$url = base64_decode( $redirect );
$parse = parse_url( $url );
if ( isset( $parse['scheme'] ) ) {
header( 'Location:' . $url, true );
exit();
} else {
header( 'Location:../../../' . $url, true );
exit();
}
}
Env::iExit( IBOS::app()->user->isGuest ? 'fail' : 'success' );
}
}
Env::iExit( '用户验证失败,尝试以下步骤的操作:<br/>'
. '1、在“微信企业号->通讯录”,找到并删除该用户<br/>'
. '2、在“IBOS后台->微信->部门及用户同步”,同步该用户<br/>'
. '3、邀请该用户关注企业号<br/>'
. '如果还存在此提示,请将问题反馈给我们的工作人员' );
data/attachment/article/201406/12/152632bocuicut9uvxjvy4.png

238 KB

data/attachment/article/201406/12/152632mu3v111x1xbmg39k.png

323 KB

data/attachment/article/201406/12/152658147lnf4wf13llk6o.png

333 KB

data/attachment/article/201406/12/152749izmygggpnigpzseq.png

323 KB

data/attachment/article/201406/12/152750dks4sx49kkecicse.png

333 KB

data/attachment/article/201406/12/152750ulvdvu51hv1p1bu9.png

238 KB

data/attachment/article/201406/12/1730558oyoffy3bnelhwfo.jpg

117 KB

data/attachment/article/201406/12/173055ddwyz7hhys06dgln.jpg

80 KB

data/attachment/article/201406/12/173055rdahnrnh78xmzmer.jpg

154 KB

data/attachment/article/201406/12/173056az6i5f3xpna0p0mf.jpg

81.1 KB

Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment