param('admin_id'); LogService::info('getToken:admin_id:' . $admin_id); if (!$admin_id) { $this->setMsg('缺少参数')->setCode(ErrorCodeConstants::PARAMS_ERROR_EMPTY)->getReturn(); } $adminConfig = model('AdminConfig')->getAdminInfoAll($admin_id); if (!$adminConfig) { $this->setMsg('参数无效')->setCode(ErrorCodeConstants::PARAMS_ERROR_INVALID)->getReturn(); } $wechat = new WeChatObject($adminConfig); $officialAccount = $wechat->getOfficialAccount(); if (!$officialAccount) { $this->setMsg('账号未授权')->setCode(ErrorCodeConstants::PERMISSION_DENY)->getReturn(); } try { $token = $officialAccount->access_token->getToken(); } catch (HttpException $e) { $this->setMsg('账号被封')->setCode(ErrorCodeConstants::PERMISSION_DENY)->getReturn(); } catch (InvalidArgumentException $e) { $this->setMsg($e->getMessage())->setCode(ErrorCodeConstants::API_ERROR)->getReturn(); } catch (\Exception $e) { $this->setMsg($e->getMessage())->setCode(ErrorCodeConstants::API_ERROR)->getReturn(); } if (isset($token) && is_array($token) && array_key_exists('authorizer_access_token', $token)) { $proxy = OpenPlatformService::instance()->getProxyconfigByChannel($admin_id, null, 'job_proxy_config', true); $data = [ 'appid' => $adminConfig['appid'], 'token' => $token['authorizer_access_token'], 'proxy_config' => $proxy ?: [], ]; $this->setData($data)->getReturn(); } else { $this->setMsg('获取token失败')->setCode(ErrorCodeConstants::API_ERROR)->getReturn(); } } }