12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?php
- /**
- * Created by KLXQ
- * user: youyi
- * Date:2024/7/02 10:36.
- */
- namespace App\Services;
- use App\Models\TencentRequest;
- use Illuminate\Support\Facades\Log;
- class TencentRequestService
- {
- public static function create($server, $action, $request, $resultArr): void
- {
- $request = \is_array($request) ? json_encode($request) : $request;
- $statusInfo = 'success';
- Log::channel('tencent')->info($action.': '.$request);
- if (200 === $resultArr['code']) {
- Log::channel('tencent')->info($action.': '.$resultArr['msg']);
- } else {
- $statusInfo = 'error';
- Log::channel('tencent')->error($action.': '.$resultArr['msg']);
- }
- if (!config('tencent.tencent_log')) {
- return;
- }
- // 回调会使用,此时没有用户信息
- $userId = 0;
- $username = 'system';
- if (auth('api')->user()) {
- $userId = auth('api')->user()->id;
- $username = auth('api')->user()->name;
- }
- TencentRequest::query()->create([
- 'server' => $server,
- 'action' => $action,
- 'u_id' => $userId,
- 'request' => $request,
- 'username' => $username,
- 'msg' => $resultArr['msg'],
- 'status_info' => $statusInfo,
- 'response' => json_encode($resultArr['data']),
- ]);
- }
- }
|