Compare commits

..

No commits in common. 'master' and 'zm' have entirely different histories.
master ... zm

@ -12,7 +12,6 @@ use think\Request;
use think\Db;
use app\common\adapter\AuthAdapter;
use app\common\controller\Common;
use think\Session;
class ApiCommon extends Common
@ -23,12 +22,9 @@ class ApiCommon extends Common
/*获取头部信息*/
$header = Request::instance()->header();
$request = Request::instance();
$authKey = trim($header['authkey']);
$sessionId = trim($header['sessionid']);
if ($authKey == "wxwork" && Session::get('user_id')) {
return;
}
$paramArr = $request->param();
$platform = $paramArr['platform'] ? '_'.$paramArr['platform'] : ''; //请求平台(mobile,ding)
$cache = Cache::get('Auth_'.$authKey.$platform);

@ -13,7 +13,6 @@ use app\admin\model\Common;
use com\verify\HonrayVerify;
use think\Cache;
use think\Request;
use think\Session;
class User extends Common
{
@ -648,15 +647,8 @@ class User extends Common
$data['loginExpire'] = $loginExpire;
//保存authKey信息
$userData = [];
$wxuser_id = Session::get('wxuser_id');
if ($wxuser_id) {
$data['authKey'] = 'wxwork';
$userData['wxwork_id'] = $wxuser_id;
} else {
$userData['authkey'] = $authKey;
$userData['authkey_time'] = time() + $loginExpire;
}
$userData['authkey'] = $authKey;
$userData['authkey_time'] = time() + $loginExpire;
//把状态未激活至为启用
if ($userInfo['status'] == 2) {
$userData['status'] = 1;

@ -9,7 +9,6 @@ namespace app\common\behavior;
use think\Cache;
use think\Request;
use think\Db;
use think\Session;
class AuthenticateBehavior
{
@ -33,9 +32,6 @@ class AuthenticateBehavior
/*获取头部信息*/
$header = $request->header();
$authKey = trim($header['authkey']);
if ($authKey == "wxwork" && Session::get('user_id')) {
return true;
}
$paramArr = $request->param();
$platform = $paramArr['platform'] ? '_'.$paramArr['platform'] : ''; //请求分类(mobile,ding)

@ -13,9 +13,6 @@ class Api {
protected static $getAccessToken = 'gettoken';
protected static $contactInfo = 'externalcontact/get';
protected static $getUserInfo = 'auth/getuserinfo';
protected static $userGet = 'user/get';
protected $corpId = '';
protected $corpSecret = '';
@ -40,30 +37,6 @@ class Api {
]);
}
/**
* 获取用户身份
* @param $code
* @return mixed
*/
function getUserInfo($code) {
return $this->get(self::$getUserInfo, [
'access_token' => $this->getAccessToken(),
'code' => $code
]);
}
/**
* 获取用户信息
* @param $code
* @return mixed
*/
function userGet($userid) {
return $this->get(self::$userGet, [
'access_token' => $this->getAccessToken(),
'userid' => $userid
]);
}
/**
* 获取accessToken
* @return false|mixed

@ -9,11 +9,9 @@ namespace app\crm\controller;
use app\common\wework\api\Api;
use app\common\wework\callback\WXBizMsgCrypt;
use think\Cache;
use think\Controller;
use think\Log;
use think\Request;
use think\Session;
class Callback extends Controller
{
@ -35,43 +33,15 @@ class Callback extends Controller
switch ($simpleXMLElement->Event->__toString()) {
case 'change_external_contact':
$api = new Api(config('wework.corpId'), config('wework.corpSecret'));
$contactInfo = $api->contactInfo($simpleXMLElement->ExternalUserID->__toString());
$contactInfo = $api->contactInfo('wm9nLQEAAA6lshIXRN5xdd1iZjqevSyA');
foreach ($contactInfo['follow_user'] as $contactUserInfo) {
if ($contactUserInfo['userid'] == $simpleXMLElement->UserID->__toString()) {
$customerInfo = model('Customer')->where('name', $contactUserInfo['remark_corp_name'])->find();
if ($customerInfo) {
$wxwork = db('admin_wxwork')->where("user_id", $contactUserInfo['userid'])->find();
if (!$wxwork) {
$userGet = $api->userGet($contactUserInfo['userid']);
$wxwork = [
'user_id' => $userGet['userid'],
'name' => $userGet['name'],
'create_time' => time(),
'update_time' => time(),
];
db('admin_wxwork')->insert($wxwork);
$wxwork = db('admin_wxwork')->where("user_id", $contactUserInfo['userid'])->find();
if (!$wxwork) {
Log::record('联系人添加失败');
return;
}
}
if ($wxwork['update_time']+86400*3 < time()) {
db('admin_wxwork')->where("id", $wxwork['id'])->update([
'name' => $userGet['name'],
'update_time' => time(),
]);
}
$contactsInfo = model('Contacts')->where([
'external_userid' => $simpleXMLElement->ExternalUserID->__toString(),
'customer_id' => $customerInfo['customer_id'],
'wxwork_id' => $wxwork['id']
'name' => $contactUserInfo['remark'],
'customer_id' => $customerInfo['customer_id']
])->find();
$mobile = '';
if ($contactUserInfo['remark_mobiles']) {
$mobile = $contactUserInfo['remark_mobiles'][0];
}
if (!$contactsInfo) {
$param = [
'business_id' => null,
@ -79,22 +49,13 @@ class Callback extends Controller
'owner_user_id' => 1,
'customer_id' => $customerInfo['customer_id'],
'name' => $contactUserInfo['remark'],
'mobile' => $mobile,
'external_userid' => $simpleXMLElement->ExternalUserID->__toString(),
'wxwork_id' => $wxwork['id']
'mobile' => $contactUserInfo['remark_mobiles'][0],
];
if (model('Contacts')->createData($param)) {
Log::record('联系人添加成功');
} else {
Log::record('联系人添加失败');
}
} else {
$param = [
'name' => $contactUserInfo['remark'],
'mobile' => $mobile
];
model('Contacts')->where('contacts_id', $contactsInfo['contacts_id'])->update($param);
Log::record('联系人更新成功');
}
}
}
@ -122,41 +83,4 @@ class Callback extends Controller
}
}
}
public function work() {
$code = Request::instance()->get('code');
$api = new Api(config('wework.corpId'), config('wework.corpSecret'));
$userInfo = $api->getUserInfo($code);
Log::record('用户信息'.json_encode($userInfo));
if (isset($userInfo['userid']) && $userInfo['userid']) {
Session::set('wxuser_id', $userInfo['userid']);
$adminUser = db('admin_user')->where('wxwork_id', $userInfo['userid'])->find();
if ($adminUser) {
Session::set('user_id', $adminUser['id']);
$info['userInfo'] = $adminUser;
$info['sessionId'] = session_id();
// $info['_AUTH_LIST_'] = $dataList['rulesList'];
$info['authKey'] = 'wxwork';
if (!Cache::get('Auth_wxwork')) {
Cache::set('Auth_wxwork', $info);
}
return redirect('http://web.lbschem.com:8088/?authkey=wxwork&sessionid='.session_id());
} elseif (Session::get('user_id')) {
db('admin_user')->where('id', Session::get('user_id'))->update([
'wxwork_id' => $userInfo['userid']
]);
$adminUser = db('admin_user')->where('id', Session::get('user_id'))->find();
$info['userInfo'] = $adminUser;
$info['sessionId'] = session_id();
// $info['_AUTH_LIST_'] = $dataList['rulesList'];
$info['authKey'] = 'wxwork';
if (!Cache::get('Auth_wxwork')) {
Cache::set('Auth_wxwork', $info);
}
return redirect('http://web.lbschem.com:8088/?authkey=wxwork&sessionid='.session_id());
}
}
return redirect('http://web.lbschem.com:8088/');
}
}

@ -206,11 +206,6 @@ class Contacts extends Common
$list[$k]['owner_user_id_info'] = isset($v['owner_user_id']) ? $userModel->getUserById($v['owner_user_id']) : [];
$list[$k]['customer_id_info']['customer_id'] = $v['customer_id'] ?: '';
$list[$k]['customer_id_info']['name'] = $v['customer_name'] ?: '';
$list[$k]['wxwork_name'] = '';
if ($list[$k]['wxwork_id']) {
$wxwork = db('admin_wxwork')->where('id', $list[$k]['wxwork_id'])->find();
$list[$k]['wxwork_name'] = $wxwork['name'];
}
foreach ($userField as $key => $val) {
$usernameField = !empty($v[$val]) ? db('admin_user')->whereIn('id', stringToArray($v[$val]))->column('realname') : [];
$list[$k][$val] = implode($usernameField, ',');

@ -536,7 +536,6 @@ return [
// 企业微信回调
'crm/callback/index' => ['crm/callback/index', ['method' => 'POST|GET']],
'crm/callback/work' => ['crm/callback/work', ['method' => 'POST|GET']],
// MISS路由
'__miss__' => 'admin/base/miss',

Loading…
Cancel
Save