-3
如何在android studio中實現移動充值API。我正在開發用於移動充值Android應用我有把鑰匙,但我需要知道如何實現這些API,請幫助如何實現移動充值API?
如何在android studio中實現移動充值API。我正在開發用於移動充值Android應用我有把鑰匙,但我需要知道如何實現這些API,請幫助如何實現移動充值API?
首先你需要的API 它可能看起來像這樣
www.yourmobilecarrier.com/api/recharge
此Web服務應接受POST請求。這裏充值業務必須有兩件事情, 1)充值針數 2)電話號碼 這一點,你需要通過Android的
地方剛下課的最後一個大括號之前發佈的數據下面的代碼後
class Recharge extends AsyncTask<String, Void, String> {
HttpURLConnection urlConnection;
String urlString;
@Override
protected String doInBackground(String... strings) {
urlString = "http://recharge.com/recharge";
try {
URL url = new URL(urlString);
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("POST");
urlConnection.setDoOutput(true);
String postingData = URLEncoder.encode("pin", "UTF-8") + "=" + URLEncoder.encode("123456789", "UTF-8") +
"&" + URLEncoder.encode("mobile-no", "UTF-8") + "=" + URLEncoder.encode("9845621456", "UTF-8");
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(urlConnection.getOutputStream()));
bufferedWriter.write(postingData);
bufferedWriter.flush();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
String line;
String result = null;
while ((line = bufferedReader.readLine()) != null) {
result = result + line;
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
爲了執行這個服務使用
Recharge recharge= new Recharge(MainActivity.this); //put you current class name where you are placing the code
recharge.execute();
哎,你可以提供更多的細節?充值API,您需要做的工作...... – Elyes