+ * 若返回值为null,则说明该号码无效 + *+ * + * @param phoneNumber 手机号码 + * @return 手机信息模型PhoneModel + */ + public static PhoneDto getPhoneDto(String phoneNumber) { + if (checkPhoneNumber(phoneNumber)) { + String geo = getGeo(phoneNumber); + PhoneDto phoneDto = new PhoneDto(); + String carrier = getCarrier(phoneNumber); + phoneDto.setCarrier(carrier); + // 直辖市 + for (String val : MUNICIPALITY) { + if (geo.equals(val)) { + phoneDto.setProvinceName(val.replace("市", "")); + phoneDto.setCityName(val); + return phoneDto; + } + } + // 自治区 + for (String val : AUTONOMOUS_REGION) { + if (geo.startsWith(val)) { + phoneDto.setProvinceName(val); + phoneDto.setCityName(geo.replace(val, "")); + return phoneDto; + } + } + + // 其它 + String[] splitArr = geo.split("省"); + if (splitArr != null && splitArr.length == 2) { + phoneDto.setProvinceName(splitArr[0]); + phoneDto.setCityName(splitArr[1]); + return phoneDto; + } + } + return null; + } + + public static void main(String[] args) { + PhoneDto phoneDto = PhoneUtil.getPhoneDto("13701001254"); + if (phoneDto != null) { + System.out.println(phoneDto.getProvinceName()); + System.out.println(phoneDto.getCityName()); + System.out.println(phoneDto.getCarrier()); + } else { + System.err.println("该号码无效"); + } + } + +} \ No newline at end of file diff --git a/esua-epdc/epdc-commons/epdc-commons-tools/src/main/java/com/elink/esua/epdc/commons/tools/utils/RandomUtil.java b/esua-epdc/epdc-commons/epdc-commons-tools/src/main/java/com/elink/esua/epdc/commons/tools/utils/RandomUtil.java new file mode 100644 index 000000000..bb1fc6faf --- /dev/null +++ b/esua-epdc/epdc-commons/epdc-commons-tools/src/main/java/com/elink/esua/epdc/commons/tools/utils/RandomUtil.java @@ -0,0 +1,40 @@ +package com.elink.esua.epdc.commons.tools.utils; + +import java.util.Random; + +/** + * @author rongchao + * @Date 18-12-17 + */ +public class RandomUtil { + /** + * 根据需要生成指定长度的纯数字随机数,这个随机数的每一位都是从(0-9)这个产生的一位 + * + * @param codeLen + * @return + */ + public static String getNewRandomCode(int codeLen) { + Random randomCode = new Random(); + String strCode = ""; + while (codeLen > 0) { + int charCode = randomCode.nextInt(9); + strCode += charCode; + codeLen--; + } + return strCode; + } + + public static int getRandomNum(int min, int max) { + Random random = new Random(); + return random.nextInt(max - min + 1) + min; + } + + public static void main(String[] args) { + for (int i = 0; i < 10000; i++) { + int s = RandomUtil.getRandomNum(1, 10); + if (s < 1 || s > 10) { + System.out.println(s); + } + } + } +} \ No newline at end of file diff --git a/esua-epdc/epdc-commons/pom.xml b/esua-epdc/epdc-commons/pom.xml index 2755b9d7a..9709e2771 100644 --- a/esua-epdc/epdc-commons/pom.xml +++ b/esua-epdc/epdc-commons/pom.xml @@ -18,5 +18,6 @@
+ * https://www.renren.io + *
+ * 版权所有,侵权必究! + */ + +package com.elink.esua.epdc.jwt; + +import io.jsonwebtoken.Claims; +import io.jsonwebtoken.Jwts; +import io.jsonwebtoken.SignatureAlgorithm; +import org.joda.time.DateTime; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.Date; + +/** + * Jwt工具类 + * + * @author Mark sunlightcs@gmail.com + * @since 1.0.0 + */ +@Component +public class JwtUtils { + private static final Logger logger = LoggerFactory.getLogger(JwtUtils.class); + + @Autowired + private JwtProperties jwtProperties; + + /** + * 生成jwt token + */ + public String generateToken(Long userId) { + return Jwts.builder() + .setHeaderParam("typ", "JWT") + .setSubject(userId + "") + .setIssuedAt(new Date()) + .setExpiration(DateTime.now().plusSeconds(jwtProperties.getExpire()).toDate()) + .signWith(SignatureAlgorithm.HS512, jwtProperties.getSecret()) + .compact(); + } + + /** + * 生成jwt token + */ + public String generateToken(String userId) { + return Jwts.builder() + .setHeaderParam("typ", "JWT") + .setSubject(userId) + .setIssuedAt(new Date()) + .setExpiration(DateTime.now().plusSeconds(jwtProperties.getExpire()).toDate()) + .signWith(SignatureAlgorithm.HS512, jwtProperties.getSecret()) + .compact(); + } + + public Claims getClaimByToken(String token) { + try { + return Jwts.parser() + .setSigningKey(jwtProperties.getSecret()) + .parseClaimsJws(token) + .getBody(); + } catch (Exception e) { + logger.debug("validate is token error, token = " + token, e); + return null; + } + } + + /** + * token是否过期 + * @return true:过期 + */ + public boolean isTokenExpired(Date expiration) { + return expiration.before(new Date()); + } +} \ No newline at end of file diff --git a/esua-epdc/epdc-module/epdc-user/epdc-user-server/src/main/resources/application.yml b/esua-epdc/epdc-module/epdc-user/epdc-user-server/src/main/resources/application.yml index eec195699..444af3748 100644 --- a/esua-epdc/epdc-module/epdc-user/epdc-user-server/src/main/resources/application.yml +++ b/esua-epdc/epdc-module/epdc-user/epdc-user-server/src/main/resources/application.yml @@ -36,6 +36,17 @@ spring: username: @spring.datasource.druid.username@ password: @spring.datasource.druid.password@ +jwt: + #秘钥 + secret: 7016867071f0ebf1c46f123eaaf4b9d6[elink.epdc] + #token有效时长,默认7天,单位秒 + expire: 604800 + +wx: + # 公众号 + mp: + appid: + secret: management: endpoints: