对接老ops
This commit is contained in:
81
src/WMS.Web.Domain/Services/Public/OpsService.cs
Normal file
81
src/WMS.Web.Domain/Services/Public/OpsService.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WMS.Web.Core.Dto;
|
||||
using WMS.Web.Domain.IService.Public;
|
||||
using WMS.Web.Domain.Options;
|
||||
|
||||
namespace WMS.Web.Domain.Services.Public
|
||||
{
|
||||
/// <summary>
|
||||
/// ops服务
|
||||
/// </summary>
|
||||
public class OpsService : IOpsService
|
||||
{
|
||||
private readonly IHttpClientService _httpClientService;
|
||||
private readonly ILogger<OpsService> _logger;
|
||||
private readonly IMemoryCache _memoryCache;
|
||||
private int hours = 10;//过期时间 默认10小时
|
||||
private readonly OpsOptions _option;
|
||||
|
||||
public OpsService(IHttpClientService httpClientService, ILogger<OpsService> logger,
|
||||
IMemoryCache memoryCache, IOptions<OpsOptions> option)
|
||||
{
|
||||
this._memoryCache = memoryCache;
|
||||
this._httpClientService = httpClientService;
|
||||
this._logger = logger;
|
||||
_option = option?.Value;
|
||||
}
|
||||
|
||||
public async Task GetBox(OpsBoxRequest request)
|
||||
{
|
||||
var token = await GetToken();
|
||||
Dictionary<string, string> dicHeaders = new Dictionary<string, string>();
|
||||
dicHeaders.Add("Authorization", "Bearer " + token);
|
||||
//_httpClientService.BuildHttpClient(contentHeaders);
|
||||
var res= await _httpClientService.PostAsync<OpsReponse>(_option.Url + "BarCode/carton-box_api/carton-box", JsonConvert.SerializeObject(request), dicHeaders);
|
||||
}
|
||||
|
||||
private async Task<string> GetToken()
|
||||
{
|
||||
OpsLogin login = new OpsLogin()
|
||||
{
|
||||
hAccount = _option.UserName,
|
||||
hPassword = _option.PassWord
|
||||
};
|
||||
var res = await _httpClientService.PostAsync<OpsReponse>(_option.Url + "api/login", JsonConvert.SerializeObject(login));
|
||||
var token = res.data?.token ?? "";
|
||||
if (string.IsNullOrEmpty(token))
|
||||
_logger.LogInformation("老Ops登录失败:" + res?.errors);
|
||||
return token;
|
||||
}
|
||||
|
||||
}
|
||||
public class OpsLogin
|
||||
{
|
||||
public OpsLogin() { }
|
||||
public string hAccount { get; set; } = "admin";
|
||||
public string hPassword { get; set; } = "888888";
|
||||
}
|
||||
public class OpsInfo
|
||||
{
|
||||
public int code { get; set; }
|
||||
public string message { get; set; }
|
||||
public string date { get; set; }
|
||||
public string token { get; set; }
|
||||
}
|
||||
public class OpsReponse
|
||||
{
|
||||
public int statusCode { get; set; }
|
||||
public bool succeeded { get; set; }
|
||||
public string errors { get; set; }
|
||||
public string extras { get; set; }
|
||||
|
||||
public OpsInfo data { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user