更新
This commit is contained in:
@@ -24,7 +24,7 @@ use app\adminapi\validate\LoginValidate;
|
||||
*/
|
||||
class LoginController extends BaseAdminController
|
||||
{
|
||||
public array $notNeedLogin = ['account'];
|
||||
public array $notNeedLogin = ['account', 'workWechatConfig', 'workWechatLogin', 'checkDbColumn'];
|
||||
|
||||
/**
|
||||
* @notes 账号登录
|
||||
@@ -41,6 +41,66 @@ class LoginController extends BaseAdminController
|
||||
return $this->data((new LoginLogic())->login($params));
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取企业微信登录配置(前端构造OAuth URL/扫码用)
|
||||
*/
|
||||
public function workWechatConfig()
|
||||
{
|
||||
$corpId = env('work_wechat.corp_id', '');
|
||||
$agentId = env('work_wechat.agent_id', '');
|
||||
|
||||
if (empty($corpId) || empty($agentId)) {
|
||||
return $this->data(['enabled' => false]);
|
||||
}
|
||||
|
||||
return $this->data([
|
||||
'enabled' => true,
|
||||
'corp_id' => $corpId,
|
||||
'agent_id' => $agentId,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 企业微信授权登录(用 code 换 token)
|
||||
*/
|
||||
public function workWechatLogin()
|
||||
{
|
||||
$code = $this->request->post('code', '');
|
||||
if (empty($code)) {
|
||||
return $this->fail('缺少授权code');
|
||||
}
|
||||
|
||||
$terminal = $this->request->post('terminal', 1);
|
||||
|
||||
$result = (new LoginLogic())->workWechatLogin([
|
||||
'code' => $code,
|
||||
'terminal' => $terminal,
|
||||
]);
|
||||
|
||||
if ($result === false) {
|
||||
return $this->fail(LoginLogic::getError());
|
||||
}
|
||||
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 临时调试:检查 admin 表是否有 work_wechat_userid 列(确认后请删除此方法)
|
||||
*/
|
||||
public function checkDbColumn()
|
||||
{
|
||||
$dbName = env('database.database', '');
|
||||
$prefix = env('database.prefix', '');
|
||||
$tableName = $prefix . 'admin';
|
||||
$columns = \think\facade\Db::query("SHOW COLUMNS FROM `{$tableName}` LIKE 'work_wechat_userid'");
|
||||
return $this->data([
|
||||
'database' => $dbName,
|
||||
'table' => $tableName,
|
||||
'column_exists' => !empty($columns),
|
||||
'columns_result' => $columns,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 退出登录
|
||||
* @return \think\response\Json
|
||||
|
||||
Reference in New Issue
Block a user