Peach VPN v4.0版本的 MD5 值为:44c7a87caba90fec9b7945dd44651111
以下内容为反编译后的 IpApiCaller.java 源代码,内容仅作参考
package com.peacholo.peach.Api;
import android.content.Context;
import com.android.volley.DefaultRetryPolicy;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.peacholo.peach.Helper.SharedPreferencesHelper;
import com.peacholo.peach.Model.NetworkDetails;
import java.util.ArrayList;
import java.util.Iterator;
import org.json.JSONObject;
public class IpApiCaller {
private static final String KEY_NETWORK_DETAILS_URLS = "KEY_NETWORK_DETAILS_URLS";
private static final String SHP_NAME = "IpApiCaller";
private ArrayList<String> apiUrls;
private int completedCalls;
private OnJobResultListener listener;
private RequestQueue requestQueue;
private int timeout;
public interface OnJobResultListener {
void onJobDone(NetworkDetails networkDetails);
void onJobFailed();
}
public IpApiCaller(Context context, int i, OnJobResultListener onJobResultListener) {
this.apiUrls = getNetworkDetailsUrls(context);
this.listener = onJobResultListener;
this.timeout = i;
this.requestQueue = Volley.newRequestQueue(context);
}
static int access$308(IpApiCaller ipApiCaller) {
int i = ipApiCaller.completedCalls;
ipApiCaller.completedCalls = i + 1;
return i;
}
private void callApi(String str) {
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(0, str, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject jSONObject) {
IpApiCaller.this.listener.onJobDone(IpApiCaller.this.parseResult(jSONObject));
IpApiCaller.this.requestQueue.cancelAll(new RequestQueue.RequestFilter() {
@Override
public boolean apply(Request<?> request) {
return true;
}
});
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
volleyError.printStackTrace();
IpApiCaller.access$308(IpApiCaller.this);
if (IpApiCaller.this.completedCalls == IpApiCaller.this.apiUrls.size()) {
IpApiCaller.this.listener.onJobFailed();
}
}
});
jsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy(this.timeout, 0, 1.0f));
this.requestQueue.add(jsonObjectRequest);
}
public static ArrayList<String> getNetworkDetailsUrls(Context context) {
String string = new SharedPreferencesHelper(context, SHP_NAME).getString(KEY_NETWORK_DETAILS_URLS);
if (string != null && !string.isEmpty()) {
return (ArrayList) new Gson().fromJson(string, new TypeToken<ArrayList<String>>() {
}.getType());
}
ArrayList<String> arrayList = new ArrayList<>();
arrayList.add("http://ip-api.com/json");
arrayList.add("https://pro.ip-api.com/json/?key=ZKVwIrnJ8rQLxW2");
arrayList.add("http://ip.ippooler.com:8080/home/GetInfo");
arrayList.add("http://ip.ipchugh.com:8080/home/GetInfo");
return arrayList;
}
public NetworkDetails parseResult(JSONObject jSONObject) {
return (NetworkDetails) new Gson().fromJson(jSONObject.toString(), NetworkDetails.class);
}
public static void setNetworkDetailsUrls(Context context, ArrayList<String> arrayList) {
SharedPreferencesHelper sharedPreferencesHelper = new SharedPreferencesHelper(context, SHP_NAME);
if (arrayList != null) {
sharedPreferencesHelper.putString(KEY_NETWORK_DETAILS_URLS, new Gson().toJson(arrayList));
}
}
public void start() {
this.completedCalls = 0;
Iterator<String> it = this.apiUrls.iterator();
while (it.hasNext()) {
callApi(it.next());
}
}
}