using Newtonsoft.Json.Serialization;
|
using Newtonsoft.Json;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using WIDESEA_DTO.MLS;
|
using WIDESEA_External.IMLSService;
|
using WIDESEA_IBasicRepository;
|
using WIDESEA_Common.APIEnum;
|
using WIDESEA_Core.Helper;
|
using WIDESEA_Model.Models;
|
|
namespace WIDESEA_External.PLSService
|
{
|
public class InvokeMLSService : IInvokeMLSService
|
{
|
private readonly IApiInfoRepository _apiInfoRepository;
|
|
public InvokeMLSService(IApiInfoRepository apiInfoRepository)
|
{
|
_apiInfoRepository = apiInfoRepository;
|
}
|
JsonSerializerSettings settings = new JsonSerializerSettings
|
{
|
ContractResolver = new CamelCasePropertyNamesContractResolver()
|
};
|
|
/// <summary>
|
/// 获取token
|
/// </summary>
|
/// <param name="receiveMLSToken"></param>
|
/// <returns></returns>
|
/// <exception cref="NotImplementedException"></exception>
|
public string ReceiveTokenVoid()
|
{
|
try
|
{
|
Dt_ApiInfo apiInfo = _apiInfoRepository.QueryFirst(x => x.ApiCode == APIEnum.InvokeMLSTokenApi.ToString());
|
|
string MlsPwd = AppSettings.Get("MlsPwd");
|
string MlsUser = AppSettings.Get("MlsUser");
|
var finalRequest = new
|
{
|
mlsUser = MlsUser,
|
mlsPwd = MlsPwd
|
};
|
|
string requestJson = JsonConvert.SerializeObject(finalRequest, settings);
|
|
string response = HttpHelper.Post(apiInfo.ApiAddress, requestJson);
|
|
MLSRequestContent mLSRequestContent = response.DeserializeObject<MLSRequestContent>();
|
|
if (mLSRequestContent.Code == "0" && mLSRequestContent.Data!= null)
|
{
|
apiInfo.Remark = (string)mLSRequestContent.Data;
|
_apiInfoRepository.UpdateData(apiInfo);
|
}
|
else
|
{
|
return "获取token失败,或返回token值为空";
|
}
|
return response;
|
}
|
catch(Exception ex)
|
{
|
return ex.Message;
|
}
|
}
|
}
|
}
|