Licence
get
https://groupez.dev
/api/v1/licence/:key
Licence

Example

GitHub - Maxlego08/GroupeZ-Licence: Licensing system for groupez.dev
GitHub
LicenceVerif
Licence
1
package fr.groupez.licence;
2
​
3
import java.io.BufferedReader;
4
import java.io.DataOutputStream;
5
import java.io.InputStream;
6
import java.io.InputStreamReader;
7
import java.net.URL;
8
import java.nio.charset.StandardCharsets;
9
import java.util.Map;
10
​
11
import javax.net.ssl.HttpsURLConnection;
12
​
13
import com.google.gson.Gson;
14
import com.google.gson.JsonObject;
15
​
16
public class LicenceVerif {
17
​
18
private final String URL = "https://groupez.dev/api/v1/licence/%s";
19
private final String licence;
20
private final String uniqueId;
21
private String status;
22
private String message;
23
private boolean isValid;
24
private boolean enableLog = false;
25
​
26
/**
27
* @param licence
28
* @param uniqueId
29
*/
30
public LicenceVerif(String licence, String uniqueId) {
31
super();
32
this.licence = licence;
33
this.uniqueId = uniqueId;
34
}
35
​
36
/**
37
* @return the enableLog
38
*/
39
public boolean isEnableLog() {
40
return enableLog;
41
}
42
​
43
/**
44
* @param enableLog
45
* the enableLog to set
46
*/
47
public void setEnableLog(boolean enableLog) {
48
this.enableLog = enableLog;
49
}
50
​
51
/**
52
* @return the uRL
53
*/
54
public String getURL() {
55
return URL;
56
}
57
​
58
/**
59
* @return the licence
60
*/
61
public String getLicence() {
62
return licence;
63
}
64
​
65
/**
66
* @return the status
67
*/
68
public String getStatus() {
69
return status;
70
}
71
​
72
/**
73
* @return the message
74
*/
75
public String getMessage() {
76
return message;
77
}
78
​
79
/**
80
* @return the isValid
81
*/
82
public boolean isValid() {
83
return isValid;
84
}
85
​
86
/**
87
* Check
88
*/
89
public void check() {
90
try {
91
JsonObject jsonObject = new JsonObject();
92
jsonObject.addProperty("unique_id", this.uniqueId);
93
Map<String, String> response = this.sendData(jsonObject, this.licence);
94
if (response.containsKey("status")) {
95
this.status = response.get("status");
96
this.message = response.get("message");
97
if (status.equals("success"))
98
this.isValid = true;
99
} else
100
this.isValid = false;
101
​
102
} catch (Exception e) {
103
if (this.enableLog)
104
e.printStackTrace();
105
this.isValid = false;
106
}
107
}
108
​
109
/**
110
*
111
* @param data
112
* @param licence
113
* @return
114
* @throws Exception
115
*/
116
@SuppressWarnings("unchecked")
117
private Map<String, String> sendData(JsonObject data, String licence) throws Exception {
118
​
119
if (data == null)
120
throw new IllegalArgumentException("Data cannot be null!");
121
​
122
URL url = new URL(String.format(URL, licence));
123
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
124
​
125
byte[] bytes = data.toString().getBytes(StandardCharsets.UTF_8);
126
int lenght = bytes.length;
127
​
128
connection.setRequestMethod("POST");
129
connection.addRequestProperty("Accept", "application/json");
130
connection.addRequestProperty("Connection", "close");
131
connection.addRequestProperty("Content-Length", String.valueOf(lenght));
132
connection.setRequestProperty("Content-Type", "application/json");
133
connection.setRequestProperty("User-Agent", "GroupeZ/1");
134
connection.setDoOutput(true);
135
DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream());
136
outputStream.write(bytes);
137
outputStream.flush();
138
outputStream.close();
139
​
140
InputStream inputStream = connection.getInputStream();
141
​
142
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
143
​
144
StringBuilder builder = new StringBuilder();
145
String line;
146
while ((line = bufferedReader.readLine()) != null)
147
builder.append(line);
148
bufferedReader.close();
149
​
150
Gson gson = new Gson();
151
return gson.fromJson(builder.toString(), Map.class);
152
}
153
​
154
/**
155
* Check async
156
*
157
* @param runnable
158
*/
159
public void asynCheck(Runnable runnable) {
160
Thread thread = new Thread(() -> {
161
this.check();
162
runnable.run();
163
});
164
thread.start();
165
}
166
​
167
}
Copied!
1
package fr.groupez.licence;
2
​
3
import java.net.UnknownHostException;
4
​
5
public class Licence {
6
​
7
public static void main(String[] args) throws UnknownHostException {
8
​
9
if (args.length != 2) {
10
System.out.println("Invalid argument: java -jar Licence.jar <licence> <unique_id>");
11
return;
12
}
13
​
14
String licence = args[0];
15
String uniqueId = args[1];
16
LicenceVerif licenceVerif = new LicenceVerif(licence, uniqueId);
17
licenceVerif.setEnableLog(true);
18
licenceVerif.asynCheck(() -> {
19
System.out.println(licenceVerif.isValid() ? "Valid" : "Invalid");
20
System.out.println(licenceVerif.getStatus());
21
System.out.println(licenceVerif.getMessage());
22
});
23
System.out.println("Start licence check with key : " + licence);
24
}
25
​
26
}
Copied!
Last modified 5mo ago
Copy link