/// <summary>
        /// 生成授权token
        /// </summary>
        /// <returns>授权token</returns>
        string BuildAuthToken(string appKey)
        {
            string nonce     = NonceGenerator.GenerateString(),
                   appSecret = GetAppSecret(appKey);
            long timestamp   = DateTime.Now.ToTimestamp();

            // Sh1加密
            List <string> list = new List <string>()
            {
                nonce,
                appSecret,
                timestamp.ToString()
            };

            // 字典排序
            list.Sort();
            ICryptor cryptor   = new Sha1Cryptor();
            string   signature = cryptor.Encrypt(string.Join(string.Empty, list));

            AuthParameterModel auth = new AuthParameterModel
            {
                AppKey    = appKey,
                Nonce     = nonce,
                Timestamp = timestamp,
                Signature = signature
            };
            string authJson = auth.SerializeObject(),
                   token    = authJson.ToBase64();

            return(token);
        }
예제 #2
0
 /// <summary>
 /// 生成验证码
 /// </summary>
 /// <param name="length">验证码长度</param>
 /// <returns></returns>
 public static string Generate(int length)
 {
     return(NonceGenerator.GenerateString(length));
 }