diff --git a/app/common/controller/AuthController.php b/app/common/controller/AuthController.php index bd14627..80ab94e 100644 --- a/app/common/controller/AuthController.php +++ b/app/common/controller/AuthController.php @@ -4,6 +4,7 @@ namespace app\common\controller; use app\common\service\AuthService; use app\common\validate\UserValidate; +use Exception; use support\Request; class AuthController extends BaseController @@ -119,6 +120,9 @@ class AuthController extends BaseController { try { $url = $request->get('url'); + if(empty($url)){ + throw new Exception("url不能为空"); + } $result = (new AuthService())->getJsApiConfig($request->corp_abbr, $request->system_code,$url); return $this->success($result); } catch (\Throwable $e) { diff --git a/app/common/utils/Feishu.php b/app/common/utils/Feishu.php index cdd6d16..b1260dc 100644 --- a/app/common/utils/Feishu.php +++ b/app/common/utils/Feishu.php @@ -269,17 +269,16 @@ class Feishu return $cachedTicket; } - $url = $this->baseUri . '/jssdk/ticket/get'; - - $headers = [ - 'Authorization: Bearer ' . $accessToken, - 'Content-Type: application/json' + // 使用 requestResult 方法发起请求,而不是 httpGet + $this->options["headers"] = [ + "Authorization" => "Bearer " . $accessToken, + "Content-Type" => "application/json; charset=utf-8" ]; - $result = $this->httpGet($url, $headers); + $result = $this->requestResult('jssdk/ticket/get', 'GET'); - if ($result['code'] !== 0) { - throw new BusinessException('获取 jsapi_ticket 失败: ' . json_encode($result)); + if (!$result) { + throw new BusinessException('获取 jsapi_ticket 失败: ' . $this->error()); } $ticket = $result['data']['ticket']; @@ -322,28 +321,4 @@ class Feishu } return $str; } - - /** - * HTTP GET 请求 - */ - private function httpGet($url, $headers = []) - { - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); - curl_setopt($ch, CURLOPT_TIMEOUT, 10); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 不验证证书 - curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // 不验证主机名 - - $response = curl_exec($ch); - $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); - curl_close($ch); - - if ($httpCode !== 200) { - throw new BusinessException("HTTP GET 请求失败: {$httpCode}"); - } - - return json_decode($response, true); - } } \ No newline at end of file