IDP对接试车

This commit is contained in:
夏菊 2025-07-11 08:58:49 +08:00
parent 9a5ffa4632
commit 7a6078e981
7 changed files with 253 additions and 12 deletions

View File

@ -592,6 +592,7 @@
<Compile Include="HSSE\Technique\SpecialSchemeService.cs" />
<Compile Include="HSSE\Technique\Technique_CheckItemDetailService.cs" />
<Compile Include="HSSE\Technique\Technique_CheckItemSetService.cs" />
<Compile Include="IDP\IDPDataService.cs" />
<Compile Include="JDGL\Check\ElectricalCompletionService.cs" />
<Compile Include="JDGL\Check\EquipmentCompletionService.cs" />
<Compile Include="JDGL\Check\LowTankCompletionService.cs" />

View File

@ -0,0 +1,170 @@
using Apache.NMS.ActiveMQ.Commands;
using Microsoft.SqlServer.Dts.Runtime;
using Model;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Org.BouncyCastle.Ocsp;
using SgManager.AI;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Security.Cryptography;
using System.Text;
namespace BLL
{
public static class IDPDataService
{
//private static readonly string IDPApiUrl = "https://idp.cwcec.com/";
private static readonly string IDPApiUrl = SysConstSetService.WuHuanIDPPath;
////private static readonly string publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQChnc2YD0YzJPx6QTh+/n7XzjR1ugFzrsmPolJhpCfWMKrSGbT7iX/Kgcm1AI+T95K4Jzv3KS42QTecZ1ziJ4Rr9Luzw+9ZCSjMZgrmAUbY5IeBaA6GzaSk8UWHZ4n5PL+GUGq+2f+COL7+KCS2AxEpaqDZVrJrIfg/UektdgNyzwIDAQAB";
private static readonly string publicKey = "<RSAKeyValue><Modulus>g1sk7Xtc1TJouHdY4+FAe5atGCu2n17NhoKVDV57pki1IL+9+S7BY4gxAjmMkUU2/cbCCdbPoUJLBrCBCjX7yI3UJW6FZwQWkn3kVoeulLEwdPCIq/GUjMXaWf3Iaaad5wBUFbfXAzv15VN6z48Nt1IY/O8YEzhIpuZdtEgDdos=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>";
/// <summary>
/// 第三方加密认证接口
/// </summary>
/// 五环IDP系统SessionId有效期30分钟
/// <returns></returns>
public static SessionItem GetAuthenticationSession()
{
//// 创建RSA加密服务提供者
////using (RSA rsa = RSA.Create())
//using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())
//{
//// 获取公钥false表示只导出公钥
//string publicKey = rsa.ToXmlString(false);
//// 获取私钥true表示导出公钥和私钥
//string privateKey = rsa.ToXmlString(true);
SessionItem session = new SessionItem();
////用户名加密
//string encryptedUsername = EncryptData("dataviewer", publicKey);
////密码加密
//string encryptedPassword = EncryptData("a3365$!", publicKey);
//用户名加密后的密文
string encryptedUsername = "k0N0tx/hfRPY0v2lq1G8eH6hCO+UiMqlSZi1PD6bhGf4YpP/koJq5hfMsDSzdn3dZjzExrwyrjFWp/1jZLde0+gRbQ0D7tzm0R5D6AmriodD2cJvrEiwtDy7SeGNloSaNmpTEMuycpuueiOeGhMkKnTwWfRkEw73lxEpTmaahq4=";
//密码加密后的密文
string encryptedPassword = "HLLroiNJJzyTWJt9td1xgChbVzyQkoxWCGGXqdwI2cvlUF/A30FAPaInszSwEhNRQlJZZ01EODElemkgv36DMF+XGwfDi0BfIq9jKG+/+wq0TVOHNhiu2NPzpn5Ji2X3yXIXpH1zv6XEtkvx/qiLToZYfRQCufsl5vH1cZxk2fQ=";
string url = $"{IDPApiUrl}UAMS/authEncrypt";
string contenttype = "application/json;charset=utf-8";
var body = new
{
encryptedUsername = encryptedUsername,
encryptedPassword = encryptedPassword
};
string pushContent = JsonConvert.SerializeObject(body);
//var returndata = BLL.APIGetHttpService.OutsideHttp(url, "POST", null, null, pushContent);
string strJosn = APIGetHttpService.Http(url, "POST", contenttype, null, pushContent);
JObject obj = JObject.Parse(strJosn);
if (!string.IsNullOrEmpty(strJosn))
{
string value = obj["value"].ToString();
string name = obj["name"].ToString();
session.value = value;
session.name = name;
}
return session;
//}
}
/// <summary>
/// 加密字符串
/// </summary>
/// <param name="data">加密信息</param>
/// <param name="publicKey">公钥</param>
/// <returns></returns>
public static string EncryptData(string data, string publicKey)
{
using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())
{
string result = string.Empty;
try
{
rsa.FromXmlString(publicKey); //从字符串加载公钥
byte[] dataBytes = Encoding.UTF8.GetBytes(data);
byte[] encryptedBytes = rsa.Encrypt(dataBytes, false); //使用公钥加密数据false表示使用OAEP填充方式
result = Convert.ToBase64String(encryptedBytes); //返回Base64编码的加密数据
}
catch (Exception ex)
{
Console.WriteLine("Error encrypting: {0}", ex.Message);
}
return result;
}
}
/// <summary>
/// 获取工作包结构化数据
/// </summary>
public static void GetIDPProjectMasterData()
{
string projectId = string.Empty;//五环主数据项目Id
string wbsCode = string.Empty;//五环主数据wbs编码
string workitemCode = string.Empty;//五环主数据文件类别码
//https://idp.cwcec.com/OSS/projects/9100168/wbs/000000/workitems/CP2100/objects/latest
//string url = $"{IDPApiUrl}/OSS/projects/{projectId}/wbs/{wbsCode}/workitems/{workitemCode}/objects/latest";
string url = $"{IDPApiUrl}/OSS/projects/9100168/wbs/000000/workitems/CP2100/objects/latest";
try
{
var session = GetAuthenticationSession();
ErrLogInfo.WriteLog($"Session——name{session.name}value{session.value}");
Hashtable newToken = new Hashtable { { session.name, session.value } };
var returndata = BLL.APIGetHttpService.OutsideHttp(url, "GET", null, newToken, null);
}
catch (WebException ex)
{
}
finally
{
}
}
//public static void AddPMP_Project(List<Model.PMP_Project> newtables)
//{
// Model.SGGLDB db = Funs.DB;
// db.PMP_Project.InsertAllOnSubmit(newtables);
// db.SubmitChanges();
//}
//public static void DeleteAllPMP_Project()
//{
// Model.SGGLDB db = Funs.DB;
// if (db.PMP_Project.FirstOrDefault() != null)
// {
// db.PMP_Project.DeleteAllOnSubmit(db.PMP_Project);
// db.SubmitChanges();
// }
//}
}
public class SessionItem
{
/// <summary>
/// value
/// </summary>
public string value { get; set; }
/// <summary>
/// name
/// </summary>
public string name { get; set; }
}
}

