//读取图片 string path = Path.Combine(@"c:", DateTime.Now.ToString("yyyyMM") + ".png"); FileStream fs = new FileStream(path, FileMode.Open); MemoryStream memory = new MemoryStream(); fs.CopyTo(memory); //创建MD5 byte[] bytes= memory.ToArray(); var result = MD5.Create().ComputeHash(bytes); StringBuilder @string= new StringBuilder(); foreach (var item in result) { @string.Append(item.ToString("X2")); } string md5 = @string.ToString().ToUpper(); memory.Close(); fs.Close(); //创建base64 string base64 = Convert.ToBase64String(bytes); //var temp = Regex.Replace(base64, @"[\r\n]", ""); //如果有换行需要去掉换行 StringBuilder builder = new StringBuilder(); builder.Append("{"); builder.Append("\"msgtype\":\"image\","); builder.Append("\"image\":{"); builder.Append("\"base64\":"); builder.AppendFormat("\"{0}\",", base64); builder.AppendFormat("\"md5\":\"{0}\"", md5); builder.Append("}"); builder.Append("}"); Post("机器人的webhook", builder.ToString());
MD5大小写没关系
创建MD5的时候不要用Stream创建
猜你喜欢
网友评论
- 搜索
- 最新文章
- 热门文章