飞书增加获取企业邮箱

This commit is contained in:
2025-07-28 14:03:15 +08:00
parent 8f7b6a1ec3
commit 1a54a55653
+19 -4
View File
@@ -86,16 +86,23 @@ class AuthLogic
{ {
try { try {
$phone = $this->sanitizePhone($feishuUserInfo['mobile'] ?? ''); $phone = $this->sanitizePhone($feishuUserInfo['mobile'] ?? '');
$user = User::where('phone', $phone)->where('corp_id', $feishuUserInfo['corp_id'])->first(); $email = $feishuUserInfo['enterprise_email'];
$user = User::where('corp_id', $feishuUserInfo['corp_id'])
->where(function($query) use ($phone, $email) {
$query->where('phone', $phone)
->orWhere('email', $email);
})
->first();
if (!$user) { if (!$user) {
// 获取编号 // 获取编号
$userSn = $this->getAvailableUserSn(); $userSn = $this->getAvailableUserSn();
// 创建用户 // 创建用户
$user = User::create([ $user = User::create([
'name' => $feishuUserInfo['en_name'], 'name' => $feishuUserInfo['name'],
'avatar' => $feishuUserInfo['avatar_middle'], 'avatar' => $feishuUserInfo['avatar_middle'],
'phone' => $this->sanitizePhone($feishuUserInfo['mobile'] ?? ''), 'phone' => $this->sanitizePhone($feishuUserInfo['mobile'] ?? ''),
'email' => $feishuUserInfo['enterprise_email'],
'union_id' => $feishuUserInfo['union_id'], 'union_id' => $feishuUserInfo['union_id'],
'user_id' => $feishuUserInfo['user_id'], 'user_id' => $feishuUserInfo['user_id'],
'open_id' => $feishuUserInfo['open_id'], 'open_id' => $feishuUserInfo['open_id'],
@@ -112,12 +119,20 @@ class AuthLogic
// 是否登陆 // 是否登陆
$user->isLogin = false; $user->isLogin = false;
} else { } else {
$user->update([ $updated = [
'union_id' => $feishuUserInfo['union_id'], 'union_id' => $feishuUserInfo['union_id'],
'user_id' => $feishuUserInfo['user_id'], 'user_id' => $feishuUserInfo['user_id'],
'open_id' => $feishuUserInfo['open_id'], 'open_id' => $feishuUserInfo['open_id'],
'tenant_key' => $feishuUserInfo['tenant_key'] 'tenant_key' => $feishuUserInfo['tenant_key']
]); ];
if ($phone && $phone == $user->phone) {
$updated['phone'] = $phone;
}
if ($phone && $phone == $user->phone) {
$updated['email'] = $email;
}
// 更新飞书信息
$user->update($updated);
} }
return $user; return $user;
} catch (\Throwable $e) { } catch (\Throwable $e) {