<?php
$platformFileMap = array('weixinqy' => 'inc/weixinqy/class/weixinqy.base.funcs.php', 'dingding' => 'inc/dingding/class/dingding.base.funcs.php', 'qyweixin' => 'inc/qyweixin/class/qyweixin.base.funcs.php');
$platformClassMap = array('weixinqy' => 'WeiXinQY', 'dingding' => 'DingDing', 'qyweixin' => 'QYWeiXin');
$platformIdMap = array('weixinqy' => 8, 'dingding' => 9, 'qyweixin' => 10);
$agentid = '';
$state = addslashes($_GET['state']);
$code = addslashes($_GET['code']);
$state_arr = explode('_', $state);
$agentid = intval($state_arr[1]);
$platform = 'qyweixin';
$class = $platformClassMap[$platform];
$platformId = $platformIdMap[$platform];
include_once $platformFileMap[$platform];
$sql = 'SELECT app_name from qyweixin_app where app_id=\'' . $agentid . '\'';
$result = exequery(TD::conn(), $sql);
if ($row = mysql_fetch_array($result)) {
$app_name = $row['app_name'];
}
$platformInstance = new $class($app_name);
$params = array('agentid' => intval($agentid), 'code' => $code);
$userid = $platformInstance->getUserId($params, $app_name);
header("Location: http://XXXXX/general/app/sso.php?qywxuid=$userid");
?>
sso.php
<?
include_once 'inc/session.php';
session_start();
if (!$_SESSION['LOGIN_UID']) {
$userid2 = $_GET['qywxuid'];
$query = 'SELECT user_id from user_qyweixin where open_id=\'' . $userid2 . '\'';
$cursor = exequery(TD::conn(), $query);
if ($row = mysql_fetch_array($cursor)) {
$userid = $row['user_id'];
}
if(!$userid){
header("Location: /app/index.html?qywxuid=$userid2");exit;
echo "用户绑定错误,请联系系统管理员。企业微信用户名: $userid2";exit;
}
$query = 'SELECT * from USER where USER_ID=\'' . $userid . '\'';
$cursor = exequery(TD::conn(), $query);
if ($ROW = mysql_fetch_array($cursor)) {
$UID = $ROW['UID'];
$USER_ID = $ROW['USER_ID'];
$BYNAME = $ROW['BYNAME'];
$USER_NAME = $ROW['USER_NAME'];
$LOGIN_USER_PRIV = $ROW['USER_PRIV'];
$USER_PRIV_OTHER = $ROW['USER_PRIV_OTHER'];
$LOGIN_AVATAR = $ROW['AVATAR'];
$LOGIN_DEPT_ID = $ROW['DEPT_ID'];
$LOGIN_DEPT_ID_OTHER = $ROW['DEPT_ID_OTHER'];
$LOGIN_THEME = $ROW['THEME'];
$LOGIN_NOT_VIEW_USER = $ROW['NOT_VIEW_USER'];
$LOGIN_USER_SEX = $ROW['SEX'];
}
include_once 'inc/utility_org.php';
$LOGIN_FUNC_STR = '';
$query1 = 'select user_func_id_str from user_function where uid=\'' . $UID . '\'';
$cursor1 = exequery(TD::conn(), $query1);
if ($row = mysql_fetch_array($cursor1)) {
$LOGIN_FUNC_STR = $row['user_func_id_str'];
}
$LOGIN_UID = $UID;
$LOGIN_USER_ID = $USER_ID;
$LOGIN_BYNAME = $BYNAME;
$LOGIN_USER_NAME = $USER_NAME;
$LOGIN_ANOTHER = '0';
$LOGIN_USER_PRIV_OTHER = $USER_PRIV_OTHER;
$LOGIN_DEPT_ID_JUNIOR = GetUnionSetOfChildDeptId($LOGIN_DEPT_ID . ',' . $LOGIN_DEPT_ID_OTHER);
$_SESSION['LOGIN_UID'] = $LOGIN_UID;
$_SESSION['LOGIN_USER_ID'] = $LOGIN_USER_ID;
$_SESSION['LOGIN_BYNAME'] = $LOGIN_BYNAME;
$_SESSION['LOGIN_USER_NAME'] = $LOGIN_USER_NAME;
$_SESSION['LOGIN_USER_PRIV'] = $LOGIN_USER_PRIV;
$_SESSION['LOGIN_USER_PRIV_OTHER'] = $LOGIN_USER_PRIV_OTHER;
$_SESSION['LOGIN_SYS_ADMIN'] = $LOGIN_USER_PRIV == '1' || find_id($LOGIN_USER_PRIV_OTHER, '1') ? 1 : 0;
$_SESSION['LOGIN_DEPT_ID'] = $LOGIN_DEPT_ID;
$_SESSION['LOGIN_DEPT_ID_OTHER'] = $LOGIN_DEPT_ID_OTHER;
$_SESSION['LOGIN_AVATAR'] = $LOGIN_AVATAR;
$_SESSION['LOGIN_FUNC_STR'] = $LOGIN_FUNC_STR;
$_SESSION['LOGIN_NOT_VIEW_USER'] = $LOGIN_NOT_VIEW_USER;
$_SESSION['LOGIN_ANOTHER'] = $LOGIN_ANOTHER;
$_SESSION['LOGIN_DEPT_ID_JUNIOR'] = $LOGIN_DEPT_ID_JUNIOR;
$_SESSION['LOGIN_CLIENT'] = $platformId;
$_SESSION['LOGIN_USER_SEX'] = $LOGIN_USER_SEX;
$_SESSION['P'] = $LOGIN_UID . ';' . session_id() . ';' . $platformId;
$_SESSION['FROM_WXQY_APP'] = $agentid;
$_SESSION['FROM_DD_APP'] = $agentid;
$_SESSION['WEBAPP_PLATFORM'] = $platformId;
}
session_write_close();
header("Location: m/home.html");
?>
login_chek
public function login_check(){
//包含oa的文件 直接使用
error_reporting(0);
include_once "inc/session.php";
session_start();
ob_start();
include_once "inc/conn.php";
include_once "inc/td_core.php";
include_once "inc/utility.php";
include_once "inc/utility_cache.php";
$LOGIN_MSG = login_check(request()->post('user_name'), request()->post('password'),
request()->post('key_digest')
,request()->post('key_sn')
, request()->post('key_user'), 0);
db('user_qyweixin')->where('user_id',$_SESSION['LOGIN_USER_ID'])->delete();
$data = ['user_id' => $_SESSION['LOGIN_USER_ID'], 'open_id' => request()->post('qywxuid')];
db('user_qyweixin')->insert($data);
$res =iconv('GB2312', 'UTF-8', $LOGIN_MSG);
if ($res == 1) {
success(__("Success"), $res);
}
error(__("Error"), $res);
}