Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
gsc
/
gsc-vcp-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 49eb783d
authored
Nov 07, 2025
by
林冲
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
修改车源号生成
1 parent
8d941f6d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
28 deletions
src/main/java/com/gsc4cloud/gsc/vpc/api/util/ShortLinkComponent.java
src/main/java/com/gsc4cloud/gsc/vpc/api/util/ShortLinkComponent.java
View file @
49eb783
package
com
.
gsc4cloud
.
gsc
.
vpc
.
api
.
util
;
package
com
.
gsc4cloud
.
gsc
.
vpc
.
api
.
util
;
import
org.springframework.stereotype.Component
;
import
java.security.SecureRandom
;
/**
/**
* @BelongsProject: glsx-accounts-test
* @BelongsProject: glsx-accounts-test
...
@@ -10,42 +10,27 @@ import org.springframework.stereotype.Component;
...
@@ -10,42 +10,27 @@ import org.springframework.stereotype.Component;
* @Description: TODO
* @Description: TODO
* @Version: 1.0
* @Version: 1.0
*/
*/
@Component
public
class
ShortLinkComponent
{
public
class
ShortLinkComponent
{
private
static
final
SecureRandom
RANDOM
=
new
SecureRandom
();
/**
/**
* 62个字符
* 62个字符
*/
*/
private
static
final
String
CHARS
=
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
;
private
static
final
String
CHARS
=
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
;
/**
/**
* 生成短链码
* 随机生成指定长度的字符串
* @param param
* @param length 长度
* @return
* @return 随机字符串
*/
public
String
createShortLinkCode
(
String
param
){
long
murmurhash
=
CommonUtil
.
murmurHash32
(
param
);
//进制转换
String
code
=
encodeToBase62
(
murmurhash
);
return
code
;
}
/**
* 10进制转62进制
* @param num
* @return
*/
*/
private
String
encodeToBase62
(
long
num
){
public
static
String
randomCode
(
int
length
)
{
// StringBuffer线程安全,StringBuilder线程不安全
StringBuilder
sb
=
new
StringBuilder
(
length
);
StringBuffer
sb
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
do
{
int
index
=
RANDOM
.
nextInt
(
CHARS
.
length
());
int
i
=
(
int
)(
num
%
62
);
sb
.
append
(
CHARS
.
charAt
(
index
));
sb
.
append
(
CHARS
.
charAt
(
i
));
}
num
=
num
/
62
;
return
sb
.
toString
();
}
while
(
num
>
0
);
String
value
=
sb
.
reverse
().
toString
();
return
value
;
}
}
}
}
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment