From 705909e14fe4e9f2fc261ee4eb40a8b41fa2f6d4 Mon Sep 17 00:00:00 2001 From: wzp <2880584989@qq.com> Date: 星期二, 12 七月 2022 17:37:26 +0800 Subject: [PATCH] 增加免密登陆的token --- web/Common/DataConverter.cs | 98 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 98 insertions(+), 0 deletions(-) diff --git a/web/Common/DataConverter.cs b/web/Common/DataConverter.cs index 421765e..39c3785 100644 --- a/web/Common/DataConverter.cs +++ b/web/Common/DataConverter.cs @@ -1,8 +1,10 @@ 锘縩amespace Common { using System; + using System.Collections.Generic; using System.Runtime.InteropServices; using System.Text.RegularExpressions; + using System.Linq; public class DataConverter { @@ -179,6 +181,102 @@ [FieldOffset(0)] public DataConverter.IPAdress _IP; } + + //鑾峰彇闅忔満鐮� + public static string getRandom(int strLength) + { + string random = ""; + if (strLength <= 0) + { + strLength = 6; //榛樿6浣嶉暱搴� + } + //random = Guid.NewGuid().ToString().Replace("-", "").Substring(0, strLength); + random = Guid.NewGuid().ToString(); + random = random.Replace("-", ""); + random = random.Substring(0, strLength); + + return random; + } + + //瀛楃涓茶浆鏁扮粍 + public static object[] stringToArray(string str) + { + object[] array = str.Split(','); + return array; + } + + //鏁扮粍杞瓧绗︿覆 + public static string arrayToString(object[] array) + { + if (array == null) + return ""; + string str = string.Join(",", array); + return str; + } + + //鏁扮粍杞崲List锛歴tring[] str ={ "str","string","abc"}杞� List<string> + public static List<object> arrayToList(object[] array) + { + List<object> list = new List<object>(array); + + return list; + } + + //List杞崲鏁扮粍锛歀ist<string>杞埌string[] + public static object[] listToArray(List<object> list) + { + object[] array = list.ToArray(); + + return array; + } + + //瀛楃涓茶浆List + public static List<object> stringToList(string str) + { + if (string.IsNullOrEmpty(str)) + return null; + + List<object> list = new List<object>(); + //瀛楃涓茶浆鏁扮粍锛屽啀鏁扮粍鍚堝苟 + list.AddRange(str.Split(',')); + + return list; + } + + //鏁扮粍鍘婚噸锛岀Щ闄ゆ暟缁勪腑閲嶅鏁版嵁 + public static string[] DelRepeatData(string[] array) + { + return array.GroupBy(p => p).Select(p => p.Key).ToArray(); + } + + //妫�鏌ユ暟缁勬牸寮忓瓧绗︿覆涓槸鍚﹀寘鍚煇鍏冪礌 + public static bool checkStrForArrayStr(object str, string arrayStr ) + { + return stringToArray(arrayStr).Contains(str.ToString() ); + } + + //妫�鏌ユ暟缁勪腑鏄惁鍖呭惈鏌愬厓绱� + public static bool checkStrForArray(object str, object[] array) + { + return array.Contains(str); + } + + //鏍规嵁鏁扮粍瀛楃涓茶浆鎹㈠瓧鍏� + public Dictionary<string, object> arrayStrToDict(object userId, string arrayStr) + { + Dictionary<string, object> dictionary = new Dictionary<string, object>(); + if (string.IsNullOrEmpty(arrayStr)) + return dictionary; + + List<object> list = DataConverter.stringToList(arrayStr); + for (int i = 0; i < list.Count; i++) + { + dictionary[userId.ToString()] = list[i]; + } + return dictionary; + } + } + } -- Gitblit v1.9.1