Business Requirements: Write an interface in the background, pass in the mobile phone number, return to the home of the mobile phone number.

There are many free api addresses on the Internet that can query the location of mobile phone number, and their functions are similar to each other. I'm calling Baidu's api here.
api address:

http://mobsec-dianhua.baidu.com/dianhua_api/open/location?tel=13216999149

Data format returned
Class Java:

package com.pinlor.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClientBuilder;
import org.springframework.stereotype.Component;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URI;

/**
 * @Auther sunjincheng
 * @Date 2019/9/11
 * Input number to inquire mobile phone ownership
 */
@Component("phoneLocation")
public class PhoneLocation {

    //Baidu interface, when used, the request parameters are added to the number of the mobile phone that needs to be queried.
    private static String url = "http://mobsec-dianhua.baidu.com/dianhua_api/open/location?tel=";
    
    public static String getPhoneLocation(String phoneNumber)throws Exception{
        if(phoneNumber == null || phoneNumber.length() < 7){
            throw new WrongPhoneException("Please enter at least 7 cell phone numbers.");
        }
        String result = "";
        BufferedReader in = null;
        //Get DefaultHttpClient request
        HttpClient client = HttpClientBuilder.create().build();
        HttpGet request = new HttpGet();
        HttpResponse response = null;
        try{
            request.setURI(new URI(url+phoneNumber));
            response = client.execute(request);
            //Get the corresponding data, convert the data from stream to String, and finally to json format
            in = new BufferedReader( new InputStreamReader(response.getEntity().getContent()));
            String line;
            while((line = in.readLine()) != null){
                result += line;
            }
            JSONObject json = JSON.parseObject(result);
            //Extract message headers
            JSONObject responseHeader = json.getJSONObject("responseHeader");
            if("200".equals(responseHeader.get("status").toString())){
                //Successful inquiry to extract city information
                JSONObject data = json.getJSONObject("response").getJSONObject(phoneNumber);
                String location = data.get("location").toString();
                return location.substring(0,location.length()-2);//The last two location s are the operators'names, which are not needed here
            }else{
                throw new WrongPhoneException("Query failed!");
            }
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }
}

Custom exception classes, nothing special, normally override Exception methods:

package com.pinlor.utils;

public class WrongPhoneException extends Exception {
    public WrongPhoneException() {
        super();
    }

    public WrongPhoneException(String message) {
        super(message);
    }

    public WrongPhoneException(String message, Throwable cause) {
        super(message, cause);
    }

    public WrongPhoneException(Throwable cause) {
        super(cause);
    }

    protected WrongPhoneException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
        super(message, cause, enableSuppression, writableStackTrace);
    }
}

test

public static void main(String[] args) {
        try{
            System.out.println(getPhoneLocation("15327592111"));
        }catch (Exception e){
            e.printStackTrace();
        }
    }

Output results: