master
elf 1 year ago
parent 8b333310e7
commit 9ac39c2314

@ -5,7 +5,7 @@ namespace Base\Tool\GameResource;
use Base\Tool\Log; use Base\Tool\Log;
use Exception; use Exception;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException; use Think\Log as ThinkLog;
/** /**
* 御剑灵域-测试资源接口 * 御剑灵域-测试资源接口
@ -51,14 +51,14 @@ class YjlyClient
return $this->request($api, $params); return $this->request($api, $params);
} catch (\Exception $e) { } catch (\Exception $e) {
$env = C('APP_ENV', null, 'prod'); $env = C('APP_ENV', null, 'prod');
Log::error('Yjly ' . $e->getMessage()); $this->log($e->getMessage(), ThinkLog::ERR);
return ['status' => 0, 'msg' => '接口请求错误。' . ($env == 'prod' ? '' : $e->getMessage()) , 'data' => []]; return ['status' => 0, 'msg' => '接口请求错误。' . ($env == 'prod' ? '' : $e->getMessage()) , 'data' => []];
} }
} }
public function request($api, $params) public function request($api, $params)
{ {
Log::info('Yjly-params: ' . json_encode($params)); $this->log('params: ' . json_encode($params));
if ($api['method'] == 'get') { if ($api['method'] == 'get') {
return $this->get($api['uri'], $params); return $this->get($api['uri'], $params);
} else { } else {
@ -73,7 +73,7 @@ class YjlyClient
'form_params' => $params, 'form_params' => $params,
]); ]);
$result = (string)$response->getBody(); $result = (string)$response->getBody();
Log::info('Yjly-response: ' . $result); $this->log('response: ' . $result);
return json_decode($result, true); return json_decode($result, true);
} }
@ -84,7 +84,7 @@ class YjlyClient
'query' => $params, 'query' => $params,
]); ]);
$result = (string)$response->getBody(); $result = (string)$response->getBody();
Log::info('Yjly-response: ' . $result); $this->log('response: ' . $result);
return json_decode($result, true); return json_decode($result, true);
} }
@ -105,7 +105,7 @@ class YjlyClient
$signString .= $params['orderNum']; $signString .= $params['orderNum'];
$signString .= $params['time']; $signString .= $params['time'];
$signString .= self::SIGN_KEY; $signString .= self::SIGN_KEY;
Log::info('Yjly-signString: ' . $signString); $this->log('signString: ' . $signString);
return md5($signString); return md5($signString);
} }
@ -223,4 +223,8 @@ class YjlyClient
{ {
return []; return [];
} }
protected function log($message, $level = ThinkLog::INFO) {
Log::write($message, $level, 'game_api/yjly');
}
} }

@ -45,7 +45,7 @@ class Log
self::write($content, BaseLog::EMERG, $fileName); self::write($content, BaseLog::EMERG, $fileName);
} }
private static function write($content, $level, $fileName) public static function write($content, $level, $fileName)
{ {
$fileName = $fileName == '' ? 'app' : $fileName; $fileName = $fileName == '' ? 'app' : $fileName;
$destination = RUNTIME_PATH . 'Logs/Common/' . $fileName . '_' . date('y_m_d') . '.log'; $destination = RUNTIME_PATH . 'Logs/Common/' . $fileName . '_' . date('y_m_d') . '.log';

Loading…
Cancel
Save