Skip to content

lazycece/au-api-spring-boot

Repository files navigation

au-api-spring-boot

Maven Central License GitHub release

Spring boot project for Au api.

Environment

Au environment dependency as follow:

Au Api Spring Boot Java Spring Boot
1.x 1.8+ 2.x
2.x 17+ 3.x

Quick Start

Complete example can view au-api-spring-boot-sample

Maven dependency

    <!-- add sonatype repository when use SNAPSHOT version-->
    <repositories>
        <repository>
            <id>sonatype</id>
            <name>sonatype</name>
            <url>https://oss.sonatype.org/content/groups/public</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
            <releases>
                <enabled>true</enabled>
            </releases>
        </repository>
    </repositories>
    <dependencies>
        <dependency>
            <groupId>com.lazycece.au</groupId>
            <artifactId>au-api-spring-boot-starter</artifactId>
            <version>${au.api.spring.boot.version}</version>
        </dependency>
    </dependencies>

Enable au api

Add the necessary configuration, as follow:

au:
  enable: true
  api:
    token:
      enable: true
      secret: secret-key
    param:
      enable: true
      secret: secret-key

Implements TokenHandler and ParamsHandler, as follow:

@Configuration
public class AuApiConfig {

    @Bean
    public TokenHandler tokenHandler() {
        return new TokenHandler() {
            @Override
            public String noToken() {
                // deal response, and return.
            }

            @Override
            public String invalidToken() {
                // deal response, and return.
            }
        };
    }

    @Bean
    public ParamsHandler paramsHandler() {
        return new ParamsHandler() {
            @Override
            public String validateParamsFail() {
                // deal response, and return.
            }

            @Override
            public String validateTimeFail() {
                // deal response, and return.
            }

            @Override
            public String validateSignFail() {
                // deal response, and return.
            }

            @Override
            public String getWaitEncodeData(String responseBody) {
                // deal response, and return.
            }

            @Override
            public String getResponseBody(String responseBody, String encodeData, String salt) {
                // deal response, and return.
            }
        };
    }
}

License

Apache-2.0