|
@@ -13,6 +13,14 @@ using Newtonsoft.Json;
|
|
|
|
|
|
namespace HengshanPaymentTerminal.Http
|
|
namespace HengshanPaymentTerminal.Http
|
|
{
|
|
{
|
|
|
|
+ public enum SEND_MOTHOD
|
|
|
|
+ {
|
|
|
|
+ GET,
|
|
|
|
+ POST,
|
|
|
|
+ PUT,
|
|
|
|
+ DELETE,
|
|
|
|
+ }
|
|
|
|
+
|
|
public class HttpClientUtils:IHttpClientUtil
|
|
public class HttpClientUtils:IHttpClientUtil
|
|
{
|
|
{
|
|
static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
|
static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
|
@@ -33,18 +41,22 @@ namespace HengshanPaymentTerminal.Http
|
|
_httpClientService = new HttpClientService(httpClientFactory);
|
|
_httpClientService = new HttpClientService(httpClientFactory);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
+ public async Task<HttpResponseMessage> SendRquest(string api,string requestJson,SEND_MOTHOD mothod)
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- public async Task<HttpResponseMessage> SendOilInfo(string requestJson)
|
|
|
|
{
|
|
{
|
|
try
|
|
try
|
|
{
|
|
{
|
|
var requesStr = new StringContent(requestJson, Encoding.UTF8, "application/json");
|
|
var requesStr = new StringContent(requestJson, Encoding.UTF8, "application/json");
|
|
- return await _httpClientService.PostAsync("api/nozzle/uploadProduct", requesStr);
|
|
+ switch(mothod)
|
|
|
|
+ {
|
|
|
|
+ case SEND_MOTHOD.POST:
|
|
|
|
+ return await _httpClientService.PostAsync(api, requesStr);
|
|
|
|
+ case SEND_MOTHOD.PUT:
|
|
|
|
+ return await _httpClientService.PutAsync(api, requesStr);
|
|
|
|
+ case SEND_MOTHOD.DELETE:
|
|
|
|
+ return await _httpClientService.DeleteAsync(api, requesStr);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ throw new Exception("未定义的请求方式");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
catch (Exception ex)
|
|
{
|
|
{
|
|
@@ -66,6 +78,16 @@ namespace HengshanPaymentTerminal.Http
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public async Task<HttpResponseMessage> SendOilInfo(string requestJson)
|
|
|
|
+ {
|
|
|
|
+ return await SendRquest("api/nozzle/uploadProduct", requestJson,SEND_MOTHOD.POST);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -73,29 +95,7 @@ namespace HengshanPaymentTerminal.Http
|
|
|
|
|
|
public async Task<HttpResponseMessage> UpdateOilInfo(string requestJson)
|
|
public async Task<HttpResponseMessage> UpdateOilInfo(string requestJson)
|
|
{
|
|
{
|
|
- try
|
|
+ return await SendRquest("api/nozzle/UpdateProduct", requestJson, SEND_MOTHOD.PUT);
|
|
- {
|
|
|
|
- var requesStr = new StringContent(requestJson, Encoding.UTF8, "application/json");
|
|
|
|
- return await _httpClientService.PutAsync("api/nozzle/UpdateProduct", requesStr);
|
|
|
|
- }
|
|
|
|
- catch (Exception ex)
|
|
|
|
- {
|
|
|
|
- logger.Error(ex.Message);
|
|
|
|
-
|
|
|
|
- var error = new
|
|
|
|
- {
|
|
|
|
- Message = "发生错误",
|
|
|
|
- Error = ex.Message,
|
|
|
|
- StackTrace = ex.StackTrace
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- return new HttpResponseMessage(HttpStatusCode.InternalServerError)
|
|
|
|
- {
|
|
|
|
- Content = new StringContent(JsonConvert.SerializeObject(error), Encoding.UTF8, "application/json")
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -105,29 +105,7 @@ namespace HengshanPaymentTerminal.Http
|
|
|
|
|
|
public async Task<HttpResponseMessage> DeleteOilInfo(string requestJson)
|
|
public async Task<HttpResponseMessage> DeleteOilInfo(string requestJson)
|
|
{
|
|
{
|
|
- try
|
|
+ return await SendRquest("api/nozzle/DeleteProduct", requestJson, SEND_MOTHOD.DELETE);
|
|
- {
|
|
|
|
- var requesStr = new StringContent(requestJson, Encoding.UTF8, "application/json");
|
|
|
|
- return await _httpClientService.DeleteAsync("api/nozzle/DeleteProduct", requesStr);
|
|
|
|
- }
|
|
|
|
- catch (Exception ex)
|
|
|
|
- {
|
|
|
|
- logger.Error(ex.Message);
|
|
|
|
-
|
|
|
|
- var error = new
|
|
|
|
- {
|
|
|
|
- Message = "发生错误",
|
|
|
|
- Error = ex.Message,
|
|
|
|
- StackTrace = ex.StackTrace
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- return new HttpResponseMessage(HttpStatusCode.InternalServerError)
|
|
|
|
- {
|
|
|
|
- Content = new StringContent(JsonConvert.SerializeObject(error), Encoding.UTF8, "application/json")
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -137,29 +115,7 @@ namespace HengshanPaymentTerminal.Http
|
|
|
|
|
|
public async Task<HttpResponseMessage> SendTankInfo(string requestJson)
|
|
public async Task<HttpResponseMessage> SendTankInfo(string requestJson)
|
|
{
|
|
{
|
|
- try
|
|
+ return await SendRquest("api/nozzle/uploadTanks", requestJson, SEND_MOTHOD.POST);
|
|
- {
|
|
|
|
- var requesStr = new StringContent(requestJson, Encoding.UTF8, "application/json");
|
|
|
|
- return await _httpClientService.PostAsync("api/nozzle/uploadTanks", requesStr);
|
|
|
|
- }
|
|
|
|
- catch (Exception ex)
|
|
|
|
- {
|
|
|
|
- logger.Error(ex.Message);
|
|
|
|
-
|
|
|
|
- var error = new
|
|
|
|
- {
|
|
|
|
- Message = "发生错误",
|
|
|
|
- Error = ex.Message,
|
|
|
|
- StackTrace = ex.StackTrace
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- return new HttpResponseMessage(HttpStatusCode.InternalServerError)
|
|
|
|
- {
|
|
|
|
- Content = new StringContent(JsonConvert.SerializeObject(error), Encoding.UTF8, "application/json")
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -169,29 +125,7 @@ namespace HengshanPaymentTerminal.Http
|
|
|
|
|
|
public async Task<HttpResponseMessage> UpdateTankInfo(string requestJson)
|
|
public async Task<HttpResponseMessage> UpdateTankInfo(string requestJson)
|
|
{
|
|
{
|
|
- try
|
|
+ return await SendRquest("api/nozzle/UpdateTanks", requestJson, SEND_MOTHOD.PUT);
|
|
- {
|
|
|
|
- var requesStr = new StringContent(requestJson, Encoding.UTF8, "application/json");
|
|
|
|
- return await _httpClientService.PutAsync("api/nozzle/UpdateTanks", requesStr); ;
|
|
|
|
- }
|
|
|
|
- catch (Exception ex)
|
|
|
|
- {
|
|
|
|
- logger.Error(ex.Message);
|
|
|
|
-
|
|
|
|
- var error = new
|
|
|
|
- {
|
|
|
|
- Message = "发生错误",
|
|
|
|
- Error = ex.Message,
|
|
|
|
- StackTrace = ex.StackTrace
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- return new HttpResponseMessage(HttpStatusCode.InternalServerError)
|
|
|
|
- {
|
|
|
|
- Content = new StringContent(JsonConvert.SerializeObject(error), Encoding.UTF8, "application/json")
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -201,29 +135,7 @@ namespace HengshanPaymentTerminal.Http
|
|
|
|
|
|
public async Task<HttpResponseMessage> DeleteTankInfo(string requestJson)
|
|
public async Task<HttpResponseMessage> DeleteTankInfo(string requestJson)
|
|
{
|
|
{
|
|
- try
|
|
+ return await SendRquest("api/nozzle/DeleteTanks", requestJson, SEND_MOTHOD.DELETE);
|
|
- {
|
|
|
|
- var requesStr = new StringContent(requestJson, Encoding.UTF8, "application/json");
|
|
|
|
- return await _httpClientService.DeleteAsync("api/nozzle/DeleteTanks", requesStr);
|
|
|
|
- }
|
|
|
|
- catch (Exception ex)
|
|
|
|
- {
|
|
|
|
- logger.Error(ex.Message);
|
|
|
|
-
|
|
|
|
- var error = new
|
|
|
|
- {
|
|
|
|
- Message = "发生错误",
|
|
|
|
- Error = ex.Message,
|
|
|
|
- StackTrace = ex.StackTrace
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- return new HttpResponseMessage(HttpStatusCode.InternalServerError)
|
|
|
|
- {
|
|
|
|
- Content = new StringContent(JsonConvert.SerializeObject(error), Encoding.UTF8, "application/json")
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -233,29 +145,7 @@ namespace HengshanPaymentTerminal.Http
|
|
|
|
|
|
public async Task<HttpResponseMessage> SendNozzleInfo(string requestJson)
|
|
public async Task<HttpResponseMessage> SendNozzleInfo(string requestJson)
|
|
{
|
|
{
|
|
- try
|
|
+ return await SendRquest("api/nozzle/uploadNozzle", requestJson, SEND_MOTHOD.POST);
|
|
- {
|
|
|
|
- var requesStr = new StringContent(requestJson, Encoding.UTF8, "application/json");
|
|
|
|
- return await _httpClientService.PostAsync("api/nozzle/uploadNozzle", requesStr);
|
|
|
|
- }
|
|
|
|
- catch (Exception ex)
|
|
|
|
- {
|
|
|
|
- logger.Error(ex.Message);
|
|
|
|
-
|
|
|
|
- var error = new
|
|
|
|
- {
|
|
|
|
- Message = "发生错误",
|
|
|
|
- Error = ex.Message,
|
|
|
|
- StackTrace = ex.StackTrace
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- return new HttpResponseMessage(HttpStatusCode.InternalServerError)
|
|
|
|
- {
|
|
|
|
- Content = new StringContent(JsonConvert.SerializeObject(error), Encoding.UTF8, "application/json")
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -265,29 +155,7 @@ namespace HengshanPaymentTerminal.Http
|
|
|
|
|
|
public async Task<HttpResponseMessage> UpdateNozzleInfo(string requestJson)
|
|
public async Task<HttpResponseMessage> UpdateNozzleInfo(string requestJson)
|
|
{
|
|
{
|
|
- try
|
|
+ return await SendRquest("api/nozzle/UpdateNozzle", requestJson, SEND_MOTHOD.PUT);
|
|
- {
|
|
|
|
- var requesStr = new StringContent(requestJson, Encoding.UTF8, "application/json");
|
|
|
|
- return await _httpClientService.PutAsync("api/nozzle/UpdateNozzle ", requesStr);
|
|
|
|
- }
|
|
|
|
- catch (Exception ex)
|
|
|
|
- {
|
|
|
|
- logger.Error(ex.Message);
|
|
|
|
-
|
|
|
|
- var error = new
|
|
|
|
- {
|
|
|
|
- Message = "发生错误",
|
|
|
|
- Error = ex.Message,
|
|
|
|
- StackTrace = ex.StackTrace
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- return new HttpResponseMessage(HttpStatusCode.InternalServerError)
|
|
|
|
- {
|
|
|
|
- Content = new StringContent(JsonConvert.SerializeObject(error), Encoding.UTF8, "application/json")
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -297,29 +165,7 @@ namespace HengshanPaymentTerminal.Http
|
|
|
|
|
|
public async Task<HttpResponseMessage> DeleteNozzleInfo(string requestJson)
|
|
public async Task<HttpResponseMessage> DeleteNozzleInfo(string requestJson)
|
|
{
|
|
{
|
|
- try
|
|
+ return await SendRquest("api/nozzle/DeleteNozzle", requestJson, SEND_MOTHOD.DELETE);
|
|
- {
|
|
|
|
- var requesStr = new StringContent(requestJson, Encoding.UTF8, "application/json");
|
|
|
|
- return await _httpClientService.DeleteAsync("api/nozzle/DeleteNozzle", requesStr);
|
|
|
|
- }
|
|
|
|
- catch (Exception ex)
|
|
|
|
- {
|
|
|
|
- logger.Error(ex.Message);
|
|
|
|
-
|
|
|
|
- var error = new
|
|
|
|
- {
|
|
|
|
- Message = "发生错误",
|
|
|
|
- Error = ex.Message,
|
|
|
|
- StackTrace = ex.StackTrace
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- return new HttpResponseMessage(HttpStatusCode.InternalServerError)
|
|
|
|
- {
|
|
|
|
- Content = new StringContent(JsonConvert.SerializeObject(error), Encoding.UTF8, "application/json")
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -331,58 +177,58 @@ namespace HengshanPaymentTerminal.Http
|
|
|
|
|
|
public async Task<HttpResponseMessage> SendNozzleStatu(string requestJson)
|
|
public async Task<HttpResponseMessage> SendNozzleStatu(string requestJson)
|
|
{
|
|
{
|
|
- try
|
|
+ return await SendRquest("api/nozzle/updateNozzleStatus", requestJson, SEND_MOTHOD.PUT);
|
|
- {
|
|
|
|
- var requesStr = new StringContent(requestJson, Encoding.UTF8, "application/json");
|
|
|
|
- return await _httpClientService.PutAsync("api/nozzle/updateNozzleStatus", requesStr);
|
|
|
|
- }
|
|
|
|
- catch (Exception ex)
|
|
|
|
- {
|
|
|
|
- logger.Error(ex.Message);
|
|
|
|
-
|
|
|
|
- var error = new
|
|
|
|
- {
|
|
|
|
- Message = "发生错误",
|
|
|
|
- Error = ex.Message,
|
|
|
|
- StackTrace = ex.StackTrace
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- return new HttpResponseMessage(HttpStatusCode.InternalServerError)
|
|
|
|
- {
|
|
|
|
- Content = new StringContent(JsonConvert.SerializeObject(error), Encoding.UTF8, "application/json")
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
public async Task<HttpResponseMessage> CreateTransaction(string requestJson)
|
|
public async Task<HttpResponseMessage> CreateTransaction(string requestJson)
|
|
{
|
|
{
|
|
- try
|
|
+ return await SendRquest("api/Transactions/CreateTransactions", requestJson, SEND_MOTHOD.POST);
|
|
- {
|
|
+ }
|
|
- var requesStr = new StringContent(requestJson, Encoding.UTF8, "application/json");
|
|
|
|
- return await _httpClientService.PostAsync("api/Transactions/CreateTransactions", requesStr);
|
|
|
|
- }
|
|
|
|
- catch (Exception ex)
|
|
|
|
- {
|
|
|
|
- logger.Error(ex.Message);
|
|
|
|
-
|
|
|
|
- var error = new
|
|
|
|
- {
|
|
|
|
- Message = "发生错误",
|
|
|
|
- Error = ex.Message,
|
|
|
|
- StackTrace = ex.StackTrace
|
|
|
|
- };
|
|
|
|
|
|
|
|
-
|
|
+
|
|
- return new HttpResponseMessage(HttpStatusCode.InternalServerError)
|
|
+
|
|
- {
|
|
+
|
|
- Content = new StringContent(JsonConvert.SerializeObject(error), Encoding.UTF8, "application/json")
|
|
+
|
|
- };
|
|
+
|
|
|
|
+
|
|
|
|
+ public async Task<HttpResponseMessage> SendAuthorizationResult(string requestJson)
|
|
|
|
+ {
|
|
|
|
+ return await SendRquest("api/Nozzle/UpdateNozzleAuthorization", requestJson, SEND_MOTHOD.PUT);
|
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public async Task<HttpResponseMessage> SendUnAuthorizationResult(string requestJson)
|
|
|
|
+ {
|
|
|
|
+ return await SendRquest("api/Nozzle/UpdateCancelNozzleAuthorization", requestJson, SEND_MOTHOD.PUT);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public async Task<HttpResponseMessage> SendRecievePaidNotice(string requestJson)
|
|
|
|
+ {
|
|
|
|
+ return await SendRquest("", requestJson, SEND_MOTHOD.POST);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public async Task<HttpResponseMessage> SendRecieveRefundNotice(string requestJson)
|
|
|
|
+ {
|
|
|
|
+ return await SendRquest("", requestJson, SEND_MOTHOD.POST);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|