Skip to content

Instantly share code, notes, and snippets.

@cleopatra27
Created March 8, 2019 14:17
Show Gist options
  • Save cleopatra27/f80cfb5817ec6832c3876d73cefcde11 to your computer and use it in GitHub Desktop.
Save cleopatra27/f80cfb5817ec6832c3876d73cefcde11 to your computer and use it in GitHub Desktop.
mobilemoneyservice
public String doflwmobilemoney(String params) {
StringBuilder result = new StringBuilder();
try (CloseableHttpClient client = HttpClientBuilder.create().build()) {
HttpPost post = new HttpPost((raveConfig.SANDBOXMOBILEMONEY_CHARGE_URL));
LOG.info("doflwmobilemoney response ::: " + params);
System.out.println("params ===>" + params);
pay_load pay_load = new pay_load();
pay_load.setPBFPubKey(raveConfig.PUBLIC_KEY);
pay_load.setClient(params);
pay_load.setAlg("alg");
JSONObject requestJSON = new JSONObject();
requestJSON.put("PBFPubKey", raveConfig.PUBLIC_KEY);
requestJSON.put("client", params);
requestJSON.put("alg", raveConfig.alg);
StringEntity input = new StringEntity(requestJSON.toString());
input.setContentType("application/json");
post.setEntity(input);
HttpResponse response = client.execute(post);
LOG.info("doflwmobilemoney response code ::: " + response.getStatusLine().getStatusCode());
BufferedReader rd = new BufferedReader(
new InputStreamReader(response.getEntity().getContent()));
String line;
while ((line = rd.readLine()) != null) {
result.append(line);
}
LOG.info("doflwmobilemoney request" + result.toString());
if (!String.valueOf(response.getStatusLine().getStatusCode()).startsWith("2") && !response.getEntity().getContentType().getValue().contains("json")) {
return null;
}
if (response.getStatusLine().getStatusCode() == 500) {
return "there is an error with the data";
} else {
return result.toString();
}
} catch (UnsupportedEncodingException ex) {
LOG.error(Arrays.toString(ex.getStackTrace()));
} catch (IOException ex) {
LOG.error(Arrays.toString(ex.getStackTrace()));
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment