You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
241 lines
9.2 KiB
241 lines
9.2 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Net.Http;
|
|
using System.Security.Cryptography;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace TaskManager.Controllers
|
|
{
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 常熟安通林奇瑞的Http接口
|
|
///// </summary>
|
|
//public static class HttpCheryMOMController
|
|
//{
|
|
// private static string appKey = "8EG";
|
|
// private static string appSecret = "3tdmkx&v%TJqTM@GA3Va";
|
|
// private static string baseNo = "13";
|
|
// public static string DomainUrl = "https://api-mom.mychery.com:8443"; // 正式环境地址
|
|
|
|
// private static readonly HttpClient httpClient = new HttpClient
|
|
// {
|
|
// Timeout = TimeSpan.FromSeconds(30)
|
|
// };
|
|
|
|
// /// <summary>
|
|
// /// 通用POST请求方法
|
|
// /// </summary>
|
|
// /// <param name="url">请求地址</param>
|
|
// /// <param name="jsonData">JSON请求体</param>
|
|
// /// <param name="error">错误信息</param>
|
|
// /// <returns>响应结果</returns>
|
|
// public static async Task<string> PostAsync(string url, string jsonData, out string error)
|
|
// {
|
|
// error = string.Empty;
|
|
// try
|
|
// {
|
|
// // 生成时间戳和签名
|
|
// string timeStamp = HttpUtilityAnTongLin.GetCurrentTimestampMillis().ToString();
|
|
// string original = $"{appKey}{timeStamp}{appSecret}";
|
|
// string sign = HttpUtilityAnTongLin.StringEncryMD5(original);
|
|
|
|
// // 构造请求
|
|
// var request = new HttpRequestMessage(HttpMethod.Post, url)
|
|
// {
|
|
// Content = new StringContent(jsonData, Encoding.UTF8, "application/json")
|
|
// };
|
|
// request.Headers.Add("appKey", appKey);
|
|
// request.Headers.Add("timeStamp", timeStamp);
|
|
// request.Headers.Add("sign", sign);
|
|
// request.Headers.Add("signType", "MD5");
|
|
// request.Headers.Add("baseNo", baseNo);
|
|
|
|
// // 发送请求
|
|
// var response = await httpClient.SendAsync(request);
|
|
// response.EnsureSuccessStatusCode();
|
|
// return await response.Content.ReadAsStringAsync();
|
|
// }
|
|
// catch (HttpRequestException ex)
|
|
// {
|
|
// error = ex.Message;
|
|
// return string.Empty;
|
|
// }
|
|
// }
|
|
|
|
// #region 配送单接口(看板发货)
|
|
// private static string delivebillUrl = $"{DomainUrl}/api-gateway/common-api/map/info";
|
|
|
|
// /// <summary>
|
|
// /// 配送单接口
|
|
// /// </summary>
|
|
// /// <param name="mapSheetNoList">配送单号列表</param>
|
|
// /// <param name="type">1=待入库配送单信息,2=待出库配送单信息(默认)</param>
|
|
// /// <returns>接口响应结果</returns>
|
|
// public static async Task<string> DeliveBillInfoAsync(List<string> mapSheetNoList, int type = 2)
|
|
// {
|
|
// string error = string.Empty;
|
|
// var req = new SortInputPara
|
|
// {
|
|
// base_no = baseNo,
|
|
// s_datetime = DateTime.Now.AddDays(-30).ToString("yyyy-MM-dd HH:mm:ss"),
|
|
// e_datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
|
|
// map_sheet_no = mapSheetNoList.ToArray(),
|
|
// type = type
|
|
// };
|
|
|
|
// try
|
|
// {
|
|
// string jsonData = JsonConvert.SerializeObject(req);
|
|
// string result = await PostAsync(delivebillUrl, jsonData, out error);
|
|
// WebLogbHelper.WriteLog($"接口DeliveBillInfo入参:{jsonData}, 返回:{result}");
|
|
// return result;
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// WebLogbHelper.WriteLog($"接口DeliveBillInfo异常:{ex}");
|
|
// error = ex.Message;
|
|
// return string.Empty;
|
|
// }
|
|
// }
|
|
// #endregion
|
|
|
|
// #region 外排配送单接口(排序发货)
|
|
// private static string jisSheetUrl = $"{DomainUrl}/api-gateway/common-api/map/jisSheet";
|
|
|
|
// /// <summary>
|
|
// /// 外排配送单接口
|
|
// /// </summary>
|
|
// /// <param name="mapSheetNoList">单号列表</param>
|
|
// /// <returns>接口响应结果</returns>
|
|
// public static async Task<string> JisSheetAsync(List<string> mapSheetNoList)
|
|
// {
|
|
// string error = string.Empty;
|
|
// var req = new InputPara
|
|
// {
|
|
// base_no = baseNo,
|
|
// s_datetime = DateTime.Now.AddDays(-30).ToString("yyyy-MM-dd HH:mm:ss"),
|
|
// e_datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
|
|
// map_sheet_no = mapSheetNoList.ToArray()
|
|
// };
|
|
|
|
// try
|
|
// {
|
|
// string jsonData = JsonConvert.SerializeObject(req);
|
|
// string result = await PostAsync(jisSheetUrl, jsonData, out error);
|
|
// WebLogbHelper.WriteLog($"接口JisSheet入参:{jsonData}, 返回:{result}");
|
|
// return result;
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// WebLogbHelper.WriteLog($"接口JisSheet异常:{ex}");
|
|
// error = ex.Message;
|
|
// return string.Empty;
|
|
// }
|
|
// }
|
|
// #endregion
|
|
|
|
// /// <summary>
|
|
// /// 对象转JSON字符串
|
|
// /// </summary>
|
|
// public static string ObjectToJson(object obj)
|
|
// {
|
|
// return JsonConvert.SerializeObject(obj, Formatting.Indented, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
|
|
// }
|
|
|
|
// /// <summary>
|
|
// /// JSON字符串转对象
|
|
// /// </summary>
|
|
// public static T JsonToObject<T>(string json)
|
|
// {
|
|
// return JsonConvert.DeserializeObject<T>(json);
|
|
// }
|
|
//}
|
|
|
|
///// <summary>
|
|
///// 时间戳和MD5加密工具类
|
|
///// </summary>
|
|
//public static class HttpUtilityAnTongLin
|
|
//{
|
|
// /// <summary>
|
|
// /// MD5加密
|
|
// /// </summary>
|
|
// public static string StringEncryMD5(string input)
|
|
// {
|
|
// using var md5 = MD5.Create();
|
|
// byte[] hashBytes = md5.ComputeHash(Encoding.UTF8.GetBytes(input));
|
|
// return BitConverter.ToString(hashBytes).Replace("-", "").ToUpper();
|
|
// }
|
|
|
|
// /// <summary>
|
|
// /// 获取当前时间戳(毫秒)
|
|
// /// </summary>
|
|
// public static long GetCurrentTimestampMillis()
|
|
// {
|
|
// return (long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds;
|
|
// }
|
|
//}
|
|
|
|
///// <summary>
|
|
///// 接口响应基类
|
|
///// </summary>
|
|
///// <typeparam name="T">数据类型</typeparam>
|
|
//public class Res<T> where T : class
|
|
//{
|
|
// public int code { get; set; } = -1;
|
|
// public string message { get; set; } = string.Empty;
|
|
// public T data { get; set; } = default!;
|
|
//}
|
|
|
|
//#region 接口请求参数类
|
|
//public class InputPara
|
|
//{
|
|
// public string base_no { get; set; } = string.Empty;
|
|
// public string s_datetime { get; set; } = string.Empty;
|
|
// public string e_datetime { get; set; } = string.Empty;
|
|
// public string[] map_sheet_no { get; set; } = Array.Empty<string>();
|
|
//}
|
|
|
|
//public class SortInputPara : InputPara
|
|
//{
|
|
// public int type { get; set; }
|
|
//}
|
|
//#endregion
|
|
|
|
//#region 日志帮助类
|
|
//public static class WebLogbHelper
|
|
//{
|
|
// private static readonly string LogDirectory = Path.Combine(AppContext.BaseDirectory, "logs");
|
|
|
|
// static WebLogbHelper()
|
|
// {
|
|
// Directory.CreateDirectory(LogDirectory);
|
|
// }
|
|
|
|
// /// <summary>
|
|
// /// 写入日志
|
|
// /// </summary>
|
|
// /// <param name="message">日志内容</param>
|
|
// public static void WriteLog(string message)
|
|
// {
|
|
// string logPath = Path.Combine(LogDirectory, $"{DateTime.Now:yyyy-MM-dd}.log");
|
|
// lock (typeof(WebLogbHelper))
|
|
// {
|
|
// File.AppendAllText(logPath, $"{DateTime.Now:yyyy-MM-dd HH:mm:ss} >>> {message}{Environment.NewLine}");
|
|
// }
|
|
// }
|
|
//}
|
|
//#endregion
|
|
|
|
}
|
|
|