這篇文章將為大家詳細講解有關(guān)c#開發(fā)微信實現(xiàn)jssdk簽名生成的方法,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
url必須動態(tài)生成
url不能寫死,否則就算結(jié)果和官方檢測的一致,也只會是無效的
string url = Request.Url.ToString();
noncestr必須動態(tài)生成
noncestr也是動態(tài)獲取的,不能寫死
//////生成隨機字符串 /// ///目標(biāo)字符串的長度 ///是否包含數(shù)字,1=包含,默認為包含 ///是否包含小寫字母,1=包含,默認為包含 ///是否包含大寫字母,1=包含,默認為包含 ///是否包含特殊字符,1=包含,默認為不包含 ///要包含的自定義字符,直接輸入要包含的字符列表 ///指定長度的隨機字符串 public static string GetRandomString(int length, bool useNum, bool useLow, bool useUpp, bool useSpe, string custom) { byte[] b = new byte[4]; new System.Security.Cryptography.RNGCryptoServiceProvider().GetBytes(b); Random r = new Random(BitConverter.ToInt32(b, 0)); string s = null, str = custom; if (useNum == true) { str += "0123456789"; } if (useLow == true) { str += "abcdefghijklmnopqrstuvwxyz"; } if (useUpp == true) { str += "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; } if (useSpe == true) { str += "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"; } for (int i = 0; i < length; i++) { s += str.Substring(r.Next(0, str.Length - 1), 1); } return s; }
官方給取的例子長度為16,含大小寫和數(shù)字,沒有特殊字符串
即
var noncestr = GetRandomString(16, true, true, true, false,"");
關(guān)于“c#開發(fā)微信實現(xiàn)jssdk簽名生成的方法”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學(xué)到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。