171 lines
6.5 KiB
C#
171 lines
6.5 KiB
C#
|
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; }
|
|||
|
}
|
|||
|
}
|