百度apistore归属地查询如何使用?哪位知道(第一次用API)?

这个该怎么填?

img


import com.baidubce.http.ApiExplorerClient;
import com.baidubce.http.AppSigner;
import com.baidubce.http.HttpMethodName;
import com.baidubce.model.ApiExplorerRequest;
import com.baidubce.model.ApiExplorerResponse;

// 号码归属查询api Java示例代码
public class RequestDemo {
    public static void main(String[] args) {
        String path = "http://gsd.api.bdymkt.com/sms";
        ApiExplorerRequest request = new ApiExplorerRequest(HttpMethodName.POST, path);
        request.setCredentials("您的 access key", "您的 secret key");

        request.addHeaderParameter("Content-Type", "application/json;charset=UTF-8");
        
        request.addQueryParameter("mobile", "");
        
        String requestExample = "\r\nimport com.baidubce.http.ApiExplorerClient;\r\nimport com.baidubce.http.AppSigner;\r\nimport com.baidubce.http.HttpMethodName;\r\nimport com.baidubce.model.ApiExplorerRequest;\r\nimport com.baidubce.model.ApiExplorerResponse;\r\n\r\n\/\/ 号码归属查询api Java示例代码\r\npublic class RequestDemo {\r\n    public static void main(String[] args) {\r\n        String path = \"http:\/\/gsd.api.bdymkt.comhttp:\/\/gwgp-g8eennmvmcz.n.bdcloudapi.com\/sms\";\r\n        ApiExplorerRequest request = new ApiExplorerRequest(HttpMethodName.POST, path);\r\n        request.setCredentials(\"您的 access key\", \"您的 secret key\");\r\n\r\n        request.addHeaderParameter(\"Content-Type\", \"application\/json;charset=UTF-8\");\r\n        \r\n        request.addQueryParameter(\"mobile\", \"\");\r\n        \r\n        \r\n\r\n        ApiExplorerClient client = new ApiExplorerClient(new AppSigner());\r\n\r\n        try {\r\n          ApiExplorerResponse response = client.sendRequest(request);\r\n          \/\/ 返回结果格式为Json字符串\r\n          System.out.println(response.getResult());\r\n        } catch (Exception e) {\r\n          e.printStackTrace();\r\n        }\r\n    }\r\n}";
        request.setJsonBody(requestExample);
        

        ApiExplorerClient client = new ApiExplorerClient(new AppSigner());

        try {
          ApiExplorerResponse response = client.sendRequest(request);
          // 返回结果格式为Json字符串
          System.out.println(response.getResult());
        } catch (Exception e) {
          e.printStackTrace();
        }
    }
}

  • 以下回答由chatgpt基于相关博客总结生成:

    回答:

    很高兴你想要使用百度 API Store 提供的归属地查询 API。根据官方文档,该 API 的请求参数只有一个:需要查询的手机号码。请求方式为 GET 请求,请求 URL 为 http://mobsec-dianhua.baidu.com/dianhua_api/open/location?tel=手机号码。其中,手机号码需要替换为你需要查询的具体手机号码。例如,查询 13888888888 的归属地信息,请求 URL 为 http://mobsec-dianhua.baidu.com/dianhua_api/open/location?tel=13888888888。

    因此,你可以按照如下步骤使用该 API:

    1. 将需要查询的手机号码放入请求 URL 中,形成具体的请求地址。

    2. 发送 GET 请求,获取到响应结果。

    3. 解析响应结果,提取出归属地信息。

    具体的代码实现可以参考如下示例:

    var phone = "13888888888"; // 需要查询的手机号码
    var url = "http://mobsec-dianhua.baidu.com/dianhua_api/open/location?tel=" + phone; // 请求地址
    var xhr = new XMLHttpRequest(); // 创建 XMLHttpRequest 对象
    xhr.onreadystatechange = function() {
      if (xhr.readyState == 4 && xhr.status == 200) {
        var response = JSON.parse(xhr.responseText); // 将响应结果转换为 JSON 对象
        var location = response.response.location; // 提取出归属地信息
        console.log(location); // 输出归属地信息
      }
    };
    xhr.open("GET", url, true); // 发送 GET 请求
    xhr.send();
    

    需要注意的是,该 API 的使用需要先注册百度 API Store 的开发者账号,并创建应用,获取到 API Key 才能使用。因此,在实际应用中需要先进行相关的设置和认证,才能正常使用该 API。

红色星号那个手机号(mobile)填上手机号就可以,header之类的的按api文档的说明填