[23:26:09 WARN]: java.io.IOException: Server returned HTTP response code: 500 for URL: https://mobile-api-gateway.truemoney.com/mobile-api-gateway/api/v1/topup/mobile/1544113569/1d28b0f7-dd74-48b2-beca-70b666375c80/cashcard/12345678901234
[23:26:09 WARN]: at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
[23:26:09 WARN]: at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
[23:26:09 WARN]: at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)
[23:26:09 WARN]: at com.mcjust.TrueWallet.EwmAPIRequest.get(EwmAPIRequest.java:18)
[23:26:09 WARN]: at com.mcjust.TrueWallet.TrueWalletAPI.Topup(TrueWalletAPI.java:82)
EwmAPIRequest.java
Code (Java)
package com.mcjust.TrueWallet;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import javax.net.ssl.HttpsURLConnection;
public class EwmAPIRequest {
public static String get(String url) throws IOException {
HttpsURLConnection conn = (HttpsURLConnection) new URL(url).openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Host", "mobile-api-gateway.truemoney.com");
conn.setDoOutput(true);
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8));
StringBuilder sb = new StringBuilder();
while (true) {
String line = in.readLine();
if (line == null) {
return sb.toString();
}
sb.append(line);
}
}
}
Code (Java)
package com.mcjust.TrueWallet;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.security.NoSuchAlgorithmException;
import java.time.Instant;
import java.util.Calendar;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import javax.net.ssl.HttpsURLConnection;
import com.mcjust.TrueWallet.JSON.JSONObject;
public class TrueWalletAPI {
long epoch = System.currentTimeMillis()/1000;
public String GetToken(String username, String password) throws IOException {
String passhash = null;
try {
passhash = Sha1.hash(new StringBuilder(String.valueOf(username)).append(password).toString());
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
Map<String, String> params = new LinkedHashMap<String, String>();
JSONObject data = new JSONObject();
data.put("username", (Object) username);
data.put("password", (Object) passhash.toString());
data.put("type", (Object) "email");
StringBuilder postData = new StringBuilder();
for (Entry<?, ?> param : params.entrySet()) {
if (postData.length() != 0) {
postData.append('&');
}
postData.append(URLEncoder.encode((String) param.getKey(), "UTF-8"));
postData.append('=');
postData.append(URLEncoder.encode(String.valueOf(param.getValue()), "UTF-8"));
}
HttpsURLConnection conn = (HttpsURLConnection) new URL(APIURL.api_host + APIURL.api_endpoint_signin).openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Host", "mobile-api-gateway.truemoney.com");
conn.setRequestProperty("X-Requested-With", "Curl");
conn.setRequestProperty("Content-Type", "application/json");
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data.toString());
wr.flush();
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8));
StringBuilder sb = new StringBuilder();
while (true) {
String line = in.readLine();
if (line == null) {
in.close();
wr.close();
return new JSONObject(sb.toString()).getJSONObject("data").getString("accessToken");
}
sb.append(line);
}
}
public String GetProfile(String token) throws IOException {
return EwmAPIRequest.get(APIURL.api_host + APIURL.api_endpoint_profile + token);
}
public String GetTransaction(String token, String start, String end, int limit) throws IOException {
return EwmAPIRequest.get(APIURL.api_host + APIURL.api_endpoint_gettran + token + "/?startDate=" + start + "&endDate=" + end + "&limit=" + 50 + "&page=1&type=&action=");
}
public String GetReport(String token, String id) throws IOException {
return EwmAPIRequest.get(APIURL.api_host + APIURL.api_endpoint_getreport + id + "/detail/" + token);
}
public String Topup(String token, String cashcard) throws IOException {
return EwmAPIRequest.get(APIURL.api_host + APIURL.api_endpoint_topup + Instant.now().getEpochSecond() + "/" + token + "/cashcard/" + cashcard);
}
/*public static String getTime() {
Calendar cal = Calendar.getInstance();
int hour = cal.get(Calendar.HOUR_OF_DAY);
int min = cal.get(Calendar.MINUTE);
int sec = cal.get(Calendar.SECOND);
return hour + ":" + min + ":" + sec;
}*/
}