Skip to content

Commit

Permalink
Ip地址获取接口优化
Browse files Browse the repository at this point in the history
  • Loading branch information
maning0303 committed Oct 15, 2020
1 parent bc55d80 commit 6bc9fce
Show file tree
Hide file tree
Showing 14 changed files with 236 additions and 68 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package com.maning.gankmm.bean.mob;
package com.maning.gankmm.bean;

/**
* Created by maning on 2017/5/8.
*/

public class MobItemEntity {
public class CommonItemEntity {

private String title;
private String desc;

public MobItemEntity() {
public CommonItemEntity() {
}

public MobItemEntity(String title, String desc) {
public CommonItemEntity(String title, String desc) {
this.title = title;
this.desc = desc;
}
Expand Down
100 changes: 100 additions & 0 deletions app/src/main/java/com/maning/gankmm/bean/rolltools/IpResultBean.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package com.maning.gankmm.bean.rolltools;

/**
* @author : maning
* @date : 2020-10-15
* @desc :
*/
public class IpResultBean extends RollToolsBaseBean {


/**
* data : {"ip":"119.123.72.166","province":"广东省","provinceId":440000,"city":"深圳市","cityId":440300,"isp":"电信","desc":"广东省深圳市 电信"}
*/

private DataEntity data;

public DataEntity getData() {
return data;
}

public void setData(DataEntity data) {
this.data = data;
}

public static class DataEntity {
/**
* ip : 119.123.72.166
* province : 广东省
* provinceId : 440000
* city : 深圳市
* cityId : 440300
* isp : 电信
* desc : 广东省深圳市 电信
*/

private String ip;
private String province;
private int provinceId;
private String city;
private int cityId;
private String isp;
private String desc;

public String getIp() {
return ip;
}

public void setIp(String ip) {
this.ip = ip;
}

public String getProvince() {
return province;
}

public void setProvince(String province) {
this.province = province;
}

public int getProvinceId() {
return provinceId;
}

public void setProvinceId(int provinceId) {
this.provinceId = provinceId;
}

public String getCity() {
return city;
}

public void setCity(String city) {
this.city = city;
}

public int getCityId() {
return cityId;
}

public void setCityId(int cityId) {
this.cityId = cityId;
}

public String getIsp() {
return isp;
}

public void setIsp(String isp) {
this.isp = isp;
}

public String getDesc() {
return desc;
}

public void setDesc(String desc) {
this.desc = desc;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.maning.gankmm.bean.rolltools.DictionaryResultBean;
import com.maning.gankmm.bean.rolltools.HistoryTodayBean;
import com.maning.gankmm.bean.rolltools.HolidaySingleResultBean;
import com.maning.gankmm.bean.rolltools.IpResultBean;
import com.maning.gankmm.bean.rolltools.MobileLocationResultBean;
import com.maning.gankmm.bean.rolltools.RubbishTypeResultBean;
import com.maning.gankmm.bean.rolltools.WeatherFuturedaysResultBean;
Expand Down Expand Up @@ -75,4 +76,20 @@ Call<MobileLocationResultBean> getMobileLocation(
@Query("mobile") String mobile
);

@Headers({
"app_id:" + Constants.ROLL_TOOLS_APP_ID,
"app_secret:" + Constants.ROLL_TOOLS_APP_SECRET
})
@GET("ip/self")
Call<IpResultBean> getIpLocationSelf();

@Headers({
"app_id:" + Constants.ROLL_TOOLS_APP_ID,
"app_secret:" + Constants.ROLL_TOOLS_APP_SECRET
})
@GET("ip/aim_ip")
Call<IpResultBean> getIpLocation(
@Query("ip") String ip
);

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.maning.gankmm.bean.rolltools.DictionaryResultBean;
import com.maning.gankmm.bean.rolltools.HistoryTodayBean;
import com.maning.gankmm.bean.rolltools.HolidaySingleResultBean;
import com.maning.gankmm.bean.rolltools.IpResultBean;
import com.maning.gankmm.bean.rolltools.MobileLocationResultBean;
import com.maning.gankmm.bean.rolltools.RubbishTypeResultBean;
import com.maning.gankmm.bean.rolltools.WeatherFuturedaysResultBean;
Expand Down Expand Up @@ -57,6 +58,7 @@ public static void convertDictionary(String content, CommonHttpCallback<Dictiona

/**
* 垃圾分类
*
* @param content
* @param httpCallback
*/
Expand All @@ -66,12 +68,32 @@ public static void getRubbishType(String content, CommonHttpCallback<RubbishType

/**
* 手机号码归属地查询
*
* @param phone
* @param httpCallback
*/
public static void getMobileLocation(String phone, CommonHttpCallback<MobileLocationResultBean> httpCallback) {
BuildApi.getRooltoolsAPIService().getMobileLocation(phone).enqueue(httpCallback);
}

/**
* 获取Ip地址
*
* @param httpCallback
*/
public static void getIpLocationSelf(CommonHttpCallback<IpResultBean> httpCallback) {
BuildApi.getRooltoolsAPIService().getIpLocationSelf().enqueue(httpCallback);
}

/**
* 获取Ip地址
*
* @param ip
* @param httpCallback
*/
public static void getIpLocation(String ip, CommonHttpCallback<IpResultBean> httpCallback) {
BuildApi.getRooltoolsAPIService().getIpLocation(ip).enqueue(httpCallback);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import com.maning.gankmm.R;
import com.maning.gankmm.bean.mob.MobBankCard;
import com.maning.gankmm.bean.mob.MobItemEntity;
import com.maning.gankmm.bean.CommonItemEntity;
import com.maning.gankmm.http.mob.MobApi;
import com.maning.gankmm.http.callback.MyCallBack;
import com.maning.gankmm.skin.SkinManager;
Expand Down Expand Up @@ -119,11 +119,11 @@ public void onFail(int what, String result) {
private void initAdapter(MobBankCard result) {

HashMap<String, Object> mDatas = new HashMap<>();
mDatas.put("0", new MobItemEntity("所属银行:", result.getBank()));
mDatas.put("1", new MobItemEntity("卡名:", result.getCardName()));
mDatas.put("2", new MobItemEntity("卡片类型:", result.getCardType()));
mDatas.put("3", new MobItemEntity("卡号长度:", String.valueOf(result.getCardNumber())));
mDatas.put("4", new MobItemEntity("bin码:", result.getBin()));
mDatas.put("0", new CommonItemEntity("所属银行:", result.getBank()));
mDatas.put("1", new CommonItemEntity("卡名:", result.getCardName()));
mDatas.put("2", new CommonItemEntity("卡片类型:", result.getCardType()));
mDatas.put("3", new CommonItemEntity("卡号长度:", String.valueOf(result.getCardNumber())));
mDatas.put("4", new CommonItemEntity("bin码:", result.getBin()));

if (recycleMobQueryAdapter == null) {
recycleMobQueryAdapter = new RecycleMobQueryAdapter(this, mDatas);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import android.view.MenuItem;

import com.maning.gankmm.R;
import com.maning.gankmm.bean.mob.MobItemEntity;
import com.maning.gankmm.bean.CommonItemEntity;
import com.maning.gankmm.bean.rolltools.DictionaryResultBean;
import com.maning.gankmm.http.callback.CommonHttpCallback;
import com.maning.gankmm.http.rolltools.RolltoolsApi;
Expand Down Expand Up @@ -110,12 +110,12 @@ public void onFail(int code, String message) {

private void initAdapter(DictionaryResultBean.DataEntity dataEntity) {
HashMap<String, Object> mDatas = new HashMap<>();
mDatas.put("0", new MobItemEntity("原内容:", dataEntity.getWord()));
mDatas.put("1", new MobItemEntity("繁体:", dataEntity.getTraditional()));
mDatas.put("2", new MobItemEntity("拼音:", dataEntity.getPinyin()));
mDatas.put("3", new MobItemEntity("偏旁部首:", dataEntity.getRadicals()));
mDatas.put("4", new MobItemEntity("汉字释义:", dataEntity.getExplanation()));
mDatas.put("5", new MobItemEntity("汉字笔画数:", String.valueOf(dataEntity.getStrokes())));
mDatas.put("0", new CommonItemEntity("原内容:", dataEntity.getWord()));
mDatas.put("1", new CommonItemEntity("繁体:", dataEntity.getTraditional()));
mDatas.put("2", new CommonItemEntity("拼音:", dataEntity.getPinyin()));
mDatas.put("3", new CommonItemEntity("偏旁部首:", dataEntity.getRadicals()));
mDatas.put("4", new CommonItemEntity("汉字释义:", dataEntity.getExplanation()));
mDatas.put("5", new CommonItemEntity("汉字笔画数:", String.valueOf(dataEntity.getStrokes())));

if (recycleMobQueryAdapter == null) {
recycleMobQueryAdapter = new RecycleMobQueryAdapter(this, mDatas);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import com.maning.gankmm.R;
import com.maning.gankmm.bean.mob.MobIdCardEntity;
import com.maning.gankmm.bean.mob.MobItemEntity;
import com.maning.gankmm.bean.CommonItemEntity;
import com.maning.gankmm.http.mob.MobApi;
import com.maning.gankmm.http.callback.MyCallBack;
import com.maning.gankmm.skin.SkinManager;
Expand Down Expand Up @@ -119,9 +119,9 @@ public void onFail(int what, String result) {
private void initAdapter(MobIdCardEntity result) {

HashMap<String, Object> mDatas = new HashMap<>();
mDatas.put("0", new MobItemEntity("地区:", result.getArea()));
mDatas.put("1", new MobItemEntity("生日:", result.getBirthday()));
mDatas.put("2", new MobItemEntity("性别:", result.getSex()));
mDatas.put("0", new CommonItemEntity("地区:", result.getArea()));
mDatas.put("1", new CommonItemEntity("生日:", result.getBirthday()));
mDatas.put("2", new CommonItemEntity("性别:", result.getSex()));

if (recycleMobQueryAdapter == null) {
recycleMobQueryAdapter = new RecycleMobQueryAdapter(this, mDatas);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.MenuItem;
import android.widget.Button;

import com.maning.gankmm.R;
import com.maning.gankmm.bean.CommonItemEntity;
import com.maning.gankmm.bean.mob.MobIpEntity;
import com.maning.gankmm.bean.mob.MobItemEntity;
import com.maning.gankmm.http.mob.MobApi;
import com.maning.gankmm.bean.rolltools.IpResultBean;
import com.maning.gankmm.http.callback.CommonHttpCallback;
import com.maning.gankmm.http.callback.MyCallBack;
import com.maning.gankmm.http.mob.MobApi;
import com.maning.gankmm.http.rolltools.RolltoolsApi;
import com.maning.gankmm.skin.SkinManager;
import com.maning.gankmm.ui.adapter.RecycleMobQueryAdapter;
import com.maning.gankmm.ui.base.BaseActivity;
Expand Down Expand Up @@ -78,7 +82,26 @@ public boolean onOptionsItemSelected(MenuItem item) {
}


@OnClick(R.id.btn_query)
@OnClick({R.id.btn_query_self})
public void btnQuerySelf() {
showProgressDialog("正在查询...");
RolltoolsApi.getIpLocationSelf(new CommonHttpCallback<IpResultBean>() {
@Override
public void onSuccess(IpResultBean result) {
dissmissProgressDialog();
IpResultBean.DataEntity data = result.getData();
initAdapter(data);
}

@Override
public void onFail(int code, String message) {
dissmissProgressDialog();
MySnackbar.makeSnackBarRed(toolbar, message);
}
});
}

@OnClick({R.id.btn_query})
public void btnQuery() {

KeyboardUtils.hideSoftInput(this);
Expand All @@ -90,38 +113,32 @@ public void btnQuery() {
MySnackbar.makeSnackBarRed(toolbar, "IP号码不能为空");
return;
}

showProgressDialog("正在查询...");
MobApi.queryIp(number, 0x001, new MyCallBack() {
RolltoolsApi.getIpLocation(number, new CommonHttpCallback<IpResultBean>() {
@Override
public void onSuccess(int what, Object object) {
public void onSuccess(IpResultBean result) {
dissmissProgressDialog();
if (object != null) {
MobIpEntity result = (MobIpEntity) object;
initAdapter(result);
}
IpResultBean.DataEntity data = result.getData();
initAdapter(data);
}

@Override
public void onSuccessList(int what, List results) {

}

@Override
public void onFail(int what, String result) {
public void onFail(int code, String message) {
dissmissProgressDialog();
MySnackbar.makeSnackBarRed(toolbar, result);
MySnackbar.makeSnackBarRed(toolbar, message);
}
});


}

private void initAdapter(MobIpEntity result) {
private void initAdapter(IpResultBean.DataEntity data) {

HashMap<String, Object> mDatas = new HashMap<>();
mDatas.put("0", new MobItemEntity("IP:", result.getIp()));
mDatas.put("1", new MobItemEntity("国家:", result.getCountry()));
mDatas.put("2", new MobItemEntity("城市:", result.getProvince() + " " + result.getCity()));
mDatas.put("0", new CommonItemEntity("IP:", data.getIp()));
mDatas.put("1", new CommonItemEntity("服务商名称:", data.getIsp()));
mDatas.put("2", new CommonItemEntity("IP描述:", data.getDesc()));
mDatas.put("3", new CommonItemEntity("城市:", data.getProvince() + " " + data.getCity()));

if (recycleMobQueryAdapter == null) {
recycleMobQueryAdapter = new RecycleMobQueryAdapter(this, mDatas);
Expand Down
Loading

0 comments on commit 6bc9fce

Please sign in to comment.