View File

@ -64,7 +64,7 @@ namespace BLL
}
catch (Exception eee)
{
ErrLogInfo.WriteLog("获取五环PMP系统Token出错1" + eee.StackTrace + eee.Message);
ErrLogInfo.WriteLog("获取五环PMP系统Token出错" + eee.StackTrace + eee.Message);
}
return tokenItem;
}

View File

@ -172,7 +172,40 @@
}
#region IDP
private static string _WuHuanIDPPath;
//private static string _IDPToken;
//private static string _IDPTokenExTime;
public static string WuHuanIDPPath
{
get
{
var sysSet5 = (from x in Funs.DB.Sys_Set where x.SetName == "IDP接口地址" select x).ToList().FirstOrDefault();
if (sysSet5 != null)
{
_WuHuanIDPPath = sysSet5.SetValue;
}
else
{
_WuHuanIDPPath = "";
}
return _WuHuanIDPPath;
}
set
{
_WuHuanIDPPath = value;
}
}
#endregion
#region PMP
private static string _WuHuanPMPPath;
private static string _PMPToken;
private static string _PMPTokenExTime;
public static string WuHuanPMPPath
{
@ -181,17 +214,17 @@
var sysSet5 = (from x in Funs.DB.Sys_Set where x.SetName == "PMP接口地址" select x).ToList().FirstOrDefault();
if (sysSet5 != null)
{
_CNCECPath = sysSet5.SetValue;
_WuHuanPMPPath = sysSet5.SetValue;
}
else
{
_CNCECPath = "";
_WuHuanPMPPath = "";
}
return _CNCECPath;
return _WuHuanPMPPath;
}
set
{
_CNCECPath = value;
_WuHuanPMPPath = value;
}
}
public static string WuHuanPMPToken
@ -201,13 +234,13 @@
var sysSet5 = (from x in Funs.DB.Sys_Set where x.SetName == "PMPToken" select x).ToList().FirstOrDefault();
if (sysSet5 != null)
{
_CNCECToken = sysSet5.SetValue;
_PMPToken = sysSet5.SetValue;
}
else
{
_CNCECToken = "";
_PMPToken = "";
}
return _CNCECToken;
return _PMPToken;
}
}
public static string WuHuanPMPTokenExTime
@ -217,13 +250,13 @@
var sysSet5 = (from x in Funs.DB.Sys_Set where x.SetName == "PMPTokenExTime" select x).ToList().FirstOrDefault();
if (sysSet5 != null)
{
_CNCECTokenExTime = sysSet5.SetValue;
_PMPTokenExTime = sysSet5.SetValue;
}
else
{
_CNCECTokenExTime = "";
_PMPTokenExTime = "";
}
return _CNCECTokenExTime;
return _PMPTokenExTime;
}
}
public static void SetWuHuanPMPToken(string token)
@ -291,6 +324,7 @@
}
}
#endregion

