Skip to content

Instantly share code, notes, and snippets.

@endymuhardin
Created November 26, 2012 10:12
Show Gist options
  • Save endymuhardin/4147496 to your computer and use it in GitHub Desktop.
Save endymuhardin/4147496 to your computer and use it in GitHub Desktop.
Cara mengakses aplikasi ppob melalui Android
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.apache.http.client.CookieStore;
import org.apache.http.client.protocol.ClientContext;
import org.apache.http.client.method.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.NameValuePair;
import org.apache.http.HttpResponse;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import java.util.ArrayList;
public class PpobClient {
private static final URL_LOGIN = "http://aplikasi/j_spring_security_check";
private static final URL_INQUIRY = "http://aplikasi/transaksi/inquiry";
private static final URL_PAYMENT = "http://aplikasi/transaksi/payment";
private CookieStore cookieStore = new BasicCookieStore();
private HttpContext httpContext = new BasicHttpContext();
private DefaultHttpClient client = new DefaultHttpClient();
public PpobClient(){
// inisialisasi penyimpanan cookie
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
}
public void login(String username, String password){
HttpPost loginRequest = new HttpPost(URL_LOGIN);
ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("j_username", username));
postParameters.add(new BasicNameValuePair("j_password", password));
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(postParameters);
loginRequest.setEntity(formEntity);
HttpResponse hasil = client.execute(loginRequest, httpContext);
// cek hasilnya
// kalau dapat login page lagi, berarti login gagal
// kalau dapat halaman menu utama, berarti sukses
}
public void inquiry(String pelanggan){
HttpPost inquiryRequest = new HttpPost(URL_INQUIRY);
ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("idpel", pelanggan));
HttpResponse hasil = client.execute(inquiryRequest, httpContext);
// proses hasilnya
}
public void payment(String refnum){
HttpPost paymentRequest = new HttpPost(URL_INQUIRY);
ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("reference", refnum));
HttpResponse hasil = client.execute(paymentRequest, httpContext);
// proses hasilnya
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment