UpstreamService.cs 2.17 KB
using Hh.Mes.Common.config;
using Hh.Mes.Common.Json;
using Hh.Mes.POJO.Entity;
using Hh.Mes.POJO.EnumEntitys;
using Hh.Mes.POJO.Response;
using Hh.Mes.Service.Repository;
using NPOI.POIFS.FileSystem;
using System;
using System.Collections.Generic;
using System.Text;

namespace Hh.Mes.Service.ApiService
{
    public partial class UpstreamService : RepositorySqlSugar<sys_user>
    {
        /// <summary>
        /// 删除=0
        /// </summary>
        public int DeleteFlag = (int)EnumDeleteOrAdd.删除;

        /// <summary>
        /// 新增或更新1
        /// </summary>
        public int AddOrUpdateFlag = (int)EnumDeleteOrAdd.新增或更新;

        /// <summary>
        /// 获取token true 请求成功 T2是对应的token值,false失败
        /// </summary>
        /// <returns></returns>
        public Tuple<bool, string> GetMomToken()
        {
            var url = GetDictionaryDictValue("UrlMomToken", "GetUrl");
            var jsonData = new
            {
                username = ConfigRead.GetInstance.GetAppsetConnection().AppCustomExtend2, //"esb@P_SYS_COMPANY_393bb2f058ac4a8ba59510a1a228d383",
                password = ConfigRead.GetInstance.GetAppsetConnection().AppCustomExtend3,//"efb03b68f7a0c2a331fc61a491c4b2d7",
                verify = "0"
            };

            var httpResult = HttpMan(url, jsonData, EnumLog.Mom获取Token.ToString());
            if (!httpResult.Status) return new Tuple<bool, string>(false, httpResult.Message);
            var json = DynamicJson.Parse(httpResult.Result);
            return new Tuple<bool, string>(true, json.data.access_token);
        }

        /// <summary>
        /// type is I or U value
        /// </summary>
        /// <param name="type"></param>
        /// <param name="response"></param>
        /// <returns></returns>
        public ResponseUpstream<string>  typeValidation(string type, ResponseUpstream<string> response)
        {
            if ("IU".IndexOf(type)==-1)
            {
                response.ResponseError($"【上位系统】【type 只能是I 或者U标识】,请核实确认!");
                return response;
            }
            return response;    
        }
    }
}