View File

@ -0,0 +1,33 @@
using BLL;
using System;
using System.Web.Http;
namespace WebAPI.Controllers
{
/// <summary>
/// 五环IDP平台
/// </summary>
public class IDPController : ApiController
{
/// <summary>
/// 每天夜间同步获取IDP系统项目开车数据
/// </summary>
/// <returns></returns>
[HttpPost]
public Model.ResponeData SynIDPPreRunData()
{
var responeData = new Model.ResponeData();
try
{
IDPDataService.GetIDPProjectMasterData();
}
catch (Exception ex)
{
responeData.code = 0;
responeData.message = ex.ToString();
}
return responeData;
}
}
}

View File

@ -86,8 +86,10 @@ namespace WebAPI.Filter
/// <summary>
///
/// </summary>
public static List<string> lists = new List<string> { "TowerCrane*saveTowerCraneRecord","PMP*SynPMPProjectData", "GJSX*OverdueWarningSendEmail", "User*postLoginOn", "get*token", "HazardRegister*getHazardRegisterTotalCount",
public static List<string> lists = new List<string> { "TowerCrane*saveTowerCraneRecord", "GJSX*OverdueWarningSendEmail", "User*postLoginOn", "get*token", "HazardRegister*getHazardRegisterTotalCount",
"HazardRegister*getHazardRegisterByProjectIdStates",
"PMP*SynPMPProjectData",
"IDP*SynIDPPreRunData",
"JGZL*getUserList",
"JGZL*getProjedtList",
"JGZL*getUnitWorkListByProjectId",

View File

@ -166,6 +166,7 @@
<Compile Include="Controllers\HSSE\HSSELogController.cs" />
<Compile Include="Controllers\HSSE\TestingController.cs" />
<Compile Include="Controllers\HSSE\TowerCraneController.cs" />
<Compile Include="Controllers\IDP\IDPController.cs" />
<Compile Include="Controllers\JGZL\JGZLController.cs" />
<Compile Include="Controllers\Person\PersonCheckController.cs" />
<Compile Include="Controllers\CQMS\CheckEquipmentController.cs" />