You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
BookingHeChuan/Myshipping.Application/Service/RulesEngine/RulesEngineClientService.cs

88 lines
2.6 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using Furion.FriendlyException;
using Furion.JsonSerialization;
using Furion;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Furion.RemoteRequest.Extensions;
using Furion.DependencyInjection;
using Microsoft.AspNetCore.Mvc;
using System.Xml.Linq;
using Furion.DynamicApiController;
using Microsoft.AspNetCore.Authorization;
namespace Myshipping.Application
{
/// <summary>
/// 请求规则平台
/// </summary>
public class RulesEngineClientService: IRulesEngineClientService, IDynamicApiController, ITransient
{
/// <summary>
///
/// </summary>
public RulesEngineClientService()
{
}
/// <summary>
/// 海运订舱请求规则引擎
/// </summary>
/// <param name="model">海运订舱请求业务</param>
/// <returns>返回用户信息</returns>
[AllowAnonymous]
[ApiDescriptionSettings("Application", Name = "ExcuteRulesEngineOceanBooking", Order = 1)]
[HttpPost]
public async Task<RulesEngineWebApiResult> ExcuteRulesEngineOceanBooking(RulesEngineOrderBookingMessageInfo model)
{
return await ExcuteRulesEngine(model);
}
/// <summary>
/// 请求规则平台
/// </summary>
/// <param name="BusinessMsg"></param>
/// <returns></returns>
private async Task<RulesEngineWebApiResult> ExcuteRulesEngine(RulesEngineOrderBookingMessageInfo info)
{
RulesEngineWebApiResult model = null;
/*
1、读取配置文件中的规则引擎URL
2、填充请求的类并生成JSON报文
3、POST请求接口并记录回执。
4、返回信息。
*/
var url = App.Configuration["RulesEngineUrl"];
try
{
var res = await url.SetHttpMethod(HttpMethod.Post)
.SetBody(JSON.Serialize(info), "application/json")
.SetContentEncoding(Encoding.UTF8)
.PostAsync();
if (res.StatusCode == System.Net.HttpStatusCode.OK)
{
var userResult = await res.Content.ReadAsStringAsync();
model = JSON.Deserialize<RulesEngineWebApiResult>(userResult);
}
}
catch (Exception ex)
{
//写日志
if (ex is HttpRequestException)
throw Oops.Oh(10000002);
}
return model;
}
}
}