添加客户端 #40

Merged
yunyang merged 1 commits from yy-4.20 into master 1 year ago

@ -25,6 +25,9 @@ class ApiCommon extends Common
$authKey = trim($header['authkey']); $authKey = trim($header['authkey']);
$sessionId = trim($header['sessionid']); $sessionId = trim($header['sessionid']);
if ($authKey == "wxwork") {
return;
}
$paramArr = $request->param(); $paramArr = $request->param();
$platform = $paramArr['platform'] ? '_'.$paramArr['platform'] : ''; //请求平台(mobile,ding) $platform = $paramArr['platform'] ? '_'.$paramArr['platform'] : ''; //请求平台(mobile,ding)
$cache = Cache::get('Auth_'.$authKey.$platform); $cache = Cache::get('Auth_'.$authKey.$platform);

@ -32,6 +32,9 @@ class AuthenticateBehavior
/*获取头部信息*/ /*获取头部信息*/
$header = $request->header(); $header = $request->header();
$authKey = trim($header['authkey']); $authKey = trim($header['authkey']);
if ($authKey == "wxwork") {
return true;
}
$paramArr = $request->param(); $paramArr = $request->param();
$platform = $paramArr['platform'] ? '_'.$paramArr['platform'] : ''; //请求分类(mobile,ding) $platform = $paramArr['platform'] ? '_'.$paramArr['platform'] : ''; //请求分类(mobile,ding)

@ -13,6 +13,9 @@ class Api {
protected static $getAccessToken = 'gettoken'; protected static $getAccessToken = 'gettoken';
protected static $contactInfo = 'externalcontact/get'; protected static $contactInfo = 'externalcontact/get';
protected static $getUserInfo = 'auth/getuserinfo';
protected static $userGet = 'user/get';
protected $corpId = ''; protected $corpId = '';
protected $corpSecret = ''; protected $corpSecret = '';
@ -37,6 +40,30 @@ 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 * 获取accessToken
* @return false|mixed * @return false|mixed

@ -12,6 +12,7 @@ use app\common\wework\callback\WXBizMsgCrypt;
use think\Controller; use think\Controller;
use think\Log; use think\Log;
use think\Request; use think\Request;
use think\Session;
class Callback extends Controller class Callback extends Controller
{ {
@ -33,15 +34,43 @@ class Callback extends Controller
switch ($simpleXMLElement->Event->__toString()) { switch ($simpleXMLElement->Event->__toString()) {
case 'change_external_contact': case 'change_external_contact':
$api = new Api(config('wework.corpId'), config('wework.corpSecret')); $api = new Api(config('wework.corpId'), config('wework.corpSecret'));
$contactInfo = $api->contactInfo('wm9nLQEAAA6lshIXRN5xdd1iZjqevSyA'); $contactInfo = $api->contactInfo($simpleXMLElement->ExternalUserID->__toString());
foreach ($contactInfo['follow_user'] as $contactUserInfo) { foreach ($contactInfo['follow_user'] as $contactUserInfo) {
if ($contactUserInfo['userid'] == $simpleXMLElement->UserID->__toString()) { if ($contactUserInfo['userid'] == $simpleXMLElement->UserID->__toString()) {
$customerInfo = model('Customer')->where('name', $contactUserInfo['remark_corp_name'])->find(); $customerInfo = model('Customer')->where('name', $contactUserInfo['remark_corp_name'])->find();
if ($customerInfo) { 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([ $contactsInfo = model('Contacts')->where([
'name' => $contactUserInfo['remark'], 'external_userid' => $simpleXMLElement->ExternalUserID->__toString(),
'customer_id' => $customerInfo['customer_id'] 'customer_id' => $customerInfo['customer_id'],
'wxwork_id' => $wxwork['id']
])->find(); ])->find();
$mobile = '';
if ($contactUserInfo['remark_mobiles']) {
$mobile = $contactUserInfo['remark_mobiles'][0];
}
if (!$contactsInfo) { if (!$contactsInfo) {
$param = [ $param = [
'business_id' => null, 'business_id' => null,
@ -49,13 +78,22 @@ class Callback extends Controller
'owner_user_id' => 1, 'owner_user_id' => 1,
'customer_id' => $customerInfo['customer_id'], 'customer_id' => $customerInfo['customer_id'],
'name' => $contactUserInfo['remark'], 'name' => $contactUserInfo['remark'],
'mobile' => $contactUserInfo['remark_mobiles'][0], 'mobile' => $mobile,
'external_userid' => $simpleXMLElement->ExternalUserID->__toString(),
'wxwork_id' => $wxwork['id']
]; ];
if (model('Contacts')->createData($param)) { if (model('Contacts')->createData($param)) {
Log::record('联系人添加成功'); Log::record('联系人添加成功');
} else { } else {
Log::record('联系人添加失败'); Log::record('联系人添加失败');
} }
} else {
$param = [
'name' => $contactUserInfo['remark'],
'mobile' => $mobile
];
model('Contacts')->where('contacts_id', $contactsInfo['contacts_id'])->update($param);
Log::record('联系人更新成功');
} }
} }
} }
@ -83,4 +121,12 @@ 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);
Session::set('user_id', $userInfo['userid']);
return redirect('http://web.lbschem.com:8088/?authkey=wxwork&sessionid=wxwork');
}
} }

@ -206,6 +206,11 @@ class Contacts extends Common
$list[$k]['owner_user_id_info'] = isset($v['owner_user_id']) ? $userModel->getUserById($v['owner_user_id']) : []; $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']['customer_id'] = $v['customer_id'] ?: '';
$list[$k]['customer_id_info']['name'] = $v['customer_name'] ?: ''; $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) { foreach ($userField as $key => $val) {
$usernameField = !empty($v[$val]) ? db('admin_user')->whereIn('id', stringToArray($v[$val]))->column('realname') : []; $usernameField = !empty($v[$val]) ? db('admin_user')->whereIn('id', stringToArray($v[$val]))->column('realname') : [];
$list[$k][$val] = implode($usernameField, ','); $list[$k][$val] = implode($usernameField, ',');

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

Loading…
Cancel
Save