kyle 2 年前
父节点
当前提交
595e592075
共有 1 个文件被更改,包括 38 次插入31 次删除
  1. 38
    31
      app/Http/Services/Web/Api2021Service.php

+ 38
- 31
app/Http/Services/Web/Api2021Service.php 查看文件

293
                 ],
293
                 ],
294
                 'timeout' => 60, // Response timeout
294
                 'timeout' => 60, // Response timeout
295
                 'connect_timeout' => 30, // Connection timeout
295
                 'connect_timeout' => 30, // Connection timeout
296
-//                'on_headers' => function (\Psr\Http\Message\ResponseInterface $response) {
297
-//                    if ($response->getHeaderLine('Content-Length') > 1024) {
298
-//                        throw new \Exception('The file is too big!');
299
-//                    }
300
-//                },
301
                 'on_stats' => function (\GuzzleHttp\TransferStats $stats) {
296
                 'on_stats' => function (\GuzzleHttp\TransferStats $stats) {
302
-//                    echo $stats->getEffectiveUri() . "\n";
303
-//                    echo $stats->getTransferTime() . "\n";
304
-//                    var_dump($stats->getHandlerStats());
305
-
306
-                    $this->debuglog('lineFriendCheck-on_stats', [
307
-                        'rqid' => $rqid ?? 0
308
-                    ], [
309
-                        'transferTime' => $stats->getTransferTime(),
310
-                        'handlerStats' => $stats->getHandlerStats(),
311
-                    ]);
312
-
313
-                    // You must check if a response was received before using the
314
-                    // response object.
315
-//                    if ($stats->hasResponse()) {
316
-//                        echo $stats->getResponse()->getStatusCode();
317
-//                    } else {
318
-//                        // Error data is handler specific. You will need to know what
319
-//                        // type of error data your handler uses before using this
320
-//                        // value.
321
-//                        var_dump($stats->getHandlerErrorData());
322
-//                    }
297
+                    if ($stats->hasResponse()) {
298
+                        $this->debuglog('lineFriendCheck-on_stats_ok', [
299
+                            'rqid' => $rqid ?? 0
300
+                        ], [
301
+                            'transferTime' => $stats->getTransferTime(),
302
+                            'handlerStats' => $stats->getHandlerStats(),
303
+                        ]);
304
+                    } else {
305
+                        $this->debuglog('lineFriendCheck-on_stats_ng', [
306
+                            'rqid' => $rqid ?? 0
307
+                        ], [
308
+                            'handlerErrorData' => $stats->getHandlerErrorData(),
309
+                        ]);
310
+                    }
323
                 }
311
                 }
324
             ];
312
             ];
325
 
313
 
356
             if (!$isfollow || !$ismember) return false;
344
             if (!$isfollow || !$ismember) return false;
357
         } catch (Exception $ex) {
345
         } catch (Exception $ex) {
358
             // 錯誤可能發生在 memoIn 或是 out
346
             // 錯誤可能發生在 memoIn 或是 out
359
-            $data['memoIn'] = json_encode(['error' => 'exception', 'param' => array_merge($param, $logdata)], JSON_UNESCAPED_UNICODE);
360
-            $data['memoOut'] = json_encode(['code' => $ex->getCode(), 'msg' => $ex->getMessage()], JSON_UNESCAPED_UNICODE);
347
+//            $data['memoIn'] = json_encode(['error' => 'exception', 'param' => array_merge($param, $logdata)], JSON_UNESCAPED_UNICODE);
348
+//            $data['memoOut'] = json_encode(['code' => $ex->getCode(), 'msg' => $ex->getMessage()], JSON_UNESCAPED_UNICODE);
361
 //            $this->syslog($data);
349
 //            $this->syslog($data);
362
 
350
 
363
             $this->debuglog('lineFriendCheck', [
351
             $this->debuglog('lineFriendCheck', [
1028
                 ],
1016
                 ],
1029
                 'timeout' => 60, // Response timeout
1017
                 'timeout' => 60, // Response timeout
1030
                 'connect_timeout' => 30, // Connection timeout
1018
                 'connect_timeout' => 30, // Connection timeout
1019
+                'on_stats' => function (\GuzzleHttp\TransferStats $stats) {
1020
+                    if ($stats->hasResponse()) {
1021
+                        $this->debuglog('playerTag-on_stats_ok', [
1022
+                            'rqid' => $rqid ?? 0
1023
+                        ], [
1024
+                            'transferTime' => $stats->getTransferTime(),
1025
+                            'handlerStats' => $stats->getHandlerStats(),
1026
+                        ]);
1027
+                    } else {
1028
+                        $this->debuglog('playerTag-on_stats_ng', [
1029
+                            'rqid' => $rqid ?? 0
1030
+                        ], [
1031
+                            'handlerErrorData' => $stats->getHandlerErrorData(),
1032
+                        ]);
1033
+                    }
1034
+                }
1031
             ];
1035
             ];
1032
             if (!in_array($_SERVER['SERVER_ADDR'], ['172.31.30.167', '172.31.9.233', '172.31.42.197'])) $req['proxy'] = env('CCH_PROXY');
1036
             if (!in_array($_SERVER['SERVER_ADDR'], ['172.31.30.167', '172.31.9.233', '172.31.42.197'])) $req['proxy'] = env('CCH_PROXY');
1033
 
1037
 
1034
             $requestTime = date("Y-m-d H:i:s");
1038
             $requestTime = date("Y-m-d H:i:s");
1039
+            $logdata['requestTime'] = $requestTime;
1040
+
1035
             $response = $this->c->request('POST', env('API_BASE') . '/line/api/twpapi/tag/Tagging', $req);
1041
             $response = $this->c->request('POST', env('API_BASE') . '/line/api/twpapi/tag/Tagging', $req);
1036
             $res = $response->getBody();
1042
             $res = $response->getBody();
1037
 
1043
 
1045
 
1051
 
1046
         } catch (Exception $ex) {
1052
         } catch (Exception $ex) {
1047
             // 錯誤可能發生在 memoIn 或是 out
1053
             // 錯誤可能發生在 memoIn 或是 out
1048
-            $data['memoIn'] = json_encode(['error' => 'exception'], JSON_UNESCAPED_UNICODE);
1049
-            $data['memoOut'] = json_encode(['code' => $ex->getCode(), 'msg' => $ex->getMessage()], JSON_UNESCAPED_UNICODE);
1054
+//            $data['memoIn'] = json_encode(['error' => 'exception'], JSON_UNESCAPED_UNICODE);
1055
+//            $data['memoOut'] = json_encode(['code' => $ex->getCode(), 'msg' => $ex->getMessage()], JSON_UNESCAPED_UNICODE);
1050
 //            $this->syslog($data);
1056
 //            $this->syslog($data);
1051
 
1057
 
1052
             $this->debuglog('playerTag', [
1058
             $this->debuglog('playerTag', [
1054
             ], [
1060
             ], [
1055
                 'errCode' => $ex->getCode(),
1061
                 'errCode' => $ex->getCode(),
1056
                 'requestTime' => $requestTime ?? '',
1062
                 'requestTime' => $requestTime ?? '',
1063
+                'logTime' => date("Y-m-d H:i:s"),
1057
                 'errMsg' => $ex->getMessage(),
1064
                 'errMsg' => $ex->getMessage(),
1058
             ]);
1065
             ]);
1059
-            
1066
+
1060
             return false;
1067
             return false;
1061
         }
1068
         }
1062
         
1069