Prechádzať zdrojové kódy

fix(lakala): 调整通知接口参数传递方式

- 修改 notiApi 方法签名以接收 headers 和 body 参数
- 移除方法内部获取请求头和请求体的逻辑
- 在服务层统一获取并记录请求头与请求体
- 确保日志记录内容完整且结构清晰
- 避免重复读取 php://input 流
- 提升代码可测试性和参数可控性
runphp 4 mesiacov pred
rodič
commit
f4d0181214

+ 0 - 6
src/Controller/Api/IndexController.php

@@ -13,12 +13,6 @@ class IndexController
 {
     public function notify(NotifyService $notifyService): Json
     {
-        $headers = getallheaders();
-        $body = file_get_contents('php://input');
-        Log::debug('lakala notify {headers} {body}', [
-            'headers' => json_encode($headers),
-            'body' => json_encode($body),
-        ]);
         $notifyService->notify();
         return json(['code' => 'SUCCESS', 'message' => '执行成功']);
     }

+ 1 - 4
src/OpenAPISDK/V3/Api/LakalaNotifyApi.php

@@ -25,10 +25,7 @@ class LakalaNotifyApi
         $this->config = $config;
     }
 
-    public function notiApi() {
-        $headers = getallheaders();
-        $body = file_get_contents('php://input');
-
+    public function notiApi(array $headers, string $body) {
         $verify = $this->requestVerifySign($headers['Authorization'], $body);
 
         if (!$verify) {

+ 6 - 4
src/Service/NotifyService.php

@@ -22,11 +22,13 @@ class NotifyService
 
     public function notify(): void
     {
-        $notify = $this->notifyApi->notiApi();
-        Log::debug('lakala notify {headers} {body}', [
-            'headers' => json_encode($notify->getHeaders()),
-            'body' => $notify->getOriginalText(),
+        $headers = getallheaders();
+        $body = file_get_contents('php://input');
+        Log::debug('lakala notify headers:{headers}  body:{body}', [
+            'headers' => json_encode($headers),
+            'body' => $body
         ]);
+        $notify = $this->notifyApi->notiApi($headers, $body);
         $inBody = $notify->getOriginalText();
         if (!json_validate($inBody)) {
             throw_logic_exception('lakala notify json error');