Java Integration

Please note these are examples. It is recommended that you make one that is more complex and adjustable to your needs.

To use this API, first ensure you have all the necessary dependencies added to your project. These dependencies include Maven and the following libraries:

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>RELEASE</version>
    <scope>compile</scope>
</dependency>
<dependency>
    <groupId>com.squareup.okhttp3</groupId>
    <artifactId>okhttp</artifactId>
    <version>4.9.3</version>
</dependency>
<dependency>
    <groupId>org.json</groupId>
    <artifactId>json</artifactId>
    <version>20210307</version>
</dependency>
<dependency>
    <groupId>org.jetbrains.kotlin</groupId>
    <artifactId>kotlin-stdlib-jdk8</artifactId>
    <version>1.5.30</version>
</dependency>

Or with Gradle:

groovyCopy codedependencies {
    compileOnly 'org.projectlombok:lombok:1.18.20'
    implementation 'com.squareup.okhttp3:okhttp:4.9.3'
    implementation 'org.json:json:20210307'
    implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.30'
}

Then, you can utilize the API in your Java code. Here's an example of how you could do it:

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.json.JSONObject;
import java.io.IOException;

public class Main {
    public static void main(String[] args) {
        String key = "LICENSE_KEY";
        String software = "PRODUCT_NAME";
        String version = "VERSION_NUMBER";

        checkLicense(key, software, version);
    }

    public static void checkLicense(String key, String software, String version) {
        String secret = "PUT_YOUR_SECRET_KEY";
        String type = "license";
        String url = "https://<YOUR_DOMAIN>/api.php?secret=" + secret + "&type=" + type + "&key=" + key + "&product=" + software + "&version=" + version;

        OkHttpClient client = new OkHttpClient();

        Request request = new Request.Builder()
                .url(url)
                .build();

        try {
            Response response = client.newCall(request).execute();
            if (!response.isSuccessful()) {
                System.out.println("Error...");
                return;
            }

            JSONObject json = new JSONObject(response.body().string());
            boolean valid = json.getBoolean("valid");

            if (valid) {
                System.out.println("Success!");
            } else {
                System.out.println("Incorrect.");
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Make sure to replace <license-key>, <product>, and <version> with the appropriate values for your application.

Remember to change <domain> to the correct URL of your API and <public-api-key> with your public API key. With these changes, you'll be able to use the API in your Java application.

Last updated