hwh
2024-06-21 158a01ee5fa6903111790c52bfb778f93f797028
Wms/Wms/Controllers/UpApiController.cs
@@ -15,6 +15,11 @@
using WMS.DAL;
using Microsoft.AspNetCore.Authorization;
using Utility;
using System.Collections.Generic;
using System.Reflection.Emit;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
namespace Wms.Controllers
{
@@ -31,7 +36,7 @@
        private readonly IArrivalNoticeServer _arrivalNoticeSvc;
        private readonly IStockCheckServer _stockCheckSvc;//盘点单Svc 
        private readonly IProcurePlanServer _procurePlanSvc;//采购单Svs
        public UpApiController(IOptions<ApiUrlConfig> setting,IExportNoticeServer exNoticeSvc,IArrivalNoticeServer arrivalNoticeServer,IStockCheckServer stockCheckSvc, IProcurePlanServer procurePlanSvc)
        public UpApiController(IOptions<ApiUrlConfig> setting, IExportNoticeServer exNoticeSvc, IArrivalNoticeServer arrivalNoticeServer, IStockCheckServer stockCheckSvc, IProcurePlanServer procurePlanSvc)
        {
            _config = setting.Value;
            _exNoticeSvc = exNoticeSvc;
@@ -78,7 +83,7 @@
        /// <param name="model">入库单号</param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult FinishAsn(IdVm model)
        public IActionResult FinishAsn(IdVm model)
        {
            try
            {
@@ -125,7 +130,7 @@
                    return Ok(new { code = 1, msg = "未获取到当前操作人信息" });
                }
                _arrivalNoticeSvc.ByPdaFinish(model.Code, model.Code.Substring(0,2) == "AS" ? _config.ErpHost + _config.AsnFinishUrl : _config.ErpHost + _config.SoFinishUrl, int.Parse(userId));
                _arrivalNoticeSvc.ByPdaFinish(model.Code, model.Code.Substring(0, 2) == "AS" ? _config.ErpHost + _config.AsnFinishUrl : _config.ErpHost + _config.SoFinishUrl, int.Parse(userId));
                return Ok(new { code = 0, count = 0, msg = "单据复核并上传成功" });
            }
@@ -331,7 +336,7 @@
            {
                SoResInfo result = _exNoticeSvc.ErpAddExportNotice(model);
                return Ok(result);
            }
            catch (Exception e)
            {
@@ -464,24 +469,45 @@
        }
        [HttpGet]
        public IActionResult Demo3()
        [ServiceFilter(typeof(ApiResponseActionFilter))]
        public string Demo3()
        {
            var result = new ErpModel { Success = -1, Message = "" };
            try
            {
                var time = DateTimeOffset.Now.ToUnixTimeSeconds();
                result = new ErpModel { Success = 0, Message = time.ToString() };
            string jsonParams = "{\"param1\": \"value1\", \"param2\": \"value2\"}";
                return Ok(result);
            }
            catch (Exception e)
            {
                result.Message = e.Message;
                return Ok(result);
            }
            // 生成时间戳(Unix 时间戳)
            var timestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString();
            // 生成签名
            var signature = GenerateSignature(jsonParams);
            // 输出签名
            Console.WriteLine("Generated Signature: " + signature);
            return signature;
        }
        private static string GenerateSignature(string jsonParams)
        {
            var appKey = "90170307d4184844ac2a26b431f79980";
            // 将 JSON 字符串转换为 JObject
            JObject jObject = JObject.Parse(jsonParams);
            // 过滤掉数组类型的属性
            var filteredProperties = jObject.Properties()
                .Where(p => p.Value.Type != JTokenType.Array)
                .ToDictionary(p => p.Name, p => p.Value.ToString());
            // 添加时间戳(Unix 时间戳)
            var timestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString();
            filteredProperties.Add("timestamp", timestamp);
            filteredProperties.Add("appKey", appKey);
            // 构建待签名字符串
            var signatureBaseString = string.Join("&", filteredProperties.OrderBy(p => p.Key).Select(p => p.Key + "=" + p.Value));
            // 计算 MD5 值
            var computedSignature = Md5Tools.CalcMd5(signatureBaseString);
            return computedSignature;
        }
        #endregion
    }
}