Example Analysis of generating signature in python
Today, I will talk to you about the example analysis of generating signatures in python. Many people may not know much about it. In order to make you understand better, the editor has summarized the following for you. I hope you can get something according to this article.
/ get signature / public string Sign (object body) {/ / get all attributes var signKeys = new Dictionary (); GetSignKeys (null, body, signKeys)
Var lstSignKeys = signKeys.ToList (); var indexReg = new System.Text.RegularExpressions.Regex ("\\ [(\\ d)\]"); lstSignKeys.Sort ((v1, v2) = > {var keyRepair1 = indexReg.Replace (v1.Key, "[0 $1]"); var keyRepair2 = indexReg.Replace (v2.Key, "[0 $1]"); return string.CompareOrdinal (keyRepair1, keyRepair2);}) Var signStr = lstSignKeys.Join ("&", t = > $"{t.Key} = {t.Value}"); signStr + = $"& key= {ThirdPlatServiceAPPKey}"; return getSign (signStr, ThirdPlatServiceAPPKey);} public string getSign (string stringSignTemp, string apikey) {string sign = SecurityHelper.MD5Encrypt (stringSignTemp, Encoding.UTF8); sign = SecurityHelper.HMACSHA256Encrypt (sign, apikey, Encoding.UTF8). ToLower (); return sign } private void GetSignKeys (string Key, object obj, Dictionary signKeys) {if (obj = = null) return; if (obj is string & &! string.IsNullOrEmpty (obj.ToString ()) signKeys.Add (Key, obj.ToString ()); else if (obj is double dbl) signKeys.Add (Key, dbl.ToString ("0.00")) Else if (obj is decimal dec) signKeys.Add (Key, dec.ToString ("0.00"); else if (obj.GetType () .IsValueType) signKeys.Add (Key, obj.ToString ()); else if (obj is IList lst) {/ / list object var index =-1; foreach (var item in lst) {index++ GetSignKeys ($"{Key} [{index}]", item, signKeys) }} else {if (! string.IsNullOrEmpty (obj.ToString () {if (string.IsNullOrEmpty (Key)) {foreach (var property in obj.GetType (). GetProperties ()) {GetSignKeys (property.Name) Property.GetValue (obj, null), signKeys) }} else {foreach (var property in obj.GetType (). GetProperties ()) {GetSignKeys (Key + "." + property.Name, property.GetValue (obj, null), signKeys) }} after reading the above, do you have any further understanding of the example analysis of generating signatures in python? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.