DeviceManager/TsSFCDevice.Client.Biz/Base/Service/TsSFCMainSvc.cs
2024-07-27 09:44:19 +08:00

124 lines
3.7 KiB
C#

using System;
using TsSFCDevice.Client.Biz.DeviceSvc;
namespace TsSFCDevice.Client.Biz.Base.Service
{
public class TsSFCMainSvc
{
/// <summary>
/// token
/// </summary>
#region /
const string SOPHeadUserName = "TECHSCAN_Myl";
string m_Connstring = "";
string user = "";
string pwd = "";
string version = "";
static string GUID = "";
static string Mac = "";
SFCAuthorize auth;
MainService svc;
#endregion
public TsSFCMainSvc(string User, string Pwd, string Version, string Conn)
{
m_Connstring = Conn;
user = User;
pwd = Pwd;
version = Version;
byte[] password = System.Text.Encoding.Unicode.GetBytes(user);
Array.Reverse(password, 0, password.Length);
string pass64 = Convert.ToBase64String(password, 0, password.Length);
if (pass64.Length < 10)
{
pass64 = pass64 + "YeT+=fue";
}
auth = new SFCAuthorize();
auth.Username = user;
auth.Password = pass64;
auth.Version = Version;
if (GUID == "")
{
GUID = Guid.NewGuid().ToString();
}
auth.GUID = GUID;
if (Mac == "")
{
//Mac = (new SysInfo()).GetMac();
}
auth.MacAddress = Mac;
auth.SapSetting = (ushort)(1);
svc = new MainService()
{
Url = m_Connstring,
Timeout = 300000,
SFCAuthorizeValue = auth
};
}
public MainService CurrentSvc
{
get
{
if (svc == null)
{
svc = new MainService();
byte[] password = System.Text.Encoding.Unicode.GetBytes(user);
Array.Reverse(password, 0, password.Length);
string pass64 = Convert.ToBase64String(password, 0, password.Length);
if (pass64.Length < 10)
{
pass64 = pass64 + "YeT+=fue";
}
auth = new SFCAuthorize();
auth.Username = user;
auth.Password = pass64;
auth.Version = version;
auth.SapSetting =
(ushort)(1);
svc.Url = m_Connstring;
//ser.Timeout = 300000;
svc.Timeout = 300000;
auth.GUID = GUID;
svc.SFCAuthorizeValue = auth;
}
return svc;
}
}
public void SetWebService(string svcUrl, int vServiceTimeOut = 300000)
{
svc = new MainService();
byte[] password = System.Text.Encoding.Unicode.GetBytes(user);
Array.Reverse(password, 0, password.Length);
string pass64 = Convert.ToBase64String(password, 0, password.Length);
if (pass64.Length < 10)
{
pass64 = pass64 + "YeT+=fue";
}
svc.Url = svcUrl;
//ser.Timeout = 300000;
svc.Timeout = vServiceTimeOut;
#region WS安全交互处理
auth = new SFCAuthorize();
auth.Username = SOPHeadUserName;
auth.Password = pass64;
//auth.Version = Utility.CurrentDevice.RFVersion;
auth.SapSetting = (ushort)(1);
auth.GUID = GUID;
svc.SFCAuthorizeValue = auth;
#endregion
}
}
}