新增
This commit is contained in:
@@ -20,6 +20,7 @@ use app\adminapi\validate\auth\AdminValidate;
|
||||
use app\adminapi\logic\auth\AdminLogic;
|
||||
use app\adminapi\logic\LoginLogic;
|
||||
use app\adminapi\validate\auth\editSelfValidate;
|
||||
use app\common\cache\AdminTokenCache;
|
||||
use app\common\model\auth\Admin;
|
||||
|
||||
/**
|
||||
@@ -169,9 +170,14 @@ class AdminController extends BaseAdminController
|
||||
return $this->fail('企业微信授权失败: ' . ($response['errmsg'] ?? '未知错误'));
|
||||
}
|
||||
|
||||
$wxUserId = $response['userid'] ?? '';
|
||||
if (empty($wxUserId)) {
|
||||
return $this->fail('未获取到企业微信用户身份');
|
||||
$wxUserId = LoginLogic::workWechatUserIdFromAuthResponse($response);
|
||||
if ($wxUserId === '') {
|
||||
$hasOpenId = trim((string) ($response['openid'] ?? $response['OpenId'] ?? '')) !== '';
|
||||
return $this->fail(
|
||||
$hasOpenId
|
||||
? '当前扫码账号非企业通讯录成员(或尚未同步到通讯录),无法绑定。请使用已在企业微信通讯录中的成员扫码,或联系管理员将你加入企业后再试'
|
||||
: '未获取到企业微信成员 userid。请确认 .env 中 work_wechat.secret 为「该自建应用」的 Secret(与 agent_id 对应),且绑定页完整 URL 已加入应用可信域名'
|
||||
);
|
||||
}
|
||||
|
||||
// 检查是否已被其他管理员绑定
|
||||
@@ -182,10 +188,15 @@ class AdminController extends BaseAdminController
|
||||
return $this->fail('该企业微信账号已被其他管理员绑定');
|
||||
}
|
||||
|
||||
Admin::update([
|
||||
'id' => $this->adminId,
|
||||
'work_wechat_userid' => $wxUserId,
|
||||
]);
|
||||
$affected = Admin::where('id', $this->adminId)->update(['work_wechat_userid' => $wxUserId]);
|
||||
if ($affected === 0) {
|
||||
return $this->fail('保存绑定失败,请确认账号有效后重试');
|
||||
}
|
||||
|
||||
$token = $this->request->header('token');
|
||||
if ($token) {
|
||||
(new AdminTokenCache())->deleteAdminInfo($token);
|
||||
}
|
||||
|
||||
return $this->success('绑定成功', ['work_wechat_userid' => $wxUserId]);
|
||||
}
|
||||
@@ -195,10 +206,7 @@ class AdminController extends BaseAdminController
|
||||
*/
|
||||
public function unbindWorkWechat()
|
||||
{
|
||||
Admin::update([
|
||||
'id' => $this->adminId,
|
||||
'work_wechat_userid' => '',
|
||||
]);
|
||||
Admin::where('id', $this->adminId)->update(['work_wechat_userid' => '']);
|
||||
|
||||
return $this->success('解绑成功');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user