|
|
@ -13,9 +13,12 @@ namespace QuanTan.SDK.Client |
|
|
|
|
|
|
|
protected readonly string host = "https://qt.qiyue666.com/"; |
|
|
|
|
|
|
|
public BaseClient(RestApiService restApiService) |
|
|
|
private NLog.ILogger logger; |
|
|
|
|
|
|
|
public BaseClient(RestApiService restApiService, NLog.ILogger logger) |
|
|
|
{ |
|
|
|
this.restApiService = restApiService; |
|
|
|
this.logger = logger; |
|
|
|
} |
|
|
|
|
|
|
|
public QuanTanResponse<T> SendRequest<T>(string apiPath, object param, string appId, string appSecret) |
|
|
@ -42,16 +45,25 @@ namespace QuanTan.SDK.Client |
|
|
|
Params = paramStr, |
|
|
|
token = qtToken |
|
|
|
}; |
|
|
|
|
|
|
|
RestApiResult restApiResult = null; |
|
|
|
try |
|
|
|
{ |
|
|
|
var restApiResult = restApiService.SendRequest(host, apiPath, requestParam, null, HttpMethod.Post); |
|
|
|
restApiResult = restApiService.SendRequest(host, apiPath, requestParam, null, HttpMethod.Post); |
|
|
|
if (restApiResult.StatusCode != System.Net.HttpStatusCode.OK) |
|
|
|
throw new Exception(restApiResult.Content); |
|
|
|
return JsonConvert.DeserializeObject<QuanTanResponse<T>>(restApiResult.Content); |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
if (logger != null) |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
logger.Error(ex, $"Request {JsonConvert.SerializeObject(requestParam)}\r\nResponse {(restApiResult == null ? string.Empty : JsonConvert.SerializeObject(restApiResult))}"); |
|
|
|
} |
|
|
|
catch { } |
|
|
|
} |
|
|
|
|
|
|
|
return new QuanTanResponse<T>() { Status = 0, Message = ex.Message }; |
|
|
|
} |
|
|
|
} |
|
|
|