You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
276 lines
10 KiB
276 lines
10 KiB
using KGIS.Framework.Utils; |
|
using Kingo.KMapSDK; |
|
using Kingo.PluginServiceInterface.Model; |
|
using System; |
|
using System.Collections.Generic; |
|
using System.Linq; |
|
using System.Text; |
|
using System.Threading.Tasks; |
|
using System.Xml; |
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel; |
|
|
|
namespace Kingo.PluginServiceInterface.Helper |
|
{ |
|
public class UserLoginHelper : IUserLogin |
|
{ |
|
/// <summary> |
|
/// 用户登录 |
|
/// </summary> |
|
/// <param name="UserName">用户名</param> |
|
/// <param name="Password">密码</param> |
|
/// <returns></returns> |
|
public bool UserLogin(string UserName, string Password) |
|
{ |
|
bool b = false; |
|
try |
|
{ |
|
var requestParam = new |
|
{ |
|
username = UserName, |
|
password = SHA(Password) |
|
}; |
|
ResultInfo<XJUserInfo> requestData = HttpHelper.PostResponse<ResultInfo<XJUserInfo>>(GetAppsetingValueByKey("ApiHost") + "user/UserLoginJK", requestParam); |
|
if (requestData != null && requestData.Code == 200) |
|
{ |
|
//获取登录信息后,将用户信息写入配置文件 |
|
UpdateAppsettingValueByKey("UserName", requestData.Data.username); |
|
if (requestData.Data.userid > 0 && !string.IsNullOrEmpty(requestData.Data.userid.ToString())) |
|
{ |
|
UpdateAppsettingValueByKey("UserId", requestData.Data.userid.ToString()); |
|
} |
|
UpdateAppsettingValueByKey("YWLX", string.Join(",", requestData.Data.ownedbussiness)); |
|
b = true; |
|
} |
|
return b; |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("UserLogin异常:" + ex.Message); |
|
LogAPI.Debug("UserLogin异常:" + ex.StackTrace); |
|
} |
|
return b; |
|
} |
|
|
|
/// <summary> |
|
/// 从AppSettings中获取指定key的值 |
|
/// </summary> |
|
/// <param name="key"></param> |
|
/// <returns></returns> |
|
public static string GetAppsetingValueByKey(string key) |
|
{ |
|
try |
|
{ |
|
XmlDocument doc = new XmlDocument(); |
|
string strPath = SysAppPath.GetConfigPath() + "UserLoginConfig.xml"; |
|
doc.Load(strPath); |
|
XmlNode xmlSysNode = doc.SelectSingleNode("configuration/AppSettings"); |
|
if (xmlSysNode.ChildNodes != null && xmlSysNode.ChildNodes.Count > 0) |
|
{ |
|
foreach (XmlNode node in xmlSysNode.ChildNodes) |
|
{ |
|
if (node.Attributes["Key"].Value == key) |
|
{ |
|
return node.Attributes["Value"].Value; |
|
} |
|
} |
|
} |
|
return ""; |
|
} |
|
catch (Exception ex) |
|
{ |
|
Console.WriteLine(ex.Message); |
|
return ""; |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 更新配置文件AppSetting值 |
|
/// </summary> |
|
/// <param name="key"></param> |
|
/// <param name="value"></param> |
|
/// <returns></returns> |
|
public static void UpdateAppsettingValueByKey(string key, string value) |
|
{ |
|
try |
|
{ |
|
XmlDocument doc = new XmlDocument(); |
|
string strPath = SysAppPath.GetConfigPath() + "UserLoginConfig.xml"; |
|
doc.Load(strPath); |
|
XmlNode xmlSysNode = doc.SelectSingleNode("configuration/AppSettings"); |
|
if (xmlSysNode.ChildNodes != null && xmlSysNode.ChildNodes.Count > 0) |
|
{ |
|
foreach (XmlNode node in xmlSysNode.ChildNodes) |
|
{ |
|
if (node.Attributes["Key"].Value == key) |
|
{ |
|
node.Attributes["Value"].Value = value; |
|
doc.Save(strPath); |
|
break; |
|
} |
|
} |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("UpdateAppsettingValueByKey:" + ex.Message); |
|
LogAPI.Debug("UpdateAppsettingValueByKey:" + ex.StackTrace); |
|
throw ex; |
|
} |
|
} |
|
|
|
public static List<ImageSlicing> GetAllYXGroupLayer() |
|
{ |
|
List<ImageSlicing> AllYXGroupLayer = new List<ImageSlicing>(); |
|
try |
|
{ |
|
string isShow = SysConfigsOprator.GetAppsetingValueByKey("IsShowSJYX"); |
|
if (isShow.Equals("true") || isShow.Equals("True") || isShow.Equals("TRUE")) |
|
{ |
|
XmlDocument doc = new XmlDocument(); |
|
string strPath = SysAppPath.GetConfigPath() + "UserLoginConfig.xml"; |
|
doc.Load(strPath); |
|
XmlNode xmlSysNode = doc.SelectSingleNode("configuration/AppSettings/YXGroupLayer"); |
|
if (xmlSysNode.ChildNodes != null && xmlSysNode.ChildNodes.Count > 0) |
|
{ |
|
foreach (XmlNode node in xmlSysNode.ChildNodes) |
|
{ |
|
AllYXGroupLayer.Add(new ImageSlicing() { Name = node.Attributes["Name"].Value, Alias = node.Attributes["AliasName"].Value, Path = node.Attributes["PathUrl"].Value }); |
|
} |
|
} |
|
} |
|
return AllYXGroupLayer; |
|
} |
|
catch (Exception ex) |
|
{ |
|
Console.WriteLine(ex.Message); |
|
return AllYXGroupLayer; |
|
} |
|
} |
|
|
|
public static string GetYXGroupLayerValueByAliasName(string aliasName) |
|
{ |
|
try |
|
{ |
|
XmlDocument doc = new XmlDocument(); |
|
string strPath = SysAppPath.GetConfigPath() + "UserLoginConfig.xml"; |
|
doc.Load(strPath); |
|
XmlNode xmlSysNode = doc.SelectSingleNode("configuration/AppSettings/YXGroupLayer"); |
|
if (xmlSysNode.ChildNodes != null && xmlSysNode.ChildNodes.Count > 0) |
|
{ |
|
foreach (XmlNode node in xmlSysNode.ChildNodes) |
|
{ |
|
if (node.Attributes["AliasName"].Value == aliasName) |
|
{ |
|
return node.Attributes["PathUrl"].Value; |
|
} |
|
} |
|
} |
|
return ""; |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("GetYXGroupLayerValueByAliasName 异常:" + ex.Message); |
|
LogAPI.Debug("GetYXGroupLayerValueByAliasName 异常:" + ex.StackTrace); |
|
return ""; |
|
} |
|
} |
|
|
|
public static void UpdateYXGroupLayerValueByName(string name, string aliasName, string value) |
|
{ |
|
bool isExit = false; |
|
try |
|
{ |
|
XmlDocument doc = new XmlDocument(); |
|
string strPath = SysAppPath.GetConfigPath() + "UserLoginConfig.xml"; |
|
doc.Load(strPath); |
|
XmlNode xmlSysNode = doc.SelectSingleNode("configuration/AppSettings/YXGroupLayer"); |
|
if (xmlSysNode.ChildNodes != null && xmlSysNode.ChildNodes.Count > 0) |
|
{ |
|
if (!string.IsNullOrEmpty(value) && value.Contains("@")) |
|
{ |
|
value = value.Split('@')[0]; |
|
} |
|
foreach (XmlNode node in xmlSysNode.ChildNodes) |
|
{ |
|
if (node.Attributes["Name"].Value == name) |
|
{ |
|
isExit = true; |
|
node.Attributes["AliasName"].Value = aliasName; |
|
node.Attributes["PathUrl"].Value = value; |
|
doc.Save(strPath); |
|
break; |
|
} |
|
} |
|
if (!isExit) |
|
{ |
|
XmlElement newNode = doc.CreateElement("WMTSLayer"); |
|
newNode.SetAttribute("Name", name); |
|
newNode.SetAttribute("AliasName", aliasName); |
|
newNode.SetAttribute("PathUrl", value); |
|
xmlSysNode.AppendChild(newNode); |
|
doc.Save(strPath); |
|
} |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("UpdateAppsettingValueByKey:" + ex.Message); |
|
LogAPI.Debug("UpdateAppsettingValueByKey:" + ex.StackTrace); |
|
throw ex; |
|
} |
|
} |
|
|
|
public static void DeleteYXGroupLayerValueByName(string name) |
|
{ |
|
try |
|
{ |
|
XmlDocument doc = new XmlDocument(); |
|
string strPath = SysAppPath.GetConfigPath() + "UserLoginConfig.xml"; |
|
doc.Load(strPath); |
|
XmlNode xmlSysNode = doc.SelectSingleNode("configuration/AppSettings/YXGroupLayer"); |
|
if (xmlSysNode.ChildNodes != null && xmlSysNode.ChildNodes.Count > 0) |
|
{ |
|
foreach (XmlNode node in xmlSysNode.ChildNodes) |
|
{ |
|
if (node.Attributes["Name"].Value == name) |
|
{ |
|
xmlSysNode.RemoveChild(node); |
|
doc.Save(strPath); |
|
return; |
|
} |
|
} |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
Console.WriteLine(ex.Message); |
|
} |
|
|
|
} |
|
|
|
/// <summary> |
|
/// SHA1哈希算法数字签字 |
|
/// </summary> |
|
/// <param name="str"></param> |
|
/// <returns></returns> |
|
private string SHA(string str) |
|
{ |
|
byte[] bytes = Encoding.UTF8.GetBytes(str); |
|
StringBuilder sb = new StringBuilder(); |
|
// 创建MD5哈希算法对象 |
|
using (var md5 = System.Security.Cryptography.SHA1.Create()) |
|
{ |
|
// 计算输入数据的哈希值 |
|
byte[] hash = md5.ComputeHash(bytes); |
|
|
|
// 将哈希值转换为十六进制字符串 |
|
|
|
for (int i = 0; i < hash.Length; i++) |
|
{ |
|
sb.Append(hash[i].ToString("x2")); |
|
} |
|
} |
|
return sb.ToString(); |
|
} |
|
} |
|
}
|
|
|