Skip to content

ConvertUrl 长短链接转换

实现对长链接/短链接的相互转换。

添加依赖

xml
<dependency>
	<groupId>com.hisense.pangea</groupId>
	<artifactId>pangea-converturl</artifactId>
	<version>1.0.0</version>
</dependency>

使用方法

1.yaml配置

  • 配置主域名
yaml
pangea.short-url.domain: xxxx.com
  • 配置redis
yaml
spring:
  redis:
    host: ${REDIS_HOST:10.19.52.233}
    port: ${REDIS_PORT:28338}
    password: ${REDIS_PASSWORD:123456}

2.调用工具类

  • 短域名加密
java

   @Autowired
    private ShortUrlConvertService shortUrlConvertService;

   /**
    * 短网址加密生成(为空默认有效期7天,可自定义时长)
    *
    * @param urlLong
    * @param days
    * @return
    */
   public String shorten(){
       return shortUrlConvertService.shorten("xxx.com",1);    
   }
  • 解密
java

   @Autowired
    private ShortUrlConvertService shortUrlConvertService;

   /**
    * 短网址加密生成(为空默认有效期7天,可自定义时长)
    *
    * @param urlLong
    * @param days
    * @return
    */
   public String shortde(){
       return shortUrlConvertService.shortde("xxx.com");    
   }