Skip to content

Commit

Permalink
统一社会信用代码(虚拟)
Browse files Browse the repository at this point in the history
  • Loading branch information
yindz committed Jul 9, 2022
1 parent d094fa8 commit a8a587d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/main/java/com/apifan/common/random/source/OtherSource.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.apifan.common.random.source;

import com.apifan.common.random.entity.Area;
import com.apifan.common.random.entity.EconomicCategory;
import com.apifan.common.random.entity.Poem;
import com.apifan.common.random.util.ResourceUtils;
Expand Down Expand Up @@ -159,6 +160,12 @@ public class OtherSource {
*/
private static List<String> englishWordsList = Lists.newArrayList();

/**
* 统一社会信用代码候选字符(不使用I、O、Z、S、V)
*/
private static final List<String> socialCreditCharactersList = Lists.newArrayList(
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "P", "Q", "R", "T", "U", "W", "X", "Y");

private static final OtherSource instance = new OtherSource();

private OtherSource() {
Expand Down Expand Up @@ -523,6 +530,19 @@ public String randomEnglishText(int words) {
return StringUtils.capitalize(Joiner.on(" ").join(ResourceUtils.getRandomElement(englishWordsList, words)));
}

/**
* 随机统一社会信用代码(虚拟)
*
* @return 统一社会信用代码(虚拟)
*/
public String randomSocialCreditCode() {
String prefix = "91";
//为避免与真实的社会信用代码重合,不计算校验码而是随机生成
String checkCode = String.valueOf(RandomUtils.nextInt(0, 10));
Area area = AreaSource.getInstance().nextArea();
return prefix + area.getZipCode() + Joiner.on("").join(ResourceUtils.getRandomElement(socialCreditCharactersList, 9)) + checkCode;
}

/**
* 计算校验码
*
Expand Down

0 comments on commit a8a587d

Please sign in to comment.