/// <summary> /// 根据参数和密码生成签名字符串 /// </summary> /// <param name="parameters">API参数</param> /// <param name="secret">密码</param> /// <returns>签名字符串</returns> private string GetSignature(DiscuzParam[] parameters, out string sigsource) { StringBuilder values = new StringBuilder(); foreach (DiscuzParam param in parameters) { if (param.Name == "sig" || string.IsNullOrEmpty(param.Value)) continue; values.Append(param.ToString()); } values.Append(secret); sigsource = values.ToString(); byte[] md5_result = MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(values.ToString())); StringBuilder sig_builder = new StringBuilder(); foreach (byte b in md5_result) sig_builder.Append(b.ToString("x2")); return sig_builder.ToString(); }
private static string CreateRequestParamsStream(DiscuzParam[] dp, string sig) { string url = ""; foreach (DiscuzParam d in dp) { url += "&" + d.ToString(); } return "sig=" + sig + url; }