|
|
|
@ -12,6 +12,7 @@ use app\common\wework\callback\WXBizMsgCrypt;
|
|
|
|
|
use think\Controller;
|
|
|
|
|
use think\Log;
|
|
|
|
|
use think\Request;
|
|
|
|
|
use think\Session;
|
|
|
|
|
|
|
|
|
|
class Callback extends Controller
|
|
|
|
|
{
|
|
|
|
@ -33,15 +34,43 @@ class Callback extends Controller
|
|
|
|
|
switch ($simpleXMLElement->Event->__toString()) {
|
|
|
|
|
case 'change_external_contact':
|
|
|
|
|
$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) {
|
|
|
|
|
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([
|
|
|
|
|
'name' => $contactUserInfo['remark'],
|
|
|
|
|
'customer_id' => $customerInfo['customer_id']
|
|
|
|
|
'external_userid' => $simpleXMLElement->ExternalUserID->__toString(),
|
|
|
|
|
'customer_id' => $customerInfo['customer_id'],
|
|
|
|
|
'wxwork_id' => $wxwork['id']
|
|
|
|
|
])->find();
|
|
|
|
|
$mobile = '';
|
|
|
|
|
if ($contactUserInfo['remark_mobiles']) {
|
|
|
|
|
$mobile = $contactUserInfo['remark_mobiles'][0];
|
|
|
|
|
}
|
|
|
|
|
if (!$contactsInfo) {
|
|
|
|
|
$param = [
|
|
|
|
|
'business_id' => null,
|
|
|
|
@ -49,13 +78,22 @@ class Callback extends Controller
|
|
|
|
|
'owner_user_id' => 1,
|
|
|
|
|
'customer_id' => $customerInfo['customer_id'],
|
|
|
|
|
'name' => $contactUserInfo['remark'],
|
|
|
|
|
'mobile' => $contactUserInfo['remark_mobiles'][0],
|
|
|
|
|
'mobile' => $mobile,
|
|
|
|
|
'external_userid' => $simpleXMLElement->ExternalUserID->__toString(),
|
|
|
|
|
'wxwork_id' => $wxwork['id']
|
|
|
|
|
];
|
|
|
|
|
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('联系人更新成功');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -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');
|
|
|
|
|
}
|
|
|
|
|
}
|