90 lines
3.7 KiB
C#
90 lines
3.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Security.Cryptography;
|
|
using System.Text;
|
|
using Lskj.IPersonnelConnection;
|
|
|
|
namespace Lskj.IPersonnelConnection
|
|
{
|
|
public static class PersonnelReplaceHelper
|
|
{
|
|
|
|
/// <summary>
|
|
/// i人事 许可信息
|
|
/// </summary>
|
|
private static readonly string _iPersonnelAllowInformation = "{iPersonnelAllowInformation}";
|
|
/// <summary>
|
|
/// i人事 客户唯一身份标识
|
|
/// </summary>
|
|
private static readonly string _iPersonnelCustomerId = "{iPersonnelCustomerId}";
|
|
/// <summary>
|
|
/// i人事 私钥
|
|
/// </summary>
|
|
private static readonly string _iPersonnelPrivateKey = "{iPersonnelPrivateKey}";
|
|
/// <summary>
|
|
/// i人事 加密的签名信息
|
|
/// </summary>
|
|
private static readonly string _iPersonnelEncryptedMessage = "{iPersonnelEncryptedMessage}";
|
|
|
|
|
|
/// <summary>
|
|
/// <para>说明:替换i人事接口中的参数</para>
|
|
/// <para>创建人:</para>
|
|
/// <para>创建日期:2023-04-21 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="defaultValue">url地址</param>
|
|
/// <param name="iPersonnelAllowInformation">许可信息</param>
|
|
/// <param name="iPersonnelCustomerId">客户标识</param>
|
|
/// <param name="iPersonnelPrivateKey">私钥</param>
|
|
/// <param name="UserLinkPhone">登录人电话</param>
|
|
/// <returns>System.String.</returns>
|
|
public static string UrlEncryption(string Url, string iPersonnelAllowInformation, string iPersonnelCustomerId, string iPersonnelPrivateKey, string UserLinkPhone)
|
|
{
|
|
if (Url.Contains("{iPersonnelAllowInformation}") || Url.Contains("{iPersonnelEncryptedMessage}"))
|
|
{
|
|
//替换许可
|
|
Url = Url.Replace(_iPersonnelAllowInformation, iPersonnelAllowInformation);
|
|
//替换加密的签名信息
|
|
TimeSpan ts = DateTime.Now.ToUniversalTime() - new DateTime(1970, 1, 1);
|
|
long time = (long)ts.TotalMilliseconds;//当前时间的时间戳
|
|
string EncryptedMessage = string.Format("company_id={0}&mobile_no={1}×tamp={2}", iPersonnelCustomerId, UserLinkPhone, time);
|
|
string value = EncryptByPrivateKey.encryptByPrivateKey(EncryptedMessage, iPersonnelPrivateKey);
|
|
Url = Url.Replace(_iPersonnelEncryptedMessage, value);
|
|
}
|
|
return Url;
|
|
}
|
|
/// <summary>
|
|
/// CDSBLims加密
|
|
/// </summary>
|
|
/// <param name="Url"></param>
|
|
/// <param name="CDSBLimsPrivateKey"></param>
|
|
/// <returns></returns>
|
|
public static string CDSBLimsUrlEncryption(string Url, string LoginNo, string CDSBLimsPrivateKey)
|
|
{
|
|
if (Url.Contains("{CDSBLimsLoginNo}"))
|
|
{
|
|
var aes = Aes.Create();
|
|
aes.Key = Encoding.UTF8.GetBytes(CDSBLimsPrivateKey);
|
|
aes.GenerateIV();
|
|
var encryptor = aes.CreateEncryptor(aes.Key, aes.IV);
|
|
var ms = new MemoryStream();
|
|
ms.Write(aes.IV, 0, aes.IV.Length);
|
|
using (var cs = new CryptoStream(ms, encryptor, CryptoStreamMode.Write))
|
|
using (var sw = new StreamWriter(cs, Encoding.UTF8))
|
|
{
|
|
sw.Write(LoginNo);
|
|
}
|
|
//替换许可
|
|
Url = Url.Replace("{CDSBLimsLoginNo}", Convert.ToBase64String(ms.ToArray()));
|
|
}
|
|
return Url;
|
|
}
|
|
}
|
|
}
|