|
|
@ -9,11 +9,9 @@ namespace app\crm\controller;
|
|
|
|
|
|
|
|
|
|
|
|
use app\common\wework\api\Api;
|
|
|
|
use app\common\wework\api\Api;
|
|
|
|
use app\common\wework\callback\WXBizMsgCrypt;
|
|
|
|
use app\common\wework\callback\WXBizMsgCrypt;
|
|
|
|
use think\Cache;
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -35,43 +33,15 @@ 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($simpleXMLElement->ExternalUserID->__toString());
|
|
|
|
$contactInfo = $api->contactInfo('wm9nLQEAAA6lshIXRN5xdd1iZjqevSyA');
|
|
|
|
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([
|
|
|
|
'external_userid' => $simpleXMLElement->ExternalUserID->__toString(),
|
|
|
|
'name' => $contactUserInfo['remark'],
|
|
|
|
'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,
|
|
|
@ -79,22 +49,13 @@ 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' => $mobile,
|
|
|
|
'mobile' => $contactUserInfo['remark_mobiles'][0],
|
|
|
|
'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('联系人更新成功');
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -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/');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|