完善查询手机号归属地代码
parent
a0db3b1249
commit
15c19e7ad7
|
@ -0,0 +1,63 @@
|
||||||
|
package com.muyu.cloud.background.domin.api;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:weiran
|
||||||
|
* @Package:com.muyu.cloud.background.domin.api
|
||||||
|
* @Project:cloud-background
|
||||||
|
* @name:MobileLocation
|
||||||
|
* @Date:2024/8/29 20:02
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class MobileLocationdomain {
|
||||||
|
private String province;
|
||||||
|
private String city;
|
||||||
|
private String areacode;
|
||||||
|
private String zip;
|
||||||
|
private String company;
|
||||||
|
|
||||||
|
public String getProvince() {
|
||||||
|
return province;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProvince(String province) {
|
||||||
|
this.province = province;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCity() {
|
||||||
|
return city;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCity(String city) {
|
||||||
|
this.city = city;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAreacode() {
|
||||||
|
return areacode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAreacode(String areacode) {
|
||||||
|
this.areacode = areacode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getZip() {
|
||||||
|
return zip;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setZip(String zip) {
|
||||||
|
this.zip = zip;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCompany() {
|
||||||
|
return company;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCompany(String company) {
|
||||||
|
this.company = company;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
package com.muyu.cloud.background.api;
|
package com.muyu.cloud.background.api;
|
||||||
|
|
||||||
|
import com.muyu.cloud.background.domin.api.MobileLocationdomain;
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
import net.sf.json.JSONObject;
|
import net.sf.json.JSONObject;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
@ -37,13 +38,13 @@ public class MobileLocation {
|
||||||
* @param mobile
|
* @param mobile
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static Result queryMobileLocation(String mobile)
|
public static MobileLocationdomain queryMobileLocation(String mobile)
|
||||||
{
|
{
|
||||||
Map<String, Object> params = new HashMap<>();//组合参数
|
Map<String, Object> params = new HashMap<>();//组合参数
|
||||||
params.put("phone", mobile);
|
params.put("phone", mobile);
|
||||||
params.put("key", API_KEY);
|
params.put("key", API_KEY);
|
||||||
String queryParams = urlencode(params);
|
String queryParams = urlencode(params);
|
||||||
|
MobileLocationdomain mobileLocationdomain=null;
|
||||||
String response = doGet(API_URL, queryParams);
|
String response = doGet(API_URL, queryParams);
|
||||||
try {
|
try {
|
||||||
JSONObject jsonObject = JSONObject.fromObject(response);
|
JSONObject jsonObject = JSONObject.fromObject(response);
|
||||||
|
@ -59,13 +60,20 @@ public class MobileLocation {
|
||||||
System.out.printf("邮编:%s%n", result.getString("zip"));
|
System.out.printf("邮编:%s%n", result.getString("zip"));
|
||||||
System.out.printf("运营商:%s%n", result.getString("company"));
|
System.out.printf("运营商:%s%n", result.getString("company"));
|
||||||
|
|
||||||
|
mobileLocationdomain = new MobileLocationdomain(
|
||||||
|
result.getString("province"),
|
||||||
|
result.getString("city"),
|
||||||
|
result.getString("areacode"),
|
||||||
|
result.getString("zip"),
|
||||||
|
result.getString("company"));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
System.out.println("调用接口失败:" + jsonObject.getString("reason"));
|
System.out.println("调用接口失败:" + jsonObject.getString("reason"));
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return null;
|
return mobileLocationdomain;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.muyu.cloud.background.controller;
|
package com.muyu.cloud.background.controller;
|
||||||
|
|
||||||
import com.muyu.cloud.background.api.MobileLocation;
|
import com.muyu.cloud.background.api.MobileLocation;
|
||||||
|
import com.muyu.cloud.background.domin.api.MobileLocationdomain;
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
@ -32,6 +33,7 @@ public class ApiController {
|
||||||
@GetMapping("/byphone/{phone}")
|
@GetMapping("/byphone/{phone}")
|
||||||
@Operation(summary = "手机号归属地",description = "查询手机号归属地")
|
@Operation(summary = "手机号归属地",description = "查询手机号归属地")
|
||||||
public Result MobileLocation(@Validated @PathVariable String phone){
|
public Result MobileLocation(@Validated @PathVariable String phone){
|
||||||
return MobileLocation.queryMobileLocation(phone);
|
MobileLocationdomain mobileLocationdomain = MobileLocation.queryMobileLocation(phone);
|
||||||
|
return Result.success(mobileLocationdomain);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue