init project
This commit is contained in:
35
QRCodeService/Controllers/PlaygroundController.cs
Normal file
35
QRCodeService/Controllers/PlaygroundController.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using Base62;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace QRCodeService.Controllers
|
||||
{
|
||||
[Route("[controller]/[action]")]
|
||||
public class PlaygroundController:ControllerBase
|
||||
{
|
||||
public IActionResult GenShortCode(string url)
|
||||
{
|
||||
var codes = new string[2];
|
||||
using (var md5 = MD5.Create())
|
||||
{
|
||||
var chunkSize = 8;
|
||||
var result = md5.ComputeHash(Encoding.UTF8.GetBytes(url));
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
var first = result.Take(chunkSize).ToArray();
|
||||
//即超过30位的忽略处理
|
||||
var res = BitConverter.ToInt64(first);
|
||||
var code = res.ToBase62();
|
||||
codes[i] = code;
|
||||
result = result.Skip(chunkSize).ToArray();
|
||||
}
|
||||
return Ok(codes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user