post()->goCheck(); 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 * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author 令狐冲 * @date 2021/7/8 00:36 */ public function logout() { //退出登录情况特殊,只有成功的情况,也不需要token验证 (new LoginLogic())->logout($this->adminInfo); return $this->success(); } }