Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mk.plugin.napthe.util;
- import java.io.BufferedReader;
- import java.io.DataOutputStream;
- import java.io.InputStreamReader;
- import java.net.Authenticator;
- import java.net.HttpURLConnection;
- import java.net.PasswordAuthentication;
- import java.net.URL;
- import java.util.Base64;
- import com.google.gson.JsonObject;
- import mk.plugin.napthe.config.ConfigValue;
- import mk.plugin.napthe.object.Card;
- public class CardUtils {
- public static final String GatevnURL = "https://sv.gatevn.net/api/insertCardInfo";
- public static String toJson(Card card) {
- JsonObject cac = new JsonObject();
- cac.addProperty("UserTransactionID", ConfigValue.USER_TRANSACTION_ID.get());
- cac.addProperty("ProviderID", card.getCardType().getCode());
- cac.addProperty("CardSerial", card.getSeri());
- cac.addProperty("CardPin", card.getPin());
- cac.addProperty("CardUserAmount", card.getCardPrice().getValue());
- cac.addProperty("ApiKey", ConfigValue.API_KEY.get());
- return cac.toString();
- }
- public static String post(String data) {
- try {
- URL url = new URL(GatevnURL);
- Authenticator.setDefault(new Authenticator() {
- @Override
- protected PasswordAuthentication getPasswordAuthentication() {
- return new PasswordAuthentication(ConfigValue.API_USER.get(), ConfigValue.API_KEY.get().toCharArray());
- }
- });
- HttpURLConnection con = (HttpURLConnection) url.openConnection();
- con.setDoInput(true);
- con.setDoOutput(true);
- con.setInstanceFollowRedirects(true);
- con.setRequestMethod("POST");
- con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
- con.setRequestProperty("charset", "utf-8");
- con.setRequestProperty("Content-Length", Integer.toString(data.getBytes().length));
- con.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11");
- // con.setRequestProperty("Authorization", "Basic " + getAuthantication(ConfigValue.API_USER.get(), ConfigValue.API_KEY.get()));
- con.setUseCaches(false);
- con.connect();
- DataOutputStream dos = new DataOutputStream(con.getOutputStream());
- dos.write(data.getBytes());
- dos.close();
- BufferedReader reader = new BufferedReader(new InputStreamReader(con.getInputStream()));
- StringBuilder result = new StringBuilder();
- String line = null;
- while((line = reader.readLine()) != null) {
- result.append(line);
- }
- con.disconnect();
- return result.toString();
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
- public static String getAuthantication(String username, String password) {
- String auth = new String(Base64.getEncoder().encode(new String(username + ":" + password).getBytes()));
- return auth;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement