如何实现移动充值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? 的全部内容, 来源链接: utcz.com/qa/262622.html

回到顶部