短链接
using Microsoft.AspNetCore.Mvc; using System; namespace Feed.Controllers { [ApiController] public class AaaController : Controller { [HttpGet] [Route("{url}")] public void GetBbb(string url)//短链接跳转 { if (url == "1") { Response.Redirect("https://www.baidu.com", false); } else if (url == "2") { Response.Redirect("https://www.google.com", false); } } public static string GetShortUrl(string url)//短链接生成 { string key = DateTime.Now.ToString(); string[] chars = new string[]{ "a","b","c","d","e","f","g","h", "i","j","k","l","m","n","o","p", "q","r","s","t","u","v","w","x", "y","z","0","1","2","3","4","5", "6","7","8","9","A","B","C","D", "E","F","G","H","I","J","K","L", "M","N","O","P","Q","R","S","T", "U","V","W","X","Y","Z" }; var md5 = System.Security.Cryptography.MD5.Create(); string hex = BitConverter.ToString(md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(key + url))).Replace("-", ""); string[] resUrl = new string[4]; for (int i = 0; i < 4; i++) { int hexint = 0x3FFFFFFF & Convert.ToInt32("0x" + hex.Substring(i * 8, 8), 16); string outChars = string.Empty; for (int j = 0; j < 6; j++) { int index = 0x0000003D & hexint; outChars += chars[index]; hexint >>= 5; } resUrl[i] = outChars; } return resUrl[new Random().Next(0, 3)]; } } }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
2016-03-07 visual studio 2015 中文提示